Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1930 lines
43 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /*++
  4. Copyright (c) 1990 Microsoft Corporation
  5. Module Name:
  6. vdm.c
  7. Abstract:
  8. Routines to handle VDM config files
  9. Detect Routines:
  10. ----------------
  11. 1. GetDosPathVar: This finds out the value of the DOS Path variable
  12. 2. GetWindowsPath: THis finds out the directory where windows in installed
  13. on the current system
  14. 3. GetInstalledOSNames: Finds out all the OSs installed on current system.
  15. Install Routines Workers:
  16. -------------------------
  17. 1. VdmFixupWorker: This forms the NT VDM configuration files from DOS
  18. configuration files and NT VDM template config files.
  19. 2. MigrateWinIniWorker: This migrates windows ini configuration from
  20. win.ini files. BUGBUG**REMOVED
  21. General Subroutines:
  22. --------------------
  23. 1. FFileExist: Whether a file exists or not.
  24. 2. FileSize: The size of a file.
  25. Author:
  26. Sunil Pai (sunilp) Mar 31, 1992
  27. --*/
  28. #define WIN_COM "WIN.COM"
  29. #define INI ".INI"
  30. #define TMP ".TMP"
  31. #define CONFIG_SYS "C:\\CONFIG.SYS"
  32. #define BATCH_BAT "C:\\AUTOEXEC.BAT"
  33. #define CONFIG_NT "\\CONFIG.NT"
  34. #define BATCH_NT "\\AUTOEXEC.NT"
  35. #define CONFIG_TMP "\\CONFIG.TMP"
  36. #define BATCH_TMP "\\AUTOEXEC.TMP"
  37. #define IO_SYS "C:\\IO.SYS"
  38. #define MSDOS_SYS "C:\\MSDOS.SYS"
  39. #define IBMBIO_COM "C:\\IBMBIO.COM"
  40. #define IBMDOS_COM "C:\\IBMDOS.COM"
  41. #define OS2LDR "C:\\OS2LDR"
  42. #define STARTUPCMD "C:\\STARTUP.CMD"
  43. #define DOS "DOS"
  44. #define OS2 "OS2"
  45. //
  46. // Local prototypes
  47. //
  48. BOOL FilterDosConfigFile(LPSTR szSrc, LPSTR szDst, LPSTR szTemplate);
  49. BOOL DosConfigFilter(IN OUT TEXTFILE *SrcText, IN OUT FILE *f, OUT RGSZ *rgszFound);
  50. DWORD FileSize(SZ szFile);
  51. BOOL AppendSzToFile( SZ szFileName, SZ szAddOnSz );
  52. SZ SzGetDosPathVar(DWORD MaxLength);
  53. BOOL GetPathVarFromLine( SZ, SZ, DWORD );
  54. BOOL CheckDosConfigModified( IN LPSTR szConfig);
  55. #if 0
  56. BOOL FilterDosBatchFile(LPSTR szSrc, LPSTR szDst, LPSTR szTemplate);
  57. BOOL DosBatchFilter( TEXTFILE*, FILE* );
  58. BOOL FixConfigFileMacroChar(SZ szConfigFile, CHAR cReplaceChar, SZ szSystemDir);
  59. BOOL FFindAndCopyIniFiles( SZ szSrcDir, SZ szDstDir );
  60. BOOL FMigrateStandardIniData( SZ szWindowsDir );
  61. BOOL FMigrateWinIniAppSections( SZ szWindowsDir );
  62. SZ SzMapStandardIni( SZ szIniFile );
  63. VOID CleanupIniFiles( SZ szWindowsDir );
  64. BOOL FIsStandardWinIniSection( SZ szSection );
  65. #endif
  66. // ***************************************************************************
  67. //
  68. // DOS VDM FIXUP MAIN ROUTINE
  69. //
  70. // ***************************************************************************
  71. BOOL
  72. VdmFixupWorker(
  73. LPSTR szAddOnConfig,
  74. LPSTR szAddOnBatch
  75. )
  76. {
  77. CHAR szConfigVDM[MAX_PATH], szBatchVDM[MAX_PATH];
  78. CHAR szConfigTmp[MAX_PATH], szBatchTmp[MAX_PATH];
  79. SZ szConfigDOS, szBatchDOS;
  80. CHAR szSystemDir[ MAX_PATH ];
  81. DWORD dwDosConfigAttr = FILE_ATTRIBUTE_NORMAL;
  82. DWORD dwDosBatchAttr = FILE_ATTRIBUTE_NORMAL;
  83. DWORD dw;
  84. BOOL bStatus = TRUE;
  85. //
  86. // A. Determine names to use: no renaming any more. Config.sys and
  87. // autoexec.bat on root of C drive are the files to use for DOS,
  88. // config.nt and autoexec.nt in the system directory are the files
  89. // to use for nt. the template config.nt and autoexec.nt are
  90. // still copied into the root of the C drive for reference.
  91. //
  92. GetSystemDirectory( szSystemDir, MAX_PATH );
  93. szConfigDOS = CONFIG_SYS;
  94. szBatchDOS = BATCH_BAT;
  95. lstrcpy( szConfigVDM, szSystemDir );
  96. lstrcat( szConfigVDM, CONFIG_NT );
  97. lstrcpy( szBatchVDM, szSystemDir );
  98. lstrcat( szBatchVDM, BATCH_NT );
  99. lstrcpy( szConfigTmp, szSystemDir );
  100. lstrcat( szConfigTmp, CONFIG_TMP );
  101. lstrcpy( szBatchTmp, szSystemDir );
  102. lstrcat( szBatchTmp, BATCH_TMP );
  103. //
  104. // Verify that the template files exist, else
  105. //
  106. if ( !(FFileExist( szConfigTmp ) && FFileExist( szBatchTmp )) ) {
  107. SetErrorText(IDS_ERROR_OPENFAIL);
  108. return( fFalse );
  109. }
  110. else {
  111. SetFileAttributes ( szConfigTmp, FILE_ATTRIBUTE_NORMAL );
  112. SetFileAttributes ( szBatchTmp, FILE_ATTRIBUTE_NORMAL );
  113. }
  114. //
  115. // Fix the attributes of the DOS CONFIG FILES so that we can look at
  116. // them henceforth
  117. //
  118. if ( FFileExist(szConfigDOS) ) {
  119. if ( (dw = GetFileAttributes( szConfigDOS )) != 0xFFFFFFFF) {
  120. dwDosConfigAttr = dw;
  121. }
  122. SetFileAttributes( szConfigDOS, FILE_ATTRIBUTE_NORMAL );
  123. }
  124. if ( FFileExist(szBatchDOS) ) {
  125. if ( (dw = GetFileAttributes( szBatchDOS )) != 0xFFFFFFFF) {
  126. dwDosBatchAttr = dw;
  127. }
  128. SetFileAttributes( szBatchDOS, FILE_ATTRIBUTE_NORMAL );
  129. }
  130. //
  131. // Delete the existing config files for the vdm - no upgrade supported
  132. // at this moment.
  133. //
  134. if ( FFileExist( szConfigVDM ) ) {
  135. SetFileAttributes ( szConfigVDM, FILE_ATTRIBUTE_NORMAL );
  136. DeleteFile( szConfigVDM );
  137. }
  138. if ( FFileExist( szBatchVDM ) ) {
  139. SetFileAttributes ( szBatchVDM, FILE_ATTRIBUTE_NORMAL );
  140. DeleteFile( szBatchVDM );
  141. }
  142. //
  143. // Check if configuration information exists, else just rename
  144. // the default temporary configuration files to the final names.
  145. //
  146. if ((!FFileExist(szConfigDOS)) ||
  147. (!CheckConfigTypeWorker(szConfigDOS))
  148. ) {
  149. if( !( MoveFile( szConfigTmp, szConfigVDM ) &&
  150. MoveFile( szBatchTmp, szBatchVDM ))) {
  151. SetErrorText(IDS_ERROR_WRITE);
  152. bStatus = fFalse;
  153. goto cleanup;
  154. }
  155. }
  156. else {
  157. if( !FilterDosConfigFile(szConfigDOS, szConfigVDM, szConfigTmp) ) {
  158. bStatus = fFalse;
  159. goto cleanup;
  160. }
  161. //
  162. // Nothing is being migrated from the DOS batch file, so we
  163. // can just rename the temporary file to the permanent one
  164. //
  165. if( !MoveFile( szBatchTmp, szBatchVDM ) ) {
  166. SetErrorText(IDS_ERROR_WRITE);
  167. bStatus = fFalse;
  168. goto cleanup;
  169. }
  170. }
  171. //
  172. // Append the NT Signature blocks onto the existing config files. If
  173. // files don't exist then create them
  174. //
  175. if(!CheckDosConfigModified(szConfigDOS) ) {
  176. if( !AppendSzToFile( szConfigDOS, szAddOnConfig ) ) {
  177. //
  178. // Silently fail if unable to append the signature.
  179. // Failure will occur if c: is not formatted.
  180. //
  181. // bStatus = fFalse;
  182. goto cleanup;
  183. }
  184. }
  185. if(!CheckDosConfigModified(szBatchDOS) ) {
  186. if( !AppendSzToFile( szBatchDOS, szAddOnBatch ) ) {
  187. //
  188. // Silently fail if unable to append the signature.
  189. // Failure will occur if c: is not formatted.
  190. //
  191. // bStatus = fFalse;
  192. goto cleanup;
  193. }
  194. }
  195. cleanup:
  196. //
  197. // If autoexec.nt and config.nt files not found, try creating them from
  198. // the tmp files if possible
  199. //
  200. if( !FFileExist( szConfigVDM ) ) {
  201. MoveFile( szConfigTmp, szConfigVDM );
  202. }
  203. if( !FFileExist( szBatchVDM ) ) {
  204. MoveFile( szBatchTmp, szBatchVDM );
  205. }
  206. //
  207. // Remove the temporary config files if they exist.
  208. //
  209. DeleteFile( szConfigTmp );
  210. DeleteFile( szBatchTmp );
  211. //
  212. // reset the attributs on the DOS config files, if they exist
  213. //
  214. if ( FFileExist( szConfigDOS ) ) {
  215. SetFileAttributes( szConfigDOS, dwDosConfigAttr );
  216. }
  217. if ( FFileExist( szBatchDOS ) ) {
  218. SetFileAttributes( szBatchDOS, dwDosBatchAttr );
  219. }
  220. #if 0
  221. //
  222. // If the NT config files have been created, set the attributes of these
  223. // to system and readonly
  224. //
  225. if( FFileExist( szConfigVDM ) ) {
  226. SetFileAttributes(
  227. szConfigVDM,
  228. FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY
  229. );
  230. }
  231. if( FFileExist( szBatchVDM ) ) {
  232. SetFileAttributes(
  233. szBatchVDM,
  234. FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY
  235. );
  236. }
  237. #endif
  238. return( bStatus );
  239. }
  240. // ***************************************************************************
  241. //
  242. // DOS CONFIG.SYS ROUTINES
  243. //
  244. // ***************************************************************************
  245. //
  246. // copy a DOS config file REMing out any line that is not a
  247. // SET or a PATH command
  248. //
  249. // szSrc: Source batch file (DOS c:\autoexec.bat )
  250. // szDst: Destination batch file (NT VDM c:\autoexec.nt )
  251. BOOL
  252. FilterDosConfigFile(
  253. LPSTR szSrc,
  254. LPSTR szDst,
  255. LPSTR szTemplate
  256. )
  257. {
  258. TEXTFILE SrcText, TemplateText;
  259. FILE* f;
  260. size_t Idx;
  261. RGSZ rgszFound = NULL;
  262. BOOL bStatus = TRUE;
  263. SZ sz, szLine;
  264. CHAR Buffer[ MAX_PATH ];
  265. //
  266. // If destination already exists get rid of it
  267. //
  268. if (FFileExist( szDst )) {
  269. bStatus = SetFileAttributes ( szDst, FILE_ATTRIBUTE_NORMAL );
  270. if (bStatus) {
  271. bStatus = DeleteFile( szDst );
  272. }
  273. }
  274. if (!bStatus) {
  275. SetErrorText(IDS_ERROR_WRITE);
  276. return (fFalse);
  277. }
  278. //
  279. // Open destination file for writing.
  280. //
  281. if ( !(f = fopen( szDst, "w" )) ) {
  282. SetErrorText(IDS_ERROR_WRITE);
  283. return( FALSE );
  284. }
  285. //
  286. // Open source file and filter it
  287. //
  288. if ( FFileExist( szSrc ) &&
  289. TextFileOpen( szSrc, &SrcText ) ) {
  290. bStatus = DosConfigFilter( &SrcText, f, &rgszFound );
  291. TextFileClose( &SrcText );
  292. }
  293. if( !bStatus ) {
  294. goto err;
  295. }
  296. //
  297. // Now add on the default config file from the template file
  298. //
  299. if ( !TextFileOpen( szTemplate, &TemplateText ) ) {
  300. bStatus = fFalse;
  301. SetErrorText(IDS_ERROR_OPENFAIL);
  302. goto err;
  303. }
  304. while ( TextFileReadLine( &TemplateText ) ) {
  305. BOOL fFound = FALSE;
  306. szLine = TextFileGetLine( &TemplateText );
  307. sz = TextFileSkipBlanks( szLine );
  308. //
  309. // If blank line, ignore
  310. //
  311. if ( sz && *sz != '\0' && rgszFound ) {
  312. Idx = strcspn( sz, " \t=" );
  313. if ( Idx <= strlen(sz) ) {
  314. PSZ psz;
  315. memcpy( Buffer, sz, Idx );
  316. Buffer[Idx] = '\0';
  317. //
  318. // If one of the entries we have found from a dos config file
  319. // set fFound to true so that we don't copy this file
  320. //
  321. psz = rgszFound;
  322. while ( *psz ) {
  323. if ( !lstrcmpi( Buffer, *psz ) ) {
  324. fFound = fTrue;
  325. break;
  326. }
  327. psz++;
  328. }
  329. }
  330. }
  331. if( !fFound ) {
  332. fprintf( f, "%s\n", szLine );
  333. }
  334. }
  335. TextFileClose( &TemplateText );
  336. bStatus = fTrue;
  337. err:
  338. fclose( f );
  339. if( rgszFound ) {
  340. RgszFree( rgszFound );
  341. }
  342. return(bStatus);
  343. }
  344. BOOL
  345. DosConfigFilter(
  346. IN OUT TEXTFILE * SrcText,
  347. IN OUT FILE* f,
  348. OUT RGSZ* rgszFound
  349. )
  350. {
  351. SZ szLine;
  352. SZ sz;
  353. CHAR Buffer[ MAX_PATH ];
  354. size_t Idx;
  355. int i;
  356. RGSZ rgsz;
  357. #define NUM_RESPECTED_ENTRIES 4
  358. CHAR *ConfEntry[NUM_RESPECTED_ENTRIES] = {
  359. "BREAK", "FCBS",
  360. "FILES", "LASTDRIVE"
  361. };
  362. BOOL ConfEntryFound[NUM_RESPECTED_ENTRIES] = {
  363. FALSE,FALSE,FALSE,FALSE
  364. };
  365. if( !(rgsz = RgszAlloc(1)) ) {
  366. SetErrorText(IDS_ERROR_DLLOOM);
  367. return( FALSE );
  368. }
  369. while ( TextFileReadLine( SrcText ) ) {
  370. szLine = TextFileGetLine( SrcText );
  371. sz = TextFileSkipBlanks( szLine );
  372. //
  373. // If blank line, ignore
  374. //
  375. if ( !sz || *sz == '\0' ) {
  376. continue;
  377. }
  378. Idx = strcspn( sz, " \t=" );
  379. if ( Idx <= strlen(sz) ) {
  380. memcpy( Buffer, sz, Idx );
  381. Buffer[Idx] = '\0';
  382. //
  383. // If one of the entries we respect, copy the line out verbatim
  384. //
  385. for (i = 0; i<NUM_RESPECTED_ENTRIES; i++) {
  386. if(!ConfEntryFound[i] && !lstrcmpi( Buffer, ConfEntry[i] ) ) {
  387. ConfEntryFound[i] = TRUE;
  388. if( !RgszAdd( &rgsz, SzDup(Buffer) ) ) {
  389. SetErrorText(IDS_ERROR_DLLOOM);
  390. return( FALSE );
  391. }
  392. fprintf( f, "%s\n", szLine );
  393. break;
  394. }
  395. }
  396. }
  397. }
  398. *rgszFound = rgsz;
  399. return fTrue;
  400. }
  401. // ***************************************************************************
  402. //
  403. // DOS/OS2 DETECT and WORKER ROUTINES
  404. //
  405. // ***************************************************************************
  406. /*
  407. list of installed OS names (DOS / OS2)
  408. */
  409. CB
  410. GetInstalledOSNames(
  411. IN RGSZ Args,
  412. IN USHORT cArgs,
  413. OUT SZ ReturnBuffer,
  414. IN CB cbReturnBuffer
  415. )
  416. {
  417. #define TEMP_INSTALLEDOSNAMES "{}"
  418. RGSZ rgsz;
  419. SZ sz;
  420. CB cbRet;
  421. Unused(Args);
  422. Unused(cArgs);
  423. Unused(cbReturnBuffer);
  424. rgsz = RgszAlloc(1);
  425. //
  426. // Check for DOS first
  427. //
  428. if ( FFileExist( CONFIG_SYS ) ) {
  429. //
  430. // Look for Kernel and IO files to see if DOS installed
  431. //
  432. if ( (FFileExist(MSDOS_SYS) && FFileExist(IO_SYS)) ||
  433. (FFileExist(IBMDOS_COM) && FFileExist(IBMBIO_COM)) ) {
  434. RgszAdd ( &rgsz, SzDup( DOS ) );
  435. }
  436. //
  437. // Look at OS2LDR and STARTUP.CMD to see if OS2 installed
  438. //
  439. if ( FFileExist( OS2LDR ) && FFileExist( STARTUPCMD ) ) {
  440. RgszAdd ( &rgsz, SzDup( OS2 ) );
  441. }
  442. }
  443. sz = SzListValueFromRgsz( rgsz );
  444. if ( sz ) {
  445. lstrcpy( ReturnBuffer, sz );
  446. cbRet = lstrlen( sz ) + 1;
  447. SFree( sz );
  448. }
  449. else {
  450. lstrcpy(ReturnBuffer,TEMP_INSTALLEDOSNAMES);
  451. cbRet = lstrlen( TEMP_INSTALLEDOSNAMES ) + 1;
  452. }
  453. if ( rgsz ) {
  454. RgszFree( rgsz );
  455. }
  456. return ( cbRet );
  457. }
  458. BOOL
  459. CheckConfigTypeWorker(
  460. IN LPSTR szConfig
  461. )
  462. {
  463. TEXTFILE SrcText;
  464. SZ szLine;
  465. SZ sz;
  466. CHAR Buffer[ MAX_PATH ];
  467. size_t Idx;
  468. BOOL DosType = FALSE;
  469. INT i;
  470. CHAR *ConfEntry[] = {
  471. "DISKCACHE", "LIBPATH", "PAUSEONERROR",
  472. "RMSIZE", "RUN", "SWAPPATH",
  473. "IOPL", "MAXWAIT", "MEMMAN",
  474. "PRIORITY", "PROTSHELL", "PROTECTONLY",
  475. "THREADS", "TIMESLICE", "TRACE",
  476. "TRACEBUF", "DEVINFO", NULL
  477. };
  478. //
  479. // Open source file
  480. //
  481. if ( FFileExist( szConfig ) &&
  482. TextFileOpen( szConfig, &SrcText ) ) {
  483. DosType = TRUE;
  484. //
  485. // Process config file, line by line
  486. //
  487. while ( TextFileReadLine( &SrcText ) && DosType ) {
  488. szLine = TextFileGetLine( &SrcText );
  489. sz = TextFileSkipBlanks( szLine );
  490. //
  491. // If blank line, skip
  492. //
  493. if ( !sz || *sz == '\0' ) {
  494. continue;
  495. }
  496. //
  497. // Get first field
  498. //
  499. Idx = strcspn( sz, " \t=" );
  500. if ( Idx <= strlen(sz) ) {
  501. memcpy( Buffer, sz, Idx );
  502. Buffer[Idx] = '\0';
  503. //
  504. // Compare against list of known key words for OS2
  505. //
  506. for (i = 0; ConfEntry[i] != NULL; i++) {
  507. if ( !lstrcmpi( Buffer, ConfEntry[i] ) ) {
  508. DosType = FALSE;
  509. break;
  510. }
  511. }
  512. }
  513. }
  514. TextFileClose(&SrcText);
  515. }
  516. return( DosType );
  517. }
  518. BOOL
  519. CheckDosConfigModified(
  520. IN LPSTR szConfig
  521. )
  522. {
  523. TEXTFILE SrcText;
  524. SZ szLine;
  525. SZ sz;
  526. BOOL Modified = FALSE;
  527. #define SEARCH_STRING "REM Windows NT DOS subsystem"
  528. //
  529. // Open source file
  530. //
  531. if ( FFileExist( szConfig ) &&
  532. TextFileOpen( szConfig, &SrcText ) ) {
  533. //
  534. // Process config file, line by line
  535. //
  536. while ( TextFileReadLine( &SrcText ) ) {
  537. szLine = TextFileGetLine( &SrcText );
  538. sz = TextFileSkipBlanks( szLine );
  539. //
  540. // If blank line, skip
  541. //
  542. if ( !sz || *sz == '\0' ) {
  543. continue;
  544. }
  545. //
  546. // Search for search_string. If this is found it means that
  547. // the config file has already been modified during an
  548. // earlier installation.
  549. //
  550. if( strstr( sz, SEARCH_STRING ) ) {
  551. Modified = TRUE;
  552. break;
  553. }
  554. }
  555. TextFileClose(&SrcText);
  556. }
  557. return( Modified );
  558. }
  559. BOOL
  560. AppendSzToFile(
  561. SZ szFileName,
  562. SZ szAddOnSz
  563. )
  564. {
  565. DWORD BytesWritten;
  566. HANDLE hfile;
  567. //
  568. // Open the file
  569. //
  570. hfile = CreateFile(
  571. szFileName,
  572. GENERIC_WRITE | GENERIC_READ,
  573. FILE_SHARE_READ,
  574. NULL,
  575. OPEN_ALWAYS,
  576. FILE_ATTRIBUTE_NORMAL,
  577. NULL
  578. );
  579. if (hfile == INVALID_HANDLE_VALUE) {
  580. SetErrorText(IDS_ERROR_OPENFAIL);
  581. return FALSE;
  582. }
  583. //
  584. // Go to end of file
  585. //
  586. SetFilePointer (
  587. hfile,
  588. 0,
  589. NULL,
  590. FILE_END
  591. );
  592. //
  593. // Append string passed in at the end of the file
  594. //
  595. WriteFile (
  596. hfile,
  597. szAddOnSz,
  598. lstrlen( szAddOnSz ),
  599. &BytesWritten,
  600. NULL
  601. );
  602. CloseHandle (hfile);
  603. return TRUE;
  604. }
  605. // ***************************************************************************
  606. //
  607. // DOS AND WINDOWS PATH DETECT ROUTINES
  608. //
  609. // ***************************************************************************
  610. //
  611. // Get the PATH environment variable used in AUTOEXEC.BAT
  612. //
  613. CB
  614. GetDosPathVar(
  615. IN RGSZ Args,
  616. IN USHORT cArgs,
  617. OUT SZ ReturnBuffer,
  618. IN CB cbReturnBuffer
  619. )
  620. {
  621. #define NODOSPATH "{}"
  622. SZ sz;
  623. SZ PathVar;
  624. RGSZ rgszDosPath;
  625. BOOL fOkay = fFalse;
  626. Unused( Args );
  627. Unused( cArgs );
  628. if ( PathVar = SzGetDosPathVar(cbReturnBuffer-1) ) {
  629. if (lstrcmpi( PathVar, "" )) {
  630. if ( rgszDosPath = RgszFromPath( PathVar ) ) {
  631. sz = SzListValueFromRgsz( rgszDosPath );
  632. RgszFree( rgszDosPath );
  633. if ( sz ) {
  634. strncpy( ReturnBuffer, sz, cbReturnBuffer-1 );
  635. ReturnBuffer[cbReturnBuffer-1] = 0;
  636. SFree( sz );
  637. fOkay = fTrue;
  638. }
  639. }
  640. }
  641. SFree( PathVar );
  642. }
  643. if ( !fOkay ) {
  644. lstrcpy(ReturnBuffer, NODOSPATH);
  645. }
  646. return(lstrlen(ReturnBuffer)+1);
  647. }
  648. //
  649. // Get the PATH environment variable used in AUTOEXEC.BAT
  650. //
  651. SZ
  652. SzGetDosPathVar(
  653. IN DWORD MaxLength
  654. )
  655. {
  656. TEXTFILE AutoexecBat;
  657. SZ szPath = (SZ)NULL;
  658. SZ szConfigDOS, szBatchDOS;
  659. BOOL fOkay = fFalse;
  660. szConfigDOS = CONFIG_SYS;
  661. szBatchDOS = BATCH_BAT;
  662. if (szPath = SAlloc( MaxLength )) {
  663. *szPath = '\0';
  664. //
  665. // Open AUTOEXEC.BAT file
  666. //
  667. if ( FFileExist(szConfigDOS) &&
  668. CheckConfigTypeWorker(szConfigDOS) &&
  669. FFileExist( szBatchDOS ) &&
  670. TextFileOpen( szBatchDOS, &AutoexecBat ) ) {
  671. //
  672. // Read all lines in the file and update the PATH
  673. // environment variable
  674. //
  675. while ( TextFileReadLine( &AutoexecBat ) ) {
  676. GetPathVarFromLine( TextFileGetLine( &AutoexecBat ), szPath, MaxLength );
  677. }
  678. TextFileClose( &AutoexecBat );
  679. }
  680. }
  681. return szPath;
  682. }
  683. //
  684. // Parse a line and update the PATH variable
  685. //
  686. BOOL
  687. GetPathVarFromLine(
  688. IN SZ szLine,
  689. OUT SZ szPath,
  690. IN DWORD MaxLength
  691. )
  692. {
  693. #define PATH "PATH"
  694. PCHAR PrevPath = NULL;
  695. CHAR Buffer[ MAX_PATH ];
  696. size_t Idx;
  697. BOOL fSet = fFalse;
  698. SZ pBegin, pEnd, pLast;
  699. DWORD PrevPathLen,BeginLen;
  700. //
  701. // Skip blanks. return if blank line
  702. //
  703. szLine = TextFileSkipBlanks( szLine );
  704. if( !szLine || *szLine == '\0') {
  705. return( fFalse );
  706. }
  707. //
  708. // If "no echo" command, skip the '@'
  709. //
  710. if ( *szLine == '@' ) {
  711. szLine++;
  712. }
  713. Idx = strcspn( szLine, " \t=" );
  714. if ( Idx < strlen(szLine) ) {
  715. //
  716. // If this is a SET command, skip over the SET and set the
  717. // fSet flag.
  718. //
  719. memcpy( Buffer, szLine, Idx );
  720. Buffer[Idx] = '\0';
  721. if ( !_strcmpi( Buffer, "SET" ) ) {
  722. //
  723. // SET command
  724. //
  725. fSet = fTrue;
  726. szLine = TextFileSkipBlanks( szLine+Idx );
  727. if( !szLine || *szLine == '\0' ) {
  728. return ( fFalse );
  729. }
  730. Idx = strcspn( szLine, " \t=" );
  731. if ( Idx >= strlen(szLine) ) {
  732. return fFalse;
  733. }
  734. memcpy( Buffer, szLine, Idx );
  735. Buffer[Idx] = '\0';
  736. }
  737. else if (*(szLine + Idx) == '=') {
  738. //
  739. // This is a command of type Var=Value ( A Set command without
  740. // the "SET" keyword
  741. fSet = fTrue;
  742. }
  743. //
  744. // At this point we should be pointing to "PATH" and fSet tells
  745. // us whether this is a SET command or not.
  746. //
  747. if ( !_strcmpi( Buffer, PATH ) ) {
  748. szLine = TextFileSkipBlanks( szLine+Idx );
  749. if( !szLine || *szLine == '\0' ) {
  750. return ( fFalse );
  751. }
  752. //
  753. // If SET, skip the "="
  754. //
  755. if ( fSet ) {
  756. if ( *szLine != '=' ) {
  757. return fFalse;
  758. }
  759. szLine = TextFileSkipBlanks( szLine+1 );
  760. if( !szLine || *szLine == '\0' ) {
  761. return ( fFalse );
  762. }
  763. }
  764. //
  765. // Now we point at the value of PATH.
  766. //
  767. // Remember all value of PATH
  768. //
  769. PrevPathLen = lstrlen(szPath);
  770. PrevPath = SAlloc(PrevPathLen+1);
  771. strcpy( PrevPath, szPath );
  772. szPath[0] = '\0';
  773. pBegin = szLine;
  774. pLast = pBegin + strlen( pBegin );
  775. //
  776. // Copy the new value of PATH, one directory at a time
  777. //
  778. do {
  779. pEnd = strchr(pBegin, ';' );
  780. if ( pEnd == NULL ) {
  781. pEnd = pBegin + strlen( pBegin );
  782. }
  783. *pEnd = '\0';
  784. if ( (BeginLen = strlen(pBegin)) > 0 ) {
  785. //
  786. // If a variable substitution, only do it if it is
  787. // substituting "PATH"
  788. //
  789. if ( *pBegin == '%' &&
  790. *(pEnd-1) == '%' ) {
  791. memcpy( Buffer, pBegin+1, (size_t)(pEnd-pBegin-2) );
  792. Buffer[pEnd-pBegin-2] = '\0';
  793. if ( !_strcmpi( Buffer, PATH ) ) {
  794. if(lstrlen(szPath)+PrevPathLen < MaxLength) {
  795. strcat( szPath, PrevPath );
  796. if ( pEnd != pLast ) {
  797. strcat( szPath, ";" );
  798. }
  799. }
  800. }
  801. } else {
  802. if(lstrlen(szPath)+BeginLen < MaxLength) {
  803. strcat( szPath, pBegin );
  804. if ( pEnd != pLast ) {
  805. strcat( szPath, ";" );
  806. }
  807. }
  808. }
  809. }
  810. pBegin = pEnd+1;
  811. } while ( pBegin < pLast );
  812. SFree(PrevPath);
  813. }
  814. }
  815. return fFalse;
  816. }
  817. //
  818. // Get Windows Path, "" if not installed
  819. //
  820. CB
  821. GetWindowsPath(
  822. IN RGSZ Args,
  823. IN USHORT cArgs,
  824. OUT SZ ReturnBuffer,
  825. IN CB cbReturnBuffer
  826. )
  827. {
  828. #define WIN_PTH_NONE ""
  829. SZ szDosPath;
  830. RGSZ rgszDosPath;
  831. INT i;
  832. CHAR szFile[ MAX_PATH ];
  833. BOOL fOkay = fFalse;
  834. SZ szEnd;
  835. Unused( Args );
  836. Unused( cArgs );
  837. if ( szDosPath = SzGetDosPathVar(cbReturnBuffer-1) ) {
  838. if ( rgszDosPath = RgszFromPath( szDosPath ) ) {
  839. for ( i=0; rgszDosPath[i]; i++ ) {
  840. strcpy( szFile, rgszDosPath[i] );
  841. if ( szFile[strlen(szFile)-1] != '\\' ) {
  842. strcat( szFile, "\\" );
  843. }
  844. szEnd = szFile + strlen(szFile);
  845. strcat( szFile, WIN_COM );
  846. if ( FFileExist( szFile ) ) {
  847. *szEnd = '\0';
  848. strcpy( ReturnBuffer, szFile );
  849. fOkay = fTrue;
  850. break;
  851. }
  852. }
  853. RgszFree( rgszDosPath );
  854. if ( !fOkay ) {
  855. strcpy( ReturnBuffer, WIN_PTH_NONE );
  856. fOkay = fTrue;
  857. }
  858. }
  859. SFree( szDosPath );
  860. }
  861. if ( fOkay ) {
  862. return lstrlen( ReturnBuffer )+1;
  863. } else {
  864. return 0;
  865. }
  866. }
  867. // ***************************************************************************
  868. //
  869. // COMMON SUBROUTINES
  870. //
  871. // ***************************************************************************
  872. //
  873. // Determine if the specified file is present.
  874. //
  875. BOOL
  876. FFileExist(
  877. IN LPSTR szFile
  878. )
  879. {
  880. DWORD Attr;
  881. Attr = GetFileAttributes( szFile );
  882. return ((Attr != -1) && !(Attr & FILE_ATTRIBUTE_DIRECTORY ));
  883. }
  884. //
  885. // File Size
  886. //
  887. DWORD
  888. FileSize(
  889. SZ szFile
  890. )
  891. {
  892. DWORD Size = 0xFFFFFFFF;
  893. FILE* f;
  894. if( f = fopen( szFile, "r" ) ) {
  895. if( !fseek( f, 0L, SEEK_END ) ) {
  896. Size = (DWORD) ftell( f ) ;
  897. }
  898. fclose( f );
  899. }
  900. return ( Size );
  901. }
  902. //
  903. // BUGBUG** Following code has been removed because it is no longer needed
  904. // It is still being kept in the file till it is determined that it
  905. // is definitely not needed
  906. //
  907. #if 0
  908. #define MAX_CONFIG_SIZE 1024
  909. BOOL
  910. FixConfigFileMacroChar(
  911. SZ szConfigFile,
  912. CHAR cReplaceChar,
  913. SZ szSystemDir
  914. )
  915. {
  916. CHAR Buffer [MAX_CONFIG_SIZE];
  917. DWORD len,i;
  918. DWORD BytesRead,BytesWritten;
  919. HANDLE hfile;
  920. hfile = CreateFile(
  921. szConfigFile,
  922. GENERIC_WRITE | GENERIC_READ,
  923. FILE_SHARE_READ,
  924. NULL,
  925. OPEN_EXISTING,
  926. FILE_ATTRIBUTE_NORMAL,
  927. NULL
  928. );
  929. if (hfile == INVALID_HANDLE_VALUE) {
  930. SetErrorText(IDS_ERROR_OPENFAIL);
  931. return FALSE;
  932. }
  933. if (!ReadFile(hfile, Buffer, MAX_CONFIG_SIZE, &BytesRead, NULL)){
  934. CloseHandle (hfile);
  935. SetErrorText( IDS_ERROR_READFAILED );
  936. return FALSE;
  937. }
  938. if (BytesRead == MAX_CONFIG_SIZE) {
  939. CloseHandle (hfile);
  940. SetErrorText( IDS_ERROR_READFAILED );
  941. return FALSE;
  942. }
  943. SetFilePointer (
  944. hfile,
  945. 0,
  946. NULL,
  947. FILE_BEGIN
  948. );
  949. len = strlen (szSystemDir);
  950. for (i=0; i < BytesRead; i++) {
  951. if (Buffer [i] != cReplaceChar){
  952. WriteFile (
  953. hfile,
  954. &Buffer[i],
  955. 1,
  956. &BytesWritten,
  957. NULL
  958. );
  959. }
  960. else {
  961. WriteFile (
  962. hfile,
  963. szSystemDir,
  964. len,
  965. &BytesWritten,
  966. NULL
  967. );
  968. }
  969. }
  970. CloseHandle (hfile);
  971. return TRUE;
  972. }
  973. // ***************************************************************************
  974. //
  975. // DOS AUTOEXEC.BAT ROUTINES
  976. //
  977. // ***************************************************************************
  978. //
  979. // copy a DOS batch file REMing out any line that is not a
  980. // SET or a PATH command
  981. //
  982. // szSrc: Source batch file (DOS c:\autoexec.bat )
  983. // szDst: Destination batch file (NT VDM c:\autoexec.nt )
  984. BOOL
  985. FilterDosBatchFile(
  986. LPSTR szSrc,
  987. LPSTR szDst,
  988. LPSTR szTemplate
  989. )
  990. {
  991. TEXTFILE SrcText, TemplateText;
  992. FILE* f;
  993. BOOL bStatus = TRUE;
  994. SZ szLine;
  995. CHAR Buffer[ MAX_PATH ];
  996. //
  997. // Open the destination file for write access
  998. //
  999. if (FFileExist( szDst )) {
  1000. bStatus = SetFileAttributes ( szDst, FILE_ATTRIBUTE_NORMAL );
  1001. if (bStatus) {
  1002. bStatus = DeleteFile( szDst );
  1003. }
  1004. }
  1005. if(!bStatus) {
  1006. SetErrorText(IDS_ERROR_WRITE);
  1007. return( FALSE );
  1008. }
  1009. if ( !(f = fopen( szDst, "w" )) ) {
  1010. SetErrorText(IDS_ERROR_OPENFAIL);
  1011. return( FALSE );
  1012. }
  1013. //
  1014. // Open source file
  1015. //
  1016. if ( FFileExist( szSrc ) &&
  1017. TextFileOpen( szSrc, &SrcText ) ) {
  1018. SZ TempBuffer = " @echo off\n";
  1019. //
  1020. // First put an echo off command here
  1021. //
  1022. fputs( TempBuffer, f );
  1023. //
  1024. // Then migrate the existing batch file
  1025. //
  1026. bStatus = DosBatchFilter( &SrcText, f );
  1027. TextFileClose( &SrcText );
  1028. }
  1029. if(!bStatus) {
  1030. fclose( f );
  1031. return( FALSE );
  1032. }
  1033. //
  1034. // Now add on the default autoexec file from the template file
  1035. //
  1036. if ( !TextFileOpen( szTemplate, &TemplateText ) ) {
  1037. SetErrorText(IDS_ERROR_OPENFAIL);
  1038. return( FALSE );
  1039. }
  1040. while ( TextFileReadLine( &TemplateText ) ) {
  1041. szLine = TextFileGetLine( &TemplateText );
  1042. sprintf( Buffer, " %s\n", szLine );
  1043. fputs( Buffer, f );
  1044. }
  1045. TextFileClose( &TemplateText );
  1046. fclose( f );
  1047. return( fTrue );
  1048. }
  1049. BOOL
  1050. DosBatchFilter(
  1051. IN OUT TEXTFILE * SrcText,
  1052. IN OUT FILE* f
  1053. )
  1054. {
  1055. SZ szLine;
  1056. SZ sz;
  1057. CHAR Buffer[ MAX_PATH ],*temp;
  1058. size_t Idx;
  1059. while ( TextFileReadLine( SrcText ) ) {
  1060. szLine = TextFileGetLine( SrcText );
  1061. sz = TextFileSkipBlanks( szLine );
  1062. //
  1063. // If blank line, ignore it
  1064. //
  1065. if ( !sz || *sz == '\0' || *sz == EOF ) {
  1066. // fputs( " \n", f );
  1067. // fprintf( f, "\n" );
  1068. continue;
  1069. }
  1070. //
  1071. // If this is a comment line, a SET or a PATH command, we
  1072. // write it verbatim, otherwise we REM it out
  1073. //
  1074. //
  1075. // If "no echo" command, skip the '@'
  1076. //
  1077. if ( *sz == '@' ) {
  1078. sz++;
  1079. }
  1080. Idx = strcspn( sz, " \t" );
  1081. if ( Idx <= strlen(sz) ) {
  1082. memcpy( Buffer, sz, Idx );
  1083. Buffer[Idx] = '\0';
  1084. if ( !_strcmpi( Buffer, "SET" ) ) {
  1085. // special hack to take out comspec line. we dont need
  1086. // this one for nt dos.
  1087. temp = &sz[Idx+1]; // point after set
  1088. // skip blanks
  1089. while (*temp && (*temp == ' ' || *temp == '\t')) {
  1090. temp++;
  1091. }
  1092. if (*temp == '\0') {
  1093. continue;
  1094. }
  1095. if (_strnicmp (temp,"comspec",7) == 0) { // ignore comspec
  1096. continue;
  1097. }
  1098. //
  1099. // SET line, copy verbatim
  1100. //
  1101. sprintf( Buffer, " %s\n", szLine );
  1102. fputs( Buffer, f );
  1103. //fprintf( f, "%s\n", szLine );
  1104. continue;
  1105. } else if ( !_strcmpi( Buffer, "PATH" ) ) {
  1106. //
  1107. // PATH line, copy verbatim
  1108. //
  1109. sprintf( Buffer, " %s\n", szLine );
  1110. fputs( Buffer, f );
  1111. //fprintf( f, "%s\n", szLine );
  1112. continue;
  1113. } else {
  1114. //
  1115. // Any other, ignore
  1116. //
  1117. // sprintf( Buffer, " REM %s\n", szLine );
  1118. // fputs( Buffer, f );
  1119. // fprintf( f, "REM %s\n", szLine );
  1120. continue;
  1121. }
  1122. }
  1123. }
  1124. return fTrue;
  1125. }
  1126. // ***************************************************************************
  1127. //
  1128. // Windows Ini File Migration
  1129. //
  1130. // ***************************************************************************
  1131. BOOL
  1132. MigrateWinIniWorker(
  1133. LPSTR szWin31Dir
  1134. )
  1135. {
  1136. CHAR szPath[ MAX_PATH ];
  1137. CHAR szWindowsDir[ MAX_PATH ];
  1138. BOOL bStatus = FALSE;
  1139. //
  1140. // Check validity of windows directory
  1141. //
  1142. if ( !lstrcmpi( szWin31Dir, "" ) ) {
  1143. return ( TRUE );
  1144. }
  1145. lstrcpy( szPath, szWin31Dir );
  1146. lstrcat( szPath, WIN_COM );
  1147. if ( !FFileExist( szPath ) ) {
  1148. return( TRUE );
  1149. }
  1150. //
  1151. // Initialize local variables
  1152. //
  1153. if( !GetWindowsDirectory( szWindowsDir, MAX_PATH ) ) {
  1154. // BUGBUG -- Some error here
  1155. return( FALSE );
  1156. }
  1157. lstrcat ( szWindowsDir, "\\" );
  1158. //
  1159. // If win31 directory and NT windows directory the same then we don't
  1160. // have to do anything
  1161. //
  1162. if( !lstrcmpi( szWin31Dir, szWindowsDir ) ) {
  1163. return( TRUE );
  1164. }
  1165. //
  1166. // INI FILE MIGRATION:
  1167. // -------------------
  1168. // We will copy over any ini files found in the win31 directory over
  1169. // to the NT Windows directory. standard ini files that ship with win31 are
  1170. // copied over under alternate names so that when we access these with
  1171. // profile api, these do not map to the registry. Then we will use
  1172. // private profile api to migrate information selectively from the
  1173. // standard set to the nt ini files. Lastly the win3.1 win.ini is search
  1174. // for sections which do not ship with the default win.ini and these
  1175. // sections are transferred over to the NT win.ini useing private profile
  1176. // api
  1177. //
  1178. //
  1179. // Locate all ini files and copy over ini files from win31 directory to
  1180. // nt windows directory
  1181. //
  1182. if( !FFindAndCopyIniFiles( szWin31Dir, szWindowsDir ) ) {
  1183. goto cleanup;
  1184. }
  1185. //
  1186. // Migrate over all information we need to from infs in standard set
  1187. //
  1188. if( !FMigrateStandardIniData( szWindowsDir ) ) {
  1189. goto cleanup;
  1190. }
  1191. //
  1192. // Go through win.ini using Rtl routines and migrate information to
  1193. // our win.ini
  1194. //
  1195. if( !FMigrateWinIniAppSections( szWindowsDir ) ) {
  1196. goto cleanup;
  1197. }
  1198. //
  1199. // Do Ini cleanup where all the temporary ini files that were
  1200. //
  1201. bStatus = TRUE;
  1202. cleanup:
  1203. CleanupIniFiles( szWindowsDir );
  1204. return ( bStatus );
  1205. }
  1206. BOOL
  1207. FFindAndCopyIniFiles(
  1208. SZ szSrcDir,
  1209. SZ szDstDir
  1210. )
  1211. {
  1212. HANDLE hff;
  1213. CHAR szFindFile[ MAX_PATH ];
  1214. CHAR szSrcFile[ MAX_PATH ];
  1215. CHAR szDstFile[ MAX_PATH ];
  1216. WIN32_FIND_DATA FindFileData;
  1217. //
  1218. // Do find first, find next search and copy over any infs found which
  1219. // are not in the standard set under the same name and any under the
  1220. // standard set with a tmp extenstion
  1221. //
  1222. lstrcpy( szFindFile, szSrcDir );
  1223. lstrcat( szFindFile, "*.ini" );
  1224. if ((hff = FindFirstFile( szFindFile, &FindFileData )) != (HANDLE)-1) {
  1225. do {
  1226. SZ sz;
  1227. lstrcpy( szSrcFile, szSrcDir );
  1228. lstrcat( szSrcFile, (SZ)FindFileData.cFileName );
  1229. lstrcpy( szDstFile, szDstDir );
  1230. if ( sz = SzMapStandardIni( (SZ)FindFileData.cFileName ) ) {
  1231. if( !lstrcmpi( sz, "" ) ) {
  1232. continue;
  1233. }
  1234. lstrcat( szDstFile, sz );
  1235. }
  1236. else {
  1237. lstrcat( szDstFile, (SZ)FindFileData.cFileName );
  1238. }
  1239. if( FFileExist( szDstFile ) ) {
  1240. SetFileAttributes ( szDstFile, FILE_ATTRIBUTE_NORMAL );
  1241. DeleteFile( szDstFile );
  1242. }
  1243. if (!CopyFile( szSrcFile, szDstFile, FALSE )) {
  1244. SetErrorText(IDS_ERROR_COPYFILE);
  1245. FindClose( hff );
  1246. return( FALSE );
  1247. }
  1248. }
  1249. while (FindNextFile(hff, &FindFileData));
  1250. FindClose( hff );
  1251. }
  1252. return ( TRUE );
  1253. }
  1254. //
  1255. // The following is the data the migration routines work off
  1256. //
  1257. typedef struct _inifilenames {
  1258. SZ szIniFileName;
  1259. SZ szIniTmpFileName;
  1260. } INIFILENAMES;
  1261. INIFILENAMES IniList[] = {
  1262. {"win.ini" , "win.tmp" },
  1263. {"system.ini" , "" },
  1264. {"mouse.ini" , "" },
  1265. {"winfile.ini" , "" },
  1266. {"control.ini" , "" },
  1267. {"msd.ini" , "" },
  1268. {"dosapp.ini" , "" },
  1269. {"progman.ini" , "" }
  1270. };
  1271. INT nIniList = sizeof(IniList) / sizeof( INIFILENAMES ) ;
  1272. typedef struct _inimigratedata {
  1273. SZ szSrcIniFile;
  1274. SZ szSrcSection;
  1275. SZ szSrcKey;
  1276. SZ szDstIniFile;
  1277. SZ szDstSection;
  1278. SZ szDstKey;
  1279. } INIMIGRATEDATA;
  1280. INIMIGRATEDATA IniMigrateList[] = {
  1281. {"win.tmp", "windows", "NullPort" , "win.ini", "windows", "NullPort" },
  1282. };
  1283. INT nIniMigrateList = sizeof( IniMigrateList ) / sizeof( INIMIGRATEDATA );
  1284. //
  1285. // BUGBUG ** Post BETA enumerate them from the registry
  1286. //
  1287. SZ WinIniStandardSections[] = {
  1288. "windows" ,
  1289. "Desktop" ,
  1290. "intl" ,
  1291. "ports" ,
  1292. "Sounds" ,
  1293. "Compatibility" ,
  1294. "fonts" ,
  1295. "Network" ,
  1296. "Windows Help" ,
  1297. "spooler" ,
  1298. "MS Proofing Tools" ,
  1299. "devices" ,
  1300. "Winlogon" ,
  1301. "Console" ,
  1302. "Extensions" ,
  1303. "MCI Extensions" ,
  1304. "Clock" ,
  1305. "Terminal" ,
  1306. "FontSubstitutes" ,
  1307. "FontCache" ,
  1308. "TrueType" ,
  1309. "Colors" ,
  1310. "Sounds" ,
  1311. "MMDEBUG" ,
  1312. NULL
  1313. };
  1314. //
  1315. // Migration worker routines
  1316. //
  1317. BOOL
  1318. FMigrateStandardIniData(
  1319. SZ szWindowsDir
  1320. )
  1321. {
  1322. CHAR szValue[ MAX_PATH ];
  1323. CHAR szSrcFile[ MAX_PATH ];
  1324. INT i;
  1325. for( i = 0; i < nIniMigrateList; i++ ) {
  1326. lstrcpy( szSrcFile, szWindowsDir );
  1327. lstrcat( szSrcFile, IniMigrateList[i].szSrcIniFile );
  1328. if( FFileExist( szSrcFile ) &&
  1329. GetPrivateProfileString(
  1330. IniMigrateList[i].szSrcSection,
  1331. IniMigrateList[i].szSrcKey,
  1332. "",
  1333. (LPSTR)szValue,
  1334. (DWORD)MAX_PATH,
  1335. szSrcFile
  1336. ) ) {
  1337. if( !WritePrivateProfileString(
  1338. IniMigrateList[i].szDstSection,
  1339. IniMigrateList[i].szDstKey,
  1340. szValue,
  1341. IniMigrateList[i].szDstIniFile
  1342. ) ) {
  1343. //
  1344. // BUGBUG .. what do we do here .. do we quit or do
  1345. // we continue
  1346. //
  1347. KdPrint(("SETUPDLL: Failed to migrate ini entry."));
  1348. }
  1349. }
  1350. }
  1351. return ( TRUE );
  1352. }
  1353. BOOL
  1354. FMigrateWinIniAppSections(
  1355. SZ szWindowsDir
  1356. )
  1357. {
  1358. CHAR szConfig[ MAX_PATH ];
  1359. CHAR szSection[ MAX_PATH ];
  1360. TEXTFILE SrcText;
  1361. SZ szLine;
  1362. SZ sz, szEnd;
  1363. DWORD dwSize;
  1364. #define MAX_SECTION_BUFFER 10 * 1024
  1365. PVOID Buffer;
  1366. lstrcpy( szConfig, szWindowsDir );
  1367. lstrcat( szConfig, "win.tmp" );
  1368. //
  1369. // Open source file
  1370. //
  1371. if ( FFileExist( szConfig ) &&
  1372. TextFileOpen( szConfig, &SrcText ) ) {
  1373. //
  1374. // Allocate section buffer
  1375. //
  1376. if ( !(Buffer = SAlloc((CB) MAX_SECTION_BUFFER))) {
  1377. TextFileClose(&SrcText);
  1378. SetErrorText(IDS_ERROR_DLLOOM);
  1379. return( FALSE );
  1380. }
  1381. //
  1382. // Process config file, line by line
  1383. //
  1384. while ( TextFileReadLine( &SrcText ) ) {
  1385. szLine = TextFileGetLine( &SrcText );
  1386. sz = TextFileSkipBlanks( szLine );
  1387. //
  1388. // If first character not [ get next line
  1389. //
  1390. if ( !sz || *sz != '[' ) {
  1391. continue;
  1392. }
  1393. sz++;
  1394. szEnd = strchr( sz, ']' );
  1395. if ( szEnd ) {
  1396. dwSize = szEnd - sz;
  1397. if ( dwSize > MAX_PATH ) {
  1398. continue;
  1399. }
  1400. memcpy( szSection, sz, dwSize );
  1401. *(szSection + dwSize) = '\0';
  1402. //
  1403. // If section name one of standard set ignore
  1404. //
  1405. if( FIsStandardWinIniSection( szSection ) ) {
  1406. continue;
  1407. }
  1408. //
  1409. // Read the entire section corresponding to the section
  1410. // from the source file and transfer it to the destination
  1411. // file using profile api
  1412. //
  1413. if( GetPrivateProfileSection(
  1414. szSection,
  1415. (LPSTR)Buffer,
  1416. MAX_SECTION_BUFFER,
  1417. szConfig
  1418. ) ) {
  1419. if (!WriteProfileSection( szSection, Buffer ) ) {
  1420. // BUGBUG Do we quit here??
  1421. KdPrint(("SETUPDLL: Failed to migrate ini section."));
  1422. }
  1423. }
  1424. }
  1425. }
  1426. SFree( Buffer );
  1427. TextFileClose(&SrcText);
  1428. }
  1429. return ( TRUE );
  1430. }
  1431. SZ
  1432. SzMapStandardIni(
  1433. SZ szIniFile
  1434. )
  1435. {
  1436. INT i;
  1437. for ( i = 0; i < nIniList; i++ ) {
  1438. if( !lstrcmpi(szIniFile, IniList[i].szIniFileName ) ) {
  1439. return( IniList[i].szIniTmpFileName );
  1440. }
  1441. }
  1442. return( NULL );
  1443. }
  1444. VOID
  1445. CleanupIniFiles(
  1446. SZ szWindowsDir
  1447. )
  1448. {
  1449. CHAR szFile[ MAX_PATH ];
  1450. INT i;
  1451. for ( i = 0; i < nIniList; i++ ) {
  1452. if ( lstrcmpi( IniList[i].szIniTmpFileName, "" ) ) {
  1453. lstrcpy( szFile, szWindowsDir );
  1454. lstrcat( szFile, IniList[i].szIniTmpFileName );
  1455. if( FFileExist( szFile ) ) {
  1456. SetFileAttributes ( szFile, FILE_ATTRIBUTE_NORMAL );
  1457. DeleteFile( szFile );
  1458. }
  1459. }
  1460. }
  1461. return;
  1462. }
  1463. BOOL
  1464. FIsStandardWinIniSection(
  1465. SZ szSection
  1466. )
  1467. {
  1468. PSZ psz;
  1469. psz = WinIniStandardSections;
  1470. while ( *psz ) {
  1471. if( !lstrcmpi( *psz++, szSection ) ) {
  1472. return ( TRUE );
  1473. }
  1474. }
  1475. return( FALSE );
  1476. }
  1477. #endif