Leaked source code of windows server 2003
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.

2821 lines
82 KiB

  1. #include <windows.h>
  2. #if 0
  3. #include <stdtypes.h>
  4. #endif
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <direct.h>
  8. #include <dos.h>
  9. #include <sys\types.h>
  10. #include <sys\stat.h>
  11. #include <ctype.h> /* isspace */
  12. #include <io.h>
  13. #include <limits.h> /* UINT_MAX */
  14. #include <memory.h> /* _fmemcpy, _fmemccpy */
  15. #include <lzexpand.h>
  16. #include <shellapi.h> /* HKEY, HKEY_CLASSES_ROOT, ERROR_SUCCESS */
  17. #include "setup.h"
  18. #include "genthk.h" /* thunks for calls to get 32-bit version */
  19. #include "driveex.h"
  20. #include <stdtypes.h>
  21. /* Messages for optional background task.
  22. */
  23. #define IDM_ACME_STARTING 261
  24. #define IDM_ACME_COMPLETE 262
  25. #define IDM_ACME_FAILURE 263
  26. #ifdef APPCOMP
  27. #include <decomp.h>
  28. #endif /* APPCOMP */
  29. #include <fdi.h>
  30. /* List file extension */
  31. char szLstExt[] = "LST";
  32. /* List file section names */
  33. char szDefaultParamsSect[] = "Params";
  34. char szDefaultFilesSect[] = "Files";
  35. char szWin3xParamsSect[] = "Win3.x Params";
  36. char szWin3xFilesSect[] = "Win3.x Files";
  37. char szWin95ParamsSect[] = "Windows 95 Params";
  38. char szWin95FilesSect[] = "Windows 95 Files";
  39. char szNTIntelParamsSect[] = "NT Intel Params";
  40. char szNTIntelFilesSect[] = "NT Intel Files";
  41. char szNTVerIntelParamsSect[] = "NT3.51 Intel Params";
  42. char szNTVerIntelFilesSect[] = "NT3.51 Intel Files";
  43. char * szParamsSect = szNull;
  44. char * szFilesSect = szNull;
  45. typedef struct _PLATFORM_SPEC
  46. {
  47. BYTE minMajorVersion;
  48. BYTE minMinorVersion;
  49. char *szParamsSect;
  50. char *szFilesSect;
  51. } PLATFORM_SPEC, *PPLATFORM_SPEC;
  52. PLATFORM_SPEC aIntelSpec[] =
  53. {
  54. {3, 51, szNTVerIntelParamsSect, szNTVerIntelFilesSect},
  55. {0, 0, szNTIntelParamsSect, szNTIntelFilesSect},
  56. {0, 0, NULL, NULL}
  57. };
  58. PLATFORM_SPEC aEmptySpec[] =
  59. {
  60. {0, 0, NULL, NULL}
  61. };
  62. // Note: this is indexed by PROCESSOR_ARCHITECTURE_xxx
  63. // definitions in ntexapi.h
  64. //
  65. PPLATFORM_SPEC aaPlatformSpecs[] =
  66. {
  67. aIntelSpec, // PROCESSOR_ARCHITECTURE_INTEL 0
  68. aEmptySpec, // PROCESSOR_ARCHITECTURE_MIPS 1
  69. aEmptySpec, // PROCESSOR_ARCHITECTURE_ALPHA 2
  70. aEmptySpec, // PROCESSOR_ARCHITECTURE_PPC 3
  71. aEmptySpec, // PROCESSOR_ARCHITECTURE_SHX 4
  72. aEmptySpec, // PROCESSOR_ARCHITECTURE_ARM 5
  73. aIntelSpec, // PROCESSOR_ARCHITECTURE_IA64 6
  74. aEmptySpec, // PROCESSOR_ARCHITECTURE_ALPHA64 7
  75. aEmptySpec, // PROCESSOR_ARCHITECTURE_MSIL 8
  76. aIntelSpec // PROCESSOR_ARCHITECTURE_AMD64 9
  77. };
  78. /* Bootstrapper class name */
  79. char szBootClass[] = "STUFF-BOOT";
  80. /* String buffer sizes */
  81. #define cchLstLineMax 128
  82. #define cchWinExecLineMax (256 + cchFullPathMax)
  83. /* No. of retries to attempt when removing files or dirs,
  84. * or when executing a chmod.
  85. */
  86. #define cRetryMax 1200
  87. /* SetErrorMode flags */
  88. #define fNoErrMes 1
  89. #define fErrMes 0
  90. /* Quiet Mode -- Note: EEL must be kept in sync with acmsetup.h */
  91. typedef UINT EEL; /* Exit Error Level */
  92. #define eelSuccess ((EEL)0x0000)
  93. #define eelBootstrapperFailed ((EEL)0x0009) /* Used only in Bootstrapper! */
  94. EEL eelExitErrorLevel = eelBootstrapperFailed;
  95. BOOL fQuietMode = fFalse;
  96. BOOL fExeced = fFalse;
  97. BOOL fWin31 = fFalse;
  98. /* Forward Declarations */
  99. VOID CleanUpTempDir ( char *, char * );
  100. BRC BrcInstallFiles ( char *, char *, char * );
  101. BOOL FCreateTempDir ( char *, char * );
  102. BRC BrcCopyFiles ( char *, char *, char * );
  103. VOID RemoveFiles ( char * );
  104. BRC BrcCopy ( char *, char * );
  105. LONG LcbFreeDrive ( int );
  106. BOOL FVirCheck ( HANDLE );
  107. HWND HwndInitBootWnd ( HANDLE );
  108. LRESULT CALLBACK BootWndProc ( HWND, UINT, WPARAM, LPARAM );
  109. BOOL FGetFileSize ( char *, UINT * );
  110. BRC BrcBuildFileLists ( char *, UINT );
  111. VOID FreeFileLists ( VOID );
  112. BOOL FExecAndWait ( char *, HWND );
  113. BOOL FWriteBatFile ( OFSTRUCT, char *, char * );
  114. BOOL FLstSectionExists ( char * szLstFileName, char * szSect );
  115. DWORD GetCpuArchitecture();
  116. BOOL FNotifyAcme ( VOID );
  117. BOOL FGetAcmeErrorLevel ( EEL * peel );
  118. BOOL FCreateRegKey ( CSZC cszcKey );
  119. BOOL FDoesRegKeyExist ( CSZC cszcKey );
  120. BOOL FCreateRegKeyValue ( CSZC cszcKey, CSZC cszcValue );
  121. BOOL FGetRegKeyValue ( CSZC cszcKey, SZ szBuf, CB cbBufMax );
  122. VOID DeleteRegKey ( CSZC cszcKey );
  123. BOOL FFlushRegKey ( VOID );
  124. BOOL FWriteToRestartFile ( SZ szTmpDir );
  125. BOOL FCreateIniFileName ( SZ szIniFile, CB cbBufMax );
  126. BOOL FReadIniFile ( SZ szIniFile, HLOCAL * phlocal, PCB pcbBuf );
  127. BOOL FAllocNewBuf ( CB cbOld, SZ szTmpDir, SZ szSection, SZ szKey,
  128. HLOCAL * phlocal, PCB pcbToBuf );
  129. BOOL FProcessFile ( HLOCAL hlocalFrom, HLOCAL hlocalTo, CB cbToBuf,
  130. SZ szTmpDir, SZ szSection, SZ szKey );
  131. VOID CopyIniLine ( SZ szKey, SZ szTmpDir, SZ szFile, PSZ pszToBuf );
  132. BOOL FWriteIniFile ( SZ szIniFile, HLOCAL hlocalTo );
  133. BRC BrcInsertDisk(CHAR *pchStf, CHAR *pchSrcDrive);
  134. BOOL FRenameBadMaintStf ( SZ szStf );
  135. /* Bootstrapper list file params */
  136. char rgchSetupDirName[cchLstLineMax];
  137. #ifdef UNUSED /* Replaced by DrvWinClass */
  138. char rgchDrvModName[cchLstLineMax];
  139. #endif /* UNUSED */
  140. char rgchDrvWinClass[cchLstLineMax];
  141. char rgchCmdLine[cchLstLineMax];
  142. char rgchBootTitle[cchLstLineMax];
  143. char rgchBootMess[cchLstLineMax];
  144. char rgchWin31Mess[cchLstLineMax];
  145. char rgchCabinetFName[cchLstLineMax];
  146. char rgchBackgroundFName[cchLstLineMax];
  147. char rgchBkgWinClass[cchLstLineMax];
  148. char rgchInsertCDMsg[cchLstLineMax];
  149. char rgchInsertDiskMsg[cchLstLineMax];
  150. LONG lcbDiskFreeMin;
  151. int cFirstCabinetNum;
  152. int cLastCabinetNum;
  153. HANDLE hSrcLst = NULL;
  154. HANDLE hDstLst = NULL;
  155. char rgchErrorFile[cchFullPathMax];
  156. HANDLE hinstBoot = NULL;
  157. HWND hwndBoot = NULL;
  158. CHAR rgchInsufMem[cchSzMax] = "";
  159. CHAR rgchInitErr[cchSzMax] = "";
  160. CHAR rgchSetup[cchSzMax] = "";
  161. /*
  162. ** 'Fixup' temp dir string by removing any subdirs and ensuring
  163. ** extension is only one character. (Note - Win3.0 has bug with
  164. ** WinExec'ing some EXEs from a full 8.3 directory!)
  165. **************************************************************************/
  166. void FixupTempDirName( LPSTR szDir )
  167. {
  168. LPSTR szNext;
  169. int cch = 0;
  170. if (*szDir == '\\'
  171. || *(AnsiNext(szDir)) == ':')
  172. {
  173. lstrcpy(szDir, "~msstfqf.t");
  174. return;
  175. }
  176. while (*szDir != '\\'
  177. && *szDir != '.'
  178. && *szDir != '\0'
  179. && *szDir != ':'
  180. && cch++ < 8)
  181. {
  182. szDir = AnsiNext(szDir);
  183. }
  184. szNext = AnsiNext(szDir);
  185. if (*szDir == '.'
  186. && *szNext != '.'
  187. && *szNext != '\\'
  188. && *szNext != '\0'
  189. && *szNext != ':')
  190. {
  191. *(AnsiNext(szNext)) = '\0';
  192. return;
  193. }
  194. *szDir = '\0';
  195. lstrcat(szDir, ".t");
  196. }
  197. /* Displays bootstrapper messages.
  198. * If fError is true, it's an error message, otherwise it's
  199. * just a message (e.g. insert disk 1).
  200. **************************************************************************/
  201. int DispErrBrc ( BRC brc, BOOL fError, UINT fuStyle,
  202. const char *sz1, const char *sz2,
  203. const char *sz3 )
  204. {
  205. char rgchTitle[cchSzMax];
  206. char rgchMessage[256];
  207. char szBuf[256 + cchFullPathMax + 256];
  208. #ifndef DEBUG
  209. if (fQuietMode)
  210. {
  211. return (IDCANCEL);
  212. }
  213. #endif
  214. if (LoadString(hinstBoot, brcGen, rgchTitle, 256) == 0
  215. || LoadString(hinstBoot, brc, rgchMessage, 256) == 0)
  216. {
  217. MessageBox(hwndBoot, rgchInsufMem, rgchInitErr, MB_OK | MB_ICONSTOP);
  218. return 0;
  219. }
  220. if (!fError)
  221. lstrcpy(rgchTitle, rgchSetup);
  222. if (sz1 == NULL) sz1 = "";
  223. if (sz2 == NULL) sz2 = "";
  224. if (sz3 == NULL) sz3 = "";
  225. if (brc == brcFile)
  226. wsprintf(szBuf, rgchMessage, (LPSTR)AnsiUpper(rgchErrorFile));
  227. else if (brc == brcDS || brc == brcMemDS)
  228. wsprintf(szBuf, rgchMessage, lcbDiskFreeMin / 1024L);
  229. else
  230. wsprintf(szBuf, rgchMessage, sz1, sz2, sz3);
  231. if ((brc == brcMemDS || brc == brcNoSpill)
  232. && LoadString(hinstBoot, brcMemDSHlp, rgchMessage, 256))
  233. {
  234. lstrcat(szBuf, rgchMessage);
  235. }
  236. else if (brc == brcConnectToSource
  237. && LoadString(hinstBoot, brcConnectHlp, rgchMessage, 256))
  238. {
  239. lstrcat(szBuf, rgchMessage);
  240. }
  241. return (MessageBox(hwndBoot, szBuf, rgchTitle, fuStyle));
  242. }
  243. /*
  244. ** Purpose:
  245. ** Installs Setup executable in a temporary directory on an
  246. ** available hardrive, and launches Setup. After Setup
  247. ** completes, removes the temporary files and directory.
  248. ** Arguments:
  249. ** Standard Windows WinMain args.
  250. ** Returns:
  251. ** Returns eelExitErrorLevel. 0 == Success.
  252. **************************************************************************/
  253. int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  254. LPSTR lpszCmdParam, int nCmdShow )
  255. {
  256. char chDrive;
  257. char rgchDstDir[cchFullPathMax] = " :\\"; // WARN: kept as OEM chars
  258. char * szDstDirSlash = szNull;
  259. char rgchModuleFileName[cchFullPathMax]; // WARN: kept as ANSI chars
  260. char rgchLstFileName[cchFullPathMax];
  261. char rgchTemp[cchFullPathMax];
  262. char rgchSrcDir[cchFullPathMax];
  263. UINT cbLstSize;
  264. char rgchWinExecLine[cchWinExecLineMax];
  265. UINT uiRes;
  266. int iModLen;
  267. BRC brc;
  268. BOOL fCleanupTemp = FALSE;
  269. LPSTR sz;
  270. HWND hWndBkg = 0; /* window of background task */
  271. UINT hMod;
  272. Unused(nCmdShow);
  273. hinstBoot = hInstance;
  274. rgchErrorFile[0] = '\0';
  275. if (LoadString(hinstBoot, IDS_InsufMem, rgchInsufMem,
  276. sizeof rgchInsufMem) == 0
  277. || LoadString(hinstBoot, IDS_InitErr, rgchInitErr,
  278. sizeof rgchInitErr) == 0
  279. || LoadString(hinstBoot, IDS_Setup, rgchSetup,
  280. sizeof rgchSetup) == 0)
  281. {
  282. /* REVIEW: If these LoadStrngs fail, the user will never know...
  283. * But we can't hard-code strings in an .h file because INTL
  284. * requires all localizable strings to be in resources!
  285. */
  286. #ifdef DEBUG
  287. MessageBox(NULL, "Initial LoadString's failed; probably out of memory.",
  288. szDebugMsg, MB_OK | MB_ICONEXCLAMATION);
  289. #endif /* DEBUG */
  290. }
  291. for (sz = lpszCmdParam; *sz != '\0'; sz = AnsiNext(sz))
  292. {
  293. if ((*sz == '-' || *sz == '/')
  294. && toupper(*(sz+1)) == 'Q' && toupper(*(sz+2)) == 'T')
  295. {
  296. fQuietMode = fTrue;
  297. break;
  298. }
  299. }
  300. /*
  301. * REVIEW: Check that this code is still functional before restoring it.
  302. */
  303. #if VIRCHECK
  304. if (!FVirCheck(hInstance))
  305. {
  306. DispErrBrc(brcVir, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  307. goto LCleanupAndExit;
  308. }
  309. #endif
  310. if (hPrevInstance || FindWindow(szBootClass, NULL) != NULL)
  311. {
  312. DispErrBrc(brcInst, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  313. goto LCleanupAndExit;
  314. }
  315. GetModuleFileName(hInstance, rgchModuleFileName, cchFullPathMax);
  316. /*
  317. * If the first switch on the command line is /M, then it specifies
  318. * the real module name to use.
  319. */
  320. if ((lpszCmdParam[0] == '-' || lpszCmdParam[0] == '/')
  321. && toupper(lpszCmdParam[1]) == 'M')
  322. {
  323. char *pCh, *pCh2;
  324. BOOL fQuotedFileName;
  325. /* Skip the spaces */
  326. for (pCh = lpszCmdParam+2; *pCh == ' '; pCh++);
  327. fQuotedFileName = (*pCh == '\"');
  328. if (fQuotedFileName)
  329. {
  330. pCh++;
  331. }
  332. /* Copy the file name, and add the EOS */
  333. lstrcpy(rgchModuleFileName, pCh);
  334. for (pCh2=rgchModuleFileName;
  335. (*pCh2 != ' ' || fQuotedFileName) &&
  336. (*pCh2 != '\"' || !fQuotedFileName) &&
  337. *pCh2 != '\0';
  338. pCh2++);
  339. *pCh2 = '\0';
  340. /* Remove the /M param from the command line */
  341. lpszCmdParam = pCh + lstrlen(rgchModuleFileName);
  342. if (fQuotedFileName && *lpszCmdParam == '\"')
  343. {
  344. lpszCmdParam++;
  345. }
  346. /* Remove trailing whitespace from the command line */
  347. for (pCh = lpszCmdParam; *pCh == ' '; pCh++);
  348. lpszCmdParam = pCh;
  349. }
  350. OemToAnsiBuff(rgchModuleFileName, rgchModuleFileName, sizeof(rgchModuleFileName));
  351. // Windows 3.0 bug with UNC paths - prepends windows drive letter
  352. sz = (LPSTR)rgchModuleFileName;
  353. if (*sz != '\0'
  354. && *sz != '\\'
  355. && *(sz = AnsiNext(sz)) == ':'
  356. && *(sz = AnsiNext(sz)) == '\\'
  357. && *AnsiNext(sz) == '\\')
  358. {
  359. LPSTR szDst = (LPSTR)rgchModuleFileName;
  360. while ((*szDst++ = *sz++) != '\0')
  361. ;
  362. }
  363. iModLen = lstrlen(rgchModuleFileName);
  364. lstrcpy(rgchSrcDir, rgchModuleFileName);
  365. sz = (LPSTR)&rgchSrcDir[iModLen];
  366. while (sz > (LPSTR)rgchSrcDir && *sz != '\\')
  367. sz = AnsiPrev(rgchSrcDir, sz);
  368. Assert(sz > (LPSTR)rgchSrcDir);
  369. *(AnsiNext(sz)) = '\0';
  370. /*
  371. * If the first switch on the command line is /L, then it specifies
  372. * the name of the .lst file to use.
  373. */
  374. rgchTemp[0] = '\0';
  375. if ((lpszCmdParam[0] == '-' || lpszCmdParam[0] == '/')
  376. && toupper(lpszCmdParam[1]) == 'L')
  377. {
  378. char *pCh, *pCh2;
  379. /* Skip the spaces */
  380. for (pCh = lpszCmdParam+2; *pCh == ' ' && *pCh != '\0'; pCh++);
  381. /* Copy the .lst file name, and add the newline */
  382. lstrcpy(rgchTemp, pCh);
  383. for (pCh2=rgchTemp; *pCh2 != ' ' && *pCh2!= '\0'; pCh2++);
  384. *pCh2 = '\0';
  385. /* Remove the /L param from the command line */
  386. lpszCmdParam = pCh + lstrlen(rgchTemp);
  387. for (pCh = lpszCmdParam; *pCh == ' ' && *pCh != '\0'; pCh++);
  388. lpszCmdParam = pCh;
  389. }
  390. /* If there is something on the command line, use it as the .lst file */
  391. if (*rgchTemp != '\0')
  392. {
  393. lstrcpy(rgchLstFileName, rgchSrcDir);
  394. lstrcat(rgchLstFileName, rgchTemp);
  395. }
  396. else
  397. {
  398. lstrcpy(rgchLstFileName, rgchModuleFileName);
  399. sz = (LPSTR)&rgchLstFileName[iModLen];
  400. while (sz > (LPSTR)rgchLstFileName && *sz != '.')
  401. sz = AnsiPrev(rgchLstFileName, sz);
  402. Assert(sz > (LPSTR)rgchLstFileName);
  403. *(AnsiNext(sz)) = '\0';
  404. lstrcat(rgchLstFileName, szLstExt);
  405. }
  406. if (!FGetFileSize(rgchLstFileName, &cbLstSize) || cbLstSize == 0)
  407. {
  408. lstrcpy(rgchErrorFile, rgchLstFileName);
  409. DispErrBrc(brcFile, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  410. goto LCleanupAndExit;
  411. }
  412. #ifndef WF_WINNT
  413. #define WF_WINNT 0x4000
  414. #endif
  415. /* Attempt to use appropriate platform.
  416. */
  417. szParamsSect = szNull;
  418. szFilesSect = szNull;
  419. if (1)
  420. {
  421. DWORD dwVers = 0;
  422. DWORD dwCpuArchitecture;
  423. DWORD dwMajorVersion;
  424. DWORD dwMinorVersion;
  425. PPLATFORM_SPEC pPlatformSpec;
  426. dwCpuArchitecture = GetCpuArchitecture();
  427. dwVers = GetVersion();
  428. dwMajorVersion = LOBYTE(LOWORD(dwVers));
  429. dwMinorVersion = HIBYTE(LOWORD(dwVers));
  430. if (dwCpuArchitecture < (sizeof (aaPlatformSpecs) / sizeof(aaPlatformSpecs[0])))
  431. {
  432. pPlatformSpec = aaPlatformSpecs[dwCpuArchitecture];
  433. }
  434. else
  435. {
  436. pPlatformSpec = aEmptySpec;
  437. }
  438. for (; pPlatformSpec->szParamsSect != NULL; pPlatformSpec++)
  439. {
  440. if (((pPlatformSpec->minMajorVersion < dwMajorVersion) ||
  441. (pPlatformSpec->minMajorVersion == dwMajorVersion && pPlatformSpec->minMinorVersion <= dwMinorVersion)) &&
  442. FLstSectionExists(rgchLstFileName, pPlatformSpec->szParamsSect))
  443. {
  444. szParamsSect = pPlatformSpec->szParamsSect;
  445. szFilesSect = pPlatformSpec->szFilesSect;
  446. break;
  447. }
  448. }
  449. }
  450. else /* non-WinNT */
  451. {
  452. if (FLstSectionExists(rgchLstFileName, szWin95ParamsSect)
  453. && (LOBYTE(LOWORD(GetVersion())) > 3
  454. || HIBYTE(LOWORD(GetVersion())) >= 95))
  455. {
  456. szParamsSect = szWin95ParamsSect;
  457. szFilesSect = szWin95FilesSect;
  458. }
  459. else
  460. {
  461. fWin31 = fTrue;
  462. if (FLstSectionExists(rgchLstFileName, szWin3xParamsSect))
  463. {
  464. szParamsSect = szWin3xParamsSect;
  465. szFilesSect = szWin3xFilesSect;
  466. }
  467. }
  468. }
  469. if (szParamsSect == szNull)
  470. {
  471. if (FLstSectionExists(rgchLstFileName, szDefaultParamsSect))
  472. {
  473. szParamsSect = szDefaultParamsSect;
  474. szFilesSect = szDefaultFilesSect;
  475. }
  476. else
  477. {
  478. DispErrBrc(brcNoCpuSect, TRUE, MB_OK | MB_ICONSTOP, NULL,
  479. NULL, NULL);
  480. goto LCleanupAndExit;
  481. }
  482. }
  483. if (GetPrivateProfileString(szParamsSect, "TmpDirName", "",
  484. rgchSetupDirName, cchLstLineMax, rgchLstFileName) <= 0
  485. || (lcbDiskFreeMin = GetPrivateProfileInt(szParamsSect,
  486. "TmpDirSize", 0, rgchLstFileName) * 1024L) <= 0
  487. || (cFirstCabinetNum = GetPrivateProfileInt(szParamsSect,
  488. "FirstCabNum", 1, rgchLstFileName)) <= 0
  489. || (cLastCabinetNum = GetPrivateProfileInt(szParamsSect,
  490. "LastCabNum", 1, rgchLstFileName)) <= 0
  491. #ifdef UNUSED
  492. || GetPrivateProfileString(szParamsSect, "DrvModName", "",
  493. rgchDrvModName, cchLstLineMax, rgchLstFileName) <= 0
  494. #endif /* UNUSED */
  495. || GetPrivateProfileString(szParamsSect, "DrvWinClass", "",
  496. rgchDrvWinClass, cchLstLineMax, rgchLstFileName) <= 0
  497. || GetPrivateProfileString(szParamsSect, "CmdLine", "", rgchCmdLine,
  498. cchLstLineMax, rgchLstFileName) <= 0
  499. //|| GetPrivateProfileString(szParamsSect, "Require31", "",
  500. // rgchWin31Mess, cchLstLineMax, rgchLstFileName) <= 0
  501. || GetPrivateProfileString(szParamsSect, "WndTitle", "",
  502. rgchBootTitle, cchLstLineMax, rgchLstFileName) <= 0
  503. || GetPrivateProfileString(szParamsSect, "WndMess", "",
  504. rgchBootMess, cchLstLineMax, rgchLstFileName) <= 0)
  505. {
  506. DispErrBrc(brcLst, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  507. goto LCleanupAndExit;
  508. }
  509. if (FindWindow(rgchDrvWinClass, NULL) != NULL)
  510. {
  511. DispErrBrc(brcInst, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  512. goto LCleanupAndExit;
  513. }
  514. GetPrivateProfileString(szParamsSect, "CabinetFile", "",
  515. rgchCabinetFName, cchLstLineMax, rgchLstFileName);
  516. GetPrivateProfileString(szParamsSect, "InsertCDMsg", "",
  517. rgchInsertCDMsg, cchLstLineMax, rgchLstFileName);
  518. GetPrivateProfileString(szParamsSect, "InsertDiskMsg", "",
  519. rgchInsertDiskMsg, cchLstLineMax, rgchLstFileName);
  520. if (rgchWin31Mess[0] != '\0'
  521. && LOBYTE(LOWORD((DWORD)GetVersion())) == 3
  522. && HIBYTE(LOWORD((DWORD)GetVersion())) < 10)
  523. {
  524. if (!fQuietMode)
  525. {
  526. char rgchTitle[cchSzMax];
  527. if (LoadString(hinstBoot, brcGen, rgchTitle, 256) == 0)
  528. lstrcpy(rgchTitle, rgchSetup);
  529. MessageBox(hwndBoot, rgchWin31Mess, rgchTitle,
  530. MB_OK | MB_ICONSTOP);
  531. }
  532. goto LCleanupAndExit;
  533. }
  534. FixupTempDirName(rgchSetupDirName);
  535. for (sz = rgchBootMess; *sz != '\0'; sz = AnsiNext(sz))
  536. if (*sz == '\\' && *(sz+1) == 'n')
  537. {
  538. *sz++ = '\r';
  539. *sz = '\n';
  540. }
  541. /* If there is a /W then is specifies we are in add/remove mode with
  542. the setup app not installed. We need to read it off CD/Floppy/Network
  543. */
  544. if ((lpszCmdParam[0] == '-' || lpszCmdParam[0] == '/')
  545. && toupper(lpszCmdParam[1]) == 'W')
  546. {
  547. CHAR rgchStf[_MAX_PATH];
  548. char *pCh, *pCh2, *pCh3;
  549. /* Skip the spaces */
  550. for (pCh = lpszCmdParam+2; *pCh == ' ' && *pCh != '\0'; pCh++);
  551. lstrcpy(rgchStf, rgchSrcDir);
  552. pCh3 = rgchStf + lstrlen(rgchStf);
  553. /* Copy the .stf file name, and add the newline */
  554. for (pCh2=pCh; *pCh2 != ' ' && *pCh2!= '\0'; pCh2++)
  555. *pCh3++ = *pCh2;
  556. *pCh3 = '\0';
  557. /* Remove the /W parameter */
  558. lpszCmdParam = pCh2;
  559. /* Get them to insert the correct disk */
  560. if ((brc = BrcInsertDisk(rgchStf, rgchSrcDir)) != brcOkay)
  561. {
  562. if (brc != brcMax)
  563. DispErrBrc(brc, TRUE, MB_OK | MB_ICONSTOP, rgchStf, NULL, NULL);
  564. goto LCleanupAndExit;
  565. }
  566. }
  567. GetPrivateProfileString(szParamsSect, "Background", "",
  568. rgchBackgroundFName, cchLstLineMax, rgchLstFileName);
  569. GetPrivateProfileString(szParamsSect, "BkgWinClass", "",
  570. rgchBkgWinClass, cchLstLineMax, rgchLstFileName);
  571. if (rgchBackgroundFName[0] != '\0')
  572. {
  573. lstrcpy(rgchTemp, rgchSrcDir);
  574. lstrcat(rgchTemp, rgchBackgroundFName);
  575. if (rgchBkgWinClass[0] != '\0')
  576. {
  577. lstrcat(rgchTemp, " /C");
  578. lstrcat(rgchTemp, rgchBkgWinClass);
  579. }
  580. lstrcat(rgchTemp, " /T");
  581. lstrcat(rgchTemp, rgchBootTitle);
  582. lstrcat(rgchTemp, " /M");
  583. lstrcat(rgchTemp, rgchBootMess);
  584. hMod = WinExec(rgchTemp, SW_SHOWNORMAL); /* ignore if exec failed */
  585. #ifdef DEBUG
  586. if (hMod < 32)
  587. {
  588. wsprintf(szDebugBuf, "%s: Background WinExec failed.",
  589. rgchBackgroundFName);
  590. MessageBox(NULL, szDebugBuf, szDebugMsg, MB_OK | MB_ICONSTOP);
  591. }
  592. #endif /* DEBUG */
  593. hWndBkg = FindWindow(rgchBkgWinClass, rgchBootTitle);
  594. }
  595. if (!hWndBkg && (hwndBoot = HwndInitBootWnd(hInstance)) == NULL)
  596. {
  597. DispErrBrc(brcMem, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  598. goto LCleanupAndExit;
  599. }
  600. if ((brc = BrcBuildFileLists(rgchLstFileName, cbLstSize)) != brcOkay)
  601. {
  602. DispErrBrc(brc, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  603. goto LCleanupAndExit;
  604. }
  605. lstrcat(rgchDstDir, "~MSSETUP.T");
  606. szDstDirSlash = rgchDstDir + lstrlen(rgchDstDir);
  607. lstrcat(rgchDstDir, "\\");
  608. lstrcat(rgchDstDir, rgchSetupDirName);
  609. AnsiToOem(rgchDstDir, rgchDstDir);
  610. for (chDrive = 'Z'; chDrive >= 'A'; --chDrive)
  611. {
  612. UINT fModeSav;
  613. BOOL fDriveFixed;
  614. fModeSav = SetErrorMode(fNoErrMes);
  615. fDriveFixed = (GetDriveTypeEx(chDrive - 'A') == EX_DRIVE_FIXED);
  616. SetErrorMode(fModeSav);
  617. if (fDriveFixed)
  618. {
  619. *rgchDstDir = chDrive;
  620. brc = BrcInstallFiles(rgchSrcDir, rgchDstDir, szDstDirSlash);
  621. if (brc == brcOkay)
  622. break;
  623. if (brc == brcFile)
  624. {
  625. DispErrBrc(brc, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  626. goto LCleanupAndExit;
  627. }
  628. else if (brc == brcNoSpill)
  629. {
  630. /* Message already handled in HfOpenSpillFile */
  631. goto LCleanupAndExit;
  632. }
  633. }
  634. }
  635. if (chDrive < 'A')
  636. {
  637. uiRes = GetWindowsDirectory(rgchDstDir, cchFullPathMax);
  638. Assert(uiRes > 0);
  639. #if DBCS // [J1] Fixed DBCS raid #46.
  640. AnsiUpper(rgchDstDir);
  641. #endif
  642. /* BLOCK */
  643. {
  644. LPSTR sz = (LPSTR)&rgchDstDir[uiRes];
  645. sz = AnsiPrev(rgchDstDir, sz);
  646. if (*sz != '\\')
  647. lstrcat(rgchDstDir, "\\");
  648. }
  649. lstrcat(rgchDstDir, "~MSSETUP.T");
  650. szDstDirSlash = rgchDstDir + lstrlen(rgchDstDir);
  651. lstrcat(rgchDstDir, "\\");
  652. Assert(lstrlen(rgchDstDir) + lstrlen(rgchSetupDirName)
  653. < cchFullPathMax);
  654. lstrcat(rgchDstDir, rgchSetupDirName);
  655. AnsiToOem(rgchDstDir, rgchDstDir);
  656. brc = BrcInstallFiles(rgchSrcDir, rgchDstDir, szDstDirSlash);
  657. if (brc != brcOkay)
  658. {
  659. /* NoSpill message already handled in HfOpenSpillFile */
  660. if (brc != brcNoSpill)
  661. {
  662. DispErrBrc(brc, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  663. }
  664. goto LCleanupAndExit;
  665. }
  666. }
  667. hSrcLst = LocalFree(hSrcLst); /* don't need src list anymore */
  668. Assert(hSrcLst == NULL);
  669. /* Use full path to .exe; don't rely on cwd (fails under Win95).
  670. */
  671. /* block */
  672. {
  673. char rgchTmp[cchWinExecLineMax];
  674. wsprintf(rgchTmp, rgchCmdLine, (LPSTR)rgchSrcDir,
  675. lpszCmdParam);
  676. Assert(lstrlen(rgchTmp) + lstrlen(rgchDstDir) + 1 < cchWinExecLineMax);
  677. lstrcpy(rgchWinExecLine, rgchDstDir);
  678. lstrcat(rgchWinExecLine, "\\");
  679. lstrcat(rgchWinExecLine, rgchTmp);
  680. }
  681. GlobalCompact((DWORD)(64L * 1024L));
  682. fCleanupTemp = TRUE;
  683. if (!fWin31 && !FNotifyAcme())
  684. {
  685. #if DEBUG
  686. DispErrBrc(brcRegDb, TRUE, MB_OK | MB_ICONEXCLAMATION, NULL, NULL, NULL);
  687. #endif /* DEBUG */
  688. /* Try running Acme anyway. */
  689. }
  690. if (!fWin31 && !FWriteToRestartFile(rgchDstDir))
  691. {
  692. #ifdef DEBUG
  693. MessageBox(NULL, "Write to restart file failed. Setup can continue, "
  694. "but some initialization files might not get removed "
  695. "if Setup must restart Windows.",
  696. szDebugMsg, MB_OK | MB_ICONEXCLAMATION);
  697. #endif /* DEBUG */
  698. /*
  699. * Any errors encountered will have been displayed where they occured.
  700. * Try running Acme anyway.
  701. */
  702. }
  703. if (hWndBkg)
  704. SendMessage(hWndBkg, WM_COMMAND, IDM_ACME_STARTING, 0);
  705. if (!FExecAndWait(rgchWinExecLine, hwndBoot))
  706. {
  707. DispErrBrc(brcMem, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  708. goto LCleanupAndExit;
  709. }
  710. fExeced = fTrue;
  711. LCleanupAndExit:
  712. if (fCleanupTemp && szDstDirSlash != szNull)
  713. CleanUpTempDir(rgchDstDir, szDstDirSlash);
  714. FreeFileLists();
  715. eelExitErrorLevel = eelBootstrapperFailed;
  716. if (fExeced && !FGetAcmeErrorLevel(&eelExitErrorLevel))
  717. {
  718. #ifdef UNUSED
  719. /* NOTE: Removed to avoid the message on WinNT. On NT, Acme can
  720. * exit and the bootstrapper can kick in before the restart
  721. * actually happens, causing this message (since Acme has already
  722. * removed the reg key as part of its reboot cleanup). We'll
  723. * leave the eelFailed value, though, since no one should be
  724. * relying on it at reboot anyway, and it may help catch other
  725. * problems down the road.
  726. */
  727. DispErrBrc(brcRegDb, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  728. #endif /* UNUSED */
  729. Assert(eelExitErrorLevel == eelBootstrapperFailed);
  730. }
  731. if (hwndBoot != NULL)
  732. DestroyWindow(hwndBoot);
  733. if (hWndBkg && IsWindow(hWndBkg))
  734. {
  735. SendMessage(hWndBkg, WM_COMMAND, eelExitErrorLevel == eelSuccess ?
  736. IDM_ACME_COMPLETE : IDM_ACME_FAILURE, 0);
  737. if (IsWindow(hWndBkg))
  738. PostMessage(hWndBkg, WM_QUIT, 0, 0);
  739. }
  740. return (eelExitErrorLevel);
  741. }
  742. /*
  743. ** Purpose:
  744. ** Creates and temporary subdirectory at the given path,
  745. ** appends it to the given path, and copies the Setup files
  746. ** into it.
  747. ** Arguments:
  748. ** szModule: Full path to bootstrapper's directory (ANSI chars).
  749. ** rgchDstDir: Full path to destination directory (OEM chars).
  750. ** Returns:
  751. ** One of the following Bootstrapper return codes:
  752. ** brcMem out of memory
  753. ** brcDS out of disk space
  754. ** brcMemDS out of memory or disk space
  755. ** brcFile expected source file missing
  756. ** brcOkay completed without error
  757. **************************************************************************/
  758. BRC BrcInstallFiles ( char * szModule, char * rgchDstDir,
  759. char * szDstDirSlash )
  760. {
  761. BRC brc;
  762. if (LcbFreeDrive(*rgchDstDir - 'A' + 1) < lcbDiskFreeMin)
  763. return (brcDS);
  764. if (!FCreateTempDir(rgchDstDir, szDstDirSlash))
  765. return (brcMemDS);
  766. if ((brc = BrcCopyFiles(szModule, rgchDstDir, szDstDirSlash)) != brcOkay)
  767. {
  768. CleanUpTempDir(rgchDstDir, szDstDirSlash);
  769. return (brc);
  770. }
  771. SetFileAttributes(rgchDstDir, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY);
  772. Assert(szDstDirSlash);
  773. Assert(*szDstDirSlash == '\\');
  774. *szDstDirSlash = '\0';
  775. SetFileAttributes(rgchDstDir, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY);
  776. *szDstDirSlash = '\\';
  777. return (brcOkay);
  778. }
  779. /*
  780. ** Purpose:
  781. ** Removes the temporary files and directory.
  782. ** Arguments:
  783. ** rgchDstDir: Full path to temp directory (OEM chars).
  784. ** Returns:
  785. ** None.
  786. **************************************************************************/
  787. VOID CleanUpTempDir ( char * rgchDstDir, char * szDstDirSlash )
  788. {
  789. char rgchRoot[] = " :\\";
  790. int i;
  791. RemoveFiles(rgchDstDir);
  792. rgchRoot[0] = *rgchDstDir;
  793. _chdir(rgchRoot);
  794. SetFileAttributes(rgchDstDir, FILE_ATTRIBUTE_NORMAL);
  795. /* Try to remove the directory up to cRetryMax times.
  796. */
  797. for (i = 0; i < cRetryMax; i++)
  798. {
  799. if (_rmdir(rgchDstDir) == 0)
  800. break;
  801. }
  802. Assert(szDstDirSlash);
  803. Assert(*szDstDirSlash == '\\');
  804. *szDstDirSlash = '\0';
  805. SetFileAttributes(rgchDstDir, FILE_ATTRIBUTE_NORMAL);
  806. /* Try to remove the directory up to cRetryMax times.
  807. */
  808. for (i = 0; i < cRetryMax; i++)
  809. {
  810. if (_rmdir(rgchDstDir) == 0)
  811. break;
  812. }
  813. *szDstDirSlash = '\\';
  814. }
  815. /*
  816. ** Purpose:
  817. ** Creates a temporary subdirectory at the given path,
  818. ** and appends it to the given path.
  819. ** Arguments:
  820. ** rgchDir: Full path to destination directory (OEM chars).
  821. ** Returns:
  822. ** TRUE if directory was successfully created,
  823. ** FALSE if not.
  824. **************************************************************************/
  825. BOOL FCreateTempDir ( char * rgchDir, char * szDstDirSlash )
  826. {
  827. char rgchTmp[cchFullPathMax];
  828. FILE * fp;
  829. char * pch;
  830. int fErr;
  831. int i = 0;
  832. pch = (char *)(&rgchDir[lstrlen(rgchDir)]);
  833. Assert(*pch == '\0');
  834. _chdrive(*rgchDir - 'A' + 1);
  835. Assert(szDstDirSlash);
  836. Assert(*szDstDirSlash == '\\');
  837. *szDstDirSlash = '\0';
  838. _mkdir(rgchDir);
  839. *szDstDirSlash = '\\';
  840. while (!_access(rgchDir, 0))
  841. {
  842. if (!_chdir(rgchDir))
  843. {
  844. /* verify dir is write-able */
  845. lstrcpy(rgchTmp, rgchDir);
  846. lstrcat(rgchTmp, "\\tXXXXXX");
  847. Assert(lstrlen(rgchTmp) < cchFullPathMax);
  848. if (_mktemp(rgchTmp) != NULL
  849. && (fp = fopen(rgchTmp, "w")) != NULL)
  850. {
  851. fErr = fclose(fp);
  852. Assert(!fErr);
  853. fErr = remove(rgchTmp);
  854. #ifdef DBCS // [J2] Fixed DBCS raid #28.
  855. if (fErr) // Keep the directory name
  856. *pch = '\0';
  857. #else
  858. *pch = '\0';
  859. #endif
  860. return (!fErr);
  861. }
  862. }
  863. if (++i > 9)
  864. break;
  865. _itoa(i, pch, 10);
  866. Assert(lstrlen(rgchDir) < cchFullPathMax);
  867. }
  868. if (i <= 9 && !_mkdir(rgchDir))
  869. {
  870. fErr = _chdir(rgchDir);
  871. Assert(!fErr);
  872. #ifdef DBCS // [J2] Fixed DBCS raid #28.
  873. // Keep the directory name
  874. #else
  875. *pch = '\0';
  876. #endif
  877. return (TRUE);
  878. }
  879. *pch = '\0';
  880. return (FALSE);
  881. }
  882. /*
  883. ** Purpose:
  884. ** Reopens BAT file and writes DEL or RMDIR line.
  885. ** Arguments:
  886. ** of: OFSTRUCT to REOPEN.
  887. ** szCmd: Command (ANSI chars). ["DEL" or "RMDIR"]
  888. ** szArg: Fully qualified pathname for argument (OEM chars).
  889. ** Returns:
  890. ** TRUE or FALSE.
  891. **************************************************************************/
  892. BOOL FWriteBatFile ( OFSTRUCT of, char * szCmd, char * szArg )
  893. {
  894. int fhBat = -1;
  895. BOOL fRet = TRUE;
  896. if ((fhBat = OpenFile("a", &of, OF_REOPEN | OF_WRITE)) == -1
  897. || _llseek(fhBat, 0L, 2) == -1L
  898. || _lwrite(fhBat, szCmd, lstrlen(szCmd)) != (UINT)lstrlen(szCmd)
  899. || _lwrite(fhBat, (LPSTR)" ", 1) != 1
  900. || _lwrite(fhBat, szArg, lstrlen(szArg)) != (UINT)lstrlen(szArg)
  901. || _lwrite(fhBat, (LPSTR)"\r\n", 2) != 2)
  902. {
  903. fRet = FALSE;
  904. }
  905. if (fhBat != -1)
  906. {
  907. int fErr = _lclose(fhBat);
  908. Assert(fErr != -1);
  909. }
  910. return (fRet);
  911. }
  912. #ifdef DEBUG
  913. /*
  914. ** Purpose:
  915. ** Checks if destination filename is a valid 8.3 name with no path
  916. */
  917. BOOL FValidFATFileName ( char* szName )
  918. {
  919. int iLen, ch;
  920. for (iLen = 0; (ch = *szName++) != '\0'; iLen++)
  921. {
  922. if (ch <= ' ' || ch == '\\' || ch == ':' || ch == ',')
  923. return fFalse;
  924. if (ch == '.')
  925. {
  926. if (iLen == 0 || iLen > 8)
  927. return fFalse;
  928. iLen = 9;
  929. }
  930. if (iLen == 8 || iLen == 13)
  931. return fFalse;
  932. }
  933. return (iLen > 0);
  934. }
  935. #endif /* DEBUG */
  936. /*
  937. ** Purpose:
  938. ** Copies the source files into the given destination dir.
  939. ** Arguments:
  940. ** szModule: Source path (ANSI chars).
  941. ** szDstDir: Destination path (OEM chars).
  942. ** Returns:
  943. ** One of the following bootstrapper return codes:
  944. ** brcMem out of memory
  945. ** brcDS out of disk space
  946. ** brcMemDS out of memory or disk space
  947. ** brcFile expected source file missing
  948. ** brcOkay completed without error
  949. **************************************************************************/
  950. BRC BrcCopyFiles ( char * szModule, char * szDstDir, char * szDstDirSlash )
  951. {
  952. char rgchSrcFullPath[cchFullPathMax];
  953. char rgchDstFullPath[cchFullPathMax];
  954. char rgchTmpDirPath[cchFullPathMax];
  955. char * szSrc;
  956. char * szDst;
  957. int cbSrc;
  958. BRC brc = brcOkay;
  959. int fhBat = -1;
  960. OFSTRUCT ofBat;
  961. int fErr;
  962. BOOL fCabinetFiles = FALSE;
  963. lstrcpy(rgchDstFullPath, szDstDir);
  964. lstrcat(rgchDstFullPath, "\\_MSSETUP._Q_");
  965. Assert(lstrlen(rgchDstFullPath) < cchFullPathMax);
  966. _chmod(rgchDstFullPath, S_IREAD | S_IWRITE);
  967. remove(rgchDstFullPath);
  968. OemToAnsiBuff(rgchDstFullPath, rgchDstFullPath, sizeof(rgchDstFullPath));
  969. fhBat = OpenFile(rgchDstFullPath, &ofBat, OF_CREATE | OF_WRITE);
  970. AnsiToOem(rgchDstFullPath, rgchDstFullPath);
  971. if (fhBat == -1)
  972. return (brcMemDS);
  973. fErr = _lclose(fhBat);
  974. Assert(!fErr);
  975. szSrc = (char *)LocalLock(hSrcLst);
  976. if (szSrc == NULL)
  977. return (brcMem);
  978. szDst = (char *)LocalLock(hDstLst);
  979. if (szDst == NULL) {
  980. LocalUnlock (hSrcLst);
  981. return (brcMem);
  982. }
  983. for (;
  984. (cbSrc = lstrlen(szSrc)) != 0;
  985. szSrc += cbSrc + 1, szDst += lstrlen(szDst) + 1)
  986. {
  987. //
  988. // This code has been added so that we can detect a path
  989. // in setup.lst for the right hand side of the equals sign. This
  990. // allows us flexiblity in specifying where files like setup.inf
  991. // should be pulled from, otherwise we always use the files from
  992. // the original source location. If we detect "<anything>:\" or
  993. // "\\" then we assume it is a path.
  994. //
  995. if( ((':' == szSrc[1]) && ('\\' == szSrc[2])) ||
  996. (('\\' == szSrc[0]) && ('\\' == szSrc[1])) )
  997. {
  998. rgchSrcFullPath[0] = '\0';
  999. }
  1000. else
  1001. {
  1002. lstrcpy(rgchSrcFullPath, szModule);
  1003. }
  1004. lstrcat(rgchSrcFullPath, szSrc);
  1005. lstrcpy(rgchDstFullPath, szDstDir);
  1006. lstrcat(rgchDstFullPath, "\\");
  1007. lstrcat(rgchDstFullPath, szDst);
  1008. #ifdef DEBUG
  1009. if (!FValidFATFileName(szDst))
  1010. {
  1011. wsprintf(szDebugBuf, "Invalid destination file, must be 8.3: %s",
  1012. szDst);
  1013. MessageBox(NULL, szDebugBuf, szDebugMsg, MB_OK | MB_ICONSTOP);
  1014. continue;
  1015. }
  1016. #endif /* DEBUG */
  1017. Assert(lstrlen(rgchSrcFullPath) < cchFullPathMax);
  1018. Assert(lstrlen(rgchDstFullPath) < cchFullPathMax);
  1019. if ( !FWriteBatFile(ofBat, "ATTRIB -R", rgchDstFullPath)
  1020. || !FWriteBatFile(ofBat, "DEL", rgchDstFullPath))
  1021. {
  1022. brc = brcDS;
  1023. break;
  1024. }
  1025. if (*szSrc == '@') /* cabinet file */
  1026. {
  1027. if (*rgchCabinetFName == '\0')
  1028. {
  1029. brc = brcFile;
  1030. #ifdef DEBUG
  1031. lstrcpy(rgchErrorFile, ". Missing CABINET= line");
  1032. #endif //DEBUG
  1033. break;
  1034. }
  1035. fCabinetFiles = TRUE;
  1036. continue;
  1037. }
  1038. if ((brc = BrcCopy(rgchSrcFullPath, rgchDstFullPath)) != brcOkay)
  1039. break;
  1040. _chmod(rgchDstFullPath, S_IREAD);
  1041. }
  1042. LocalUnlock(hSrcLst);
  1043. LocalUnlock(hDstLst);
  1044. lstrcpy(rgchDstFullPath, szDstDir);
  1045. lstrcat(rgchDstFullPath, "\\_MSSETUP._Q_");
  1046. Assert(lstrlen(rgchDstFullPath) < cchFullPathMax);
  1047. Assert(szDstDirSlash != szNull);
  1048. Assert(*szDstDirSlash == chDirSep);
  1049. *szDstDirSlash = chEos;
  1050. lstrcpy(rgchTmpDirPath, szDstDir);
  1051. *szDstDirSlash = chDirSep;
  1052. if (brc == brcOkay
  1053. && (!FWriteBatFile(ofBat, "DEL", rgchDstFullPath)
  1054. || !FWriteBatFile(ofBat, "RMDIR", szDstDir)
  1055. || !FWriteBatFile(ofBat, "RMDIR", rgchTmpDirPath)))
  1056. {
  1057. return (brcDS);
  1058. }
  1059. if (fCabinetFiles && brc == brcOkay)
  1060. {
  1061. szSrc = (char *)LocalLock(hSrcLst);
  1062. if(szSrc == NULL)
  1063. return (brcMem);
  1064. szDst = (char *)LocalLock(hDstLst);
  1065. if( szDst == NULL) {
  1066. LocalUnlock (hSrcLst);
  1067. return (brcMem);
  1068. }
  1069. #ifdef DEBUG
  1070. if (!FValidFATFileName(rgchCabinetFName))
  1071. {
  1072. wsprintf(szDebugBuf, "Invalid cabinet file, must be 8.3: %s",
  1073. rgchCabinetFName);
  1074. MessageBox(NULL, szDebugBuf, szDebugMsg, MB_OK | MB_ICONSTOP);
  1075. }
  1076. else
  1077. #endif /* DEBUG */
  1078. brc = BrcHandleCabinetFiles(hwndBoot, rgchCabinetFName,
  1079. cFirstCabinetNum, cLastCabinetNum, szModule, szDstDir,
  1080. szSrc, szDst, rgchErrorFile, rgchDstFullPath);
  1081. LocalUnlock(hSrcLst);
  1082. LocalUnlock(hDstLst);
  1083. }
  1084. return (brc);
  1085. }
  1086. /*
  1087. ** Purpose:
  1088. ** Removes the files previously copied to the temp dest dir.
  1089. ** Arguments:
  1090. ** szDstDir: full path to destination directory (OEM chars).
  1091. ** Returns:
  1092. ** None.
  1093. **************************************************************************/
  1094. VOID RemoveFiles ( char * szDstDir )
  1095. {
  1096. char rgchDstFullPath[cchFullPathMax];
  1097. char * szDst;
  1098. int cbDst;
  1099. int i;
  1100. OFSTRUCT ofs;
  1101. UINT fModeSav;
  1102. fModeSav = SetErrorMode(fNoErrMes);
  1103. szDst = (char *)LocalLock(hDstLst);
  1104. if (szDst == NULL)
  1105. return;
  1106. for (; (cbDst = lstrlen(szDst)) != 0; szDst += cbDst + 1)
  1107. {
  1108. lstrcpy(rgchDstFullPath, szDstDir);
  1109. lstrcat(rgchDstFullPath, "\\");
  1110. lstrcat(rgchDstFullPath, szDst);
  1111. Assert(lstrlen(rgchDstFullPath) < cchFullPathMax);
  1112. /* Don't try to remove the file if it doesn't exist */
  1113. if (OpenFile(rgchDstFullPath, &ofs, OF_EXIST) == HFILE_ERROR)
  1114. continue;
  1115. /* Try to _chmod the file up to cRetryMax times.
  1116. */
  1117. for (i = 0; i < cRetryMax; i++)
  1118. {
  1119. if (_chmod(rgchDstFullPath, S_IWRITE) == 0)
  1120. break;
  1121. FYield();
  1122. }
  1123. /* Try to remove the file up to cRetryMax times.
  1124. */
  1125. for (i = 0; i < cRetryMax; i++)
  1126. {
  1127. if (remove(rgchDstFullPath) == 0)
  1128. break;
  1129. FYield();
  1130. }
  1131. }
  1132. LocalUnlock(hDstLst);
  1133. SetErrorMode(fModeSav);
  1134. lstrcpy(rgchDstFullPath, szDstDir);
  1135. lstrcat(rgchDstFullPath, "\\_MSSETUP._Q_");
  1136. Assert(lstrlen(rgchDstFullPath) < cchFullPathMax);
  1137. _chmod(rgchDstFullPath, S_IWRITE);
  1138. remove(rgchDstFullPath);
  1139. }
  1140. /*
  1141. ** Purpose:
  1142. ** Copies the given source file to the given destination.
  1143. ** Arguments:
  1144. ** szFullPathSrc: full path name of source file (ANSI chars).
  1145. ** szFullPathDst: full path name of destination file (OEM chars).
  1146. ** Returns:
  1147. ** One of the following bootstrapper return codes:
  1148. ** brcMem out of memory
  1149. ** brcDS out of disk space
  1150. ** brcMemDS out of memory or disk space
  1151. ** brcFile expected source file missing
  1152. ** brcOkay completed without error
  1153. **************************************************************************/
  1154. BRC BrcCopy ( char * szFullPathSrc, char * szFullPathDst )
  1155. {
  1156. int fhSrc = -1;
  1157. int fhDst = -1;
  1158. OFSTRUCT ofSrc, ofDst;
  1159. BRC brc = brcMemDS;
  1160. int fErr;
  1161. #ifdef APPCOMP
  1162. if ((fhSrc = OpenFile(szFullPathSrc, &ofSrc, OF_READ)) == -1)
  1163. {
  1164. brc = brcFile;
  1165. lstrcpy(rgchErrorFile, szFullPathSrc);
  1166. goto CopyFailed;
  1167. }
  1168. #endif /* APPCOMP */
  1169. /* REVIEW: BUG: if szFullPathDst is an existing subdirectory
  1170. ** instead of a file, we'll fail trying to open it, think we're
  1171. ** out of disk space, and go back up to try another disk.
  1172. ** This is acceptable for now.
  1173. */
  1174. _chmod(szFullPathDst, S_IREAD | S_IWRITE);
  1175. OemToAnsiBuff(szFullPathDst, szFullPathDst, cchFullPathMax);
  1176. fhDst = OpenFile(szFullPathDst, &ofDst, OF_CREATE | OF_WRITE);
  1177. AnsiToOem(szFullPathDst, szFullPathDst);
  1178. if (fhDst == -1)
  1179. goto CopyFailed;
  1180. #ifdef APPCOMP
  1181. if (WReadHeaderInfo(fhSrc) > 0)
  1182. {
  1183. LONG lRet;
  1184. lRet = LcbDecompFile(fhSrc, fhDst, -1, 0, TRUE, NULL, 0L, NULL, 0,
  1185. NULL);
  1186. if (lRet < 0L)
  1187. {
  1188. if (lRet == (LONG)rcOutOfMemory)
  1189. brc = brcMem;
  1190. if (lRet == (LONG)rcWriteError)
  1191. brc = brcDS;
  1192. goto CopyFailed;
  1193. }
  1194. FFreeHeaderInfo();
  1195. }
  1196. else /* copy the file using LZExpand */
  1197. #endif /* APPCOMP */
  1198. {
  1199. HFILE hSrcLZ;
  1200. DWORD dwRet;
  1201. #ifdef APPCOMP
  1202. fErr = _lclose(fhSrc);
  1203. Assert(!fErr);
  1204. fhSrc = -1;
  1205. #endif /* APPCOMP */
  1206. if ((hSrcLZ = LZOpenFile(szFullPathSrc, &ofSrc, OF_READ)) == -1)
  1207. {
  1208. brc = brcFile;
  1209. lstrcpy(rgchErrorFile, szFullPathSrc);
  1210. goto CopyFailed;
  1211. }
  1212. /* We would like to yield more often, but LZCopy has no callbacks */
  1213. FYield();
  1214. dwRet = LZCopy(hSrcLZ, fhDst);
  1215. LZClose(hSrcLZ);
  1216. if (dwRet >= LZERROR_UNKNOWNALG)
  1217. {
  1218. if (dwRet == LZERROR_GLOBALLOC)
  1219. brc = brcMem;
  1220. if (dwRet == LZERROR_WRITE)
  1221. brc = brcDS;
  1222. goto CopyFailed;
  1223. }
  1224. }
  1225. brc = brcOkay;
  1226. CopyFailed:
  1227. #ifdef APPCOMP
  1228. if (fhSrc != -1)
  1229. {
  1230. fErr = _lclose(fhSrc);
  1231. Assert(!fErr);
  1232. }
  1233. #endif /* APPCOMP */
  1234. if (fhDst != -1)
  1235. {
  1236. fErr = _lclose(fhDst);
  1237. Assert(!fErr);
  1238. }
  1239. return (brc);
  1240. }
  1241. /*
  1242. ** Purpose:
  1243. ** Determine the storage space remaining on disk.
  1244. ** Arguments:
  1245. ** nDrive: drive number (1='A', 2='B', etc.)
  1246. ** Returns:
  1247. ** Number of bytes free on disk,
  1248. ** or 0 if not a valid drive.
  1249. +++
  1250. ** Implementation:
  1251. ** Calls DOS interrupt 21h, funct 36h.
  1252. **************************************************************************/
  1253. LONG LcbFreeDrive ( int nDrive )
  1254. {
  1255. LONG lcbRet;
  1256. CHAR achRoot[4];
  1257. ULARGE_INTEGER freeBytes;
  1258. achRoot[0] = 'A'+nDrive-1;
  1259. achRoot[1] = ':';
  1260. achRoot[2] = '\\';
  1261. achRoot[3] = 0;
  1262. memset(&freeBytes, 0, sizeof(freeBytes));
  1263. GetDiskFreeSpaceEx(achRoot, &freeBytes, 0, 0);
  1264. lcbRet = freeBytes.LowPart;
  1265. /* KLUDGE: Drives bigger than 2 GB can return zero total space!
  1266. */
  1267. if (lcbRet < 0L || lcbRet > (999999L * 1024L))
  1268. {
  1269. return (999999L * 1024L);
  1270. }
  1271. return (lcbRet);
  1272. }
  1273. /*
  1274. ** Purpose:
  1275. ** Creates and displays bootstrapper window.
  1276. ** Arguments:
  1277. ** hInstance: process instance handle
  1278. ** Returns:
  1279. ** Window handle to bootstrapper window, or
  1280. ** NULL if the window could not be created.
  1281. **************************************************************************/
  1282. HWND HwndInitBootWnd ( HANDLE hInstance )
  1283. {
  1284. WNDCLASS wc;
  1285. HWND hwnd;
  1286. int cx, cy;
  1287. wc.style = 0;
  1288. wc.lpfnWndProc = BootWndProc;
  1289. wc.cbClsExtra = 0;
  1290. wc.cbWndExtra = 0;
  1291. wc.hInstance = hInstance;
  1292. wc.hIcon = NULL;
  1293. wc.hCursor = NULL;
  1294. wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  1295. wc.lpszMenuName = NULL;
  1296. wc.lpszClassName = szBootClass;
  1297. if (!RegisterClass(&wc))
  1298. return (NULL);
  1299. cx = GetSystemMetrics(SM_CXSCREEN) / 2;
  1300. cy = GetSystemMetrics(SM_CYSCREEN) / 3;
  1301. hwnd = CreateWindow(szBootClass, rgchBootTitle,
  1302. WS_DLGFRAME, cx / 2, cy, cx, cy, NULL, NULL, hInstance, NULL);
  1303. if (hwnd == NULL)
  1304. return (NULL);
  1305. if (!fQuietMode)
  1306. {
  1307. ShowWindow(hwnd, SW_SHOWNORMAL);
  1308. UpdateWindow(hwnd);
  1309. }
  1310. return (hwnd);
  1311. }
  1312. // ripped off from mvdm\wow32\wgtext.c
  1313. ULONG GetTextExtent(HDC hdc, LPSTR lpstr, int cbString)
  1314. {
  1315. ULONG ul = 0;
  1316. SIZE size4;
  1317. if ((GetTextExtentPoint(
  1318. hdc,
  1319. lpstr,
  1320. cbString,
  1321. &size4
  1322. )))
  1323. {
  1324. // check if either cx or cy are bigger than SHRT_MAX == 7fff
  1325. // but do it in ONE SINGLE check
  1326. if ((size4.cx | size4.cy) & ~SHRT_MAX)
  1327. {
  1328. if (size4.cx > SHRT_MAX)
  1329. ul = SHRT_MAX;
  1330. else
  1331. ul = (ULONG)size4.cx;
  1332. if (size4.cy > SHRT_MAX)
  1333. ul |= (SHRT_MAX << 16);
  1334. else
  1335. ul |= (ULONG)(size4.cy << 16);
  1336. }
  1337. else
  1338. {
  1339. ul = (ULONG)(size4.cx | (size4.cy << 16));
  1340. }
  1341. }
  1342. return (ul);
  1343. }
  1344. /*
  1345. ** Purpose:
  1346. ** WndProc for bootstrapper window.
  1347. ** Arguments:
  1348. ** Standard Windows WndProc arguments.
  1349. ** Returns:
  1350. ** Result of call DefWindowProc, or zero if WM_PAINT message.
  1351. **************************************************************************/
  1352. LRESULT CALLBACK BootWndProc ( HWND hwnd, UINT wMsgID, WPARAM wParam,
  1353. LPARAM lParam )
  1354. {
  1355. HDC hdc;
  1356. PAINTSTRUCT ps;
  1357. RECT rect;
  1358. UINT iMargin;
  1359. switch (wMsgID)
  1360. {
  1361. #ifdef DBCS // [J3] Fixed KK raid #12.
  1362. case WM_CREATE:
  1363. {
  1364. if (!fQuietMode)
  1365. {
  1366. int x, y, cx, cy;
  1367. hdc = BeginPaint(hwnd, &ps);
  1368. GetClientRect(hwnd, &rect);
  1369. cx = (LOWORD(GetTextExtent(hdc, rgchBootMess, lstrlen(rgchBootMess))) + 13) / 14 * 16 + 2;
  1370. if (cx > rect.right)
  1371. {
  1372. if (cx > GetSystemMetrics(SM_CXSCREEN))
  1373. cx = GetSystemMetrics(SM_CXSCREEN);
  1374. x = (GetSystemMetrics(SM_CXSCREEN) - cx) / 2;
  1375. y = cy = GetSystemMetrics(SM_CYSCREEN) / 3;
  1376. SetWindowPos(hwnd, NULL, x, y, cx, cy, SWP_NOZORDER);
  1377. }
  1378. EndPaint(hwnd, &ps);
  1379. }
  1380. break;
  1381. }
  1382. #endif
  1383. case WM_PAINT:
  1384. if (!fQuietMode)
  1385. {
  1386. hdc = BeginPaint(hwnd, &ps);
  1387. GetClientRect(hwnd, &rect);
  1388. iMargin = rect.right / 16;
  1389. rect.top = rect.bottom / 2 - GetSystemMetrics(SM_CYCAPTION);
  1390. rect.left = iMargin;
  1391. rect.right -= iMargin;
  1392. SetBkMode(hdc, TRANSPARENT);
  1393. DrawText(hdc, rgchBootMess, -1, &rect,
  1394. DT_WORDBREAK | DT_CENTER | DT_NOPREFIX);
  1395. EndPaint(hwnd, &ps);
  1396. }
  1397. break;
  1398. default:
  1399. return (DefWindowProc(hwnd, wMsgID, wParam, lParam));
  1400. }
  1401. return (0L);
  1402. }
  1403. /*
  1404. ** Purpose:
  1405. ** Get size of file.
  1406. ** Arguments:
  1407. ** szFile: List file name (full path, ANSI).
  1408. ** pcbSize: Pointer to variable to receive file size.
  1409. ** Returns:
  1410. ** FALSE if file found and size >= 64K.
  1411. ** TRUE otherwise.
  1412. **************************************************************************/
  1413. BOOL FGetFileSize ( char * szFile, UINT * pcbSize )
  1414. {
  1415. int fh;
  1416. int fErr;
  1417. LONG lcb;
  1418. *pcbSize = 0;
  1419. if ((fh = _lopen(szFile, OF_READ)) == -1)
  1420. {
  1421. return (TRUE);
  1422. }
  1423. if ((lcb = _llseek(fh, 0L, 2)) > 65535)
  1424. {
  1425. #pragma warning(disable:4127) /* conditional expression is constant */
  1426. Assert(FALSE);
  1427. #pragma warning(default:4127)
  1428. _lclose(fh);
  1429. return (FALSE);
  1430. }
  1431. *pcbSize = (UINT)lcb;
  1432. fErr = _lclose(fh);
  1433. Assert(!fErr);
  1434. return (TRUE);
  1435. }
  1436. /*
  1437. ** Purpose:
  1438. ** Build file Src and Dst lists from LST file.
  1439. ** Arguments:
  1440. ** szFile: List file name (full path, ANSI).
  1441. ** cbFile: Size of list file
  1442. ** Note:
  1443. ** Sets globals: hSrcLst, hDstLst.
  1444. ** Returns:
  1445. ** One of the following Bootstrapper return codes:
  1446. ** brcMem out of memory
  1447. ** brcLst list file is corrupted
  1448. ** brcOkay completed without error
  1449. **************************************************************************/
  1450. BRC BrcBuildFileLists ( char * szFile, UINT cbFile )
  1451. {
  1452. char rgchDst[cchLstLineMax];
  1453. char * szSrc;
  1454. char * szDst;
  1455. char * pchDstStart;
  1456. int cbSrc;
  1457. UINT i;
  1458. HANDLE hTemp;
  1459. /* Build Src List */
  1460. if ((hSrcLst = LocalAlloc(LMEM_MOVEABLE, cbFile)) == NULL)
  1461. return (brcMem);
  1462. szSrc = (char *)LocalLock(hSrcLst);
  1463. if(szSrc == (char *)NULL)
  1464. return (brcMem);
  1465. i = GetPrivateProfileString(szFilesSect, NULL, "", szSrc, cbFile, szFile);
  1466. if (i <= 0)
  1467. {
  1468. LocalUnlock(hSrcLst);
  1469. hSrcLst = LocalFree(hSrcLst);
  1470. Assert(hSrcLst == NULL);
  1471. return (brcLst);
  1472. }
  1473. Assert(i+1 < cbFile);
  1474. szSrc[i++] = '\0'; /* force double zero at end */
  1475. szSrc[i++] = '\0';
  1476. LocalUnlock(hSrcLst);
  1477. hTemp = LocalReAlloc(hSrcLst, i, LMEM_MOVEABLE);
  1478. if(hTemp == NULL)
  1479. return (brcMem);
  1480. hSrcLst = hTemp;
  1481. /* Build Dst List */
  1482. if ((hDstLst = LocalAlloc(LMEM_MOVEABLE, cbFile)) == NULL)
  1483. {
  1484. hSrcLst = LocalFree(hSrcLst);
  1485. Assert(hSrcLst == NULL);
  1486. return (brcMem);
  1487. }
  1488. szSrc = (char *)LocalLock(hSrcLst);
  1489. if (szSrc == (char *)NULL)
  1490. return (brcMem);
  1491. szDst = pchDstStart = (char *)LocalLock(hDstLst);
  1492. if (szDst == (char *)NULL) {
  1493. LocalUnlock (hDstLst);
  1494. return (brcMem);
  1495. }
  1496. for (;
  1497. (cbSrc = lstrlen(szSrc)) != 0;
  1498. szSrc += cbSrc + 1, szDst += lstrlen(szDst) + 1)
  1499. {
  1500. if (GetPrivateProfileString(szFilesSect, szSrc, "", rgchDst,
  1501. cchLstLineMax, szFile) <= 0)
  1502. {
  1503. LocalUnlock(hSrcLst);
  1504. LocalUnlock(hDstLst);
  1505. FreeFileLists();
  1506. return (brcLst);
  1507. }
  1508. AnsiToOem(rgchDst, rgchDst);
  1509. lstrcpy(szDst, rgchDst);
  1510. }
  1511. *szDst = '\0'; /* force double zero at end */
  1512. LocalUnlock(hSrcLst);
  1513. LocalUnlock(hDstLst);
  1514. hTemp = LocalReAlloc(hDstLst, (int)(szDst - pchDstStart) + 1,
  1515. LMEM_MOVEABLE);
  1516. if (hTemp == NULL)
  1517. return (brcMem);
  1518. hDstLst = hTemp;
  1519. return (brcOkay);
  1520. }
  1521. /*
  1522. ** Purpose:
  1523. ** Frees file list buffers with non-NULL handles
  1524. ** and sets them to NULL.
  1525. ** Arguments:
  1526. ** none.
  1527. ** Returns:
  1528. ** none.
  1529. **************************************************************************/
  1530. VOID FreeFileLists ()
  1531. {
  1532. if (hSrcLst != NULL)
  1533. hSrcLst = LocalFree(hSrcLst);
  1534. if (hDstLst != NULL)
  1535. hDstLst = LocalFree(hDstLst);
  1536. Assert(hSrcLst == NULL);
  1537. Assert(hDstLst == NULL);
  1538. }
  1539. /*
  1540. ** Purpose:
  1541. ** Spawns off a process with WinExec and waits for it to complete.
  1542. ** Arguments:
  1543. ** szCmdLn: Line passed to WinExec (cannot have leading spaces).
  1544. ** Returns:
  1545. ** TRUE if successful, FALSE if not.
  1546. +++
  1547. ** Implementation:
  1548. ** GetModuleUsage will RIP under Win 3.0 Debug if module count is
  1549. ** zero (okay to ignore and continue), but the GetModuleHandle
  1550. ** check will catch all zero cases for single instances of the
  1551. ** driver, the usual case. [Under Win 3.1 we will be able to
  1552. ** replace both checks with just an IsTask(hMod) check.]
  1553. **************************************************************************/
  1554. BOOL FExecAndWait ( char * szCmdLn, HWND hwndHide )
  1555. {
  1556. UINT hMod;
  1557. MSG msg;
  1558. Assert(!isspace(*szCmdLn)); /* leading space kills WinExec */
  1559. if ((hMod = WinExec(szCmdLn, SW_SHOWNORMAL)) > 32)
  1560. {
  1561. UINT i;
  1562. UINT_PTR idTimer;
  1563. /* KLUDGE: Give the app some time to create its main window.
  1564. *
  1565. * On newer versions of NT, we were exiting the while loop
  1566. * (below) and cleaning up the temp dir before the app had
  1567. * even put up its window.
  1568. *
  1569. * NOTE: In trials, we only had to retry once, so cRetryMax
  1570. * may be overkill, but it should be pretty rare that this
  1571. * would fail in shipping products anyway.
  1572. */
  1573. for (i = 0; i < cRetryMax; i++)
  1574. {
  1575. if(FindWindow(rgchDrvWinClass, NULL) != NULL)
  1576. break;
  1577. if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  1578. {
  1579. TranslateMessage(&msg);
  1580. DispatchMessage(&msg);
  1581. }
  1582. }
  1583. /* Set the timer to fire every 1/10 of a second. This is
  1584. necessary because we might never return from GetMessage */
  1585. idTimer = SetTimer(NULL, 0, 100, NULL);
  1586. /*
  1587. ** REVIEW - FindWindow() will wait until the LAST setup quits (not
  1588. ** necessarily this setup. If exec'ing a 16-bit app we could
  1589. ** use the old code:
  1590. ** while (GetModuleHandle(rgchDrvModName) && GetModuleUsage(hMod))
  1591. ** but on NT this fails so for 32-bit apps we could attempt to
  1592. ** remove one of the executable files (slow?).
  1593. **
  1594. ** REVIEW - This loop becomes a busy wait under NT, which is bad.
  1595. ** However, it doesn't appear to affect ACME's performance
  1596. ** noticeably.
  1597. */
  1598. while (FindWindow(rgchDrvWinClass, NULL) != NULL)
  1599. {
  1600. if (GetMessage(&msg, NULL, 0, 0))
  1601. {
  1602. TranslateMessage(&msg);
  1603. DispatchMessage(&msg);
  1604. }
  1605. if (msg.message == WM_TIMER && hwndHide != (HWND)NULL)
  1606. {
  1607. ShowWindow(hwndHide, SW_HIDE);
  1608. hwndHide = (HWND)NULL;
  1609. }
  1610. }
  1611. if (idTimer != 0)
  1612. KillTimer(0, idTimer);
  1613. return (TRUE);
  1614. }
  1615. #ifdef DEBUG
  1616. wsprintf(szDebugBuf, "WinExec Error: %d", hMod);
  1617. MessageBox(NULL, szDebugBuf, szDebugMsg, MB_OK | MB_ICONSTOP);
  1618. #endif /* DEBUG */
  1619. return (FALSE);
  1620. }
  1621. /*
  1622. ** Purpose: Processes messages that may be in the queue.
  1623. ** Arguments: none
  1624. ** Returns: none
  1625. **************************************************************************/
  1626. void PUBLIC FYield ( VOID )
  1627. {
  1628. MSG msg;
  1629. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  1630. {
  1631. TranslateMessage(&msg);
  1632. DispatchMessage(&msg);
  1633. }
  1634. }
  1635. /*
  1636. **************************************************************************/
  1637. BOOL FLstSectionExists ( char * szLstFileName, char * szSect )
  1638. {
  1639. return (GetPrivateProfileString(szSect, "CmdLine", "", rgchCmdLine,
  1640. cchLstLineMax, szLstFileName) > 0);
  1641. }
  1642. /*
  1643. **************************************************************************/
  1644. DWORD GetCpuArchitecture ()
  1645. {
  1646. SYSTEM_INFO sysInfo;
  1647. GetSystemInfo(&sysInfo);
  1648. return sysInfo.wProcessorArchitecture;
  1649. }
  1650. static CSZC cszcBootstrapperKey = "MS Setup (ACME)\\Bootstrapper\\Exit Level";
  1651. static CSZC cszcEelRunning = "Running";
  1652. /*
  1653. ** Purpose:
  1654. ** Lets Acme know the bootstrapper launched it. So Acme will let
  1655. ** us know its exit error level.
  1656. ** Arguments:
  1657. ** none.
  1658. ** Returns:
  1659. ** fTrue if successful, fFalse otherwise.
  1660. ** Notes:
  1661. ** REVIEW: Probably should use DDE instead of the Registration
  1662. ** Database.
  1663. **************************************************************************/
  1664. BOOL FNotifyAcme ( VOID )
  1665. {
  1666. if (!FCreateRegKey(cszcBootstrapperKey))
  1667. {
  1668. return (fFalse);
  1669. }
  1670. if (!FCreateRegKeyValue(cszcBootstrapperKey, cszcEelRunning))
  1671. {
  1672. return (fFalse);
  1673. }
  1674. if (!FFlushRegKey())
  1675. {
  1676. return (fFalse);
  1677. }
  1678. return (fTrue);
  1679. }
  1680. /*
  1681. ** Purpose:
  1682. ** Get the exit error level set by Acme and clean up the Registration
  1683. ** Database.
  1684. ** Arguments:
  1685. ** peel: Exit error level (to be set).
  1686. ** Returns:
  1687. ** fTrue if successful, fFalse otherwise.
  1688. **************************************************************************/
  1689. BOOL FGetAcmeErrorLevel ( EEL * peel )
  1690. {
  1691. CHAR rgchValue[cchSzMax];
  1692. if (FGetRegKeyValue(cszcBootstrapperKey, rgchValue, sizeof rgchValue))
  1693. {
  1694. #ifdef DEBUG
  1695. /*
  1696. * Assert(isdigit(rgchValue[0]));
  1697. * Assert(isdigit(rgchValue[1]) || rgchValue[1] == chEos);
  1698. */
  1699. UINT i;
  1700. BOOL fValidValue = fFalse;
  1701. /* Assumes valid values are 1 or 2 digit numbers. */
  1702. for (i = 0; rgchValue[i] != chEos; i++)
  1703. {
  1704. fValidValue = fTrue;
  1705. if (!isdigit(rgchValue[i]) || i > 1)
  1706. {
  1707. fValidValue = fFalse;
  1708. break;
  1709. }
  1710. }
  1711. if (!fValidValue)
  1712. {
  1713. char szBuf[cchSzMax];
  1714. wsprintf(szBuf, "RegKeyValue (%s)", rgchValue);
  1715. MessageBox(NULL, szBuf, "Debug Assertion in FGetAcmeErrorLevel",
  1716. MB_OK | MB_ICONSTOP);
  1717. }
  1718. #endif /* DEBUG */
  1719. *peel = atoi(rgchValue);
  1720. DeleteRegKey(cszcBootstrapperKey);
  1721. return (fTrue);
  1722. }
  1723. else
  1724. {
  1725. if (fWin31)
  1726. {
  1727. *peel = eelSuccess;
  1728. return fTrue;
  1729. }
  1730. return (fFalse);
  1731. }
  1732. }
  1733. /*
  1734. ** Purpose:
  1735. ** Creates a Registration Database key that is a subkey of
  1736. ** cszcBootstrapperKey.
  1737. ****************************************************************************/
  1738. BOOL FCreateRegKey ( CSZC cszcKey )
  1739. {
  1740. HKEY hkey;
  1741. if (RegCreateKey(HKEY_CLASSES_ROOT, cszcKey, &hkey) != ERROR_SUCCESS)
  1742. {
  1743. DispErrBrc(brcRegDb, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  1744. return (fFalse);
  1745. }
  1746. if (RegCloseKey(hkey) != ERROR_SUCCESS)
  1747. {
  1748. DispErrBrc(brcRegDb, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  1749. return (fFalse);
  1750. }
  1751. return (fTrue);
  1752. }
  1753. /*
  1754. ** Purpose:
  1755. ** API to check for the existence of the specified key in
  1756. ** the Registration Database.
  1757. ****************************************************************************/
  1758. BOOL FDoesRegKeyExist ( CSZC cszcKey )
  1759. {
  1760. HKEY hkey;
  1761. if (RegOpenKey(HKEY_CLASSES_ROOT, cszcKey, &hkey) != ERROR_SUCCESS)
  1762. return (fFalse);
  1763. RegCloseKey(hkey);
  1764. return (fTrue);
  1765. }
  1766. /*
  1767. ** Purpose:
  1768. ** Creates a Registration Database key that is a subkey of
  1769. ** HKEY_CLASSES_ROOT and associates a value with the key.
  1770. ****************************************************************************/
  1771. BOOL FCreateRegKeyValue ( CSZC cszcKey, CSZC cszcValue )
  1772. {
  1773. if (RegSetValue(HKEY_CLASSES_ROOT, cszcKey, REG_SZ, cszcValue,
  1774. lstrlen(cszcKey)) != ERROR_SUCCESS)
  1775. {
  1776. DispErrBrc(brcRegDb, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  1777. return (fFalse);
  1778. }
  1779. return (fTrue);
  1780. }
  1781. /*
  1782. ** Purpose:
  1783. ** Determines the value associated with the specified Registration
  1784. ** Database key.
  1785. ****************************************************************************/
  1786. BOOL FGetRegKeyValue ( CSZC cszcKey, SZ szBuf, CB cbBufMax )
  1787. {
  1788. LONG lcb = cbBufMax;
  1789. if (szBuf != szNull && cbBufMax != 0)
  1790. *szBuf = chEos;
  1791. if (!FDoesRegKeyExist(cszcKey))
  1792. return (fFalse);
  1793. if (RegQueryValue(HKEY_CLASSES_ROOT, cszcKey, szBuf, &lcb)
  1794. != ERROR_SUCCESS)
  1795. {
  1796. DispErrBrc(brcRegDb, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  1797. return (fFalse);
  1798. }
  1799. Assert(lcb < cbMaxConst);
  1800. return (fTrue);
  1801. }
  1802. /*
  1803. ** Purpose:
  1804. ** API to remove the specified Registration Database key,
  1805. ** its associated values, and subkeys.
  1806. ****************************************************************************/
  1807. VOID DeleteRegKey ( CSZC cszcKey )
  1808. {
  1809. char rgchKey[cchSzMax], rgchBuffer[cchSzMax];
  1810. char *pch;
  1811. HKEY hKeyT = NULL;
  1812. lstrcpy(rgchKey, cszcKey);
  1813. RegDeleteKey(HKEY_CLASSES_ROOT, rgchKey);
  1814. pch = rgchKey + 1;
  1815. while(pch > rgchKey)
  1816. {
  1817. pch = rgchKey + lstrlen(rgchKey);
  1818. while (pch > rgchKey)
  1819. {
  1820. if (*pch == '\\')
  1821. break;
  1822. pch--;
  1823. }
  1824. if (*pch != '\\')
  1825. break;
  1826. *pch = '\0';
  1827. if (RegOpenKey(HKEY_CLASSES_ROOT, rgchKey, &hKeyT) != ERROR_SUCCESS)
  1828. break;
  1829. if (RegEnumKey(hKeyT, 0, rgchBuffer, sizeof(rgchBuffer)) == ERROR_SUCCESS)
  1830. {
  1831. break;
  1832. }
  1833. RegCloseKey(hKeyT);
  1834. hKeyT = NULL;
  1835. RegDeleteKey(HKEY_CLASSES_ROOT, rgchKey);
  1836. }
  1837. if (hKeyT != NULL)
  1838. RegCloseKey(hKeyT);
  1839. }
  1840. /*
  1841. ** Purpose:
  1842. ** API to flush the specified Registration Database key.
  1843. ****************************************************************************/
  1844. BOOL FFlushRegKey ( VOID )
  1845. {
  1846. /* REVIEW: Does 16 bit code need to flush the RegDb? RegFlushKey is
  1847. 32 bit.
  1848. if (RegFlushKey(HKEY_CLASSES_ROOT)) != ERROR_SUCCESS)
  1849. {
  1850. DispErrBrc(brcRegDb, TRUE, MB_OK | MB_ICONSTOP, NULL, NULL, NULL);
  1851. return (fFalse);
  1852. }
  1853. */
  1854. return (fTrue);
  1855. }
  1856. /*
  1857. ** Purpose:
  1858. ** Write temporary files to restart ini file. So that if Acme reboots,
  1859. ** the files in the temporary directory will be removed. Win95 only.
  1860. ** Arguments:
  1861. ** szTmpDir: Full path to destination directory (OEM chars).
  1862. ** Returns:
  1863. ** fTrue if successful, fFalse otherwise.
  1864. **
  1865. ** REVIEW: The files are removed, but not the temp directories.
  1866. ** There may be a way to do that via the wininit.ini file.
  1867. ** This should be looked into.
  1868. **************************************************************************/
  1869. BOOL FWriteToRestartFile ( SZ szTmpDir )
  1870. {
  1871. char rgchIniFile[_MAX_PATH];
  1872. CB cbFrom;
  1873. CB cbTo;
  1874. HLOCAL hlocalFrom = (HLOCAL)NULL;
  1875. HLOCAL hlocalTo = (HLOCAL)NULL;
  1876. BOOL fRet = fFalse;
  1877. SZ szSection = "rename";
  1878. SZ szKey = "NUL";
  1879. /* This code is not used under NT. */
  1880. if (1)
  1881. {
  1882. return (fTrue);
  1883. }
  1884. if (!FCreateIniFileName(rgchIniFile, sizeof rgchIniFile))
  1885. {
  1886. goto LCleanupAndReturn;
  1887. }
  1888. if (!FGetFileSize(rgchIniFile, &cbFrom))
  1889. {
  1890. goto LCleanupAndReturn;
  1891. }
  1892. if (!FReadIniFile(rgchIniFile, &hlocalFrom, &cbFrom))
  1893. {
  1894. goto LCleanupAndReturn;
  1895. }
  1896. if (!FAllocNewBuf(cbFrom, szTmpDir, szSection, szKey, &hlocalTo, &cbTo))
  1897. {
  1898. goto LCleanupAndReturn;
  1899. }
  1900. if (!FProcessFile(hlocalFrom, hlocalTo, cbTo, szTmpDir, szSection, szKey))
  1901. {
  1902. goto LCleanupAndReturn;
  1903. }
  1904. if (!FWriteIniFile(rgchIniFile, hlocalTo))
  1905. {
  1906. goto LCleanupAndReturn;
  1907. }
  1908. fRet = fTrue;
  1909. LCleanupAndReturn:
  1910. if (hlocalFrom != (HLOCAL)NULL)
  1911. {
  1912. hlocalFrom = LocalFree(hlocalFrom);
  1913. Assert(hlocalFrom == (HLOCAL)NULL);
  1914. }
  1915. if (hlocalTo != (HLOCAL)NULL)
  1916. {
  1917. hlocalTo = LocalFree(hlocalTo);
  1918. Assert(hlocalTo == (HLOCAL)NULL);
  1919. }
  1920. return (fRet);
  1921. }
  1922. /*
  1923. ** Purpose:
  1924. ** Create the restart file name.
  1925. ** Arguments:
  1926. ** szIniFile: Buffer to hold file name.
  1927. ** cbBufMax: Size of buffer.
  1928. ** Returns:
  1929. ** fTrue if successful, fFalse otherwise.
  1930. **************************************************************************/
  1931. BOOL FCreateIniFileName ( SZ szIniFile, CB cbBufMax )
  1932. {
  1933. CB cbWinDir;
  1934. cbWinDir = GetWindowsDirectory((LPSTR)szIniFile, cbBufMax);
  1935. if (cbWinDir == 0)
  1936. {
  1937. #pragma warning(disable:4127) /* conditional expression is constant */
  1938. Assert(fFalse); /* Unusual if this happens. */
  1939. #pragma warning(default:4127)
  1940. return (fFalse);
  1941. }
  1942. Assert(isalpha(*szIniFile));
  1943. Assert(*(szIniFile + 1) == ':');
  1944. if (*(AnsiPrev((LPSTR)szIniFile, (LPSTR)&szIniFile[cbWinDir])) != '\\')
  1945. lstrcat((LPSTR)szIniFile, "\\");
  1946. lstrcat((LPSTR)szIniFile, "wininit.ini");
  1947. Assert((CB)lstrlen(szIniFile) < cbBufMax);
  1948. return (fTrue);
  1949. }
  1950. /*
  1951. ** Purpose:
  1952. ** Read the data from the ini file
  1953. ** Arguments:
  1954. ** szIniFile: Ini file name
  1955. ** phlocal: Pointer to memory handle.
  1956. ** pcbBuf: Pointer to the number of bytes in the buffer.
  1957. ** Returns:
  1958. ** fTrue if successful, fFalse otherwise.
  1959. **************************************************************************/
  1960. BOOL FReadIniFile ( SZ szIniFile, HLOCAL * phlocal, PCB pcbBuf )
  1961. {
  1962. UINT fModeSav;
  1963. HLOCAL hlocal;
  1964. SZ szBuf;
  1965. CB cbBuf;
  1966. BOOL fRet = fFalse;
  1967. Assert(szIniFile != szNull);
  1968. Assert(phlocal != (HLOCAL *)NULL);
  1969. Assert(pcbBuf != pcbNull);
  1970. fModeSav = SetErrorMode(fNoErrMes);
  1971. hlocal = *phlocal;
  1972. cbBuf = *pcbBuf;
  1973. Assert(hlocal == (HLOCAL)NULL);
  1974. if (cbBuf == 0) /* Ini file does not exist or is empty. */
  1975. {
  1976. /* Alloc room for CR, LF, EOS. */
  1977. hlocal = LocalAlloc(LMEM_MOVEABLE, 3);
  1978. if (hlocal == NULL)
  1979. {
  1980. #ifdef DEBUG
  1981. MessageBox(NULL, "Out of memory in FReadIniFile.", szDebugMsg,
  1982. MB_OK | MB_ICONEXCLAMATION);
  1983. #endif /* DEBUG */
  1984. }
  1985. else
  1986. {
  1987. szBuf = (SZ)LocalLock(hlocal);
  1988. if(szBuf == szNull)
  1989. return fFalse;
  1990. *szBuf++ = chCR;
  1991. *szBuf++ = chEol;
  1992. *szBuf = chEos;
  1993. *pcbBuf = 2;
  1994. fRet = fTrue;
  1995. }
  1996. }
  1997. else
  1998. {
  1999. HFILE hfile;
  2000. OFSTRUCT ofs;
  2001. CB cbRead;
  2002. /* Flush cache before calling OpenFile() */
  2003. WritePrivateProfileString(szNull, szNull, szNull, szIniFile);
  2004. hfile = OpenFile(szIniFile, &ofs, OF_READWRITE | OF_SHARE_EXCLUSIVE);
  2005. if (hfile == HFILE_ERROR)
  2006. {
  2007. #ifdef DEBUG
  2008. wsprintf(szDebugBuf, "Can't open file: %s.", szIniFile);
  2009. MessageBox(NULL, szDebugBuf, szDebugMsg,
  2010. MB_OK | MB_ICONEXCLAMATION);
  2011. #endif /* DEBUG */
  2012. goto LCleanupAndReturn;
  2013. }
  2014. hlocal = LocalAlloc(LMEM_MOVEABLE, cbBuf + 1);
  2015. if (hlocal == NULL)
  2016. {
  2017. #ifdef DEBUG
  2018. MessageBox(NULL, "Out of memory in FReadIniFile.", szDebugMsg,
  2019. MB_OK | MB_ICONEXCLAMATION);
  2020. #endif /* DEBUG */
  2021. }
  2022. else
  2023. {
  2024. szBuf = (SZ)LocalLock(hlocal);
  2025. if(szBuf == szNull)
  2026. return fFalse;
  2027. cbRead = (CB)_lread(hfile, szBuf, cbBuf + 1);
  2028. if (cbRead == HFILE_ERROR)
  2029. {
  2030. #ifdef DEBUG
  2031. wsprintf(szDebugBuf, "Can't read file: %s.", szIniFile);
  2032. MessageBox(NULL, szDebugBuf, szDebugMsg,
  2033. MB_OK | MB_ICONEXCLAMATION);
  2034. #endif /* DEBUG */
  2035. }
  2036. else
  2037. {
  2038. Assert(cbRead == cbBuf);
  2039. *(szBuf + cbBuf) = chEos;
  2040. fRet = fTrue;
  2041. }
  2042. }
  2043. hfile = _lclose(hfile);
  2044. Assert(hfile != HFILE_ERROR);
  2045. }
  2046. LCleanupAndReturn:
  2047. if (hlocal != NULL)
  2048. {
  2049. LocalUnlock(hlocal);
  2050. }
  2051. *phlocal = hlocal;
  2052. SetErrorMode(fModeSav);
  2053. return (fRet);
  2054. }
  2055. /*
  2056. ** Purpose:
  2057. ** Allocate buffer for new file.
  2058. ** Arguments:
  2059. ** cbOld: Size of existing file
  2060. ** szTmpDir: Full path to destination directory (OEM chars).
  2061. ** szSection: Ini section name
  2062. ** szKey: Ini key name
  2063. ** phlocal: Pointer to memory handle.
  2064. ** pcbToBuf: Pointer to total size of new buffer.
  2065. ** Returns:
  2066. ** fTrue if successful, fFalse if LocalAlloc failed.
  2067. **************************************************************************/
  2068. BOOL FAllocNewBuf ( CB cbOld, SZ szTmpDir, SZ szSection, SZ szKey,
  2069. HLOCAL * phlocal, PCB pcbToBuf )
  2070. {
  2071. UINT fModeSav;
  2072. SZ szDst;
  2073. CB cbDst;
  2074. CB cbOverhead;
  2075. CB cbNew;
  2076. BOOL fRet = fFalse;
  2077. fModeSav = SetErrorMode(fNoErrMes);
  2078. szDst = (SZ)LocalLock(hDstLst);
  2079. if(szDst == szNull)
  2080. return fFalse;
  2081. /*
  2082. * Added to the old file will be one line per temporary file
  2083. * and (possibly) a section line. cbNew is initialized with
  2084. * the size of the section line, plus enough for the file
  2085. * (_MSSETUP._Q_) which is not in the DstLst.
  2086. *
  2087. * Each line will look like:
  2088. * <szKey>=<szTmpDir>\<szFile><CR><LF>
  2089. */
  2090. cbOverhead = lstrlen(szKey) + 1 + lstrlen(szTmpDir) + 1 + 2;
  2091. cbNew = lstrlen(szSection) + 5 + _MAX_PATH;
  2092. for (; (cbDst = lstrlen(szDst)) != 0; szDst += cbDst + 1)
  2093. {
  2094. cbNew += cbOverhead + cbDst;
  2095. }
  2096. LocalUnlock(hDstLst);
  2097. *pcbToBuf = cbOld + cbNew;
  2098. *phlocal = LocalAlloc(LMEM_MOVEABLE, *pcbToBuf);
  2099. if (*phlocal == NULL)
  2100. {
  2101. #ifdef DEBUG
  2102. MessageBox(NULL, "Out of memory in FAllocNewBuf.", szDebugMsg,
  2103. MB_OK | MB_ICONEXCLAMATION);
  2104. #endif /* DEBUG */
  2105. }
  2106. else
  2107. fRet = fTrue;
  2108. SetErrorMode(fModeSav);
  2109. return (fRet);
  2110. }
  2111. /*
  2112. ** Purpose:
  2113. ** Add the new lines to the ini file.
  2114. ** Arguments:
  2115. ** hlocalFrom: Handle to Src memory.
  2116. ** hlocalTo: Handle to Dst memory.
  2117. ** cbToBuf: Total size of Dst memory.
  2118. ** szTmpDir: Full path to destination directory (OEM chars).
  2119. ** szSection: Ini section name
  2120. ** szKey: Ini key name
  2121. ** Returns:
  2122. ** fTrue if successful, fFalse otherwise.
  2123. **
  2124. ** REVIEW: DBCS writes out different order. See DBCS J6 code and
  2125. ** comments in sysinicm.c.
  2126. **************************************************************************/
  2127. BOOL FProcessFile ( HLOCAL hlocalFrom, HLOCAL hlocalTo, CB cbToBuf,
  2128. SZ szTmpDir, SZ szSection, SZ szKey )
  2129. {
  2130. UINT fModeSav;
  2131. SZ szFromBuf;
  2132. SZ szToBuf;
  2133. SZ szToStart;
  2134. SZ szCur;
  2135. SZ szDst;
  2136. CB cbSect;
  2137. CB cbDst;
  2138. Unused(cbToBuf); /* Used in debug only */
  2139. fModeSav = SetErrorMode(fNoErrMes);
  2140. szFromBuf = (SZ)LocalLock(hlocalFrom);
  2141. if(szFromBuf == szNull)
  2142. return fFalse;
  2143. szToBuf = (SZ)LocalLock(hlocalTo);
  2144. if(szToBuf != szNull) {
  2145. LocalUnlock (hlocalFrom);
  2146. return fFalse;
  2147. }
  2148. szToStart = szToBuf;
  2149. cbSect = lstrlen(szSection);
  2150. for (szCur = szFromBuf; *szCur != chEos; szCur = AnsiNext(szCur))
  2151. {
  2152. if (*szCur == '[' && *((szCur + cbSect + 1)) == ']'
  2153. && _memicmp(szSection, AnsiNext(szCur), cbSect) == 0)
  2154. {
  2155. /* Found section. Copy up to section line. */
  2156. CB cbCopy = (CB)(szCur - szFromBuf);
  2157. memcpy(szToBuf, szFromBuf, cbCopy);
  2158. szToBuf += cbCopy;
  2159. break;
  2160. }
  2161. }
  2162. /* Copy section line. */
  2163. *szToBuf++ = '[';
  2164. memcpy(szToBuf, szSection, cbSect);
  2165. szToBuf += cbSect;
  2166. *szToBuf++ = ']';
  2167. *szToBuf++ = chCR;
  2168. *szToBuf++ = chEol;
  2169. /* Copy new lines. */
  2170. szDst = (SZ)LocalLock(hDstLst);
  2171. if (szDst == szNull) {
  2172. LocalUnlock(hlocalFrom);
  2173. LocalUnlock(hlocalTo);
  2174. return fFalse;
  2175. }
  2176. for (; (cbDst = lstrlen(szDst)) != 0; szDst += cbDst + 1)
  2177. {
  2178. CopyIniLine(szKey, szTmpDir, szDst, &szToBuf);
  2179. }
  2180. LocalUnlock(hDstLst);
  2181. CopyIniLine(szKey, szTmpDir, "_MSSETUP._Q_", &szToBuf);
  2182. /* Copy rest of file. */
  2183. if (*szCur == '[')
  2184. {
  2185. /*
  2186. * Skip section line in From buffer. Allow room for '[', section,
  2187. * ']', CR, LF.
  2188. */
  2189. szCur += cbSect + 4;
  2190. }
  2191. else
  2192. {
  2193. szCur = szFromBuf;
  2194. }
  2195. szToBuf = _memccpy(szToBuf, szCur, chEos, UINT_MAX);
  2196. Assert(szToBuf != szNull);
  2197. Assert((CB)lstrlen(szToStart) < cbToBuf);
  2198. LocalUnlock(hlocalFrom);
  2199. LocalUnlock(hlocalTo);
  2200. SetErrorMode(fModeSav);
  2201. return (fTrue);
  2202. }
  2203. /*
  2204. ** Purpose:
  2205. ** Constructs and copies an ini line to a buffer.
  2206. ** Arguments:
  2207. ** szKey: Ini key name
  2208. ** szTmpDir: Full path to destination directory (OEM chars).
  2209. ** szFile: Name of file in temporary directory.
  2210. ** pszToBuf: Pointer to new buffer.
  2211. ** Returns:
  2212. ** none
  2213. **************************************************************************/
  2214. VOID CopyIniLine ( SZ szKey, SZ szTmpDir, SZ szFile, PSZ pszToBuf )
  2215. {
  2216. char rgchSysIniLine[256];
  2217. CB cbCopy;
  2218. lstrcpy(rgchSysIniLine, szKey);
  2219. lstrcat(rgchSysIniLine, "=");
  2220. lstrcat(rgchSysIniLine, szTmpDir);
  2221. lstrcat(rgchSysIniLine, "\\");
  2222. lstrcat(rgchSysIniLine, szFile);
  2223. Assert(lstrlen(rgchSysIniLine) < sizeof rgchSysIniLine);
  2224. cbCopy = lstrlen(rgchSysIniLine);
  2225. memcpy(*pszToBuf, rgchSysIniLine, cbCopy);
  2226. (*pszToBuf) += cbCopy;
  2227. *(*pszToBuf)++ = chCR;
  2228. *(*pszToBuf)++ = chEol;
  2229. }
  2230. /*
  2231. ** Purpose:
  2232. ** Writes out the new ini file.
  2233. ** Arguments:
  2234. ** szIniFile: Buffer to hold file name.
  2235. ** hlocalTo: Handle to Src memory.
  2236. ** Returns:
  2237. ** fTrue if successful, fFalse otherwise.
  2238. **************************************************************************/
  2239. BOOL FWriteIniFile ( SZ szIniFile, HLOCAL hlocalTo )
  2240. {
  2241. UINT fModeSav;
  2242. SZ szToBuf;
  2243. HFILE hfile;
  2244. OFSTRUCT ofs;
  2245. CB cbWrite;
  2246. BOOL fRet = fFalse;
  2247. fModeSav = SetErrorMode(fNoErrMes);
  2248. szToBuf = (SZ)LocalLock(hlocalTo);
  2249. if(szToBuf == szNull)
  2250. return fFalse;
  2251. hfile = OpenFile(szIniFile, &ofs, OF_CREATE | OF_WRITE);
  2252. if (hfile == HFILE_ERROR)
  2253. {
  2254. #ifdef DEBUG
  2255. wsprintf(szDebugBuf, "Can't open file: %s.", szIniFile);
  2256. MessageBox(NULL, szDebugBuf, szDebugMsg,
  2257. MB_OK | MB_ICONEXCLAMATION);
  2258. #endif /* DEBUG */
  2259. goto LUnlockAndReturn;
  2260. }
  2261. cbWrite = _lwrite(hfile, szToBuf, lstrlen(szToBuf));
  2262. if (cbWrite == HFILE_ERROR)
  2263. {
  2264. #ifdef DEBUG
  2265. wsprintf(szDebugBuf, "Can't write to file: %s.", szIniFile);
  2266. MessageBox(NULL, szDebugBuf, szDebugMsg,
  2267. MB_OK | MB_ICONEXCLAMATION);
  2268. #endif /* DEBUG */
  2269. }
  2270. else
  2271. {
  2272. fRet = fTrue;
  2273. }
  2274. hfile = _lclose(hfile);
  2275. Assert(hfile != HFILE_ERROR);
  2276. LUnlockAndReturn:
  2277. LocalUnlock(hlocalTo);
  2278. SetErrorMode(fModeSav);
  2279. return (fRet);
  2280. }
  2281. CHAR szcStfSrcDir[] = "Source Directory\t";
  2282. #define cchStfSrcDir (sizeof(szcStfSrcDir)-1)
  2283. /* Finds the source directory for the installation, asks the user
  2284. to insert the disk. And returns */
  2285. BRC BrcInsertDisk(CHAR *pchStf, CHAR *pchSrcDrive)
  2286. {
  2287. CHAR rgbBuf[_MAX_PATH];
  2288. BYTE rgbFileBuf[32];
  2289. UINT iFileBuf = sizeof(rgbFileBuf), cFileBuf = sizeof(rgbFileBuf);
  2290. CHAR *pchBuf = rgbBuf;
  2291. CHAR *pchMsg;
  2292. int iStf = 0;
  2293. HFILE hFile;
  2294. BRC brc = brcLst;
  2295. char chDrv;
  2296. BOOL fQuote = FALSE;
  2297. int drvType;
  2298. BOOL fFirst = TRUE;
  2299. BOOL fOpen = FALSE;
  2300. HFILE hFileT;
  2301. BOOL fRenameStf = fFalse;
  2302. if ((hFile = _lopen(pchStf, OF_READ)) == HFILE_ERROR)
  2303. return brcNoStf;
  2304. /* Find the path to the original setup. This is stored in the .stf file on the
  2305. Source Directory line */
  2306. while (pchBuf < rgbBuf + sizeof(rgbBuf))
  2307. {
  2308. BYTE ch;
  2309. if (iFileBuf == cFileBuf)
  2310. {
  2311. if ((cFileBuf = _lread(hFile, rgbFileBuf, sizeof(rgbFileBuf))) == 0)
  2312. goto LDone;
  2313. iFileBuf = 0;
  2314. }
  2315. ch = rgbFileBuf[iFileBuf++];
  2316. if (iStf < cchStfSrcDir)
  2317. {
  2318. if (ch == szcStfSrcDir[iStf])
  2319. iStf++;
  2320. else
  2321. iStf = 0;
  2322. continue;
  2323. }
  2324. if(fQuote)
  2325. fQuote = FALSE;
  2326. else if (ch == '"')
  2327. {
  2328. fQuote = TRUE;
  2329. continue;
  2330. }
  2331. else if (ch == '\x0d' || ch == '\t')
  2332. break;
  2333. *pchBuf++ = (CHAR)ch;
  2334. /* Case of having the last character be a DBCS character */
  2335. if (IsDBCSLeadByte(ch))
  2336. {
  2337. if (iFileBuf == cFileBuf)
  2338. {
  2339. _lread(hFile, &ch, 1);
  2340. *pchBuf++ = (CHAR) ch;
  2341. }
  2342. else
  2343. *pchBuf++ = rgbFileBuf[iFileBuf++];
  2344. }
  2345. }
  2346. LDone:
  2347. *pchBuf = 0;
  2348. if (rgbBuf[0] == 0)
  2349. {
  2350. fRenameStf = fTrue;
  2351. goto LClose;
  2352. }
  2353. chDrv = (char)toupper(rgbBuf[0]);
  2354. if (rgbBuf[1] != ':' || chDrv < 'A' || chDrv > 'Z')
  2355. {
  2356. /* We know this is a network drive - UNC Name */
  2357. drvType = EX_DRIVE_REMOTE;
  2358. Assert(rgbBuf[0] == '\\' && rgbBuf[1] == '\\');
  2359. }
  2360. else
  2361. {
  2362. drvType = GetDriveTypeEx(chDrv - 'A');
  2363. }
  2364. lstrcpy(pchSrcDrive, rgbBuf);
  2365. if (*AnsiPrev(rgbBuf, pchBuf) != '\\')
  2366. {
  2367. *pchBuf++ = '\\';
  2368. *pchBuf = 0;
  2369. }
  2370. lstrcat(rgbBuf, "Setup.ini");
  2371. while (!fOpen)
  2372. {
  2373. switch (drvType)
  2374. {
  2375. case EX_DRIVE_FIXED:
  2376. case EX_DRIVE_REMOTE:
  2377. case EX_DRIVE_RAMDISK:
  2378. case EX_DRIVE_INVALID:
  2379. default:
  2380. if (!fFirst)
  2381. {
  2382. /* We've been here before */
  2383. DispErrBrc(brcConnectToSource, TRUE, MB_OK | MB_ICONSTOP, pchSrcDrive, NULL, NULL);
  2384. brc = brcMax;
  2385. goto LClose;
  2386. }
  2387. /* The setup stuff should be available, change directories and go for it */
  2388. break;
  2389. case EX_DRIVE_FLOPPY:
  2390. case EX_DRIVE_REMOVABLE:
  2391. /* Ask to insert disk */
  2392. pchMsg = rgchInsertDiskMsg;
  2393. goto LAskUser;
  2394. break;
  2395. case EX_DRIVE_CDROM:
  2396. /* Ask to insert their CD */
  2397. pchMsg = rgchInsertCDMsg;
  2398. LAskUser:
  2399. if (fFirst)
  2400. {
  2401. if (DispErrBrc(brcString, FALSE, MB_ICONEXCLAMATION|MB_OKCANCEL,
  2402. pchMsg, NULL, NULL) != IDOK)
  2403. {
  2404. brc = brcUserQuit;
  2405. goto LClose;
  2406. }
  2407. }
  2408. else
  2409. {
  2410. if (DispErrBrc(brcInsCDRom2, FALSE, MB_ICONEXCLAMATION|MB_OKCANCEL,
  2411. rgbBuf, pchMsg, NULL) != IDOK)
  2412. {
  2413. brc = brcUserQuit;
  2414. goto LClose;
  2415. }
  2416. }
  2417. break;
  2418. }
  2419. if ((hFileT = _lopen(rgbBuf, OF_READ)) != HFILE_ERROR)
  2420. {
  2421. _lclose(hFileT);
  2422. fOpen = fTrue;
  2423. }
  2424. fFirst = FALSE;
  2425. }
  2426. brc = brcOkay;
  2427. LClose:
  2428. _lclose(hFile);
  2429. /* If we can't find the source path in the maintenance mode .STF,
  2430. * assume it's corrupted and rename it, so when the user runs again
  2431. * from the source image, we will just run in 'floppy' mode,
  2432. * avoiding the bad .STF file.
  2433. * (NOTE: Assumes /W is only used in maint mode!!)
  2434. */
  2435. if (fRenameStf)
  2436. {
  2437. FRenameBadMaintStf(pchStf);
  2438. brc = brcNoStf;
  2439. }
  2440. return brc;
  2441. }
  2442. /*
  2443. ****************************************************************************/
  2444. BOOL FRenameBadMaintStf ( SZ szStf )
  2445. {
  2446. CHAR rgch[_MAX_FNAME];
  2447. _splitpath(szStf, szNull, szNull, rgch, szNull);
  2448. if (*rgch == '\0')
  2449. lstrcpy(rgch, "stf");
  2450. Assert(lstrlen(rgch) + 4 < sizeof rgch);
  2451. lstrcat(rgch, ".000");
  2452. rename(szStf, rgch);
  2453. /* Remove the original .STF in case the rename failed
  2454. * (probably due to a previously renamed .STF file).
  2455. */
  2456. remove(szStf);
  2457. return (fTrue); /* Always returns true */
  2458. }