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.

5893 lines
188 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. dynupdt.c
  5. Abstract:
  6. The Dynamic Update feature of WINNT32.
  7. Author:
  8. Ovidiu Temereanca (ovidiut) 02-Jul-2000
  9. Revision History:
  10. <alias> <date> <comment>
  11. --*/
  12. #include "precomp.h"
  13. //
  14. // BUGBUG - comment functions
  15. //
  16. #define GUIDRVS_FIELD_CABNAME 1
  17. #define GUIDRVS_FIELD_INFNAME 2
  18. #define GUIDRVS_FIELD_DRIVERVER 3
  19. #define GUIDRVS_FIELD_HARDWAREID 4
  20. #define MAX_UPGCHK_ELAPSED_SECONDS (30 * 60)
  21. PDYNUPDT_STATUS g_DynUpdtStatus;
  22. static WORD g_MapProductTypeToSuite[] = {
  23. 0, // pro
  24. VER_SUITE_SMALLBUSINESS, // srv
  25. VER_SUITE_ENTERPRISE, // ads
  26. VER_SUITE_DATACENTER, // dtc
  27. VER_SUITE_PERSONAL, // per
  28. VER_SUITE_BLADE, // bla
  29. VER_SUITE_SMALLBUSINESS_RESTRICTED, // sbs
  30. };
  31. static BYTE g_MapProductTypeToPT[] = {
  32. VER_NT_WORKSTATION,
  33. VER_NT_SERVER,
  34. VER_NT_SERVER,
  35. VER_NT_SERVER,
  36. VER_NT_WORKSTATION,
  37. VER_NT_SERVER,
  38. VER_NT_SERVER,
  39. };
  40. typedef
  41. BOOL
  42. (*PCOMPLOADFN) (
  43. IN PCTSTR LibraryPath
  44. );
  45. BOOL
  46. DynUpdtDebugLog(
  47. IN Winnt32DebugLevel Level,
  48. IN LPCTSTR Text,
  49. IN UINT MessageId,
  50. ...
  51. )
  52. {
  53. va_list arglist;
  54. BOOL b;
  55. TCHAR bigBuffer[1024];
  56. PCTSTR prefix;
  57. DWORD rc = GetLastError ();
  58. //
  59. // this param is never used momentarily
  60. //
  61. MYASSERT (Text);
  62. if (!Text) {
  63. return FALSE;
  64. }
  65. MYASSERT (!MessageId);
  66. if (Level <= Winnt32LogError) {
  67. prefix = TEXT("DUError");
  68. } else if (Level == Winnt32LogWarning) {
  69. prefix = TEXT("DUWarning");
  70. } else {
  71. prefix = TEXT("DUInfo");
  72. }
  73. _sntprintf (bigBuffer, sizeof (bigBuffer) / sizeof (TCHAR) - 1, TEXT("%s: %s"), prefix, Text);
  74. bigBuffer[sizeof (bigBuffer) / sizeof (TCHAR) - 1] = 0;
  75. va_start(arglist,MessageId);
  76. b = DebugLog2 (Level, bigBuffer, MessageId, arglist);
  77. va_end(arglist);
  78. SetLastError (rc);
  79. return b;
  80. }
  81. BOOL
  82. pDoesFileExist (
  83. IN PCTSTR FilePath
  84. )
  85. {
  86. WIN32_FIND_DATA fd;
  87. return FileExists (FilePath, &fd) && !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
  88. }
  89. BOOL
  90. pDoesDirectoryExist (
  91. IN PCTSTR DirPath
  92. )
  93. {
  94. WIN32_FIND_DATA fd;
  95. return FileExists (DirPath, &fd) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
  96. }
  97. BOOL
  98. pNonemptyFilePresent (
  99. IN PCTSTR FilePath
  100. )
  101. {
  102. WIN32_FIND_DATA fd;
  103. return FileExists (FilePath, &fd) &&
  104. fd.nFileSizeLow > 0 &&
  105. !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
  106. }
  107. BOOL
  108. pGetTargetInfo (
  109. OUT POSVERSIONINFOEX TargetVersion, OPTIONAL
  110. OUT PTSTR TargetPlatform, OPTIONAL
  111. IN DWORD TargetPlatformChars, OPTIONAL
  112. OUT PLCID LocaleID OPTIONAL
  113. )
  114. {
  115. TCHAR buffer[256];
  116. UINT productType;
  117. //
  118. // get some data from the main inf
  119. //
  120. if (!FullInfName[0]) {
  121. if (!FindPathToWinnt32File (InfName, FullInfName, ARRAYSIZE(FullInfName))) {
  122. DynUpdtDebugLog (
  123. Winnt32LogError,
  124. TEXT("pGetTargetInfo: FindPathToWinnt32File failed"),
  125. 0
  126. );
  127. return FALSE;
  128. }
  129. }
  130. if (TargetVersion) {
  131. if (!GetPrivateProfileString (
  132. TEXT("Miscellaneous"),
  133. TEXT("ProductType"),
  134. TEXT(""),
  135. buffer,
  136. ARRAYSIZE(buffer),
  137. FullInfName
  138. )) {
  139. DynUpdtDebugLog (
  140. Winnt32LogError,
  141. TEXT("%1 key in [%2] section is missing from %3; aborting operation"),
  142. 0,
  143. TEXT("ProductType"),
  144. TEXT("Miscellaneous"),
  145. FullInfName
  146. );
  147. return FALSE;
  148. }
  149. productType = _ttoi (buffer);
  150. MYASSERT (ARRAYSIZE(g_MapProductTypeToSuite) == ARRAYSIZE(g_MapProductTypeToPT));
  151. if (productType >= ARRAYSIZE(g_MapProductTypeToPT)) {
  152. DynUpdtDebugLog (
  153. Winnt32LogError,
  154. TEXT("Invalid %1 value (%2) in %3"),
  155. 0,
  156. TEXT("ProductType"),
  157. buffer,
  158. FullInfName
  159. );
  160. return FALSE;
  161. }
  162. if (!GetPrivateProfileString (
  163. TEXT("Miscellaneous"),
  164. TEXT("ServicePack"),
  165. TEXT(""),
  166. buffer,
  167. ARRAYSIZE(buffer),
  168. FullInfName
  169. )) {
  170. DynUpdtDebugLog (
  171. Winnt32LogError,
  172. TEXT("%1 key in [%2] section is missing from %3; aborting operation"),
  173. 0,
  174. TEXT("ServicePack"),
  175. TEXT("Miscellaneous"),
  176. FullInfName
  177. );
  178. return FALSE;
  179. }
  180. if (_stscanf (
  181. buffer,
  182. TEXT("%hu.%hu"),
  183. &TargetVersion->wServicePackMajor,
  184. &TargetVersion->wServicePackMinor
  185. ) != 2) {
  186. DynUpdtDebugLog (
  187. Winnt32LogError,
  188. TEXT("Invalid %1 value (%2) in %3"),
  189. 0,
  190. TEXT("ServicePack"),
  191. buffer,
  192. FullInfName
  193. );
  194. return FALSE;
  195. }
  196. TargetVersion->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  197. TargetVersion->dwMajorVersion = VER_PRODUCTMAJORVERSION;
  198. TargetVersion->dwMinorVersion = VER_PRODUCTMINORVERSION;
  199. TargetVersion->dwBuildNumber = VER_PRODUCTBUILD;
  200. TargetVersion->dwPlatformId = VER_PLATFORM_WIN32_NT;
  201. TargetVersion->wSuiteMask = g_MapProductTypeToSuite[productType];
  202. TargetVersion->wProductType = g_MapProductTypeToPT[productType];
  203. }
  204. if (TargetPlatform) {
  205. if (!GetPrivateProfileString (
  206. TEXT("Miscellaneous"),
  207. TEXT("DestinationPlatform"),
  208. TEXT(""),
  209. TargetPlatform,
  210. TargetPlatformChars,
  211. FullInfName
  212. )) {
  213. DynUpdtDebugLog (
  214. Winnt32LogError,
  215. TEXT("%1 key in [%2] section is missing from %3; aborting operation"),
  216. 0,
  217. TEXT("DestinationPlatform"),
  218. TEXT("Miscellaneous"),
  219. FullInfName
  220. );
  221. return FALSE;
  222. }
  223. }
  224. if (LocaleID) {
  225. MYASSERT (SourceNativeLangID);
  226. *LocaleID = SourceNativeLangID;
  227. }
  228. return TRUE;
  229. }
  230. BOOL
  231. pInitializeSupport (
  232. IN PCTSTR ComponentName,
  233. IN PCOMPLOADFN LoadFn,
  234. IN BOOL UseRegistryReplacement
  235. )
  236. {
  237. TCHAR pathSupportLib[MAX_PATH];
  238. #ifdef PRERELEASE
  239. if (UseRegistryReplacement) {
  240. HKEY key;
  241. DWORD rc;
  242. BOOL b = FALSE;
  243. rc = RegOpenKey (
  244. HKEY_LOCAL_MACHINE,
  245. TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Setup\\Winnt32\\5.1"),
  246. &key
  247. );
  248. if (rc == ERROR_SUCCESS) {
  249. DWORD size = 0;
  250. rc = RegQueryValueEx (key, ComponentName, NULL, NULL, NULL, &size);
  251. if (rc == ERROR_SUCCESS && size > 0) {
  252. PTSTR buf = MALLOC (size);
  253. if (buf) {
  254. rc = RegQueryValueEx (key, ComponentName, NULL, NULL, (LPBYTE)buf, &size);
  255. if (rc == ERROR_SUCCESS && (*LoadFn) (buf)) {
  256. DynUpdtDebugLog (
  257. Winnt32LogInformation,
  258. TEXT("pInitializeSupport: using registry specified replacement file <%1>"),
  259. 0,
  260. buf
  261. );
  262. b = TRUE;
  263. }
  264. FREE (buf);
  265. }
  266. }
  267. RegCloseKey (key);
  268. }
  269. if (b) {
  270. return TRUE;
  271. }
  272. }
  273. #endif
  274. if (FindPathToWinnt32File (ComponentName, pathSupportLib, ARRAYSIZE(pathSupportLib))) {
  275. if ((*LoadFn) (pathSupportLib)) {
  276. return TRUE;
  277. }
  278. }
  279. DynUpdtDebugLog (
  280. Winnt32LogError,
  281. TEXT("pInitializeSupport: %1 could not be loaded or is corrupt"),
  282. 0,
  283. ComponentName
  284. );
  285. return FALSE;
  286. }
  287. BOOL
  288. pLoadHwdbLib (
  289. IN PCTSTR LibraryPath
  290. )
  291. {
  292. DWORD rc;
  293. //
  294. // Use WinVerifyTrust first?
  295. //
  296. g_DynUpdtStatus->HwdbLib = LoadLibraryEx (LibraryPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
  297. if (!g_DynUpdtStatus->HwdbLib) {
  298. return FALSE;
  299. }
  300. g_DynUpdtStatus->HwdbInitialize = (PHWDBINITIALIZE) GetProcAddress (g_DynUpdtStatus->HwdbLib, S_HWDBAPI_HWDBINITIALIZE);
  301. g_DynUpdtStatus->HwdbTerminate = (PHWDBTERMINATE) GetProcAddress (g_DynUpdtStatus->HwdbLib, S_HWDBAPI_HWDBTERMINATE);
  302. g_DynUpdtStatus->HwdbOpen = (PHWDBOPEN) GetProcAddress (g_DynUpdtStatus->HwdbLib, S_HWDBAPI_HWDBOPEN);
  303. g_DynUpdtStatus->HwdbClose = (PHWDBCLOSE) GetProcAddress (g_DynUpdtStatus->HwdbLib, S_HWDBAPI_HWDBCLOSE);
  304. g_DynUpdtStatus->HwdbAppendInfs = (PHWDBAPPENDINFS) GetProcAddress (g_DynUpdtStatus->HwdbLib, S_HWDBAPI_HWDBAPPENDINFS);
  305. g_DynUpdtStatus->HwdbFlush = (PHWDBFLUSH) GetProcAddress (g_DynUpdtStatus->HwdbLib, S_HWDBAPI_HWDBFLUSH);
  306. g_DynUpdtStatus->HwdbHasDriver = (PHWDBHASDRIVER) GetProcAddress (g_DynUpdtStatus->HwdbLib, S_HWDBAPI_HWDBHASDRIVER);
  307. g_DynUpdtStatus->HwdbHasAnyDriver = (PHWDBHASANYDRIVER) GetProcAddress (g_DynUpdtStatus->HwdbLib, S_HWDBAPI_HWDBHASANYDRIVER);
  308. if (!g_DynUpdtStatus->HwdbInitialize ||
  309. !g_DynUpdtStatus->HwdbTerminate ||
  310. !g_DynUpdtStatus->HwdbOpen ||
  311. !g_DynUpdtStatus->HwdbClose ||
  312. !g_DynUpdtStatus->HwdbAppendInfs ||
  313. !g_DynUpdtStatus->HwdbFlush ||
  314. !g_DynUpdtStatus->HwdbHasDriver ||
  315. !g_DynUpdtStatus->HwdbHasAnyDriver
  316. ) {
  317. g_DynUpdtStatus->HwdbInitialize = NULL;
  318. g_DynUpdtStatus->HwdbTerminate = NULL;
  319. g_DynUpdtStatus->HwdbOpen = NULL;
  320. g_DynUpdtStatus->HwdbClose = NULL;
  321. g_DynUpdtStatus->HwdbAppendInfs = NULL;
  322. g_DynUpdtStatus->HwdbFlush = NULL;
  323. g_DynUpdtStatus->HwdbHasDriver = NULL;
  324. g_DynUpdtStatus->HwdbHasAnyDriver = NULL;
  325. rc = GetLastError ();
  326. FreeLibrary (g_DynUpdtStatus->HwdbLib);
  327. g_DynUpdtStatus->HwdbLib = NULL;
  328. SetLastError (rc);
  329. return FALSE;
  330. }
  331. return TRUE;
  332. }
  333. BOOL
  334. pLoadDuLib (
  335. IN PCTSTR LibraryPath
  336. )
  337. {
  338. DWORD rc;
  339. g_DynUpdtStatus->DuLib = LoadLibraryEx (LibraryPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
  340. if (!g_DynUpdtStatus->DuLib) {
  341. return FALSE;
  342. }
  343. g_DynUpdtStatus->DuIsSupported = (PDUISSUPPORTED) GetProcAddress (g_DynUpdtStatus->DuLib, API_DU_ISSUPPORTED);
  344. g_DynUpdtStatus->DuInitialize = (PDUINITIALIZE) GetProcAddress (g_DynUpdtStatus->DuLib, API_DU_INITIALIZE);
  345. g_DynUpdtStatus->DuDoDetection = (PDUDODETECTION) GetProcAddress (g_DynUpdtStatus->DuLib, API_DU_DODETECTION);
  346. g_DynUpdtStatus->DuQueryUnsupDrvs = (PDUQUERYUNSUPDRVS) GetProcAddress (g_DynUpdtStatus->DuLib, API_DU_QUERYUNSUPDRVS);
  347. g_DynUpdtStatus->DuBeginDownload = (PDUBEGINDOWNLOAD) GetProcAddress (g_DynUpdtStatus->DuLib, API_DU_BEGINDOWNLOAD);
  348. g_DynUpdtStatus->DuAbortDownload = (PDUABORTDOWNLOAD) GetProcAddress (g_DynUpdtStatus->DuLib, API_DU_ABORTDOWNLOAD);
  349. g_DynUpdtStatus->DuUninitialize = (PDUUNINITIALIZE) GetProcAddress (g_DynUpdtStatus->DuLib, API_DU_UNINITIALIZE);
  350. if (!g_DynUpdtStatus->DuIsSupported ||
  351. !g_DynUpdtStatus->DuInitialize ||
  352. !g_DynUpdtStatus->DuDoDetection ||
  353. !g_DynUpdtStatus->DuQueryUnsupDrvs ||
  354. !g_DynUpdtStatus->DuBeginDownload ||
  355. !g_DynUpdtStatus->DuAbortDownload ||
  356. !g_DynUpdtStatus->DuUninitialize
  357. ) {
  358. DynUpdtDebugLog (
  359. Winnt32LogError,
  360. TEXT("pLoadDuLib: %1 is missing one or more required entry points"),
  361. 0,
  362. LibraryPath
  363. );
  364. g_DynUpdtStatus->DuIsSupported = NULL;
  365. g_DynUpdtStatus->DuInitialize = NULL;
  366. g_DynUpdtStatus->DuDoDetection = NULL;
  367. g_DynUpdtStatus->DuQueryUnsupDrvs = NULL;
  368. g_DynUpdtStatus->DuBeginDownload = NULL;
  369. g_DynUpdtStatus->DuAbortDownload = NULL;
  370. g_DynUpdtStatus->DuUninitialize = NULL;
  371. rc = GetLastError ();
  372. FreeLibrary (g_DynUpdtStatus->DuLib);
  373. g_DynUpdtStatus->DuLib = NULL;
  374. SetLastError (rc);
  375. return FALSE;
  376. }
  377. return TRUE;
  378. }
  379. #ifndef UNICODE
  380. BOOL
  381. pLoadWin9xDuSupport (
  382. VOID
  383. )
  384. {
  385. if (!UpgradeSupport.DllModuleHandle) {
  386. return FALSE;
  387. }
  388. g_DynUpdtStatus->Win9xGetIncompDrvs = (PWIN9XGETINCOMPDRVS)
  389. GetProcAddress (UpgradeSupport.DllModuleHandle, "Win9xGetIncompDrvs");
  390. g_DynUpdtStatus->Win9xReleaseIncompDrvs = (PWIN9XRELEASEINCOMPDRVS)
  391. GetProcAddress (UpgradeSupport.DllModuleHandle, "Win9xReleaseIncompDrvs");
  392. if (!g_DynUpdtStatus->Win9xGetIncompDrvs) {
  393. DynUpdtDebugLog (
  394. Winnt32LogError,
  395. TEXT("Winnt32DuIsSupported: %1 is missing in the upgrade support module"),
  396. 0,
  397. "Win9xGetIncompDrvs"
  398. );
  399. return FALSE;
  400. }
  401. return TRUE;
  402. }
  403. #endif
  404. BOOL
  405. pInitSupportLibs (
  406. VOID
  407. )
  408. {
  409. return (Winnt32Restarted () || pInitializeSupport (S_DUCTRL_DLL, pLoadDuLib, TRUE)) &&
  410. pInitializeSupport (S_HWDB_DLL, pLoadHwdbLib, FALSE) &&
  411. g_DynUpdtStatus->HwdbInitialize (g_DynUpdtStatus->TempDir);
  412. }
  413. BOOL
  414. pInitNtPnpDb (
  415. IN BOOL AllowRebuild
  416. )
  417. {
  418. TCHAR hwdbPath[MAX_PATH];
  419. BOOL b = TRUE;
  420. if (!FindPathToWinnt32File (S_HWCOMP_DAT, hwdbPath, ARRAYSIZE(hwdbPath))) {
  421. DynUpdtDebugLog (Winnt32LogError, TEXT("pInitNtPnpDb: %1 not found"), 0, S_HWCOMP_DAT);
  422. b = FALSE;
  423. }
  424. MYASSERT (g_DynUpdtStatus->HwdbInitialize);
  425. if (b && !g_DynUpdtStatus->HwdbInitialize (g_DynUpdtStatus->TempDir)) {
  426. DynUpdtDebugLog (Winnt32LogError, TEXT("pInitNtPnpDb: HwdbInitialize(%1) FAILED"), 0, g_DynUpdtStatus->TempDir);
  427. b = FALSE;
  428. }
  429. MYASSERT (g_DynUpdtStatus->HwdbOpen);
  430. if (b) {
  431. g_DynUpdtStatus->HwdbDatabase = g_DynUpdtStatus->HwdbOpen (hwdbPath);
  432. if (!g_DynUpdtStatus->HwdbDatabase) {
  433. DynUpdtDebugLog (Winnt32LogError, TEXT("pInitNtPnpDb: HwdbOpen(%1) FAILED"), 0, hwdbPath);
  434. b = FALSE;
  435. }
  436. }
  437. if (!b && AllowRebuild) {
  438. //
  439. // just rebuild the database in memory
  440. //
  441. g_DynUpdtStatus->HwdbDatabase = g_DynUpdtStatus->HwdbOpen (NULL);
  442. if (g_DynUpdtStatus->HwdbDatabase) {
  443. b = g_DynUpdtStatus->HwdbAppendInfs (g_DynUpdtStatus->HwdbDatabase, NativeSourcePaths[0], NULL, NULL);
  444. if (b) {
  445. DynUpdtDebugLog (Winnt32LogWarning, TEXT("pInitNtPnpDb: PnP database was successfully rebuilt"), 0);
  446. //
  447. // also try to save the database
  448. //
  449. if (g_DynUpdtStatus->HwdbFlush) {
  450. BuildPath (hwdbPath, NativeSourcePaths[0], S_HWCOMP_DAT);
  451. g_DynUpdtStatus->HwdbFlush (g_DynUpdtStatus->HwdbDatabase, hwdbPath);
  452. }
  453. }
  454. }
  455. }
  456. return b;
  457. }
  458. BOOL
  459. IsNetConnectivityAvailable (
  460. VOID
  461. )
  462. {
  463. #ifdef UNICODE
  464. return TRUE;
  465. #else
  466. BOOL (*pfnWin9xAnyNetDevicePresent) (VOID);
  467. if (UpgradeSupport.DllModuleHandle) {
  468. (FARPROC)pfnWin9xAnyNetDevicePresent = GetProcAddress (UpgradeSupport.DllModuleHandle, "Win9xAnyNetDevicePresent");
  469. if (pfnWin9xAnyNetDevicePresent) {
  470. return pfnWin9xAnyNetDevicePresent();
  471. }
  472. }
  473. return TRUE;
  474. #endif
  475. }
  476. BOOL
  477. DynamicUpdateIsSupported (
  478. IN HWND ParentWnd
  479. )
  480. {
  481. DWORD rc;
  482. if (g_DynUpdtStatus->Disabled) {
  483. return FALSE;
  484. }
  485. //
  486. // disable this for DTC
  487. //
  488. if (ProductFlavor == DATACENTER_PRODUCTTYPE) {
  489. return FALSE;
  490. }
  491. if (AnyBlockingCompatibilityItems ()) {
  492. //
  493. // no point in supporting DU; setup will stop anyway
  494. //
  495. return FALSE;
  496. }
  497. CleanUpOldLocalSources (ParentWnd);
  498. if (!InspectFilesystems (ParentWnd)) {
  499. DynUpdtDebugLog (Winnt32LogWarning, TEXT("InspectFilesystems blocks DU"), 0);
  500. return FALSE;
  501. }
  502. if (!EnoughMemory (ParentWnd, TRUE)) {
  503. return FALSE;
  504. }
  505. if (!FindLocalSourceAndCheckSpace (ParentWnd, TRUE, DYN_DISKSPACE_PADDING)) {
  506. DynUpdtDebugLog (Winnt32LogWarning, TEXT("Not enough disk space blocks DU"), 0);
  507. return FALSE;
  508. }
  509. if (!g_DynUpdtStatus->SupportQueried) {
  510. g_DynUpdtStatus->SupportQueried = TRUE;
  511. if (g_DynUpdtStatus->DynamicUpdatesSource[0]) {
  512. g_DynUpdtStatus->SupportPresent = TRUE;
  513. } else {
  514. g_DynUpdtStatus->SupportPresent =
  515. Winnt32DuIsSupported () &&
  516. IsNetConnectivityAvailable ();
  517. if (!g_DynUpdtStatus->SupportPresent) {
  518. rc = GetLastError ();
  519. DynamicUpdateUninitialize ();
  520. SetLastError (rc);
  521. }
  522. }
  523. }
  524. return g_DynUpdtStatus->SupportPresent;
  525. }
  526. BOOL
  527. DynamicUpdateInitDownload (
  528. IN HWND hNotifyWnd
  529. )
  530. {
  531. DYNUPDT_INIT dynUpdtInit;
  532. MYASSERT (!g_DynUpdtStatus->Disabled);
  533. MYASSERT (!Winnt32Restarted ());
  534. MyDelnode (g_DynUpdtStatus->WorkingDir);
  535. BuildPath (g_DynUpdtStatus->TempDir, g_DynUpdtStatus->WorkingDir, S_SUBDIRNAME_TEMP);
  536. if (CreateMultiLevelDirectory (g_DynUpdtStatus->TempDir) != ERROR_SUCCESS) {
  537. DynUpdtDebugLog (
  538. Winnt32LogError,
  539. TEXT("DynamicUpdateInitDownload: CreateMultiLevelDirectory failed"),
  540. 0
  541. );
  542. return FALSE;
  543. }
  544. if (!pGetTargetInfo (
  545. &g_DynUpdtStatus->TargetOsVersion,
  546. NULL,
  547. 0,
  548. &g_DynUpdtStatus->TargetLCID
  549. )) {
  550. return FALSE;
  551. }
  552. dynUpdtInit.TargetOsVersion = &g_DynUpdtStatus->TargetOsVersion;
  553. dynUpdtInit.TargetPlatform = g_DynUpdtStatus->TargetPlatform;
  554. dynUpdtInit.TargetLCID = g_DynUpdtStatus->TargetLCID;
  555. dynUpdtInit.Upgrade = Upgrade;
  556. dynUpdtInit.SourceDirs = info.SourceDirectories;
  557. dynUpdtInit.SourceDirsCount = SourceCount;
  558. dynUpdtInit.Unattend = UnattendSwitchSpecified;
  559. dynUpdtInit.AnswerFile = UnattendedScriptFile;
  560. dynUpdtInit.ProgressWindow = hNotifyWnd;
  561. dynUpdtInit.DownloadRoot = g_DynUpdtStatus->WorkingDir;
  562. dynUpdtInit.TempDir = g_DynUpdtStatus->TempDir;
  563. return Winnt32DuInitialize (&dynUpdtInit);
  564. }
  565. BOOL
  566. DynamicUpdateStart (
  567. OUT PDWORD TotalEstimatedTime,
  568. OUT PDWORD TotalEstimatedSize
  569. )
  570. {
  571. if (g_DynUpdtStatus->Disabled) {
  572. return FALSE;
  573. }
  574. return Winnt32DuInitiateGetUpdates (TotalEstimatedTime, TotalEstimatedSize);
  575. }
  576. VOID
  577. DynamicUpdateCancel (
  578. VOID
  579. )
  580. {
  581. if (g_DynUpdtStatus->Disabled) {
  582. return;
  583. }
  584. Winnt32DuCancel ();
  585. }
  586. BOOL
  587. DynamicUpdateProcessFiles (
  588. OUT PBOOL StopSetup
  589. )
  590. {
  591. if (g_DynUpdtStatus->Disabled) {
  592. return TRUE;
  593. }
  594. return Winnt32DuProcessFiles (StopSetup);
  595. }
  596. BOOL
  597. DynamicUpdateWriteParams (
  598. IN PCTSTR ParamsFile
  599. )
  600. {
  601. return Winnt32DuWriteParams (ParamsFile);
  602. }
  603. VOID
  604. DynamicUpdateUninitialize (
  605. VOID
  606. )
  607. {
  608. if (g_DynUpdtStatus->Disabled) {
  609. return;
  610. }
  611. Winnt32DuUninitialize ();
  612. }
  613. BOOL
  614. DynamicUpdatePrepareRestart (
  615. VOID
  616. )
  617. {
  618. PCTSTR prevCmdLine;
  619. DWORD size;
  620. #if defined(_X86_)
  621. TCHAR reportNum[16];
  622. #endif
  623. if (g_DynUpdtStatus->Disabled) {
  624. return FALSE;
  625. }
  626. #define S_ARG_RESTART TEXT("Restart")
  627. if (!UnattendedOperation) {
  628. //
  629. // build the restart answer file
  630. //
  631. BuildPath (g_DynUpdtStatus->RestartAnswerFile, g_DynUpdtStatus->WorkingDir, S_RESTART_TXT);
  632. #if defined(_X86_)
  633. wsprintf (reportNum, TEXT("%u"), g_UpgradeReportMode);
  634. #endif
  635. //
  636. // write data to the restart answer file
  637. //
  638. if (!WritePrivateProfileString (
  639. WINNT_UNATTENDED,
  640. ISNT() ? WINNT_D_NTUPGRADE : WINNT_D_WIN95UPGRADE,
  641. Upgrade ? WINNT_A_YES : WINNT_A_NO,
  642. g_DynUpdtStatus->RestartAnswerFile
  643. ) ||
  644. ProductId[0] && !WritePrivateProfileString (
  645. WINNT_USERDATA,
  646. WINNT_US_PRODUCTKEY,
  647. ProductId,
  648. g_DynUpdtStatus->RestartAnswerFile
  649. ) ||
  650. !WritePrivateProfileString (
  651. WINNT_UNATTENDED,
  652. WINNT_U_DYNAMICUPDATESHARE,
  653. g_DynUpdtStatus->DynamicUpdatesSource,
  654. g_DynUpdtStatus->RestartAnswerFile
  655. ) ||
  656. #if defined(_X86_)
  657. !WritePrivateProfileString (
  658. WINNT_UNATTENDED,
  659. WINNT_D_REPORTMODE,
  660. reportNum,
  661. g_DynUpdtStatus->RestartAnswerFile
  662. ) ||
  663. #endif
  664. (ForceNTFSConversion &&
  665. !WritePrivateProfileString (
  666. WINNT_UNATTENDED,
  667. TEXT("ForceNTFSConversion"),
  668. WINNT_A_YES,
  669. g_DynUpdtStatus->RestartAnswerFile
  670. )) ||
  671. !SaveAdvancedOptions (
  672. g_DynUpdtStatus->RestartAnswerFile
  673. ) ||
  674. !SaveLanguageOptions (
  675. g_DynUpdtStatus->RestartAnswerFile
  676. ) ||
  677. !SaveAccessibilityOptions (
  678. g_DynUpdtStatus->RestartAnswerFile
  679. )
  680. ) {
  681. return FALSE;
  682. }
  683. }
  684. prevCmdLine = GetCommandLine ();
  685. size = (lstrlen (prevCmdLine) + 1 + 1) * sizeof (TCHAR) + sizeof (S_ARG_RESTART) +
  686. (UnattendedOperation ? 0 : (1 + lstrlen (g_DynUpdtStatus->RestartAnswerFile)) * sizeof (TCHAR));
  687. g_DynUpdtStatus->RestartCmdLine = HeapAlloc (GetProcessHeap (), 0, size);
  688. if (!g_DynUpdtStatus->RestartCmdLine) {
  689. return FALSE;
  690. }
  691. _sntprintf (
  692. g_DynUpdtStatus->RestartCmdLine,
  693. size / sizeof(TCHAR),
  694. UnattendedOperation ? TEXT("%s /%s") : TEXT("%s /%s:%s"),
  695. prevCmdLine,
  696. S_ARG_RESTART,
  697. g_DynUpdtStatus->RestartAnswerFile
  698. );
  699. return TRUE;
  700. }
  701. BOOL
  702. pComputeChecksum (
  703. IN PCTSTR FileName,
  704. OUT PDWORD Chksum
  705. )
  706. {
  707. DWORD chksum, size, dwords, bytes;
  708. HANDLE hFile, hMap;
  709. PVOID viewBase;
  710. PDWORD base, limit;
  711. PBYTE base2;
  712. DWORD rc;
  713. rc = MapFileForRead (FileName, &size, &hFile, &hMap, &viewBase);
  714. if (rc != ERROR_SUCCESS) {
  715. SetLastError (rc);
  716. return FALSE;
  717. }
  718. dwords = size / sizeof (DWORD);
  719. base = (PDWORD)viewBase;
  720. limit = base + dwords;
  721. chksum = 0;
  722. while (base < limit) {
  723. chksum += *base;
  724. base++;
  725. }
  726. bytes = size % sizeof (DWORD);
  727. base2 = (PBYTE)base;
  728. while (bytes) {
  729. chksum += *base2;
  730. base2++;
  731. bytes--;
  732. }
  733. UnmapFile (hMap, viewBase);
  734. CloseHandle (hFile);
  735. *Chksum = chksum;
  736. return TRUE;
  737. }
  738. BOOL
  739. pGetFiletimeStamps (
  740. IN PCTSTR FileName,
  741. OUT PFILETIME CreationTime,
  742. OUT PFILETIME LastWriteTime
  743. )
  744. {
  745. WIN32_FIND_DATA fd;
  746. HANDLE h;
  747. h = FindFirstFile (FileName, &fd);
  748. if (h == INVALID_HANDLE_VALUE) {
  749. return FALSE;
  750. }
  751. FindClose (h);
  752. *CreationTime = fd.ftCreationTime;
  753. *LastWriteTime = fd.ftLastWriteTime;
  754. return TRUE;
  755. }
  756. BOOL
  757. pSaveLastDownloadInfo (
  758. VOID
  759. )
  760. {
  761. SYSTEMTIME currentTime;
  762. DWORD chksum;
  763. FILETIME ftCreationTime;
  764. FILETIME ftLastWriteTime;
  765. ULONGLONG data[2];
  766. DWORD rc;
  767. HKEY key;
  768. TCHAR keyName[MAX_PATH];
  769. TCHAR filePath[MAX_PATH];
  770. PTSTR p;
  771. //
  772. // we always want to get to the CD dosnet.inf (in the same directory as winnt32.exe)
  773. //
  774. if (!MyGetModuleFileName (NULL, filePath, ARRAYSIZE(filePath))) {
  775. return FALSE;
  776. }
  777. p = _tcsrchr (filePath, TEXT('\\'));
  778. if (!p) {
  779. return FALSE;
  780. }
  781. lstrcpy (p + 1, InfName);
  782. GetCurrentWinnt32RegKey (keyName, ARRAYSIZE(keyName));
  783. ConcatenatePaths (keyName, WINNT_U_DYNAMICUPDATESHARE, ARRAYSIZE(keyName));
  784. rc = RegCreateKey (HKEY_LOCAL_MACHINE, keyName, &key);
  785. if (rc == ERROR_SUCCESS) {
  786. GetSystemTime (&currentTime);
  787. rc = RegSetValueEx (
  788. key,
  789. TEXT("LastDownloadTime"),
  790. 0,
  791. REG_BINARY,
  792. (CONST BYTE *) (&currentTime),
  793. sizeof (currentTime)
  794. );
  795. if (rc == ERROR_SUCCESS) {
  796. rc = RegSetValueEx (
  797. key,
  798. TEXT(""),
  799. 0,
  800. REG_SZ,
  801. (CONST BYTE *) g_DynUpdtStatus->DynamicUpdatesSource,
  802. (lstrlen (g_DynUpdtStatus->DynamicUpdatesSource) + 1) * sizeof (TCHAR)
  803. );
  804. }
  805. if (rc == ERROR_SUCCESS) {
  806. if (pComputeChecksum (filePath, &chksum)) {
  807. rc = RegSetValueEx (
  808. key,
  809. TEXT("Checksum"),
  810. 0,
  811. REG_DWORD,
  812. (CONST BYTE *) (&chksum),
  813. sizeof (chksum)
  814. );
  815. }
  816. }
  817. if (rc == ERROR_SUCCESS) {
  818. if (pGetFiletimeStamps (filePath, &ftCreationTime, &ftLastWriteTime)) {
  819. data[0] = ((ULONGLONG)ftCreationTime.dwHighDateTime << 32) | (ULONGLONG)ftCreationTime.dwLowDateTime;
  820. data[1] = ((ULONGLONG)ftLastWriteTime.dwHighDateTime << 32 ) | (ULONGLONG)ftLastWriteTime.dwLowDateTime;
  821. rc = RegSetValueEx (
  822. key,
  823. TEXT("TimeStamp"),
  824. 0,
  825. REG_BINARY,
  826. (CONST BYTE *)data,
  827. sizeof (data)
  828. );
  829. }
  830. }
  831. RegCloseKey (key);
  832. }
  833. if (rc != ERROR_SUCCESS) {
  834. SetLastError (rc);
  835. }
  836. return rc == ERROR_SUCCESS;
  837. }
  838. BOOL
  839. pGetRecentDUShare (
  840. IN DWORD MaxElapsedSeconds
  841. )
  842. {
  843. SYSTEMTIME lastDownload, currentTime;
  844. ULONGLONG lastDownloadIn100Ns, currentTimeIn100Ns;
  845. ULONGLONG difference;
  846. DWORD rc, size, type;
  847. HKEY key = NULL;
  848. BOOL b = FALSE;
  849. PTSTR duShare = NULL;
  850. TCHAR keyName[MAX_PATH];
  851. FILETIME ftCreationTime;
  852. FILETIME ftLastWriteTime;
  853. ULONGLONG data[2], storedData[2];
  854. DWORD chksum, storedChksum;
  855. TCHAR filePath[MAX_PATH];
  856. PTSTR p;
  857. if (!MyGetModuleFileName (NULL, filePath, ARRAYSIZE(filePath))) {
  858. return FALSE;
  859. }
  860. p = _tcsrchr (filePath, TEXT('\\'));
  861. if (!p) {
  862. return FALSE;
  863. }
  864. lstrcpy (p + 1, InfName);
  865. GetCurrentWinnt32RegKey (keyName, ARRAYSIZE(keyName));
  866. ConcatenatePaths (keyName, WINNT_U_DYNAMICUPDATESHARE, ARRAYSIZE(keyName));
  867. rc = RegOpenKeyEx (
  868. HKEY_LOCAL_MACHINE,
  869. keyName,
  870. 0,
  871. KEY_READ,
  872. &key
  873. );
  874. if (rc == ERROR_SUCCESS) {
  875. size = sizeof (lastDownload);
  876. rc = RegQueryValueEx (
  877. key,
  878. TEXT("LastDownloadTime"),
  879. NULL,
  880. &type,
  881. (PBYTE) (&lastDownload),
  882. &size
  883. );
  884. }
  885. if (rc == ERROR_SUCCESS && type == REG_BINARY && size == sizeof (lastDownload)) {
  886. //
  887. // Compare current time to report time
  888. //
  889. GetSystemTime (&currentTime);
  890. lastDownloadIn100Ns = SystemTimeToFileTime64 (&lastDownload);
  891. currentTimeIn100Ns = SystemTimeToFileTime64 (&currentTime);
  892. if (currentTimeIn100Ns > lastDownloadIn100Ns) {
  893. //
  894. // Compute difference in seconds
  895. //
  896. difference = currentTimeIn100Ns - lastDownloadIn100Ns;
  897. difference /= (10 * 1000 * 1000);
  898. if (difference < MaxElapsedSeconds) {
  899. b = TRUE;
  900. }
  901. }
  902. }
  903. if (b) {
  904. b = FALSE;
  905. rc = RegQueryValueEx (
  906. key,
  907. TEXT(""),
  908. NULL,
  909. &type,
  910. NULL,
  911. &size
  912. );
  913. if (rc == ERROR_SUCCESS && type == REG_SZ && size > 0 && size <= sizeof (g_DynUpdtStatus->DynamicUpdatesSource)) {
  914. duShare = MALLOC (size);
  915. if (duShare) {
  916. rc = RegQueryValueEx (
  917. key,
  918. TEXT(""),
  919. NULL,
  920. NULL,
  921. (LPBYTE)duShare,
  922. &size
  923. );
  924. if (rc == ERROR_SUCCESS && pDoesDirectoryExist (duShare)) {
  925. b = TRUE;
  926. } else {
  927. FREE (duShare);
  928. duShare = NULL;
  929. }
  930. }
  931. }
  932. }
  933. if (b) {
  934. b = FALSE;
  935. if (pGetFiletimeStamps (filePath, &ftCreationTime, &ftLastWriteTime)) {
  936. rc = RegQueryValueEx (
  937. key,
  938. TEXT("TimeStamp"),
  939. 0,
  940. &type,
  941. (LPBYTE)storedData,
  942. &size
  943. );
  944. if (rc == ERROR_SUCCESS && type == REG_BINARY) {
  945. data[0] = ((ULONGLONG)ftCreationTime.dwHighDateTime << 32) | (ULONGLONG)ftCreationTime.dwLowDateTime;
  946. data[1] = ((ULONGLONG)ftLastWriteTime.dwHighDateTime << 32 ) | (ULONGLONG)ftLastWriteTime.dwLowDateTime;
  947. if (data[0] == storedData[0] && data[1] == storedData[1]) {
  948. b = TRUE;
  949. }
  950. }
  951. }
  952. }
  953. if (b) {
  954. b = FALSE;
  955. if (pComputeChecksum (filePath, &chksum)) {
  956. rc = RegQueryValueEx (
  957. key,
  958. TEXT("Checksum"),
  959. NULL,
  960. &type,
  961. (LPBYTE)&storedChksum,
  962. &size
  963. );
  964. if (rc == ERROR_SUCCESS && type == REG_DWORD && storedChksum == chksum) {
  965. b = TRUE;
  966. }
  967. }
  968. }
  969. if (!b && duShare) {
  970. FREE (duShare);
  971. duShare = NULL;
  972. }
  973. if (duShare) {
  974. MYASSERT (b);
  975. MYASSERT (!g_DynUpdtStatus->DynamicUpdatesSource[0]);
  976. lstrcpy (g_DynUpdtStatus->DynamicUpdatesSource, duShare);
  977. RemoveTrailingWack (g_DynUpdtStatus->DynamicUpdatesSource);
  978. g_DynUpdtStatus->UserSpecifiedUpdates = TRUE;
  979. }
  980. if (key) {
  981. RegCloseKey (key);
  982. }
  983. return b;
  984. }
  985. BOOL
  986. DynamicUpdateInitialize (
  987. VOID
  988. )
  989. {
  990. if (g_DynUpdtStatus->Disabled) {
  991. return TRUE;
  992. }
  993. if (!MyGetWindowsDirectory (g_DynUpdtStatus->WorkingDir, ARRAYSIZE(g_DynUpdtStatus->WorkingDir))) {
  994. return FALSE;
  995. }
  996. if (!ConcatenatePaths (g_DynUpdtStatus->WorkingDir, S_DOWNLOAD_ROOT, ARRAYSIZE(g_DynUpdtStatus->WorkingDir))) {
  997. return FALSE;
  998. }
  999. if (!BuildPath (g_DynUpdtStatus->TempDir, g_DynUpdtStatus->WorkingDir, S_SUBDIRNAME_TEMP)) {
  1000. return FALSE;
  1001. }
  1002. g_DynUpdtStatus->Diamond = DiamondInitialize (g_DynUpdtStatus->TempDir);
  1003. if (!g_DynUpdtStatus->Diamond) {
  1004. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to initialize compression/decompression engine"), 0);
  1005. return FALSE;
  1006. }
  1007. if (!CheckUpgradeOnly && !g_DynUpdtStatus->UserSpecifiedUpdates) {
  1008. if (pGetRecentDUShare (MAX_UPGCHK_ELAPSED_SECONDS)) {
  1009. g_DynUpdtStatus->PreserveWorkingDir = TRUE;
  1010. //
  1011. // this might be considered sensitive information;
  1012. // only log it if the user asks for it
  1013. //
  1014. DynUpdtDebugLog (
  1015. Winnt32LogDetailedInformation,
  1016. TEXT("Using recent share %1"),
  1017. 0,
  1018. g_DynUpdtStatus->DynamicUpdatesSource
  1019. );
  1020. }
  1021. }
  1022. if (!g_DynUpdtStatus->PreserveWorkingDir && !Winnt32Restarted ()) {
  1023. MyDelnode (g_DynUpdtStatus->WorkingDir);
  1024. }
  1025. if (g_DynUpdtStatus->UserSpecifiedUpdates) {
  1026. BuildPath (g_DynUpdtStatus->DriversSource, g_DynUpdtStatus->DynamicUpdatesSource, S_SUBDIRNAME_DRIVERS);
  1027. } else {
  1028. BuildPath (g_DynUpdtStatus->DriversSource, g_DynUpdtStatus->WorkingDir, S_SUBDIRNAME_DRIVERS);
  1029. }
  1030. BuildPath (g_DynUpdtStatus->SelectedDrivers, g_DynUpdtStatus->WorkingDir, S_SUBDIRNAME_DRIVERS);
  1031. if (Winnt32Restarted ()) {
  1032. BuildPath (g_DynUpdtStatus->Winnt32Path, g_DynUpdtStatus->WorkingDir, S_SUBDIRNAME_WINNT32);
  1033. } else {
  1034. BuildPath (
  1035. g_DynUpdtStatus->Winnt32Path,
  1036. g_DynUpdtStatus->UserSpecifiedUpdates ?
  1037. g_DynUpdtStatus->DynamicUpdatesSource :
  1038. g_DynUpdtStatus->WorkingDir,
  1039. S_SUBDIRNAME_WINNT32
  1040. );
  1041. }
  1042. if (!pGetTargetInfo (
  1043. NULL,
  1044. g_DynUpdtStatus->TargetPlatform,
  1045. ARRAYSIZE(g_DynUpdtStatus->TargetPlatform),
  1046. NULL
  1047. )) {
  1048. return FALSE;
  1049. }
  1050. return TRUE;
  1051. }
  1052. PTSTR
  1053. GetFileExtension (
  1054. IN PCTSTR FileSpec
  1055. )
  1056. {
  1057. PTSTR p;
  1058. p = _tcsrchr (FileSpec, TEXT('.'));
  1059. if (p && _tcschr (p, TEXT('\\'))) {
  1060. p = NULL;
  1061. }
  1062. return p;
  1063. }
  1064. BOOL
  1065. BuildSifName (
  1066. IN PCTSTR CabName,
  1067. OUT PTSTR SifName,
  1068. IN UINT CchSifName
  1069. )
  1070. {
  1071. PTSTR p;
  1072. if (FAILED(StringCchCopy (SifName, CchSifName, CabName))) {
  1073. return FALSE;
  1074. }
  1075. p = GetFileExtension (SifName);
  1076. if (!p) {
  1077. p = _tcschr (SifName, 0);
  1078. }
  1079. return SUCCEEDED (StringCchCopy (p, SifName + CchSifName - p, TEXT(".sif")));
  1080. }
  1081. BOOL
  1082. WINAPI
  1083. Winnt32QueryCallback (
  1084. IN DWORD SetupQueryId,
  1085. IN PVOID InData,
  1086. IN DWORD InDataSize,
  1087. IN OUT PVOID OutData, OPTIONAL
  1088. IN OUT PDWORD OutDataSize
  1089. )
  1090. {
  1091. BOOL b = FALSE;
  1092. BOOL bException = FALSE;
  1093. switch (SetupQueryId) {
  1094. case SETUPQUERYID_PNPID:
  1095. {
  1096. PPNPID_INFO p;
  1097. PTSTR listPnpIds = NULL;
  1098. if (!OutData ||
  1099. !OutDataSize ||
  1100. *OutDataSize < sizeof (PNPID_INFO)
  1101. ) {
  1102. SetLastError (ERROR_INVALID_PARAMETER);
  1103. break;
  1104. }
  1105. if (!g_DynUpdtStatus->HwdbHasAnyDriver) {
  1106. SetLastError (ERROR_INVALID_FUNCTION);
  1107. break;
  1108. }
  1109. __try {
  1110. p = (PPNPID_INFO)OutData;
  1111. if (g_DynUpdtStatus->HwdbDatabase) {
  1112. #ifdef UNICODE
  1113. listPnpIds = MultiSzAnsiToUnicode ((PCSTR)InData);
  1114. #else
  1115. listPnpIds = (PSTR)InData;
  1116. #endif
  1117. p->Handled = (*g_DynUpdtStatus->HwdbHasAnyDriver) (
  1118. g_DynUpdtStatus->HwdbDatabase,
  1119. listPnpIds,
  1120. &p->Unsupported
  1121. );
  1122. } else {
  1123. //
  1124. // disable all driver downloads by doing this
  1125. //
  1126. p->Handled = TRUE;
  1127. }
  1128. }
  1129. __except (EXCEPTION_EXECUTE_HANDLER) {
  1130. SetLastError (GetExceptionCode());
  1131. DynUpdtDebugLog (Winnt32LogError, TEXT("Winnt32QueryCallback: HwdbHasAnyDriver threw an exception"), 0);
  1132. bException = TRUE;
  1133. p->Handled = TRUE;
  1134. }
  1135. if (bException) {
  1136. __try {
  1137. //
  1138. // bad string passed back, or some internal error
  1139. // try to print the string
  1140. //
  1141. if (listPnpIds) {
  1142. PTSTR multisz = CreatePrintableString (listPnpIds);
  1143. DynUpdtDebugLog (Winnt32LogError, TEXT(" - The string was %1"), 0, multisz);
  1144. FREE (multisz);
  1145. }
  1146. }
  1147. __except (EXCEPTION_EXECUTE_HANDLER) {
  1148. DynUpdtDebugLog (Winnt32LogError, TEXT(" - Bad string"), 0);
  1149. }
  1150. }
  1151. #ifdef UNICODE
  1152. if (listPnpIds) {
  1153. FREE (listPnpIds);
  1154. }
  1155. #endif
  1156. b = TRUE;
  1157. }
  1158. break;
  1159. case SETUPQUERYID_DOWNLOADDRIVER:
  1160. {
  1161. if (!OutData ||
  1162. !OutDataSize ||
  1163. *OutDataSize < sizeof (BOOL)
  1164. ) {
  1165. SetLastError (ERROR_INVALID_PARAMETER);
  1166. break;
  1167. }
  1168. b = TRUE;
  1169. }
  1170. break;
  1171. }
  1172. return b;
  1173. }
  1174. BOOL
  1175. WINAPI
  1176. Winnt32DuIsSupported (
  1177. VOID
  1178. )
  1179. {
  1180. BOOL b = FALSE;
  1181. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Enter Winnt32DuIsSupported"), 0);
  1182. #ifndef UNICODE
  1183. if (!pLoadWin9xDuSupport ()) {
  1184. DynUpdtDebugLog (
  1185. Winnt32LogWarning,
  1186. TEXT("Winnt32DuIsSupported: %1 support module not loaded; no drivers will be downloaded"),
  1187. 0,
  1188. "w95upg.dll"
  1189. );
  1190. }
  1191. #endif
  1192. TRY {
  1193. b = pInitSupportLibs () &&
  1194. (Winnt32Restarted () || g_DynUpdtStatus->DuIsSupported ());
  1195. }
  1196. EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
  1197. SetLastError (_exception_code ());
  1198. DynUpdtDebugLog (Winnt32LogError, TEXT("Winnt32DuIsSupported: an exception occured"), 0);
  1199. }
  1200. END_EXCEPT
  1201. #ifndef UNICODE
  1202. if (!b) {
  1203. g_DynUpdtStatus->Win9xGetIncompDrvs = NULL;
  1204. g_DynUpdtStatus->Win9xReleaseIncompDrvs = NULL;
  1205. }
  1206. #endif
  1207. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Leave Winnt32DuIsSupported (%1!d!)"), 0, b);
  1208. return b;
  1209. }
  1210. BOOL
  1211. WINAPI
  1212. Winnt32DuInitialize (
  1213. IN PDYNUPDT_INIT InitData
  1214. )
  1215. {
  1216. DWORD rc;
  1217. BOOL b = FALSE;
  1218. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Enter Winnt32DuInitialize"), 0);
  1219. __try {
  1220. MYASSERT (InitData);
  1221. MYASSERT (InitData->TempDir);
  1222. MYASSERT (g_DynUpdtStatus->DuInitialize);
  1223. MYASSERT (!Winnt32Restarted ());
  1224. if (CreateMultiLevelDirectory (InitData->TempDir) != ERROR_SUCCESS) {
  1225. DynUpdtDebugLog (Winnt32LogError, TEXT("Winnt32DuInitialize: CreateDirectory(%1) FAILED"), 0, InitData->TempDir);
  1226. __leave;
  1227. }
  1228. //
  1229. // initialize the Whistler PNP database
  1230. //
  1231. if (!g_DynUpdtStatus->HwdbDatabase) {
  1232. //
  1233. // ignore db load error
  1234. //
  1235. pInitNtPnpDb (FALSE);
  1236. }
  1237. TRY {
  1238. //
  1239. // if a download source already exists, no need to initialize the control
  1240. // since no download will be really necessary
  1241. //
  1242. MYASSERT (!g_DynUpdtStatus->DynamicUpdatesSource[0]);
  1243. g_DynUpdtStatus->Connection = (*g_DynUpdtStatus->DuInitialize) (
  1244. InitData->DownloadRoot,
  1245. InitData->TempDir,
  1246. InitData->TargetOsVersion,
  1247. InitData->TargetPlatform,
  1248. InitData->TargetLCID,
  1249. InitData->Unattend,
  1250. InitData->Upgrade,
  1251. Winnt32QueryCallback
  1252. );
  1253. if (g_DynUpdtStatus->Connection == INVALID_HANDLE_VALUE) {
  1254. DynUpdtDebugLog (
  1255. Winnt32LogError,
  1256. TEXT("DuInitialize FAILED"),
  1257. 0
  1258. );
  1259. __leave;
  1260. }
  1261. g_DynUpdtStatus->ProgressWindow = InitData->ProgressWindow;
  1262. b = TRUE;
  1263. }
  1264. EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
  1265. SetLastError (_exception_code ());
  1266. DynUpdtDebugLog (Winnt32LogError, TEXT("Winnt32DuInitialize: an exception occured"), 0);
  1267. }
  1268. END_EXCEPT
  1269. }
  1270. __finally {
  1271. if (!b) {
  1272. DynUpdtDebugLog (Winnt32LogError, TEXT("Winnt32DuInitialize FAILED"), 0);
  1273. }
  1274. }
  1275. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Leave Winnt32DuInitialize (%1!d!)"), 0, b);
  1276. return b;
  1277. }
  1278. BOOL
  1279. WINAPI
  1280. Winnt32DuInitiateGetUpdates (
  1281. OUT PDWORD TotalEstimatedTime,
  1282. OUT PDWORD TotalEstimatedSize
  1283. )
  1284. {
  1285. BOOL b = FALSE;
  1286. #ifndef UNICODE
  1287. PSTR* incompWin9xDrivers;
  1288. PSTRINGLIST listEntry;
  1289. PCSTR* q;
  1290. BOOL free;
  1291. PSTR empty = TEXT("");
  1292. #endif
  1293. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Enter Winnt32DuInitiateGetUpdates"), 0);
  1294. if (g_DynUpdtStatus->Connection != INVALID_HANDLE_VALUE &&
  1295. g_DynUpdtStatus->DuDoDetection &&
  1296. g_DynUpdtStatus->DuBeginDownload
  1297. ) {
  1298. TRY {
  1299. #ifdef UNICODE
  1300. b = (*g_DynUpdtStatus->DuDoDetection) (g_DynUpdtStatus->Connection, TotalEstimatedTime, TotalEstimatedSize);
  1301. if (!b) {
  1302. DynUpdtDebugLog (
  1303. DynUpdtLogLevel,
  1304. TEXT("DuDoDetection returned FALSE; no files will be downloaded"),
  1305. 0
  1306. );
  1307. }
  1308. #else
  1309. b = TRUE;
  1310. g_DynUpdtStatus->IncompatibleDriversCount = 0;
  1311. if (g_DynUpdtStatus->Win9xGetIncompDrvs) {
  1312. //
  1313. // let the upgrade module do detection on Win95
  1314. //
  1315. b = (*g_DynUpdtStatus->Win9xGetIncompDrvs) (&incompWin9xDrivers);
  1316. free = TRUE;
  1317. } else {
  1318. incompWin9xDrivers = &empty;
  1319. free = FALSE;
  1320. }
  1321. if (b) {
  1322. b = (*g_DynUpdtStatus->DuQueryUnsupDrvs) (
  1323. g_DynUpdtStatus->Connection,
  1324. incompWin9xDrivers,
  1325. TotalEstimatedTime,
  1326. TotalEstimatedSize
  1327. );
  1328. if (incompWin9xDrivers) {
  1329. for (q = incompWin9xDrivers; *q; q++) {
  1330. g_DynUpdtStatus->IncompatibleDriversCount++;
  1331. }
  1332. }
  1333. if (free && g_DynUpdtStatus->Win9xReleaseIncompDrvs) {
  1334. (*g_DynUpdtStatus->Win9xReleaseIncompDrvs) (incompWin9xDrivers);
  1335. }
  1336. if (!b) {
  1337. DynUpdtDebugLog (
  1338. DynUpdtLogLevel,
  1339. TEXT("DuQueryUnsupportedDrivers returned FALSE; no files will be downloaded"),
  1340. 0
  1341. );
  1342. }
  1343. } else {
  1344. DynUpdtDebugLog (
  1345. DynUpdtLogLevel,
  1346. TEXT("Win9xGetIncompDrvs returned FALSE; no files will be downloaded"),
  1347. 0
  1348. );
  1349. }
  1350. #endif
  1351. if (b) {
  1352. b = (*g_DynUpdtStatus->DuBeginDownload) (g_DynUpdtStatus->Connection, g_DynUpdtStatus->ProgressWindow);
  1353. if (!b) {
  1354. DynUpdtDebugLog (
  1355. DynUpdtLogLevel,
  1356. TEXT("DuBeginDownload returned FALSE; no files will be downloaded"),
  1357. 0
  1358. );
  1359. }
  1360. }
  1361. }
  1362. EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
  1363. SetLastError (_exception_code ());
  1364. DynUpdtDebugLog (
  1365. Winnt32LogError,
  1366. TEXT("Winnt32DuInitiateGetUpdates: an exception occured; no files will be downloaded"),
  1367. 0
  1368. );
  1369. }
  1370. END_EXCEPT
  1371. } else {
  1372. SetLastError (ERROR_INVALID_FUNCTION);
  1373. }
  1374. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Leave Winnt32DuInitiateGetUpdates (%1!d!)"), 0, b);
  1375. return b;
  1376. }
  1377. VOID
  1378. WINAPI
  1379. Winnt32DuCancel (
  1380. VOID
  1381. )
  1382. {
  1383. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Enter Winnt32DuCancel"), 0);
  1384. TRY {
  1385. if (g_DynUpdtStatus->Connection != INVALID_HANDLE_VALUE &&
  1386. g_DynUpdtStatus->DuAbortDownload
  1387. ) {
  1388. (*g_DynUpdtStatus->DuAbortDownload) (g_DynUpdtStatus->Connection);
  1389. }
  1390. }
  1391. EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
  1392. SetLastError (_exception_code ());
  1393. DynUpdtDebugLog (Winnt32LogError, TEXT("Winnt32DuCancel: an exception occured"), 0);
  1394. }
  1395. END_EXCEPT
  1396. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Leave Winnt32DuCancel"), 0);
  1397. }
  1398. BOOL
  1399. WINAPI
  1400. Winnt32DuProcessFiles (
  1401. OUT PBOOL StopSetup
  1402. )
  1403. {
  1404. BOOL b;
  1405. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Enter Winnt32DuProcessFiles"), 0);
  1406. b = ProcessDownloadedFiles (StopSetup);
  1407. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Leave Winnt32DuProcessFiles (%1!d!)"), 0, b);
  1408. return b;
  1409. }
  1410. BOOL
  1411. WINAPI
  1412. Winnt32DuWriteParams (
  1413. IN PCTSTR ParamsFile
  1414. )
  1415. {
  1416. PSDLIST p;
  1417. PSTRINGLIST q;
  1418. DWORD len1, len2;
  1419. PTSTR pathList1 = NULL, pathList2 = NULL;
  1420. PTSTR append1, append2;
  1421. BOOL b = TRUE;
  1422. if (!DynamicUpdateSuccessful ()) {
  1423. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Winnt32DuWriteParams: disabled because DU did not succeed"), 0);
  1424. return TRUE;
  1425. }
  1426. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Enter Winnt32DuWriteParams"), 0);
  1427. //
  1428. // store paths to all downloaded drivers in a key in the answer file,
  1429. // so later on Textmode Setup (or GUI setup) will append this list to the OemPnPDriversPath
  1430. //
  1431. if (g_DynUpdtStatus->NewDriversList) {
  1432. len1 = len2 = 0;
  1433. for (p = g_DynUpdtStatus->NewDriversList; p; p = p->Next) {
  1434. if (p->Data) {
  1435. len1 += lstrlen (p->String) + 1;
  1436. } else {
  1437. len2 += lstrlen (p->String) + 1;
  1438. }
  1439. }
  1440. if (len1) {
  1441. pathList1 = (PTSTR) MALLOC (len1 * sizeof (TCHAR));
  1442. if (!pathList1) {
  1443. b = FALSE;
  1444. goto exit;
  1445. }
  1446. *pathList1 = 0;
  1447. append1 = pathList1;
  1448. }
  1449. if (len2) {
  1450. pathList2 = (PTSTR) MALLOC (len2 * sizeof (TCHAR));
  1451. if (!pathList2) {
  1452. FREE (pathList1);
  1453. b = FALSE;
  1454. goto exit;
  1455. }
  1456. *pathList2 = 0;
  1457. append2 = pathList2;
  1458. }
  1459. for (p = g_DynUpdtStatus->NewDriversList; p; p = p->Next) {
  1460. if (p->Data) {
  1461. if (append1 != pathList1) {
  1462. *append1++ = TEXT(',');
  1463. }
  1464. lstrcpy (append1, p->String);
  1465. append1 = _tcschr (append1, 0);
  1466. } else {
  1467. if (append2 != pathList2) {
  1468. *append2++ = TEXT(',');
  1469. }
  1470. lstrcpy (append2, p->String);
  1471. append2 = _tcschr (append2, 0);
  1472. }
  1473. }
  1474. if (len1) {
  1475. if (!WritePrivateProfileString (
  1476. WINNT_SETUPPARAMS,
  1477. WINNT_SP_DYNUPDTADDITIONALGUIDRIVERS,
  1478. pathList1,
  1479. ParamsFile
  1480. )) {
  1481. b = FALSE;
  1482. }
  1483. }
  1484. if (b && len2) {
  1485. if (!WritePrivateProfileString (
  1486. WINNT_SETUPPARAMS,
  1487. WINNT_SP_DYNUPDTADDITIONALPOSTGUIDRIVERS,
  1488. pathList2,
  1489. ParamsFile
  1490. )) {
  1491. b = FALSE;
  1492. }
  1493. }
  1494. if (pathList1) {
  1495. FREE (pathList1);
  1496. }
  1497. if (pathList2) {
  1498. FREE (pathList2);
  1499. }
  1500. if (b && g_DynUpdtStatus->GuidrvsInfSource[0]) {
  1501. if (!WritePrivateProfileString (
  1502. WINNT_SETUPPARAMS,
  1503. WINNT_SP_DYNUPDTDRIVERINFOFILE,
  1504. g_DynUpdtStatus->GuidrvsInfSource,
  1505. ParamsFile
  1506. )) {
  1507. b = FALSE;
  1508. }
  1509. }
  1510. }
  1511. //
  1512. // store paths to all downloaded BOOT drivers in a key in the answer file,
  1513. // so later on Textmode Setup will append this to the boot drivers list
  1514. //
  1515. if (b && g_DynUpdtStatus->BootDriverPathList) {
  1516. len1 = 0;
  1517. for (q = g_DynUpdtStatus->BootDriverPathList; q; q = q->Next) {
  1518. len1 += lstrlen (q->String) + 1;
  1519. }
  1520. pathList1 = (PTSTR) MALLOC (len1 * sizeof (TCHAR));
  1521. if (!pathList1) {
  1522. b = FALSE;
  1523. goto exit;
  1524. }
  1525. *pathList1 = 0;
  1526. append1 = pathList1;
  1527. for (q = g_DynUpdtStatus->BootDriverPathList; q; q = q->Next) {
  1528. if (append1 != pathList1) {
  1529. *append1++ = TEXT(',');
  1530. }
  1531. lstrcpy (append1, q->String);
  1532. append1 = _tcschr (append1, 0);
  1533. }
  1534. if (!WritePrivateProfileString (
  1535. WINNT_SETUPPARAMS,
  1536. WINNT_SP_DYNUPDTBOOTDRIVERPRESENT,
  1537. WINNT_A_YES,
  1538. ParamsFile
  1539. ) ||
  1540. !WritePrivateProfileString (
  1541. WINNT_SETUPPARAMS,
  1542. WINNT_SP_DYNUPDTBOOTDRIVERROOT,
  1543. S_SUBDIRNAME_DRIVERS,
  1544. ParamsFile
  1545. ) ||
  1546. !WritePrivateProfileString (
  1547. WINNT_SETUPPARAMS,
  1548. WINNT_SP_DYNUPDTBOOTDRIVERS,
  1549. pathList1,
  1550. ParamsFile
  1551. )) {
  1552. b = FALSE;
  1553. }
  1554. FREE (pathList1);
  1555. }
  1556. if (b && g_DynUpdtStatus->UpdatesCabTarget[0]) {
  1557. TCHAR buffer[2*MAX_PATH];
  1558. _sntprintf (
  1559. buffer,
  1560. ARRAYSIZE(buffer),
  1561. TEXT("\"%s\""),
  1562. g_DynUpdtStatus->UpdatesCabTarget
  1563. );
  1564. b = WritePrivateProfileString (
  1565. WINNT_SETUPPARAMS,
  1566. WINNT_SP_UPDATEDSOURCES,
  1567. buffer,
  1568. ParamsFile
  1569. );
  1570. }
  1571. //
  1572. // new assemblies to be installed during GUI setup
  1573. //
  1574. if (b && g_DynUpdtStatus->DuasmsTarget[0]) {
  1575. b = WritePrivateProfileString (
  1576. WINNT_SETUPPARAMS,
  1577. WINNT_SP_UPDATEDDUASMS,
  1578. g_DynUpdtStatus->DuasmsTarget,
  1579. ParamsFile
  1580. );
  1581. }
  1582. #if defined(_X86_)
  1583. //
  1584. // last but not least, replace the Win9xupg NT side migration dll (w95upgnt.dll)
  1585. // if a new one is available
  1586. //
  1587. if (b && Upgrade && !ISNT() && g_DynUpdtStatus->Winnt32Path[0]) {
  1588. TCHAR source[MAX_PATH];
  1589. TCHAR target[MAX_PATH];
  1590. BuildPath (target, g_DynUpdtStatus->Winnt32Path, TEXT("w95upgnt.dll"));
  1591. if (pDoesFileExist (target)) {
  1592. //
  1593. // check file versions first
  1594. //
  1595. BuildPath (source, NativeSourcePaths[0], TEXT("w95upgnt.dll"));
  1596. if (!IsFileVersionLesser (target, source)) {
  1597. if (_tcsnicmp (
  1598. g_DynUpdtStatus->Winnt32Path,
  1599. g_DynUpdtStatus->WorkingDir,
  1600. lstrlen (g_DynUpdtStatus->WorkingDir)
  1601. )) {
  1602. //
  1603. // copy the file in a local directory first
  1604. //
  1605. BuildPath (source, g_DynUpdtStatus->WorkingDir, TEXT("w95upgnt.dll"));
  1606. if (CopyFile (target, source, FALSE)) {
  1607. lstrcpy (target, source);
  1608. } else {
  1609. //
  1610. // failed to copy the NT-side upgrade module!
  1611. // fail the upgrade
  1612. //
  1613. DynUpdtDebugLog (
  1614. Winnt32LogSevereError,
  1615. TEXT("Failed to copy replacement %1 to %2; upgrade aborted"),
  1616. 0,
  1617. target,
  1618. source
  1619. );
  1620. b = FALSE;
  1621. }
  1622. }
  1623. if (b) {
  1624. b = WritePrivateProfileString (
  1625. WINNT_WIN95UPG_95_DIR,
  1626. WINNT_WIN95UPG_NTKEY,
  1627. target,
  1628. ParamsFile
  1629. );
  1630. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Will use replacement %1 on the NT side of migration"), 0, target);
  1631. }
  1632. }
  1633. }
  1634. }
  1635. #endif
  1636. if (b) {
  1637. if (g_DynUpdtStatus->WorkingDir[0]) {
  1638. b = WritePrivateProfileString (
  1639. WINNT_SETUPPARAMS,
  1640. WINNT_SP_DYNUPDTWORKINGDIR,
  1641. g_DynUpdtStatus->WorkingDir,
  1642. ParamsFile
  1643. );
  1644. }
  1645. }
  1646. if (b) {
  1647. //
  1648. // flush it to disk
  1649. //
  1650. WritePrivateProfileString (NULL, NULL, NULL, ParamsFile);
  1651. }
  1652. exit:
  1653. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Leave Winnt32DuWriteParams (%1!d!)"), 0, b);
  1654. return b;
  1655. }
  1656. VOID
  1657. WINAPI
  1658. Winnt32DuUninitialize (
  1659. VOID
  1660. )
  1661. {
  1662. DWORD i;
  1663. #if 0
  1664. TCHAR pathPss[MAX_PATH];
  1665. PTSTR p;
  1666. #endif
  1667. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Enter Winnt32DuUninitialize"), 0);
  1668. TRY {
  1669. if (g_DynUpdtStatus->Connection != INVALID_HANDLE_VALUE) {
  1670. if (g_DynUpdtStatus->DuUninitialize) {
  1671. (*g_DynUpdtStatus->DuUninitialize) (g_DynUpdtStatus->Connection);
  1672. }
  1673. g_DynUpdtStatus->Connection = INVALID_HANDLE_VALUE;
  1674. }
  1675. g_DynUpdtStatus->DuIsSupported = NULL;
  1676. g_DynUpdtStatus->ProgressWindow = NULL;
  1677. g_DynUpdtStatus->DuInitialize = NULL;
  1678. g_DynUpdtStatus->DuDoDetection = NULL;
  1679. g_DynUpdtStatus->DuQueryUnsupDrvs = NULL;
  1680. g_DynUpdtStatus->DuBeginDownload = NULL;
  1681. g_DynUpdtStatus->DuAbortDownload = NULL;
  1682. g_DynUpdtStatus->DuUninitialize = NULL;
  1683. if (g_DynUpdtStatus->DuLib) {
  1684. FreeLibrary (g_DynUpdtStatus->DuLib);
  1685. g_DynUpdtStatus->DuLib = NULL;
  1686. }
  1687. if (g_DynUpdtStatus->HwdbDatabase) {
  1688. g_DynUpdtStatus->HwdbClose (g_DynUpdtStatus->HwdbDatabase);
  1689. g_DynUpdtStatus->HwdbDatabase = NULL;
  1690. }
  1691. if (g_DynUpdtStatus->HwdbTerminate) {
  1692. (*g_DynUpdtStatus->HwdbTerminate) ();
  1693. }
  1694. g_DynUpdtStatus->HwdbInitialize = NULL;
  1695. g_DynUpdtStatus->HwdbTerminate = NULL;
  1696. g_DynUpdtStatus->HwdbOpen = NULL;
  1697. g_DynUpdtStatus->HwdbClose = NULL;
  1698. g_DynUpdtStatus->HwdbAppendInfs = NULL;
  1699. g_DynUpdtStatus->HwdbFlush = NULL;
  1700. g_DynUpdtStatus->HwdbHasDriver = NULL;
  1701. g_DynUpdtStatus->HwdbHasAnyDriver = NULL;
  1702. if (g_DynUpdtStatus->HwdbLib) {
  1703. FreeLibrary (g_DynUpdtStatus->HwdbLib);
  1704. g_DynUpdtStatus->HwdbLib = NULL;
  1705. }
  1706. #ifndef UNICODE
  1707. g_DynUpdtStatus->Win9xGetIncompDrvs = NULL;
  1708. g_DynUpdtStatus->Win9xReleaseIncompDrvs = NULL;
  1709. #endif
  1710. #if 0
  1711. if (g_DynUpdtStatus->WorkingDir[0]) {
  1712. p = _tcsrchr (g_DynUpdtStatus->WorkingDir, TEXT('\\'));
  1713. if (!p) {
  1714. p = g_DynUpdtStatus->WorkingDir;
  1715. }
  1716. lstrcpyn (
  1717. pathPss,
  1718. g_DynUpdtStatus->WorkingDir,
  1719. MIN (ARRAYSIZE(pathPss), (INT)(p - g_DynUpdtStatus->WorkingDir + 2))
  1720. );
  1721. ConcatenatePaths (pathPss, TEXT("setup.pss"), ARRAYSIZE(pathPss));
  1722. CreateMultiLevelDirectory (pathPss);
  1723. ConcatenatePaths (pathPss, p, ARRAYSIZE(pathPss));
  1724. MyDelnode (pathPss);
  1725. }
  1726. #endif
  1727. if (!DynamicUpdateSuccessful ()) {
  1728. if (g_DynUpdtStatus->WorkingDir[0]) {
  1729. #if 0
  1730. //
  1731. // rename this directory to make sure no module uses any DU files
  1732. //
  1733. MYASSERT (pathPss[0]);
  1734. if (!MoveFile (g_DynUpdtStatus->WorkingDir, pathPss)) {
  1735. DynUpdtDebugLog (
  1736. Winnt32LogError,
  1737. TEXT("Winnt32DuUninitialize: MoveFile %1 -> %2 failed"),
  1738. 0,
  1739. g_DynUpdtStatus->WorkingDir,
  1740. pathPss
  1741. );
  1742. MyDelnode (g_DynUpdtStatus->WorkingDir);
  1743. }
  1744. #else
  1745. MyDelnode (g_DynUpdtStatus->WorkingDir);
  1746. #endif
  1747. }
  1748. }
  1749. DiamondTerminate (g_DynUpdtStatus->Diamond);
  1750. }
  1751. EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
  1752. SetLastError (_exception_code ());
  1753. DynUpdtDebugLog (Winnt32LogError, TEXT("Winnt32DuUninitialize: an exception occured"), 0);
  1754. }
  1755. END_EXCEPT
  1756. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Leave Winnt32DuUninitialize"), 0);
  1757. }
  1758. BOOL
  1759. pAddMissingPrinterDrivers (
  1760. IN OUT PSTRINGLIST* List
  1761. )
  1762. {
  1763. DWORD nBytesNeeded = 0;
  1764. DWORD nDriverRetrieved = 0;
  1765. DWORD rc;
  1766. PDRIVER_INFO_6 buffer = NULL;
  1767. DWORD index;
  1768. PCTSTR printerPnpId;
  1769. PSTRINGLIST p;
  1770. BOOL unsupported;
  1771. BOOL b = FALSE;
  1772. if (!EnumPrinterDrivers (
  1773. NULL,
  1774. NULL,
  1775. 6,
  1776. NULL,
  1777. 0,
  1778. &nBytesNeeded,
  1779. &nDriverRetrieved
  1780. )) {
  1781. if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
  1782. goto exit;
  1783. }
  1784. }
  1785. if (nBytesNeeded) {
  1786. buffer = (PDRIVER_INFO_6) MALLOC (nBytesNeeded);
  1787. if (!buffer) {
  1788. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  1789. goto exit;
  1790. }
  1791. //
  1792. // get printer driver information
  1793. //
  1794. if (!EnumPrinterDrivers (
  1795. NULL,
  1796. NULL,
  1797. 6,
  1798. (LPBYTE)buffer,
  1799. nBytesNeeded,
  1800. &nBytesNeeded,
  1801. &nDriverRetrieved
  1802. )) {
  1803. if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
  1804. goto exit;
  1805. }
  1806. }
  1807. for (index = 0; index < nDriverRetrieved; index++) {
  1808. printerPnpId = buffer[index].pszHardwareID;
  1809. if (!printerPnpId) {
  1810. continue;
  1811. }
  1812. if (g_DynUpdtStatus->HwdbHasDriver (
  1813. g_DynUpdtStatus->HwdbDatabase,
  1814. printerPnpId,
  1815. &unsupported
  1816. )) {
  1817. continue;
  1818. }
  1819. //
  1820. // not an in-box driver
  1821. //
  1822. p = (PSTRINGLIST) MALLOC (sizeof (STRINGLIST));
  1823. if (!p) {
  1824. SetLastError (ERROR_NOT_ENOUGH_MEMORY);
  1825. goto exit;
  1826. }
  1827. p->String = MALLOC ((lstrlen (printerPnpId) + 2) * sizeof (TCHAR));
  1828. if (!p->String) {
  1829. FREE (p);
  1830. SetLastError (ERROR_NOT_ENOUGH_MEMORY);
  1831. goto exit;
  1832. }
  1833. wsprintf (p->String, TEXT("%s%c"), printerPnpId, TEXT('\0'));
  1834. p->Next = NULL;
  1835. if (!InsertList ((PGENERIC_LIST*)List, (PGENERIC_LIST)p)) {
  1836. DeleteStringCell (p);
  1837. SetLastError (ERROR_NOT_ENOUGH_MEMORY);
  1838. goto exit;
  1839. }
  1840. }
  1841. }
  1842. b = TRUE;
  1843. exit:
  1844. rc = GetLastError();
  1845. if (buffer) {
  1846. FREE (buffer);
  1847. }
  1848. SetLastError(rc);
  1849. return b;
  1850. }
  1851. HDEVINFO
  1852. (WINAPI* SetupapiDiGetClassDevs) (
  1853. IN CONST GUID *ClassGuid, OPTIONAL
  1854. IN PCWSTR Enumerator, OPTIONAL
  1855. IN HWND hwndParent, OPTIONAL
  1856. IN DWORD Flags
  1857. );
  1858. BOOL
  1859. (WINAPI* SetupapiDiGetDeviceRegistryProperty) (
  1860. IN HDEVINFO DeviceInfoSet,
  1861. IN PSP_DEVINFO_DATA DeviceInfoData,
  1862. IN DWORD Property,
  1863. OUT PDWORD PropertyRegDataType, OPTIONAL
  1864. OUT PBYTE PropertyBuffer,
  1865. IN DWORD PropertyBufferSize,
  1866. OUT PDWORD RequiredSize OPTIONAL
  1867. );
  1868. BOOL
  1869. (WINAPI* SetupapiDiEnumDeviceInfo) (
  1870. IN HDEVINFO DeviceInfoSet,
  1871. IN DWORD MemberIndex,
  1872. OUT PSP_DEVINFO_DATA DeviceInfoData
  1873. );
  1874. BOOL
  1875. (WINAPI* SetupapiDiDestroyDeviceInfoList) (
  1876. IN HDEVINFO DeviceInfoSet
  1877. );
  1878. #ifdef UNICODE
  1879. PSTRINGLIST
  1880. BuildMissingPnpIdList (
  1881. VOID
  1882. )
  1883. {
  1884. HDEVINFO hDeviceInfoSet;
  1885. INT nIndex = 0;
  1886. SP_DEVINFO_DATA DeviceInfoData;
  1887. PTSTR buffer = NULL;
  1888. ULONG uHwidSize, uCompatidSize;
  1889. DWORD rc;
  1890. BOOL unsupported;
  1891. PSTRINGLIST p;
  1892. PSTRINGLIST list = NULL;
  1893. HMODULE hSetupapi;
  1894. BOOL b;
  1895. BOOL bException;
  1896. if (OsVersion.dwMajorVersion <= 4) {
  1897. return list;
  1898. }
  1899. hSetupapi = LoadLibrary (TEXT("setupapi.dll"));
  1900. if (!hSetupapi) {
  1901. return list;
  1902. }
  1903. //
  1904. // get the entry points
  1905. //
  1906. (FARPROC)SetupapiDiEnumDeviceInfo = GetProcAddress (hSetupapi, "SetupDiEnumDeviceInfo");
  1907. (FARPROC)SetupapiDiDestroyDeviceInfoList = GetProcAddress (hSetupapi, "SetupDiDestroyDeviceInfoList");
  1908. (FARPROC)SetupapiDiGetClassDevs = GetProcAddress (hSetupapi, "SetupDiGetClassDevsW");
  1909. (FARPROC)SetupapiDiGetDeviceRegistryProperty = GetProcAddress (hSetupapi, "SetupDiGetDeviceRegistryPropertyW");
  1910. if (!SetupapiDiEnumDeviceInfo ||
  1911. !SetupapiDiDestroyDeviceInfoList ||
  1912. !SetupapiDiGetClassDevs ||
  1913. !SetupapiDiGetDeviceRegistryProperty
  1914. ) {
  1915. FreeLibrary (hSetupapi);
  1916. return list;
  1917. }
  1918. hDeviceInfoSet = SetupapiDiGetClassDevs (NULL, NULL, NULL, DIGCF_ALLCLASSES);
  1919. if (hDeviceInfoSet == INVALID_HANDLE_VALUE) {
  1920. FreeLibrary (hSetupapi);
  1921. return list;
  1922. }
  1923. DeviceInfoData.cbSize = sizeof (SP_DEVINFO_DATA);
  1924. while (SetupapiDiEnumDeviceInfo (hDeviceInfoSet, nIndex++, &DeviceInfoData)) {
  1925. uHwidSize = uCompatidSize = 0;
  1926. if (!SetupapiDiGetDeviceRegistryProperty (
  1927. hDeviceInfoSet,
  1928. &DeviceInfoData,
  1929. SPDRP_HARDWAREID,
  1930. NULL,
  1931. NULL,
  1932. 0,
  1933. &uHwidSize
  1934. )) {
  1935. if (GetLastError() != ERROR_INSUFFICIENT_BUFFER &&
  1936. GetLastError() != ERROR_INVALID_DATA
  1937. ) {
  1938. goto exit;
  1939. }
  1940. }
  1941. if (!SetupapiDiGetDeviceRegistryProperty (
  1942. hDeviceInfoSet,
  1943. &DeviceInfoData,
  1944. SPDRP_COMPATIBLEIDS,
  1945. NULL,
  1946. NULL,
  1947. 0,
  1948. &uCompatidSize
  1949. )) {
  1950. if (GetLastError() != ERROR_INSUFFICIENT_BUFFER &&
  1951. GetLastError() != ERROR_INVALID_DATA
  1952. ) {
  1953. goto exit;
  1954. }
  1955. }
  1956. //
  1957. // allocate memory for the multi-sz buffer
  1958. //
  1959. if (!uHwidSize && !uCompatidSize) {
  1960. continue;
  1961. }
  1962. buffer = (PTSTR) MALLOC ((uHwidSize + uCompatidSize) * sizeof (TCHAR));
  1963. if (!buffer) {
  1964. SetLastError (ERROR_NOT_ENOUGH_MEMORY);
  1965. goto exit;
  1966. }
  1967. //
  1968. // get the hardware id and compatible id
  1969. //
  1970. if (uHwidSize) {
  1971. if (!SetupapiDiGetDeviceRegistryProperty(
  1972. hDeviceInfoSet,
  1973. &DeviceInfoData,
  1974. SPDRP_HARDWAREID,
  1975. NULL,
  1976. (PBYTE)buffer,
  1977. uHwidSize,
  1978. NULL
  1979. )) {
  1980. goto exit;
  1981. }
  1982. }
  1983. if (uCompatidSize) {
  1984. rc = uHwidSize / sizeof (TCHAR);
  1985. if (rc > 0) {
  1986. rc--;
  1987. }
  1988. if (!SetupapiDiGetDeviceRegistryProperty(
  1989. hDeviceInfoSet,
  1990. &DeviceInfoData,
  1991. SPDRP_COMPATIBLEIDS,
  1992. NULL,
  1993. (PBYTE)&buffer[rc],
  1994. uCompatidSize,
  1995. NULL
  1996. )) {
  1997. goto exit;
  1998. }
  1999. }
  2000. //
  2001. // check if there is an inbox driver for this device
  2002. //
  2003. bException = FALSE;
  2004. __try {
  2005. b = g_DynUpdtStatus->HwdbHasAnyDriver (
  2006. g_DynUpdtStatus->HwdbDatabase,
  2007. buffer,
  2008. &unsupported
  2009. );
  2010. }
  2011. __except (EXCEPTION_EXECUTE_HANDLER) {
  2012. SetLastError (GetExceptionCode());
  2013. DynUpdtDebugLog (Winnt32LogError, TEXT("BuildMissingPnpIdList: HwdbHasAnyDriver threw an exception"), 0);
  2014. bException = TRUE;
  2015. b = TRUE;
  2016. }
  2017. if (bException) {
  2018. __try {
  2019. //
  2020. // bad string passed back, or some internal error
  2021. // try to print the string
  2022. //
  2023. PTSTR multisz = CreatePrintableString (buffer);
  2024. DynUpdtDebugLog (Winnt32LogError, TEXT(" - The string was %1"), 0, multisz);
  2025. FREE (multisz);
  2026. }
  2027. __except (EXCEPTION_EXECUTE_HANDLER) {
  2028. DynUpdtDebugLog (Winnt32LogError, TEXT(" - Bad string"), 0);
  2029. }
  2030. }
  2031. if (b) {
  2032. FREE (buffer);
  2033. buffer = NULL;
  2034. continue;
  2035. }
  2036. //
  2037. // no inbox driver - add it to the list
  2038. //
  2039. p = (PSTRINGLIST) MALLOC (sizeof (STRINGLIST));
  2040. if (!p) {
  2041. SetLastError (ERROR_NOT_ENOUGH_MEMORY);
  2042. goto exit;
  2043. }
  2044. p->String = buffer;
  2045. p->Next = NULL;
  2046. buffer = NULL;
  2047. if (!InsertList ((PGENERIC_LIST*)&list, (PGENERIC_LIST)p)) {
  2048. DeleteStringCell (p);
  2049. DeleteStringList (list);
  2050. list = NULL;
  2051. SetLastError (ERROR_NOT_ENOUGH_MEMORY);
  2052. goto exit;
  2053. }
  2054. }
  2055. if (GetLastError() == ERROR_NO_MORE_ITEMS) {
  2056. SetLastError (ERROR_SUCCESS);
  2057. }
  2058. exit:
  2059. rc = GetLastError();
  2060. SetupapiDiDestroyDeviceInfoList(hDeviceInfoSet);
  2061. FreeLibrary (hSetupapi);
  2062. if (buffer) {
  2063. FREE (buffer);
  2064. }
  2065. if (rc == ERROR_SUCCESS) {
  2066. //
  2067. // get printer drivers
  2068. //
  2069. if (ISNT()) {
  2070. if (!pAddMissingPrinterDrivers (&list)) {
  2071. rc = GetLastError();
  2072. DeleteStringList (list);
  2073. list = NULL;
  2074. }
  2075. }
  2076. }
  2077. SetLastError(rc);
  2078. return list;
  2079. }
  2080. #endif
  2081. BOOL
  2082. pHwdbHasAnyMissingDrivers (
  2083. IN HANDLE Hwdb,
  2084. IN PSTRINGLIST MissingPnpIds
  2085. )
  2086. {
  2087. PSTRINGLIST p;
  2088. BOOL unsupported;
  2089. BOOL b = FALSE;
  2090. for (p = MissingPnpIds; p; p = p->Next) {
  2091. BOOL bException = FALSE;
  2092. __try {
  2093. if (g_DynUpdtStatus->HwdbHasAnyDriver (Hwdb, p->String, &unsupported)) {
  2094. b = TRUE;
  2095. break;
  2096. }
  2097. }
  2098. __except (EXCEPTION_EXECUTE_HANDLER) {
  2099. SetLastError (GetExceptionCode());
  2100. DynUpdtDebugLog (
  2101. Winnt32LogError,
  2102. TEXT("pHwdbHasAnyMissingDrivers: HwdbHasAnyDriver threw an exception"),
  2103. 0
  2104. );
  2105. bException = TRUE;
  2106. }
  2107. if (bException) {
  2108. __try {
  2109. //
  2110. // bad string passed back, or some internal error
  2111. // try to print the string
  2112. //
  2113. PTSTR multisz = CreatePrintableString (p->String);
  2114. DynUpdtDebugLog (Winnt32LogError, TEXT(" - The string was %1"), 0, multisz);
  2115. FREE (multisz);
  2116. }
  2117. __except (EXCEPTION_EXECUTE_HANDLER) {
  2118. DynUpdtDebugLog (Winnt32LogError, TEXT(" - Bad string"), 0);
  2119. }
  2120. }
  2121. }
  2122. return b;
  2123. }
  2124. typedef struct {
  2125. PCTSTR BaseDir;
  2126. PCTSTR Filename;
  2127. } CONTEXT_EXTRACTFILEINDIR, *PCONTEXT_EXTRACTFILEINDIR;
  2128. UINT
  2129. pExtractFileInDir (
  2130. IN PVOID Context,
  2131. IN UINT Code,
  2132. IN UINT_PTR Param1,
  2133. IN UINT_PTR Param2
  2134. )
  2135. {
  2136. if (g_DynUpdtStatus->Cancelled) {
  2137. return ERROR_CANCELLED;
  2138. }
  2139. switch (Code) {
  2140. case SPFILENOTIFY_FILEINCABINET:
  2141. {
  2142. PFILE_IN_CABINET_INFO FileInCabInfo = (PFILE_IN_CABINET_INFO)Param1;
  2143. PCONTEXT_EXTRACTFILEINDIR ctx = (PCONTEXT_EXTRACTFILEINDIR)Context;
  2144. PTSTR p;
  2145. if (lstrcmpi (FileInCabInfo->NameInCabinet, ctx->Filename)) {
  2146. return FILEOP_SKIP;
  2147. }
  2148. BuildPath (FileInCabInfo->FullTargetName, ctx->BaseDir, FileInCabInfo->NameInCabinet);
  2149. if (_tcschr (FileInCabInfo->NameInCabinet, TEXT('\\'))) {
  2150. //
  2151. // target file is in a subdir; first create it
  2152. //
  2153. p = _tcsrchr (FileInCabInfo->FullTargetName, TEXT('\\'));
  2154. if (p) {
  2155. *p = 0;
  2156. }
  2157. if (CreateMultiLevelDirectory (FileInCabInfo->FullTargetName) != ERROR_SUCCESS) {
  2158. return FILEOP_ABORT;
  2159. }
  2160. if (p) {
  2161. *p = TEXT('\\');
  2162. }
  2163. }
  2164. return FILEOP_DOIT;
  2165. }
  2166. case SPFILENOTIFY_NEEDNEWCABINET:
  2167. {
  2168. PCABINET_INFO CabInfo = (PCABINET_INFO)Param1;
  2169. DynUpdtDebugLog (
  2170. Winnt32LogError,
  2171. TEXT("pExtractFileInDir: NeedNewCabinet %1\\%2 on %3 (SetId=%4!u!;CabinetNumber=%5!u!)"),
  2172. 0,
  2173. CabInfo->CabinetPath,
  2174. CabInfo->CabinetFile,
  2175. CabInfo->DiskName,
  2176. CabInfo->SetId,
  2177. CabInfo->CabinetNumber
  2178. );
  2179. return ERROR_FILE_NOT_FOUND;
  2180. }
  2181. }
  2182. return NO_ERROR;
  2183. }
  2184. UINT
  2185. pExpandCabInDir (
  2186. IN PVOID Context,
  2187. IN UINT Code,
  2188. IN UINT_PTR Param1,
  2189. IN UINT_PTR Param2
  2190. )
  2191. {
  2192. if (g_DynUpdtStatus->Cancelled) {
  2193. return ERROR_CANCELLED;
  2194. }
  2195. switch (Code) {
  2196. case SPFILENOTIFY_FILEINCABINET:
  2197. {
  2198. PFILE_IN_CABINET_INFO FileInCabInfo = (PFILE_IN_CABINET_INFO)Param1;
  2199. PTSTR p;
  2200. BuildPath (FileInCabInfo->FullTargetName, (PCTSTR)Context, FileInCabInfo->NameInCabinet);
  2201. if (_tcschr (FileInCabInfo->NameInCabinet, TEXT('\\'))) {
  2202. //
  2203. // target file is in a subdir; first create it
  2204. //
  2205. p = _tcsrchr (FileInCabInfo->FullTargetName, TEXT('\\'));
  2206. if (p) {
  2207. *p = 0;
  2208. }
  2209. if (CreateMultiLevelDirectory (FileInCabInfo->FullTargetName) != ERROR_SUCCESS) {
  2210. return FILEOP_ABORT;
  2211. }
  2212. if (p) {
  2213. *p = TEXT('\\');
  2214. }
  2215. }
  2216. return FILEOP_DOIT;
  2217. }
  2218. case SPFILENOTIFY_NEEDNEWCABINET:
  2219. {
  2220. PCABINET_INFO CabInfo = (PCABINET_INFO)Param1;
  2221. DynUpdtDebugLog (
  2222. Winnt32LogError,
  2223. TEXT("pExpandCabInDir: NeedNewCabinet %1\\%2 on %3 (SetId=%4!u!;CabinetNumber=%5!u!)"),
  2224. 0,
  2225. CabInfo->CabinetPath,
  2226. CabInfo->CabinetFile,
  2227. CabInfo->DiskName,
  2228. CabInfo->SetId,
  2229. CabInfo->CabinetNumber
  2230. );
  2231. return ERROR_FILE_NOT_FOUND;
  2232. }
  2233. }
  2234. return NO_ERROR;
  2235. }
  2236. BOOL
  2237. pGetAutoSubdirName (
  2238. IN PCTSTR FilePath,
  2239. OUT PTSTR DirName,
  2240. IN DWORD DirNameChars
  2241. )
  2242. {
  2243. PTSTR p, q;
  2244. lstrcpyn (DirName, FilePath, DirNameChars);
  2245. p = _tcsrchr (DirName, TEXT('.'));
  2246. q = _tcsrchr (DirName, TEXT('\\'));
  2247. if (!p || (q && p < q)) {
  2248. return FALSE;
  2249. }
  2250. *p = 0;
  2251. return TRUE;
  2252. }
  2253. BOOL
  2254. pAddLibrariesForCompToCopyQueue (
  2255. IN PCTSTR ModuleName,
  2256. IN PCTSTR Subdir,
  2257. IN PCTSTR BaseDir,
  2258. IN HSPFILEQ SetupQueue
  2259. )
  2260. {
  2261. static struct {
  2262. PCTSTR SubDir;
  2263. PCTSTR LibsMultiSz;
  2264. } g_SubdirReqLibs [] = {
  2265. TEXT("win9xupg"), TEXT("setupapi.dll\0cfgmgr32.dll\0msvcrt.dll\0cabinet.dll\0imagehlp.dll\0"),
  2266. TEXT("winntupg"), TEXT("setupapi.dll\0cfgmgr32.dll\0msvcrt.dll\0"),
  2267. };
  2268. INT i;
  2269. TCHAR dst[MAX_PATH];
  2270. TCHAR src[MAX_PATH];
  2271. TCHAR sourceFile[MAX_PATH];
  2272. PTSTR p, q;
  2273. PCTSTR fileName;
  2274. for (i = 0; i < ARRAYSIZE (g_SubdirReqLibs); i++) {
  2275. if (Subdir == g_SubdirReqLibs[i].SubDir ||
  2276. Subdir && !lstrcmpi (Subdir, g_SubdirReqLibs[i].SubDir)
  2277. ) {
  2278. break;
  2279. }
  2280. }
  2281. if (i >= ARRAYSIZE (g_SubdirReqLibs)) {
  2282. return TRUE;
  2283. }
  2284. //
  2285. // prepare src and dest path
  2286. //
  2287. if (!MyGetModuleFileName (NULL, src, ARRAYSIZE(src))) {
  2288. return FALSE;
  2289. }
  2290. p = _tcsrchr (src, TEXT('\\'));
  2291. if (!p) {
  2292. return FALSE;
  2293. }
  2294. *p = 0;
  2295. i = _sntprintf (dst, ARRAYSIZE(dst), TEXT("%s"), BaseDir);
  2296. if (i < 0) {
  2297. return FALSE;
  2298. }
  2299. q = dst + i;
  2300. if (Subdir) {
  2301. i = _sntprintf (p, ARRAYSIZE(src) - (p - src), TEXT("\\%s"), Subdir);
  2302. if (i < 0) {
  2303. return FALSE;
  2304. }
  2305. p += i;
  2306. i = _sntprintf (q, ARRAYSIZE(dst) - (q - dst), TEXT("\\%s"), Subdir);
  2307. if (i < 0) {
  2308. return FALSE;
  2309. }
  2310. q += i;
  2311. }
  2312. //
  2313. // copy each source file
  2314. //
  2315. for (fileName = g_SubdirReqLibs[i].LibsMultiSz;
  2316. *fileName;
  2317. fileName = _tcschr (fileName, 0) + 1) {
  2318. i = _sntprintf (q, ARRAYSIZE(dst) - (q - dst), TEXT("\\%s"), fileName);
  2319. if (i < 0) {
  2320. return FALSE;
  2321. }
  2322. //
  2323. // check if file already exists at dest
  2324. //
  2325. if (!pDoesFileExist (dst)) {
  2326. //
  2327. // check if the source file actually exists
  2328. //
  2329. if (!BuildPath (sourceFile, src, fileName)) {
  2330. return FALSE;
  2331. }
  2332. if (!pDoesFileExist (sourceFile)) {
  2333. DynUpdtDebugLog (Winnt32LogError, TEXT("Source file %1 not found"), 0, sourceFile);
  2334. return FALSE;
  2335. }
  2336. //
  2337. // prepare source path and copy file
  2338. //
  2339. *q = 0;
  2340. if (!SetupapiQueueCopy (
  2341. SetupQueue,
  2342. src,
  2343. NULL,
  2344. fileName,
  2345. NULL,
  2346. NULL,
  2347. dst,
  2348. NULL,
  2349. SP_COPY_SOURCEPATH_ABSOLUTE
  2350. )) {
  2351. return FALSE;
  2352. }
  2353. }
  2354. }
  2355. return TRUE;
  2356. }
  2357. BOOL
  2358. pIsBootDriver (
  2359. IN PCTSTR DriverFilesDir
  2360. )
  2361. {
  2362. FILEPATTERN_ENUM e;
  2363. BOOL b = FALSE;
  2364. if (EnumFirstFilePattern (&e, DriverFilesDir, TEXT("txtsetup.oem"))) {
  2365. b = !(e.FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
  2366. AbortEnumFilePattern (&e);
  2367. }
  2368. return b;
  2369. }
  2370. BOOL
  2371. pIsExcluded (
  2372. IN HINF GuiDrvsInf,
  2373. IN PCTSTR PnPId,
  2374. IN PCTSTR ActualInfFilename,
  2375. IN PCTSTR SourceDir,
  2376. IN PCTSTR FullInfPath
  2377. )
  2378. {
  2379. TCHAR buffer[MAX_PATH];
  2380. PTSTR packageName;
  2381. INFCONTEXT ic;
  2382. TCHAR field[MAX_PATH];
  2383. TCHAR driverVer[MAX_PATH];
  2384. if (!((GuiDrvsInf != INVALID_HANDLE_VALUE && PnPId && ActualInfFilename && SourceDir && FullInfPath))) {
  2385. MYASSERT (FALSE);
  2386. return FALSE;
  2387. }
  2388. if (FAILED (StringCchCopy (buffer, ARRAYSIZE(buffer), SourceDir))) {
  2389. MYASSERT (FALSE);
  2390. return FALSE;
  2391. }
  2392. packageName = _tcsrchr (buffer, TEXT('\\'));
  2393. if (!packageName) {
  2394. return FALSE;
  2395. }
  2396. packageName++;
  2397. if (SetupapiFindFirstLine (GuiDrvsInf, TEXT("ExcludedDrivers"), NULL, &ic)) {
  2398. do {
  2399. if (!SetupapiGetStringField (&ic, GUIDRVS_FIELD_CABNAME, field, ARRAYSIZE(field), NULL)) {
  2400. continue;
  2401. }
  2402. if (lstrcmpi (field, packageName)) {
  2403. continue;
  2404. }
  2405. if (!SetupapiGetStringField (&ic, GUIDRVS_FIELD_INFNAME, field, ARRAYSIZE(field), NULL)) {
  2406. return TRUE;
  2407. }
  2408. if (lstrcmpi (field, ActualInfFilename)) {
  2409. continue;
  2410. }
  2411. if (SetupapiGetStringField (&ic, GUIDRVS_FIELD_DRIVERVER, field, ARRAYSIZE(field), NULL)) {
  2412. if (field[0] != TEXT('*')) {
  2413. //
  2414. // read the DriverVer value out of this INF
  2415. //
  2416. GetPrivateProfileString (
  2417. TEXT("Version"),
  2418. TEXT("DriverVer"),
  2419. TEXT(""),
  2420. driverVer,
  2421. ARRAYSIZE(driverVer),
  2422. FullInfPath
  2423. );
  2424. if (lstrcmpi (field, driverVer)) {
  2425. continue;
  2426. }
  2427. }
  2428. }
  2429. if (SetupapiGetStringField (&ic, GUIDRVS_FIELD_HARDWAREID, field, ARRAYSIZE(field), NULL) &&
  2430. lstrcmpi (field, PnPId)
  2431. ) {
  2432. continue;
  2433. }
  2434. return TRUE;
  2435. } while (SetupapiFindNextLine (&ic, &ic));
  2436. }
  2437. return FALSE;
  2438. }
  2439. BOOL
  2440. Winnt32HwdbAppendInfsCallback (
  2441. IN PVOID Context,
  2442. IN PCTSTR PnpId,
  2443. IN PCTSTR ActualInfFilename,
  2444. IN PCTSTR SourceDir,
  2445. IN PCTSTR FullInfPath
  2446. )
  2447. {
  2448. HINF hGuiDrvs = (HINF)Context;
  2449. MYASSERT (hGuiDrvs != INVALID_HANDLE_VALUE);
  2450. return !pIsExcluded (hGuiDrvs, PnpId, ActualInfFilename, SourceDir, FullInfPath);
  2451. }
  2452. BOOL
  2453. pBuildHwcompDat (
  2454. IN PCTSTR DriverDir,
  2455. IN HINF GuidrvsInf, OPTIONAL
  2456. IN BOOL AlwaysRebuild,
  2457. IN BOOL AllowUI
  2458. )
  2459. {
  2460. HANDLE hDB;
  2461. TCHAR datFile[MAX_PATH];
  2462. BOOL b = TRUE;
  2463. BuildPath (datFile, DriverDir, S_HWCOMP_DAT);
  2464. if (AlwaysRebuild) {
  2465. SetFileAttributes (datFile, FILE_ATTRIBUTE_NORMAL);
  2466. DeleteFile (datFile);
  2467. }
  2468. if (pDoesFileExist (datFile)) {
  2469. return TRUE;
  2470. }
  2471. hDB = g_DynUpdtStatus->HwdbOpen (NULL);
  2472. if (!hDB) {
  2473. return FALSE;
  2474. }
  2475. if (g_DynUpdtStatus->HwdbAppendInfs (
  2476. hDB,
  2477. DriverDir,
  2478. GuidrvsInf != INVALID_HANDLE_VALUE ? Winnt32HwdbAppendInfsCallback : NULL,
  2479. (PVOID)GuidrvsInf
  2480. )) {
  2481. if (g_DynUpdtStatus->HwdbFlush (hDB, datFile)) {
  2482. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Successfully built %1"), 0, datFile);
  2483. } else {
  2484. if (AllowUI) {
  2485. MessageBoxFromMessage (
  2486. g_DynUpdtStatus->ProgressWindow,
  2487. MSG_ERROR_WRITING_FILE,
  2488. FALSE,
  2489. AppTitleStringId,
  2490. MB_OK | MB_ICONERROR | MB_TASKMODAL,
  2491. GetLastError (),
  2492. datFile
  2493. );
  2494. }
  2495. b = FALSE;
  2496. }
  2497. } else {
  2498. if (AllowUI) {
  2499. MessageBoxFromMessage (
  2500. g_DynUpdtStatus->ProgressWindow,
  2501. MSG_ERROR_PROCESSING_DRIVER,
  2502. FALSE,
  2503. AppTitleStringId,
  2504. MB_OK | MB_ICONERROR | MB_TASKMODAL,
  2505. DriverDir
  2506. );
  2507. }
  2508. b = FALSE;
  2509. }
  2510. g_DynUpdtStatus->HwdbClose (hDB);
  2511. return b;
  2512. }
  2513. UINT
  2514. pWriteAnsiFilelistToFile (
  2515. IN PVOID Context,
  2516. IN UINT Code,
  2517. IN UINT_PTR Param1,
  2518. IN UINT_PTR Param2
  2519. )
  2520. {
  2521. if (g_DynUpdtStatus->Cancelled) {
  2522. return ERROR_CANCELLED;
  2523. }
  2524. switch (Code) {
  2525. case SPFILENOTIFY_FILEINCABINET:
  2526. {
  2527. PFILE_IN_CABINET_INFO FileInCabInfo = (PFILE_IN_CABINET_INFO)Param1;
  2528. CHAR ansi[MAX_PATH];
  2529. INT size;
  2530. DWORD bytes;
  2531. PCTSTR p;
  2532. MYASSERT (!_tcschr (FileInCabInfo->NameInCabinet, TEXT('\\')));
  2533. #pragma prefast(suppress:53, the result of _snprintf is tested)
  2534. #ifdef UNICODE
  2535. size = _snprintf (ansi, ARRAYSIZE(ansi), "%ls\r\n", FileInCabInfo->NameInCabinet);
  2536. #else
  2537. size = _snprintf (ansi, ARRAYSIZE(ansi), "%s\r\n", FileInCabInfo->NameInCabinet);
  2538. #endif
  2539. if (size < 0) {
  2540. return FILEOP_ABORT;
  2541. }
  2542. //
  2543. // Warning: ansi may not be nul-terminated, but it doesn't matter
  2544. // for the write operation below
  2545. //
  2546. if (!WriteFile ((HANDLE)Context, ansi, size, &bytes, NULL) || bytes != size) {
  2547. return FILEOP_ABORT;
  2548. }
  2549. return FILEOP_SKIP;
  2550. }
  2551. }
  2552. return NO_ERROR;
  2553. }
  2554. BOOL
  2555. CreateFileListSif (
  2556. IN PCTSTR SifPath,
  2557. IN PCTSTR SectionName,
  2558. IN PCTSTR CabinetToScan
  2559. )
  2560. {
  2561. HANDLE sif;
  2562. CHAR ansi[MAX_PATH];
  2563. INT size;
  2564. DWORD bytes;
  2565. BOOL b = TRUE;
  2566. //
  2567. // First prepare the section string
  2568. //
  2569. #ifdef UNICODE
  2570. #pragma prefast(suppress:53, the result of _snprintf is tested)
  2571. size = _snprintf (ansi, ARRAYSIZE(ansi), "[%ls]\r\n", SectionName);
  2572. #else
  2573. #pragma prefast(suppress:53, the result of _snprintf is tested)
  2574. size = _snprintf (ansi, ARRAYSIZE(ansi), "[%s]\r\n", SectionName);
  2575. #endif
  2576. if (size < 0) {
  2577. return FALSE;
  2578. }
  2579. //
  2580. // Warning: the string above may not be nul-terminated, but it doesn't matter
  2581. // for the write operation below
  2582. //
  2583. sif = CreateFile (
  2584. SifPath,
  2585. GENERIC_WRITE,
  2586. FILE_SHARE_READ,
  2587. NULL,
  2588. CREATE_ALWAYS,
  2589. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
  2590. NULL
  2591. );
  2592. if (sif == INVALID_HANDLE_VALUE) {
  2593. return FALSE;
  2594. }
  2595. if (!WriteFile (sif, ansi, size, &bytes, NULL) || bytes != size) {
  2596. b = FALSE;
  2597. goto exit;
  2598. }
  2599. b = MySetupIterateCabinet (CabinetToScan, 0, pWriteAnsiFilelistToFile, (PVOID)sif);
  2600. exit:
  2601. CloseHandle (sif);
  2602. if (!b) {
  2603. DeleteFile (SifPath);
  2604. }
  2605. return b;
  2606. }
  2607. BOOL
  2608. pIsExecutableModule (
  2609. IN PCTSTR ModulePath
  2610. )
  2611. {
  2612. PCTSTR p;
  2613. p = GetFileExtension (ModulePath);
  2614. return p && !lstrcmpi (p, TEXT(".dll"));
  2615. }
  2616. UINT
  2617. pCopyFilesCallback (
  2618. IN PVOID Context, //context used by the callback routine
  2619. IN UINT Notification, //notification sent to callback routine
  2620. IN UINT_PTR Param1, //additional notification information
  2621. IN UINT_PTR Param2 //additional notification information
  2622. )
  2623. {
  2624. switch (Notification) {
  2625. case SPFILENOTIFY_COPYERROR:
  2626. return FILEOP_ABORT;
  2627. case SPFILENOTIFY_STARTCOPY:
  2628. //
  2629. // try to avoid unnecessary setupapi warnings that the files are not signed
  2630. // or even blocked because of this; try to copy the file ourselves first
  2631. //
  2632. {
  2633. PFILEPATHS paths = (PFILEPATHS)Param1;
  2634. if (CopyFile (paths->Source, paths->Target, FALSE)) {
  2635. return FILEOP_SKIP;
  2636. }
  2637. }
  2638. break;
  2639. case SPFILENOTIFY_STARTQUEUE:
  2640. case SPFILENOTIFY_STARTSUBQUEUE:
  2641. case SPFILENOTIFY_ENDSUBQUEUE:
  2642. case SPFILENOTIFY_ENDQUEUE:
  2643. return !g_DynUpdtStatus->Cancelled;
  2644. }
  2645. return SetupapiDefaultQueueCallback (Context, Notification, Param1, Param2);
  2646. }
  2647. BOOL
  2648. pProcessWinnt32Files (
  2649. IN PCTSTR Winnt32Cab,
  2650. IN BOOL ClientInstall,
  2651. OUT PBOOL StopSetup
  2652. )
  2653. {
  2654. FILEPATTERNREC_ENUM e;
  2655. TCHAR winnt32WorkingDir[MAX_PATH];
  2656. TCHAR dst[MAX_PATH];
  2657. PTSTR p, subdir;
  2658. HSPFILEQ hq;
  2659. BOOL bLoaded;
  2660. BOOL bRestartRequired;
  2661. BOOL bReloadMainInf = FALSE;
  2662. TCHAR buffer[MAX_PATH];
  2663. TCHAR origSubPath[MAX_PATH];
  2664. TCHAR origFileName[MAX_PATH];
  2665. TCHAR origFilePath[MAX_PATH];
  2666. TCHAR destFilePath[MAX_PATH];
  2667. TCHAR version[100];
  2668. BOOL b = TRUE;
  2669. *StopSetup = FALSE;
  2670. if (!pNonemptyFilePresent (Winnt32Cab)) {
  2671. if (!ClientInstall) {
  2672. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Package %1 is not present"), 0, Winnt32Cab);
  2673. }
  2674. return TRUE;
  2675. } else {
  2676. //
  2677. // don't process the cabinet in client installation mode; just warn about that
  2678. //
  2679. if (ClientInstall) {
  2680. //
  2681. // user specified updates location, but they didn't run winnt32 /prepare now or before
  2682. //
  2683. MessageBoxFromMessage (
  2684. g_DynUpdtStatus->ProgressWindow,
  2685. MSG_MUST_PREPARE_SHARE,
  2686. FALSE,
  2687. AppTitleStringId,
  2688. MB_OK | MB_ICONSTOP | MB_TASKMODAL,
  2689. g_DynUpdtStatus->DynamicUpdatesSource
  2690. );
  2691. *StopSetup = TRUE;
  2692. return FALSE;
  2693. }
  2694. }
  2695. DynUpdtDebugLog (
  2696. DynUpdtLogLevel,
  2697. TEXT("Analyzing package %1..."),
  2698. 0,
  2699. Winnt32Cab
  2700. );
  2701. //
  2702. // expand it in the corresponding subdir
  2703. //
  2704. BuildPath (
  2705. winnt32WorkingDir,
  2706. g_DynUpdtStatus->PrepareWinnt32 ?
  2707. g_DynUpdtStatus->DynamicUpdatesSource :
  2708. g_DynUpdtStatus->WorkingDir,
  2709. S_SUBDIRNAME_WINNT32
  2710. );
  2711. //
  2712. // expand CAB in this dir
  2713. //
  2714. if (CreateMultiLevelDirectory (winnt32WorkingDir) != ERROR_SUCCESS) {
  2715. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to create dir %1"), 0, winnt32WorkingDir);
  2716. return FALSE;
  2717. }
  2718. if (!MySetupIterateCabinet (Winnt32Cab, 0, pExpandCabInDir, (PVOID)winnt32WorkingDir)) {
  2719. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to expand cabinet %1"), 0, Winnt32Cab);
  2720. return FALSE;
  2721. }
  2722. //
  2723. // ISSUE: the patching support is currently not available for platforms other than x86
  2724. //
  2725. #if defined(_X86_)
  2726. //
  2727. // now let's look for any patches
  2728. //
  2729. if (EnumFirstFilePatternRecursive (&e, winnt32WorkingDir, S_PATCH_FILE_EXT, 0)) {
  2730. do {
  2731. BOOL bDeleteTempFile = FALSE;
  2732. if (g_DynUpdtStatus->Cancelled) {
  2733. SetLastError (ERROR_CANCELLED);
  2734. b = FALSE;
  2735. break;
  2736. }
  2737. if (e.FindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  2738. continue;
  2739. }
  2740. DynUpdtDebugLog (
  2741. DynUpdtLogLevel,
  2742. TEXT("pProcessWinnt32Files: found patch %1"),
  2743. 0,
  2744. e.FullPath
  2745. );
  2746. //
  2747. // get the original file from the sources location
  2748. // the filename is obtained cutting the ._p1 extension
  2749. //
  2750. if (FAILED(StringCchCopy (origFileName, ARRAYSIZE(origFileName), e.FileName))) {
  2751. //
  2752. // should never happen, as e.FileName comes from an enum routine
  2753. //
  2754. MYASSERT (FALSE);
  2755. b = FALSE;
  2756. break;
  2757. }
  2758. p = GetFileExtension (origFileName);
  2759. if (!p) {
  2760. MYASSERT (FALSE);
  2761. continue;
  2762. }
  2763. *p = 0;
  2764. if (FAILED(StringCchCopy (origSubPath, ARRAYSIZE(origSubPath), e.SubPath))) {
  2765. MYASSERT (FALSE);
  2766. b = FALSE;
  2767. break;
  2768. }
  2769. p = GetFileExtension (origSubPath);
  2770. if (!p) {
  2771. MYASSERT (FALSE);
  2772. continue;
  2773. }
  2774. *p = 0;
  2775. if (!MyGetModuleFileName (NULL, origFilePath, ARRAYSIZE(origFilePath)) ||
  2776. !(p = _tcsrchr (origFilePath, TEXT('\\')))) {
  2777. b = FALSE;
  2778. break;
  2779. }
  2780. *p = 0;
  2781. if (!ConcatenatePaths (origFilePath, origSubPath, ARRAYSIZE(origFilePath))) {
  2782. MYASSERT (FALSE);
  2783. b = FALSE;
  2784. break;
  2785. }
  2786. //
  2787. // now check if this file (in it's compressed form or not) actually exists
  2788. //
  2789. if (!pDoesFileExist (origFilePath)) {
  2790. //
  2791. // try the compressed form
  2792. //
  2793. p = _tcschr (origFilePath, 0);
  2794. MYASSERT (p);
  2795. if (!p) {
  2796. continue;
  2797. }
  2798. p = _tcsdec (origFilePath, p);
  2799. MYASSERT (p);
  2800. if (!p) {
  2801. continue;
  2802. }
  2803. *p = TEXT('_');
  2804. if (!pDoesFileExist (origFilePath)) {
  2805. DynUpdtDebugLog (
  2806. Winnt32LogError,
  2807. TEXT("pProcessWinnt32Files: Unable to find original file %1 to apply the patch"),
  2808. 0,
  2809. origSubPath
  2810. );
  2811. b = FALSE;
  2812. break;
  2813. }
  2814. //
  2815. // expand the file to the temp dir
  2816. //
  2817. if (!BuildPath (buffer, g_DynUpdtStatus->TempDir, origSubPath)) {
  2818. MYASSERT (FALSE);
  2819. b = FALSE;
  2820. break;
  2821. }
  2822. p = _tcsrchr (buffer, TEXT('\\'));
  2823. MYASSERT (p);
  2824. if (!p) {
  2825. continue;
  2826. }
  2827. *p = 0;
  2828. if (CreateMultiLevelDirectory (buffer) != ERROR_SUCCESS) {
  2829. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessWinnt32Files: Unable to create dir %1"), 0, buffer);
  2830. b = FALSE;
  2831. break;
  2832. }
  2833. if (!MySetupIterateCabinet (origFilePath, 0, pExpandCabInDir, buffer)) {
  2834. DynUpdtDebugLog (
  2835. Winnt32LogError,
  2836. TEXT("pProcessWinnt32Files: Unable to expand original file %1 to dir %2"),
  2837. 0,
  2838. origFilePath,
  2839. buffer
  2840. );
  2841. b = FALSE;
  2842. break;
  2843. }
  2844. *p = TEXT('\\');
  2845. //
  2846. // dest is NOT shorter than source
  2847. //
  2848. MYASSERT (ARRAYSIZE(origFilePath) <= ARRAYSIZE(buffer));
  2849. lstrcpy (origFilePath, buffer);
  2850. bDeleteTempFile = TRUE;
  2851. }
  2852. BuildPath (destFilePath, winnt32WorkingDir, TEXT("$$temp$$.~~~"));
  2853. //
  2854. // now really apply the patch
  2855. //
  2856. if (!ApplyPatchToFile (e.FullPath, origFilePath, destFilePath, 0)) {
  2857. DynUpdtDebugLog (
  2858. Winnt32LogError,
  2859. TEXT("pProcessWinnt32Files: ApplyPatchToFile failed to apply patch %1 to file %2"),
  2860. 0,
  2861. e.FullPath,
  2862. origFilePath
  2863. );
  2864. b = FALSE;
  2865. break;
  2866. }
  2867. //
  2868. // success! now move the file to the real destination
  2869. //
  2870. if (!BuildPath (buffer, winnt32WorkingDir, origSubPath)) {
  2871. b = FALSE;
  2872. break;
  2873. }
  2874. p = _tcsrchr (buffer, TEXT('\\'));
  2875. MYASSERT (p);
  2876. if (!p) {
  2877. continue;
  2878. }
  2879. *p = 0;
  2880. if (CreateMultiLevelDirectory (buffer) != ERROR_SUCCESS) {
  2881. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessWinnt32Files: Unable to create dir %1"), 0, buffer);
  2882. b = FALSE;
  2883. break;
  2884. }
  2885. *p = TEXT('\\');
  2886. SetFileAttributes (buffer, FILE_ATTRIBUTE_NORMAL);
  2887. DeleteFile (buffer);
  2888. if (!MoveFile (destFilePath, buffer)) {
  2889. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessWinnt32Files: Unable to move file %1 to final dest %2"), 0, destFilePath, buffer);
  2890. b = FALSE;
  2891. break;
  2892. }
  2893. if (!GetFileVersion (buffer, version)) {
  2894. MYASSERT (ARRAYSIZE(version) <= ARRAYSIZE("<unknown>"));
  2895. lstrcpy (version, TEXT("<unknown>"));
  2896. }
  2897. DynUpdtDebugLog (
  2898. DynUpdtLogLevel,
  2899. TEXT("pProcessWinnt32Files: successfully applied patch %1 to file %2; the new file %3 has version %4"),
  2900. 0,
  2901. e.FullPath,
  2902. origFilePath,
  2903. buffer,
  2904. version
  2905. );
  2906. //
  2907. // now remove the patch file
  2908. //
  2909. SetFileAttributes (e.FullPath, FILE_ATTRIBUTE_NORMAL);
  2910. DeleteFile (e.FullPath);
  2911. if (bDeleteTempFile) {
  2912. SetFileAttributes (origFilePath, FILE_ATTRIBUTE_NORMAL);
  2913. DeleteFile (origFilePath);
  2914. }
  2915. } while (EnumNextFilePatternRecursive (&e));
  2916. AbortEnumFilePatternRecursive (&e);
  2917. }
  2918. #endif
  2919. if (!b) {
  2920. goto exit;
  2921. }
  2922. //
  2923. // process new Winnt32 components
  2924. //
  2925. hq = SetupapiOpenFileQueue ();
  2926. if (hq == INVALID_HANDLE_VALUE) {
  2927. return FALSE;
  2928. }
  2929. if (EnumFirstFilePatternRecursive (&e, winnt32WorkingDir, TEXT("*"), 0)) {
  2930. do {
  2931. if (g_DynUpdtStatus->Cancelled) {
  2932. SetLastError (ERROR_CANCELLED);
  2933. b = FALSE;
  2934. break;
  2935. }
  2936. if (e.FindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  2937. continue;
  2938. }
  2939. if (!MyGetModuleFileName (NULL, dst, MAX_PATH) ||
  2940. !(p = _tcsrchr (dst, TEXT('\\')))) {
  2941. b = FALSE;
  2942. break;
  2943. }
  2944. *p = 0;
  2945. if (!ConcatenatePaths (dst, e.SubPath, MAX_PATH)) {
  2946. b = FALSE;
  2947. break;
  2948. }
  2949. //
  2950. // check file versions first
  2951. //
  2952. if (IsFileVersionLesser (e.FullPath, dst)) {
  2953. continue;
  2954. }
  2955. //
  2956. // if there's a file named winnt32.rst, force restart
  2957. //
  2958. if (!lstrcmpi (e.FileName, S_RESTART_FILENAME)) {
  2959. if (!g_DynUpdtStatus->PrepareWinnt32) {
  2960. g_DynUpdtStatus->RestartWinnt32 = TRUE;
  2961. DynUpdtDebugLog (
  2962. DynUpdtLogLevel,
  2963. TEXT("File %1 present; winnt32 will restart"),
  2964. 0,
  2965. e.FileName
  2966. );
  2967. }
  2968. } else {
  2969. //
  2970. // check if dosnet.inf is present; if it is, reset the global variables
  2971. //
  2972. if (!lstrcmpi (e.FileName, InfName) && FullInfName[0]) {
  2973. FullInfName[0] = 0;
  2974. bReloadMainInf = TRUE;
  2975. }
  2976. bLoaded = FALSE;
  2977. bRestartRequired = Upgrade || !_tcschr (e.SubPath, TEXT('\\'));
  2978. if (GetModuleHandle (e.FileName) != NULL) {
  2979. bLoaded = TRUE;
  2980. if (!g_DynUpdtStatus->PrepareWinnt32) {
  2981. //
  2982. // do NOT restart if it's NOT an upgrade and this is one of the upgrade modules
  2983. //
  2984. if (bRestartRequired) {
  2985. //
  2986. // need to restart winnt32 so the newly registered component can be used instead
  2987. //
  2988. g_DynUpdtStatus->RestartWinnt32 = TRUE;
  2989. DynUpdtDebugLog (
  2990. DynUpdtLogLevel,
  2991. TEXT("A newer version is available for %1; winnt32 will restart"),
  2992. 0,
  2993. e.SubPath
  2994. );
  2995. }
  2996. }
  2997. }
  2998. if ((bLoaded || pIsExecutableModule (e.FullPath)) &&
  2999. (bRestartRequired || g_DynUpdtStatus->PrepareWinnt32)
  3000. ) {
  3001. //
  3002. // make all required libraries available for this module
  3003. //
  3004. p = _tcsrchr (e.SubPath, TEXT('\\'));
  3005. if (p) {
  3006. *p = 0;
  3007. subdir = e.SubPath;
  3008. } else {
  3009. subdir = NULL;
  3010. }
  3011. if (!pAddLibrariesForCompToCopyQueue (e.FileName, subdir, winnt32WorkingDir, hq)) {
  3012. b = FALSE;
  3013. break;
  3014. }
  3015. if (p) {
  3016. *p = TEXT('\\');
  3017. }
  3018. }
  3019. }
  3020. } while (EnumNextFilePatternRecursive (&e));
  3021. AbortEnumFilePatternRecursive (&e);
  3022. if (b) {
  3023. PVOID ctx;
  3024. ctx = SetupapiInitDefaultQueueCallback (NULL);
  3025. b = SetupapiCommitFileQueue (NULL, hq, pCopyFilesCallback, ctx);
  3026. SetupapiTermDefaultQueueCallback (ctx);
  3027. if (!b) {
  3028. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessWinnt32Files: SetupapiCommitFileQueue failed"), 0);
  3029. }
  3030. }
  3031. }
  3032. SetupapiCloseFileQueue (hq);
  3033. if (b) {
  3034. SetFileAttributes (Winnt32Cab, FILE_ATTRIBUTE_NORMAL);
  3035. if (!DeleteFile (Winnt32Cab)) {
  3036. DynUpdtDebugLog (Winnt32LogSevereError, TEXT("pProcessWinnt32Files: unable to delete file %1"), 0, Winnt32Cab);
  3037. b = FALSE;
  3038. }
  3039. }
  3040. if (b && bReloadMainInf) {
  3041. b = FindPathToWinnt32File (InfName, FullInfName, MAX_PATH);
  3042. MYASSERT (b);
  3043. if (MainInf) {
  3044. UnloadInfFile (MainInf);
  3045. MainInf = NULL;
  3046. b = LoadInfFile (FullInfName, TRUE, &MainInf) == NO_ERROR;
  3047. }
  3048. }
  3049. exit:
  3050. return b;
  3051. }
  3052. BOOL
  3053. pValidOsFile (
  3054. IN PCTSTR FilePath
  3055. )
  3056. {
  3057. DWORD headerSum, checkSum;
  3058. if (!g_DynUpdtStatus->ImagehlpDll) {
  3059. //
  3060. // first time, try to load the library
  3061. //
  3062. g_DynUpdtStatus->ImagehlpDll = LoadLibrary (TEXT("imagehlp.dll"));
  3063. if (!g_DynUpdtStatus->ImagehlpDll) {
  3064. //
  3065. // mark the failure
  3066. //
  3067. DynUpdtDebugLog (
  3068. Winnt32LogWarning,
  3069. TEXT("pValidOsFile: unable to load %1 (rc=%2!u!); all files are assumed valid"),
  3070. 0,
  3071. TEXT("imagehlp.dll"),
  3072. GetLastError ()
  3073. );
  3074. g_DynUpdtStatus->ImagehlpDll = (HANDLE)-1;
  3075. return TRUE;
  3076. }
  3077. g_DynUpdtStatus->IhMapFileAndCheckSum = (PFNMAPFILEANDCHECKSUM) GetProcAddress (
  3078. g_DynUpdtStatus->ImagehlpDll,
  3079. #ifdef UNICODE
  3080. "MapFileAndCheckSumW"
  3081. #else
  3082. "MapFileAndCheckSumA"
  3083. #endif
  3084. );
  3085. if (!g_DynUpdtStatus->IhMapFileAndCheckSum) {
  3086. //
  3087. // mark the failure
  3088. //
  3089. DynUpdtDebugLog (
  3090. Winnt32LogWarning,
  3091. TEXT("pValidOsFile: unable to find required proc in %1 (rc=%2!u!); all files are assumed valid"),
  3092. 0,
  3093. TEXT("imagehlp.dll"),
  3094. GetLastError ()
  3095. );
  3096. FreeLibrary (g_DynUpdtStatus->ImagehlpDll);
  3097. g_DynUpdtStatus->ImagehlpDll = (HANDLE)-1;
  3098. return TRUE;
  3099. }
  3100. }
  3101. if (g_DynUpdtStatus->ImagehlpDll == (HANDLE)-1) {
  3102. //
  3103. // imagehlp not available, just asssume it's good
  3104. //
  3105. return TRUE;
  3106. }
  3107. if (g_DynUpdtStatus->IhMapFileAndCheckSum ((PTSTR)FilePath, &headerSum, &checkSum) != CHECKSUM_SUCCESS) {
  3108. DynUpdtDebugLog (
  3109. Winnt32LogWarning,
  3110. TEXT("pValidOsFile: unable to compute checksum of %1 (rc=%2!u!); file is assumed valid"),
  3111. 0,
  3112. FilePath,
  3113. GetLastError ()
  3114. );
  3115. return TRUE;
  3116. }
  3117. //
  3118. // verify if the 2 values match
  3119. //
  3120. if (headerSum != 0 && headerSum != checkSum) {
  3121. DynUpdtDebugLog (
  3122. Winnt32LogError,
  3123. TEXT("pValidOsFile: invalid checksum for %1 (header=%2!x!,file=%3!x!)"),
  3124. 0,
  3125. FilePath,
  3126. headerSum,
  3127. checkSum
  3128. );
  3129. return FALSE;
  3130. }
  3131. return TRUE;
  3132. }
  3133. BOOL
  3134. pProcessUpdates (
  3135. IN PCTSTR UpdatesCab,
  3136. IN BOOL ClientInstall,
  3137. OUT PBOOL StopSetup
  3138. )
  3139. {
  3140. TCHAR updatesSourceDir[MAX_PATH];
  3141. TCHAR buffer[MAX_PATH];
  3142. FILEPATTERNREC_ENUM e;
  3143. TCHAR origSubPath[MAX_PATH];
  3144. TCHAR origFileName[MAX_PATH];
  3145. TCHAR origFilePath[MAX_PATH];
  3146. TCHAR destFilePath[MAX_PATH];
  3147. TCHAR version[100];
  3148. PTSTR p;
  3149. TCHAR updatesCabPath[MAX_PATH];
  3150. HANDLE hCabContext;
  3151. BOOL result;
  3152. BOOL bPatchApplied = FALSE;
  3153. HANDLE hCab;
  3154. PSTRINGLIST listUpdatesFiles = NULL;
  3155. PCTSTR cabPath;
  3156. BOOL bCatalogFileFound;
  3157. BOOL b = TRUE;
  3158. *StopSetup = FALSE;
  3159. if (!pNonemptyFilePresent (UpdatesCab)) {
  3160. if (!ClientInstall) {
  3161. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Package %1 is not present"), 0, UpdatesCab);
  3162. }
  3163. return TRUE;
  3164. }
  3165. DynUpdtDebugLog (
  3166. DynUpdtLogLevel,
  3167. TEXT("Analyzing package %1..."),
  3168. 0,
  3169. UpdatesCab
  3170. );
  3171. if (ClientInstall) {
  3172. BOOL bMustPrepare = TRUE;
  3173. if (BuildSifName (UpdatesCab, destFilePath, ARRAYSIZE(destFilePath)) &&
  3174. pDoesFileExist (destFilePath) &&
  3175. BuildPath (updatesSourceDir, g_DynUpdtStatus->DynamicUpdatesSource, S_SUBDIRNAME_UPDATES) &&
  3176. DoesDirectoryExist (updatesSourceDir)) {
  3177. bMustPrepare = FALSE;
  3178. }
  3179. if (bMustPrepare) {
  3180. //
  3181. // user specified updates location, but they didn't run winnt32 /prepare now or before
  3182. //
  3183. MessageBoxFromMessage (
  3184. g_DynUpdtStatus->ProgressWindow,
  3185. MSG_MUST_PREPARE_SHARE,
  3186. FALSE,
  3187. AppTitleStringId,
  3188. MB_OK | MB_ICONSTOP | MB_TASKMODAL,
  3189. g_DynUpdtStatus->DynamicUpdatesSource
  3190. );
  3191. *StopSetup = TRUE;
  3192. return FALSE;
  3193. }
  3194. } else {
  3195. if (!BuildPath (
  3196. updatesSourceDir,
  3197. g_DynUpdtStatus->PrepareWinnt32 ?
  3198. g_DynUpdtStatus->DynamicUpdatesSource :
  3199. g_DynUpdtStatus->WorkingDir,
  3200. S_SUBDIRNAME_UPDATES
  3201. )) {
  3202. return FALSE;
  3203. }
  3204. //
  3205. // expand CAB in this dir
  3206. // make sure dir is initially empty
  3207. //
  3208. MyDelnode (updatesSourceDir);
  3209. if (CreateMultiLevelDirectory (updatesSourceDir) != ERROR_SUCCESS) {
  3210. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to create dir %1"), 0, updatesSourceDir);
  3211. return FALSE;
  3212. }
  3213. if (!MySetupIterateCabinet (UpdatesCab, 0, pExpandCabInDir, (PVOID)updatesSourceDir)) {
  3214. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to expand cabinet %1"), 0, UpdatesCab);
  3215. return FALSE;
  3216. }
  3217. //
  3218. // ISSUE: the patching support is currently not available for platforms other than x86
  3219. //
  3220. #if defined(_X86_)
  3221. //
  3222. // now let's look for any patches
  3223. //
  3224. if (EnumFirstFilePatternRecursive (&e, updatesSourceDir, S_PATCH_FILE_EXT, 0)) {
  3225. //
  3226. // load drvindex.inf in advance
  3227. //
  3228. TCHAR driverInfName[MAX_PATH];
  3229. PVOID driverInfHandle;
  3230. TCHAR driverCabName[MAX_PATH];
  3231. TCHAR driverCabPath[MAX_PATH];
  3232. if (!FindPathToInstallationFile (DRVINDEX_INF, driverInfName, MAX_PATH)) {
  3233. DynUpdtDebugLog (
  3234. Winnt32LogError,
  3235. TEXT("pProcessUpdates: Unable to find %1"),
  3236. 0,
  3237. DRVINDEX_INF
  3238. );
  3239. AbortEnumFilePatternRecursive (&e);
  3240. b = FALSE;
  3241. goto exit;
  3242. }
  3243. if (LoadInfFile (driverInfName, FALSE, &driverInfHandle) != NO_ERROR) {
  3244. DynUpdtDebugLog (
  3245. Winnt32LogError,
  3246. TEXT("pProcessUpdates: Unable to load %1"),
  3247. 0,
  3248. driverInfName
  3249. );
  3250. AbortEnumFilePatternRecursive (&e);
  3251. b = FALSE;
  3252. goto exit;
  3253. }
  3254. do {
  3255. BOOL bDeleteTempFile = FALSE;
  3256. if (g_DynUpdtStatus->Cancelled) {
  3257. SetLastError (ERROR_CANCELLED);
  3258. b = FALSE;
  3259. break;
  3260. }
  3261. if (e.FindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  3262. continue;
  3263. }
  3264. DynUpdtDebugLog (
  3265. DynUpdtLogLevel,
  3266. TEXT("pProcessUpdates: found patch %1"),
  3267. 0,
  3268. e.FullPath
  3269. );
  3270. //
  3271. // get the original file from the sources location
  3272. // the filename is obtained cutting the ._p1 extension
  3273. //
  3274. if (FAILED (StringCchCopy (origFileName, ARRAYSIZE(origFileName), e.FileName))) {
  3275. MYASSERT (FALSE);
  3276. b = FALSE;
  3277. break;
  3278. }
  3279. p = GetFileExtension (origFileName);
  3280. if (!p) {
  3281. MYASSERT (FALSE);
  3282. continue;
  3283. }
  3284. *p = 0;
  3285. if (FAILED (StringCchCopy (origSubPath, ARRAYSIZE(origSubPath), e.SubPath))) {
  3286. MYASSERT (FALSE);
  3287. b = FALSE;
  3288. break;
  3289. }
  3290. p = GetFileExtension (origSubPath);
  3291. if (!p) {
  3292. MYASSERT (FALSE);
  3293. continue;
  3294. }
  3295. *p = 0;
  3296. if (!BuildPath (origFilePath, SourcePaths[0], origSubPath)) {
  3297. MYASSERT (FALSE);
  3298. b = FALSE;
  3299. break;
  3300. }
  3301. //
  3302. // now check if this file (in it's compressed form or not) actually exists
  3303. // note that the file may exist in driver.cab
  3304. //
  3305. if (InDriverCacheInf (driverInfHandle, origFileName, driverCabName, MAX_PATH)) {
  3306. CONTEXT_EXTRACTFILEINDIR ctx;
  3307. //
  3308. // extract the file to the temp dir
  3309. //
  3310. if (!driverCabName[0]) {
  3311. DynUpdtDebugLog (
  3312. Winnt32LogError,
  3313. TEXT("pProcessUpdates: cab name not found for %1 in %2"),
  3314. 0,
  3315. origFileName,
  3316. driverInfName
  3317. );
  3318. b = FALSE;
  3319. break;
  3320. }
  3321. if (!BuildPath (buffer, g_DynUpdtStatus->TempDir, origSubPath)) {
  3322. MYASSERT (FALSE);
  3323. b = FALSE;
  3324. break;
  3325. }
  3326. p = _tcsrchr (buffer, TEXT('\\'));
  3327. MYASSERT (p);
  3328. if (!p) {
  3329. MYASSERT (FALSE);
  3330. continue;
  3331. }
  3332. *p = 0;
  3333. if (CreateMultiLevelDirectory (buffer) != ERROR_SUCCESS) {
  3334. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpdates: Unable to create dir %1"), 0, buffer);
  3335. b = FALSE;
  3336. break;
  3337. }
  3338. ctx.BaseDir = buffer;
  3339. ctx.Filename = origFileName;
  3340. if (!FindPathToInstallationFile (driverCabName, driverCabPath, MAX_PATH)) {
  3341. DynUpdtDebugLog (
  3342. Winnt32LogError,
  3343. TEXT("pProcessUpdates: Unable to find cabinet %1"),
  3344. 0,
  3345. driverCabName
  3346. );
  3347. b = FALSE;
  3348. break;
  3349. }
  3350. if (!MySetupIterateCabinet (driverCabPath, 0, pExtractFileInDir, &ctx)) {
  3351. DynUpdtDebugLog (
  3352. Winnt32LogError,
  3353. TEXT("pProcessUpdates: Unable to extract file %1 from %2 to %3"),
  3354. 0,
  3355. origFileName,
  3356. driverCabName,
  3357. buffer
  3358. );
  3359. b = FALSE;
  3360. break;
  3361. }
  3362. *p = TEXT('\\');
  3363. if (FAILED (StringCchCopy (origFilePath, ARRAYSIZE(origFilePath), buffer))) {
  3364. b = FALSE;
  3365. break;
  3366. }
  3367. bDeleteTempFile = TRUE;
  3368. } else {
  3369. if (!pDoesFileExist (origFilePath)) {
  3370. //
  3371. // try the compressed form
  3372. //
  3373. p = _tcschr (origFilePath, 0);
  3374. MYASSERT (p);
  3375. if (!p) {
  3376. continue;
  3377. }
  3378. p = _tcsdec (origFilePath, p);
  3379. MYASSERT (p);
  3380. if (!p) {
  3381. continue;
  3382. }
  3383. *p = TEXT('_');
  3384. if (!pDoesFileExist (origFilePath)) {
  3385. DynUpdtDebugLog (
  3386. Winnt32LogError,
  3387. TEXT("pProcessUpdates: Unable to find original file %1 to apply the patch"),
  3388. 0,
  3389. origSubPath
  3390. );
  3391. b = FALSE;
  3392. break;
  3393. }
  3394. //
  3395. // expand the file to the temp dir
  3396. //
  3397. if (!BuildPath (buffer, g_DynUpdtStatus->TempDir, origSubPath)) {
  3398. b = FALSE;
  3399. break;
  3400. }
  3401. p = _tcsrchr (buffer, TEXT('\\'));
  3402. MYASSERT (p);
  3403. if (!p) {
  3404. continue;
  3405. }
  3406. *p = 0;
  3407. if (CreateMultiLevelDirectory (buffer) != ERROR_SUCCESS) {
  3408. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpdates: Unable to create dir %1"), 0, buffer);
  3409. b = FALSE;
  3410. break;
  3411. }
  3412. if (!MySetupIterateCabinet (origFilePath, 0, pExpandCabInDir, buffer)) {
  3413. DynUpdtDebugLog (
  3414. Winnt32LogError,
  3415. TEXT("pProcessUpdates: Unable to expand original file %1 to dir %2"),
  3416. 0,
  3417. origFilePath,
  3418. buffer
  3419. );
  3420. b = FALSE;
  3421. break;
  3422. }
  3423. *p = TEXT('\\');
  3424. if (FAILED (StringCchCopy (origFilePath, ARRAYSIZE(origFilePath), buffer))) {
  3425. b = FALSE;
  3426. break;
  3427. }
  3428. bDeleteTempFile = TRUE;
  3429. }
  3430. }
  3431. BuildPath (destFilePath, updatesSourceDir, TEXT("$$temp$$.~~~"));
  3432. //
  3433. // now really apply the patch
  3434. //
  3435. if (!ApplyPatchToFile (e.FullPath, origFilePath, destFilePath, 0)) {
  3436. DynUpdtDebugLog (
  3437. Winnt32LogError,
  3438. TEXT("pProcessUpdates: ApplyPatchToFile failed to apply patch %1 to file %2"),
  3439. 0,
  3440. e.FullPath,
  3441. origFilePath
  3442. );
  3443. b = FALSE;
  3444. break;
  3445. }
  3446. //
  3447. // success! now move the file to the real destination
  3448. //
  3449. if (!BuildPath (buffer, updatesSourceDir, origSubPath)) {
  3450. b = FALSE;
  3451. break;
  3452. }
  3453. p = _tcsrchr (buffer, TEXT('\\'));
  3454. MYASSERT (p);
  3455. if (!p) {
  3456. continue;
  3457. }
  3458. *p = 0;
  3459. if (CreateMultiLevelDirectory (buffer) != ERROR_SUCCESS) {
  3460. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpdates: Unable to create dir %1"), 0, buffer);
  3461. b = FALSE;
  3462. break;
  3463. }
  3464. *p = TEXT('\\');
  3465. SetFileAttributes (buffer, FILE_ATTRIBUTE_NORMAL);
  3466. DeleteFile (buffer);
  3467. if (!MoveFile (destFilePath, buffer)) {
  3468. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpdates: Unable to move file %1 to final dest %2"), 0, destFilePath, buffer);
  3469. b = FALSE;
  3470. break;
  3471. }
  3472. if (!GetFileVersion (buffer, version)) {
  3473. MYASSERT(ARRAYSIZE(version) <= ARRAYSIZE("<unknown>"));
  3474. lstrcpy (version, TEXT("<unknown>"));
  3475. }
  3476. DynUpdtDebugLog (
  3477. DynUpdtLogLevel,
  3478. TEXT("pProcessUpdates: successfully applied patch %1 to file %2; the new file %3 has version %4"),
  3479. 0,
  3480. e.FullPath,
  3481. origFilePath,
  3482. buffer,
  3483. version
  3484. );
  3485. //
  3486. // now remove the patch file
  3487. //
  3488. SetFileAttributes (e.FullPath, FILE_ATTRIBUTE_NORMAL);
  3489. DeleteFile (e.FullPath);
  3490. bPatchApplied = TRUE;
  3491. if (bDeleteTempFile) {
  3492. SetFileAttributes (origFilePath, FILE_ATTRIBUTE_NORMAL);
  3493. DeleteFile (origFilePath);
  3494. }
  3495. } while (EnumNextFilePatternRecursive (&e));
  3496. AbortEnumFilePatternRecursive (&e);
  3497. UnloadInfFile (driverInfHandle);
  3498. if (!b) {
  3499. goto exit;
  3500. }
  3501. }
  3502. #endif
  3503. //
  3504. // build a new updates.cab that will contain the patched versions of files
  3505. // and no relative paths
  3506. //
  3507. if (!BuildPath (updatesCabPath, g_DynUpdtStatus->TempDir, S_CABNAME_UPDATES)) {
  3508. b = FALSE;
  3509. goto exit;
  3510. }
  3511. SetFileAttributes (updatesCabPath, FILE_ATTRIBUTE_NORMAL);
  3512. DeleteFile (updatesCabPath);
  3513. hCabContext = DiamondStartNewCabinet (updatesCabPath);
  3514. if (!hCabContext) {
  3515. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpdates: DiamondStartNewCabinet failed"), 0);
  3516. b = FALSE;
  3517. goto exit;
  3518. }
  3519. bCatalogFileFound = FALSE;
  3520. if (EnumFirstFilePatternRecursive (&e, updatesSourceDir, TEXT("*"), 0)) {
  3521. do {
  3522. if (e.FindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  3523. continue;
  3524. }
  3525. hCab = hCabContext;
  3526. cabPath = updatesCabPath;
  3527. //
  3528. // search for a previous file with the same name
  3529. //
  3530. if (FindStringCell (listUpdatesFiles, e.FileName, FALSE)) {
  3531. DynUpdtDebugLog (
  3532. Winnt32LogError,
  3533. TEXT("pProcessUpdates: found duplicate filename %1; aborting operation"),
  3534. 0,
  3535. e.FileName
  3536. );
  3537. b = FALSE;
  3538. break;
  3539. }
  3540. if (!InsertList (
  3541. (PGENERIC_LIST*)&listUpdatesFiles,
  3542. (PGENERIC_LIST)CreateStringCell (e.FileName))
  3543. ) {
  3544. b = FALSE;
  3545. break;
  3546. }
  3547. //
  3548. // make sure the file is valid (the checksum is correct etc.)
  3549. //
  3550. if (!pValidOsFile (e.FullPath)) {
  3551. b = FALSE;
  3552. break;
  3553. }
  3554. b = DiamondAddFileToCabinet (hCab, e.FullPath, e.FileName);
  3555. if (!b) {
  3556. DynUpdtDebugLog (
  3557. Winnt32LogError,
  3558. TEXT("pProcessUpdates: DiamondAddFileToCabinet(%1,%2) failed"),
  3559. 0,
  3560. e.FullPath,
  3561. cabPath
  3562. );
  3563. break;
  3564. }
  3565. DynUpdtDebugLog (
  3566. DynUpdtLogLevel,
  3567. TEXT(" ... successfully added file %1 to %2"),
  3568. 0,
  3569. e.FullPath,
  3570. cabPath
  3571. );
  3572. p = GetFileExtension (e.FileName);
  3573. if (p && !lstrcmpi (p, TEXT(".cat"))) {
  3574. bCatalogFileFound = TRUE;
  3575. }
  3576. } while (EnumNextFilePatternRecursive (&e));
  3577. AbortEnumFilePatternRecursive (&e);
  3578. if (!b) {
  3579. goto exit;
  3580. }
  3581. }
  3582. result = DiamondTerminateCabinet (hCabContext);
  3583. if (!b) {
  3584. DiamondTerminateCabinet (hCabContext);
  3585. goto exit;
  3586. }
  3587. if (!result) {
  3588. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpdates: DiamondTerminateCabinet(%1) failed"), 0, updatesCabPath);
  3589. b = FALSE;
  3590. goto exit;
  3591. }
  3592. DynUpdtDebugLog (DynUpdtLogLevel, TEXT(" ... done"), 0);
  3593. if (!bCatalogFileFound) {
  3594. DynUpdtDebugLog (Winnt32LogWarning, TEXT("pProcessUpdates: no catalog found in package %1"), 0, UpdatesCab);
  3595. }
  3596. if (!BuildPath (
  3597. buffer,
  3598. g_DynUpdtStatus->PrepareWinnt32 ? g_DynUpdtStatus->DynamicUpdatesSource : g_DynUpdtStatus->WorkingDir,
  3599. S_CABNAME_UPDATES
  3600. )) {
  3601. b = FALSE;
  3602. goto exit;
  3603. }
  3604. if (!SetFileAttributes (buffer, FILE_ATTRIBUTE_NORMAL) ||
  3605. !DeleteFile (buffer)) {
  3606. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpdates: Unable to remove file %1 in order to replace it"), 0, buffer);
  3607. b = FALSE;
  3608. goto exit;
  3609. }
  3610. SetFileAttributes (buffer, FILE_ATTRIBUTE_NORMAL);
  3611. DeleteFile (buffer);
  3612. if (!MoveFile (updatesCabPath, buffer)) {
  3613. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpdates: Unable to move file %1 to %2"), 0, updatesCabPath, buffer);
  3614. b = FALSE;
  3615. goto exit;
  3616. }
  3617. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("pProcessUpdates: moved file %1 to %2"), 0, updatesCabPath, buffer);
  3618. if (FAILED (StringCchCopy (updatesCabPath, ARRAYSIZE(updatesCabPath), buffer))) {
  3619. b = FALSE;
  3620. goto exit;
  3621. }
  3622. if (!BuildSifName (updatesCabPath, destFilePath, ARRAYSIZE(destFilePath))) {
  3623. b = FALSE;
  3624. goto exit;
  3625. }
  3626. if (!CreateFileListSif (destFilePath, S_SECTIONNAME_UPDATES, updatesCabPath)) {
  3627. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to build file %1"), 0, destFilePath);
  3628. b = FALSE;
  3629. goto exit;
  3630. }
  3631. DynUpdtDebugLog (
  3632. DynUpdtLogLevel,
  3633. TEXT("pProcessUpdates: created %1 containing the list of files in %2"),
  3634. 0,
  3635. destFilePath,
  3636. updatesCabPath
  3637. );
  3638. }
  3639. if (!g_DynUpdtStatus->PrepareWinnt32) {
  3640. //
  3641. // build the default path to updates.cab used by the rest of setup
  3642. //
  3643. MYASSERT (IsArc() ? LocalSourceWithPlatform[0] : LocalBootDirectory[0]);
  3644. if (!BuildPath (
  3645. g_DynUpdtStatus->UpdatesCabTarget,
  3646. IsArc() ? LocalSourceWithPlatform : LocalBootDirectory,
  3647. S_CABNAME_UPDATES
  3648. )) {
  3649. b = FALSE;
  3650. goto exit;
  3651. }
  3652. //
  3653. // remember current location of updates.cab
  3654. //
  3655. if (FAILED (StringCchCopy (
  3656. g_DynUpdtStatus->UpdatesCabSource,
  3657. ARRAYSIZE(g_DynUpdtStatus->UpdatesCabSource),
  3658. UpdatesCab))) {
  3659. b = FALSE;
  3660. goto exit;
  3661. }
  3662. //
  3663. // the location of updated files for replacement
  3664. //
  3665. MYASSERT (ARRAYSIZE(g_DynUpdtStatus->UpdatesPath) <= ARRAYSIZE(updatesSourceDir));
  3666. lstrcpy (g_DynUpdtStatus->UpdatesPath, updatesSourceDir);
  3667. //
  3668. // also check for the presence of a file that will cause winnt32 to build the ~LS directory
  3669. //
  3670. if (BuildPath (destFilePath, updatesSourceDir, S_MAKE_LS_FILENAME)) {
  3671. if (pDoesFileExist (destFilePath)) {
  3672. MakeLocalSource = TRUE;
  3673. }
  3674. }
  3675. }
  3676. exit:
  3677. if (listUpdatesFiles) {
  3678. DeleteStringList (listUpdatesFiles);
  3679. }
  3680. if (!b && UpgradeAdvisorMode) {
  3681. //
  3682. // in UpgradeAdvisor mode we expect failures
  3683. //
  3684. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Unable to process %1 in UpgradeAdvisor mode; ignoring error"), 0, UpdatesCab);
  3685. g_DynUpdtStatus->ForceRemoveWorkingDir = TRUE;
  3686. b = TRUE;
  3687. }
  3688. return b;
  3689. }
  3690. BOOL
  3691. pProcessDuasms (
  3692. IN PCTSTR DuasmsCab,
  3693. IN BOOL ClientInstall
  3694. )
  3695. {
  3696. FILEPATTERN_ENUM e;
  3697. TCHAR duasmsLocalDir[MAX_PATH];
  3698. TCHAR dirName[MAX_PATH];
  3699. DWORD rc;
  3700. HKEY key;
  3701. PCTSTR strDuasmsRegKey;
  3702. BOOL duasms = FALSE;
  3703. BOOL b = TRUE;
  3704. if (!pNonemptyFilePresent (DuasmsCab)) {
  3705. if (!ClientInstall) {
  3706. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Package %1 is not present"), 0, DuasmsCab);
  3707. }
  3708. return TRUE;
  3709. }
  3710. if (g_DynUpdtStatus->PrepareWinnt32) {
  3711. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("pProcessDuasms: Skipping it due to /%1 switch"), 0, WINNT_U_DYNAMICUPDATESPREPARE);
  3712. return TRUE;
  3713. }
  3714. DynUpdtDebugLog (
  3715. DynUpdtLogLevel,
  3716. TEXT("Analyzing package %1..."),
  3717. 0,
  3718. DuasmsCab
  3719. );
  3720. if (!BuildPath (duasmsLocalDir, g_DynUpdtStatus->WorkingDir, S_SUBDIRNAME_DUASMS)) {
  3721. return FALSE;
  3722. }
  3723. //
  3724. // expand CAB in this dir
  3725. //
  3726. MyDelnode (duasmsLocalDir);
  3727. if (CreateMultiLevelDirectory (duasmsLocalDir) != ERROR_SUCCESS) {
  3728. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to create dir %1"), 0, duasmsLocalDir);
  3729. return FALSE;
  3730. }
  3731. if (!MySetupIterateCabinet (DuasmsCab, 0, pExpandCabInDir, (PVOID)duasmsLocalDir)) {
  3732. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to expand cabinet %1"), 0, DuasmsCab);
  3733. return FALSE;
  3734. }
  3735. MYASSERT (IsArc() ? LocalSourceWithPlatform[0] : LocalBootDirectory[0]);
  3736. if (!BuildPath (
  3737. g_DynUpdtStatus->DuasmsTarget,
  3738. IsArc() ? LocalSourceWithPlatform : LocalBootDirectory,
  3739. S_SUBDIRNAME_DUASMS
  3740. )) {
  3741. return FALSE;
  3742. }
  3743. //
  3744. // remember current location of duasms folder
  3745. //
  3746. MYASSERT (ARRAYSIZE(g_DynUpdtStatus->DuasmsSource) <= ARRAYSIZE(duasmsLocalDir));
  3747. lstrcpy (g_DynUpdtStatus->DuasmsSource, duasmsLocalDir);
  3748. return TRUE;
  3749. }
  3750. BOOL
  3751. pFindPackage (
  3752. IN HINF InfHandle,
  3753. IN PCTSTR Section,
  3754. IN PCTSTR CabName,
  3755. OUT PBOOL Partial
  3756. )
  3757. {
  3758. INFCONTEXT ic;
  3759. TCHAR value[MAX_PATH];
  3760. if (SetupapiFindFirstLine (InfHandle, Section, NULL, &ic)) {
  3761. do {
  3762. if (SetupapiGetStringField (&ic, GUIDRVS_FIELD_CABNAME, value, MAX_PATH, NULL) &&
  3763. !lstrcmpi (value, CabName)
  3764. ) {
  3765. if (Partial) {
  3766. *Partial = SetupapiGetStringField (&ic, GUIDRVS_FIELD_INFNAME, value, MAX_PATH, NULL);
  3767. }
  3768. return TRUE;
  3769. }
  3770. } while (SetupapiFindNextLine (&ic, &ic));
  3771. }
  3772. return FALSE;
  3773. }
  3774. VOID
  3775. pSanitizeDriverCabName (
  3776. IN PTSTR CabName
  3777. )
  3778. {
  3779. #define CRC_SUFFIX_LENGTH (sizeof("B842485F4D3B024E675653929B247BE9C685BBD7") - 1)
  3780. PTSTR p, q;
  3781. DWORD len;
  3782. //
  3783. // cut an extension like _B842485F4D3B024E675653929B247BE9C685BBD7 from the cab name
  3784. //
  3785. p = GetFileExtension (CabName);
  3786. if (p) {
  3787. MYASSERT (*p == TEXT('.'));
  3788. *p = 0;
  3789. q = _tcsrchr (CabName, TEXT('_'));
  3790. if (q) {
  3791. q++;
  3792. len = lstrlen (q);
  3793. if (len == CRC_SUFFIX_LENGTH) {
  3794. PTSTR s = q;
  3795. TCHAR ch;
  3796. while (ch = (TCHAR)_totlower (*s++)) {
  3797. if (!((ch >= TEXT('0') && ch <= TEXT('9')) ||
  3798. (ch >= TEXT('a') && ch <= TEXT('f')))
  3799. ) {
  3800. break;
  3801. }
  3802. }
  3803. if (!ch) {
  3804. //
  3805. // we found what we expect
  3806. //
  3807. *(q - 1) = TEXT('.');
  3808. lstrcpy (q, p + 1);
  3809. p = NULL;
  3810. }
  3811. }
  3812. }
  3813. if (p) {
  3814. *p = TEXT('.');
  3815. }
  3816. }
  3817. }
  3818. BOOL
  3819. pIsDriverExcluded (
  3820. IN HINF InfHandle,
  3821. IN PCTSTR CabName
  3822. )
  3823. {
  3824. BOOL bPartial;
  3825. if (!pFindPackage (InfHandle, S_SECTION_EXCLUDED_DRVS, CabName, &bPartial)) {
  3826. return FALSE;
  3827. }
  3828. return !bPartial;
  3829. }
  3830. BOOL
  3831. pIsPrivateCabinet (
  3832. IN PCTSTR Filename
  3833. )
  3834. {
  3835. static PCTSTR privateCabNames[] = {
  3836. S_CABNAME_IDENT,
  3837. S_CABNAME_WSDUENG,
  3838. S_CABNAME_UPDATES,
  3839. S_CABNAME_UPGINFS,
  3840. S_CABNAME_WINNT32,
  3841. S_CABNAME_MIGDLLS,
  3842. S_CABNAME_DUASMS,
  3843. };
  3844. INT i;
  3845. for (i = 0; i < sizeof (privateCabNames) / sizeof (privateCabNames[0]); i++) {
  3846. if (!lstrcmpi (Filename, privateCabNames[i])) {
  3847. return TRUE;
  3848. }
  3849. }
  3850. return FALSE;
  3851. }
  3852. BOOL
  3853. pIsPrivateSubdir (
  3854. IN PCTSTR Subdir
  3855. )
  3856. {
  3857. static PCTSTR privateSubDirNames[] = {
  3858. S_SUBDIRNAME_TEMP,
  3859. S_SUBDIRNAME_DRIVERS,
  3860. S_SUBDIRNAME_WINNT32,
  3861. S_SUBDIRNAME_UPDATES,
  3862. S_SUBDIRNAME_UPGINFS,
  3863. S_SUBDIRNAME_MIGDLLS,
  3864. S_SUBDIRNAME_DUASMS,
  3865. };
  3866. INT i;
  3867. for (i = 0; i < sizeof (privateSubDirNames) / sizeof (privateSubDirNames[0]); i++) {
  3868. if (!lstrcmpi (Subdir, privateSubDirNames[i])) {
  3869. return TRUE;
  3870. }
  3871. }
  3872. return FALSE;
  3873. }
  3874. BOOL
  3875. pFindValueInSectionAtFieldIndex (
  3876. IN HINF InfHandle,
  3877. IN PCTSTR Section,
  3878. IN DWORD FieldIndex,
  3879. IN PCTSTR FieldValue
  3880. )
  3881. {
  3882. INFCONTEXT ic;
  3883. TCHAR value[MAX_PATH];
  3884. if (SetupapiFindFirstLine (InfHandle, Section, NULL, &ic)) {
  3885. do {
  3886. if (SetupapiGetStringField (&ic, FieldIndex, value, ARRAYSIZE(value), NULL)) {
  3887. if (lstrcmpi (FieldValue, value) == 0) {
  3888. return TRUE;
  3889. }
  3890. }
  3891. } while (SetupapiFindNextLine (&ic, &ic));
  3892. }
  3893. return FALSE;
  3894. }
  3895. BOOL
  3896. pProcessNewdrvs (
  3897. IN PCTSTR NewdrvDir,
  3898. IN BOOL ClientInstall
  3899. )
  3900. /*++
  3901. All CABs in this dir except pIsPrivateCabinet() files are assumed
  3902. as containing new drivers. Each cab will be expanded in its own subdir (derived from cab filename)
  3903. --*/
  3904. {
  3905. FILEPATTERN_ENUM e;
  3906. FILEPATTERNREC_ENUM er;
  3907. TCHAR dirName[MAX_PATH];
  3908. TCHAR datFile[MAX_PATH];
  3909. TCHAR relocDriverPath[MAX_PATH];
  3910. PTSTR p;
  3911. PSDLIST entry;
  3912. HANDLE hDB;
  3913. BOOL bCreateHwdb;
  3914. BOOL bDriverNeeded;
  3915. HINF infHandle = INVALID_HANDLE_VALUE;
  3916. enum {
  3917. CT_UNKNOWN,
  3918. CT_GUI_APPROVED,
  3919. CT_GUI_NOT_APPROVED
  3920. } eContentType;
  3921. BOOL bDriverIsGuiApproved;
  3922. PSTRINGLIST missingPnpIds = NULL;
  3923. PSTRINGLIST listEntry;
  3924. BOOL bEntryFound;
  3925. INFCONTEXT ic;
  3926. TCHAR value[MAX_PATH];
  3927. TCHAR sanitizedName[MAX_PATH];
  3928. BOOL b = TRUE;
  3929. __try {
  3930. //
  3931. // first open guidrvs.inf
  3932. //
  3933. if (!BuildPath (datFile, g_DynUpdtStatus->DynamicUpdatesSource, S_GUI_DRIVERS_INF)) {
  3934. b = FALSE;
  3935. __leave;
  3936. }
  3937. infHandle = SetupapiOpenInfFile (datFile, NULL, INF_STYLE_WIN4, NULL);
  3938. if (infHandle != INVALID_HANDLE_VALUE) {
  3939. //
  3940. // copy this file together with the drivers packages (if any)
  3941. //
  3942. MYASSERT(ARRAYSIZE(g_DynUpdtStatus->GuidrvsInfSource) == ARRAYSIZE(datFile));
  3943. lstrcpy (g_DynUpdtStatus->GuidrvsInfSource, datFile);
  3944. } else {
  3945. DynUpdtDebugLog (
  3946. Winnt32LogWarning,
  3947. TEXT("Could not open INF file %1 (rc=%2!u!)"),
  3948. 0,
  3949. datFile,
  3950. GetLastError ()
  3951. );
  3952. }
  3953. //
  3954. // look for CAB files and expand each one in its own subdir
  3955. //
  3956. if (!ClientInstall) {
  3957. if (EnumFirstFilePatternRecursive (&er, NewdrvDir, TEXT("*.cab"), ECF_ENUM_SUBDIRS)) {
  3958. do {
  3959. if (g_DynUpdtStatus->Cancelled) {
  3960. SetLastError (ERROR_CANCELLED);
  3961. b = FALSE;
  3962. break;
  3963. }
  3964. if (er.FindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  3965. if (pIsPrivateSubdir (er.SubPath)) {
  3966. er.ControlFlags |= ECF_ABORT_ENUM_DIR;
  3967. }
  3968. continue;
  3969. }
  3970. if (!er.FindData->nFileSizeLow) {
  3971. DynUpdtDebugLog (Winnt32LogWarning, TEXT("File %1 has size 0 and will be ignored"), 0, er.FullPath);
  3972. continue;
  3973. }
  3974. if (FAILED (StringCchCopy (sanitizedName, ARRAYSIZE(sanitizedName), er.FileName))) {
  3975. //
  3976. // this should never happen; the enumeration routine
  3977. // never returns paths longer than MAX_PATH
  3978. //
  3979. MYASSERT (FALSE);
  3980. continue;
  3981. }
  3982. pSanitizeDriverCabName (sanitizedName);
  3983. if (pIsPrivateCabinet (sanitizedName)) {
  3984. continue;
  3985. }
  3986. if (!BuildPath (dirName, g_DynUpdtStatus->DriversSource, sanitizedName)) {
  3987. b = FALSE;
  3988. break;
  3989. }
  3990. p = GetFileExtension (dirName);
  3991. if (!p) {
  3992. MYASSERT (FALSE);
  3993. continue;
  3994. }
  3995. *p = 0;
  3996. //
  3997. // is this an excluded driver?
  3998. //
  3999. MYASSERT(ARRAYSIZE(datFile) == ARRAYSIZE(sanitizedName));
  4000. lstrcpy (datFile, sanitizedName);
  4001. p = GetFileExtension (datFile);
  4002. if (!p) {
  4003. MYASSERT (FALSE);
  4004. continue;
  4005. }
  4006. *p = 0;
  4007. if (pIsDriverExcluded (infHandle, datFile)) {
  4008. DynUpdtDebugLog (
  4009. Winnt32LogWarning,
  4010. TEXT("Driver %1 is excluded from processing via %2"),
  4011. 0,
  4012. sanitizedName,
  4013. g_DynUpdtStatus->GuidrvsInfSource
  4014. );
  4015. if (DoesDirectoryExist (dirName)) {
  4016. //
  4017. // make sure there's no hwcomp.dat in this folder
  4018. //
  4019. if (BuildPath (datFile, dirName, S_HWCOMP_DAT)) {
  4020. if (pDoesFileExist (datFile)) {
  4021. SetFileAttributes (datFile, FILE_ATTRIBUTE_NORMAL);
  4022. DeleteFile (datFile);
  4023. }
  4024. }
  4025. }
  4026. continue;
  4027. }
  4028. DynUpdtDebugLog (
  4029. DynUpdtLogLevel,
  4030. TEXT("Analyzing driver package %1..."),
  4031. 0,
  4032. er.FullPath
  4033. );
  4034. if (DoesDirectoryExist (dirName)) {
  4035. DynUpdtDebugLog (
  4036. Winnt32LogWarning,
  4037. TEXT("Recreating existing driver %1"),
  4038. 0,
  4039. dirName
  4040. );
  4041. MyDelnode (dirName);
  4042. }
  4043. if (CreateMultiLevelDirectory (dirName) != ERROR_SUCCESS) {
  4044. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to create dir %1"), 0, dirName);
  4045. continue;
  4046. }
  4047. //
  4048. // expand CAB in this dir
  4049. //
  4050. if (!MySetupIterateCabinet (er.FullPath, 0, pExpandCabInDir, dirName)) {
  4051. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to expand cabinet %1"), 0, er.FullPath);
  4052. if (GetLastError () == ERROR_DISK_FULL) {
  4053. DynUpdtDebugLog (Winnt32LogSevereError, TEXT("Disk is full; aborting operation"), 0);
  4054. b = FALSE;
  4055. break;
  4056. }
  4057. continue;
  4058. }
  4059. if (g_DynUpdtStatus->PrepareWinnt32) {
  4060. //
  4061. // just rebuild the hardware database
  4062. //
  4063. if (!pBuildHwcompDat (dirName, infHandle, TRUE, TRUE)) {
  4064. DynUpdtDebugLog (
  4065. Winnt32LogError,
  4066. TEXT("Unable to build %1 (pBuildHwcompDat failed)"),
  4067. 0,
  4068. dirName
  4069. );
  4070. continue;
  4071. }
  4072. }
  4073. } while (EnumNextFilePatternRecursive (&er));
  4074. AbortEnumFilePatternRecursive (&er);
  4075. }
  4076. }
  4077. if (!b) {
  4078. __leave;
  4079. }
  4080. if (!g_DynUpdtStatus->PrepareWinnt32 &&
  4081. (!ISNT() || OsVersion.dwMajorVersion > 4)
  4082. ) {
  4083. //
  4084. // look for driver dirs and analyze them
  4085. //
  4086. if (infHandle != INVALID_HANDLE_VALUE) {
  4087. //
  4088. // read the value of "DriversAreGuiApproved" key
  4089. // 1. if set to "Yes" that means all drivers listed in the [Drivers] section are approved
  4090. // for installation in GUI setup; any other driver is not approved for installation in GUI setup
  4091. // 2. if set to "No" all drivers listed are NOT good for installation in GUI setup; their install
  4092. // will be deferred post setup; any driver not listed in that section is good for GUI
  4093. // 3. if not present or set to any other value, it is ignored and the section [Drivers] is ignored;
  4094. // all drivers will be installed post GUI setup
  4095. //
  4096. eContentType = CT_UNKNOWN;
  4097. if (SetupapiFindFirstLine (infHandle, S_SECTION_VERSION, S_DRIVER_TYPE_KEY, &ic) &&
  4098. SetupapiGetStringField (&ic, 1, value, ARRAYSIZE(value), NULL)
  4099. ) {
  4100. if (!lstrcmpi (value, WINNT_A_YES)) {
  4101. eContentType = CT_GUI_APPROVED;
  4102. } else if (!lstrcmpi (value, WINNT_A_NO)) {
  4103. eContentType = CT_GUI_NOT_APPROVED;
  4104. }
  4105. }
  4106. if (eContentType != CT_UNKNOWN) {
  4107. DynUpdtDebugLog (
  4108. Winnt32LogInformation,
  4109. TEXT("Entries in section [%1] of %2 will be treated as drivers to %3 be installed during GUI setup"),
  4110. 0,
  4111. S_SECTION_DRIVERS,
  4112. g_DynUpdtStatus->GuidrvsInfSource,
  4113. eContentType == CT_GUI_APPROVED ? TEXT("") : TEXT("NOT")
  4114. );
  4115. } else {
  4116. DynUpdtDebugLog (
  4117. Winnt32LogWarning,
  4118. TEXT("Key %1 %5 in file %2 section [%3];")
  4119. TEXT(" entries in section [%4] will be ignored and all drivers will be installed post setup"),
  4120. 0,
  4121. S_DRIVER_TYPE_KEY,
  4122. g_DynUpdtStatus->GuidrvsInfSource,
  4123. S_SECTION_VERSION,
  4124. S_SECTION_DRIVERS,
  4125. value ? TEXT("has an invalid value") : TEXT("is not present")
  4126. );
  4127. }
  4128. }
  4129. if (EnumFirstFilePattern (&e, g_DynUpdtStatus->DriversSource, TEXT("*"))) {
  4130. //
  4131. // initialize the Whistler PNP database
  4132. //
  4133. if (!g_DynUpdtStatus->HwdbDatabase) {
  4134. //
  4135. // ignore db load error
  4136. //
  4137. pInitNtPnpDb (TRUE);
  4138. }
  4139. do {
  4140. if (g_DynUpdtStatus->Cancelled) {
  4141. SetLastError (ERROR_CANCELLED);
  4142. b = FALSE;
  4143. break;
  4144. }
  4145. if (!(e.FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  4146. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("File %1 is NOT a directory and will be ignored"), 0, e.FullPath);
  4147. continue;
  4148. }
  4149. //
  4150. // is this a needed driver?
  4151. //
  4152. bDriverNeeded = TRUE;
  4153. if (g_DynUpdtStatus->UserSpecifiedUpdates) {
  4154. //
  4155. // first build the list of missing drivers
  4156. //
  4157. if (!missingPnpIds) {
  4158. #ifdef UNICODE
  4159. missingPnpIds = BuildMissingPnpIdList ();
  4160. if (!missingPnpIds) {
  4161. DynUpdtDebugLog (
  4162. Winnt32LogInformation,
  4163. TEXT("No PNP device drivers are needed"),
  4164. 0
  4165. );
  4166. }
  4167. #else
  4168. //
  4169. // let the upgrade module do driver detection on Win9x
  4170. //
  4171. if (pLoadWin9xDuSupport ()) {
  4172. PSTR* incompWin9xDrivers;
  4173. PCSTR* q;
  4174. if (g_DynUpdtStatus->Win9xGetIncompDrvs (&incompWin9xDrivers)) {
  4175. //
  4176. // convert the array returned by this function to a list style
  4177. //
  4178. g_DynUpdtStatus->IncompatibleDriversCount = 0;
  4179. if (incompWin9xDrivers) {
  4180. for (q = incompWin9xDrivers; *q; q++) {
  4181. listEntry = (PSTRINGLIST) MALLOC (sizeof (STRINGLIST));
  4182. if (listEntry) {
  4183. listEntry->String = DupMultiSz (*q);
  4184. if (!listEntry->String) {
  4185. break;
  4186. }
  4187. listEntry->Next = NULL;
  4188. if (!InsertList ((PGENERIC_LIST*)&missingPnpIds, (PGENERIC_LIST)listEntry)) {
  4189. DeleteStringCell (listEntry);
  4190. break;
  4191. }
  4192. g_DynUpdtStatus->IncompatibleDriversCount++;
  4193. }
  4194. }
  4195. }
  4196. if (g_DynUpdtStatus->Win9xReleaseIncompDrvs) {
  4197. g_DynUpdtStatus->Win9xReleaseIncompDrvs (incompWin9xDrivers);
  4198. }
  4199. } else {
  4200. DynUpdtDebugLog (
  4201. DynUpdtLogLevel,
  4202. TEXT("Win9xGetIncompDrvs returned FALSE; no drivers will be analyzed"),
  4203. 0
  4204. );
  4205. }
  4206. }
  4207. #endif
  4208. if (!missingPnpIds) {
  4209. break;
  4210. }
  4211. }
  4212. bCreateHwdb = FALSE;
  4213. //
  4214. // use the existing hardware database
  4215. //
  4216. if (!BuildPath (datFile, e.FullPath, S_HWCOMP_DAT)) {
  4217. continue;
  4218. }
  4219. if (!pDoesFileExist (datFile)) {
  4220. bCreateHwdb = TRUE;
  4221. }
  4222. hDB = g_DynUpdtStatus->HwdbOpen (bCreateHwdb ? NULL : datFile);
  4223. if (!hDB) {
  4224. if (bCreateHwdb) {
  4225. b = FALSE;
  4226. break;
  4227. }
  4228. DynUpdtDebugLog (
  4229. Winnt32LogError,
  4230. TEXT("Hardware database %1 is corrupt; contact your system administrator"),
  4231. 0,
  4232. datFile
  4233. );
  4234. continue;
  4235. }
  4236. if (bCreateHwdb) {
  4237. if (!g_DynUpdtStatus->HwdbAppendInfs (
  4238. hDB,
  4239. e.FullPath,
  4240. infHandle != INVALID_HANDLE_VALUE ? Winnt32HwdbAppendInfsCallback : NULL,
  4241. (PVOID)infHandle
  4242. )) {
  4243. DynUpdtDebugLog (
  4244. Winnt32LogError,
  4245. TEXT("Unable to build %1; contact your system administrator"),
  4246. 0,
  4247. datFile
  4248. );
  4249. g_DynUpdtStatus->HwdbClose (hDB);
  4250. continue;
  4251. }
  4252. //
  4253. // rebuild the default HW precompiled database
  4254. //
  4255. b = FALSE;
  4256. if (BuildPath (datFile, e.FullPath, S_HWCOMP_DAT)) {
  4257. SetFileAttributes (datFile, FILE_ATTRIBUTE_NORMAL);
  4258. DeleteFile (datFile);
  4259. b = g_DynUpdtStatus->HwdbFlush (hDB, datFile);
  4260. }
  4261. if (!b) {
  4262. DynUpdtDebugLog (
  4263. Winnt32LogError,
  4264. TEXT("Unable to build %1; contact your system administrator"),
  4265. 0,
  4266. datFile
  4267. );
  4268. g_DynUpdtStatus->HwdbClose (hDB);
  4269. continue;
  4270. }
  4271. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Successfully built precompiled hardware database %1"), 0, datFile);
  4272. }
  4273. //
  4274. // check if this particular driver is among the ones that are needed
  4275. //
  4276. if (!pHwdbHasAnyMissingDrivers (hDB, missingPnpIds)) {
  4277. //
  4278. // this driver is not needed
  4279. //
  4280. bDriverNeeded = FALSE;
  4281. }
  4282. g_DynUpdtStatus->HwdbClose (hDB);
  4283. }
  4284. if (!bDriverNeeded) {
  4285. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("No needed drivers found in package %1"), 0, e.FullPath);
  4286. continue;
  4287. }
  4288. //
  4289. // is this a boot driver or a regular one?
  4290. //
  4291. if (pIsBootDriver (e.FullPath)) {
  4292. //
  4293. // add this driver to the list of boot drivers
  4294. //
  4295. if (!InsertList (
  4296. (PGENERIC_LIST*)&g_DynUpdtStatus->BootDriverPathList,
  4297. (PGENERIC_LIST)CreateStringCell (e.FileName))
  4298. ) {
  4299. b = FALSE;
  4300. break;
  4301. }
  4302. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Added driver %1 to the list of BOOT drivers"), 0, e.FullPath);
  4303. }
  4304. //
  4305. // all needed drivers will be copied under LocalBootDir to be protected
  4306. // from being deleted if user decides to remove the current OS partition
  4307. //
  4308. if (!BuildPath (
  4309. relocDriverPath,
  4310. IsArc() ? LocalSourceWithPlatform : LocalBootDirectory,
  4311. S_SUBDIRNAME_DRIVERS
  4312. )) {
  4313. continue;
  4314. }
  4315. if (!ConcatenatePaths (relocDriverPath, e.FileName, ARRAYSIZE(relocDriverPath))) {
  4316. continue;
  4317. }
  4318. //
  4319. // is this a GUI driver or not?
  4320. //
  4321. if (eContentType == CT_UNKNOWN) {
  4322. bDriverIsGuiApproved = FALSE;
  4323. } else {
  4324. if (pFindValueInSectionAtFieldIndex (infHandle, S_SECTION_EXCLUDED_DRVS, GUIDRVS_FIELD_CABNAME, e.FileName)) {
  4325. //
  4326. // we don't support "partially excluded" packages for the device install
  4327. // phase of GUI setup
  4328. //
  4329. DynUpdtDebugLog (
  4330. DynUpdtLogLevel,
  4331. TEXT("Driver %1 is partially excluded; it will be installed at the end of GUI setup"),
  4332. 0,
  4333. e.FullPath
  4334. );
  4335. bDriverIsGuiApproved = FALSE;
  4336. } else {
  4337. BOOL bPartial;
  4338. bEntryFound = pFindPackage (infHandle, S_SECTION_DRIVERS, e.FileName, &bPartial);
  4339. bDriverIsGuiApproved = eContentType == CT_GUI_APPROVED && bEntryFound && !bPartial ||
  4340. eContentType == CT_GUI_NOT_APPROVED && !bEntryFound;
  4341. }
  4342. }
  4343. //
  4344. // always make sure there's a precompiled database hwcomp.dat
  4345. // to be used at the time setup will install these additional drivers
  4346. //
  4347. if (!pBuildHwcompDat (e.FullPath, infHandle, FALSE, FALSE)) {
  4348. DynUpdtDebugLog (
  4349. Winnt32LogError,
  4350. TEXT("Unable to build %1 (pBuildHwcompDat failed)"),
  4351. 0,
  4352. datFile
  4353. );
  4354. continue;
  4355. }
  4356. entry = MALLOC (sizeof (SDLIST));
  4357. if (!entry) {
  4358. b = FALSE;
  4359. break;
  4360. }
  4361. entry->String = DupString (relocDriverPath);
  4362. if (!entry->String) {
  4363. FREE (entry);
  4364. b = FALSE;
  4365. break;
  4366. }
  4367. entry->Data = (DWORD_PTR)bDriverIsGuiApproved;
  4368. entry->Next = NULL;
  4369. if (!InsertList (
  4370. (PGENERIC_LIST*)&g_DynUpdtStatus->NewDriversList,
  4371. (PGENERIC_LIST)entry
  4372. )) {
  4373. FREE (entry);
  4374. b = FALSE;
  4375. break;
  4376. }
  4377. DynUpdtDebugLog (
  4378. DynUpdtLogLevel,
  4379. bDriverIsGuiApproved ?
  4380. TEXT("Driver %1 is approved for installation during GUI setup") :
  4381. TEXT("Driver %1 is NOT approved for installation during GUI setup; installation will be deferred post-setup"),
  4382. 0,
  4383. e.FullPath
  4384. );
  4385. //
  4386. // copy locally this driver package (if from a share)
  4387. //
  4388. if (!BuildPath (relocDriverPath, g_DynUpdtStatus->SelectedDrivers, e.FileName)) {
  4389. continue;
  4390. }
  4391. if (lstrcmpi (e.FullPath, relocDriverPath)) {
  4392. if (!CopyTree (e.FullPath, relocDriverPath)) {
  4393. DynUpdtDebugLog (
  4394. Winnt32LogError,
  4395. TEXT("Unable to copy driver %1 to %2"),
  4396. 0,
  4397. e.FullPath,
  4398. relocDriverPath
  4399. );
  4400. b = FALSE;
  4401. break;
  4402. }
  4403. DynUpdtDebugLog (
  4404. Winnt32LogInformation,
  4405. TEXT("Driver %1 successfully copied to %2"),
  4406. 0,
  4407. e.FullPath,
  4408. relocDriverPath
  4409. );
  4410. }
  4411. } while (EnumNextFilePattern (&e));
  4412. AbortEnumFilePattern (&e);
  4413. } else {
  4414. DynUpdtDebugLog (
  4415. DynUpdtLogLevel,
  4416. TEXT("No drivers found in %1"),
  4417. 0,
  4418. g_DynUpdtStatus->DriversSource
  4419. );
  4420. }
  4421. if (!b) {
  4422. __leave;
  4423. }
  4424. //
  4425. // copy guidrvs.inf if present and any driver package that will be migrated over
  4426. //
  4427. if (g_DynUpdtStatus->GuidrvsInfSource[0] && g_DynUpdtStatus->NewDriversList) {
  4428. if (!BuildPath (datFile, g_DynUpdtStatus->SelectedDrivers, S_GUI_DRIVERS_INF)) {
  4429. b = FALSE;
  4430. __leave;
  4431. }
  4432. if (lstrcmpi (g_DynUpdtStatus->GuidrvsInfSource, datFile)) {
  4433. if (!CopyFile (g_DynUpdtStatus->GuidrvsInfSource, datFile, FALSE)) {
  4434. DynUpdtDebugLog (
  4435. Winnt32LogError,
  4436. TEXT("Failed to copy %1 to %2"),
  4437. 0,
  4438. g_DynUpdtStatus->GuidrvsInfSource,
  4439. datFile
  4440. );
  4441. b = FALSE;
  4442. }
  4443. }
  4444. if (b) {
  4445. //
  4446. // update the location of guidrvs.inf after file copy will have been done
  4447. //
  4448. if (!BuildPath (
  4449. g_DynUpdtStatus->GuidrvsInfSource,
  4450. IsArc() ? LocalSourceWithPlatform : LocalBootDirectory,
  4451. S_SUBDIRNAME_DRIVERS
  4452. ) ||
  4453. !ConcatenatePaths (
  4454. g_DynUpdtStatus->GuidrvsInfSource,
  4455. S_GUI_DRIVERS_INF,
  4456. ARRAYSIZE(g_DynUpdtStatus->GuidrvsInfSource)
  4457. )) {
  4458. b = FALSE;
  4459. __leave;
  4460. }
  4461. }
  4462. }
  4463. }
  4464. }
  4465. __finally {
  4466. if (missingPnpIds) {
  4467. DeleteStringList (missingPnpIds);
  4468. }
  4469. if (infHandle != INVALID_HANDLE_VALUE) {
  4470. SetupapiCloseInfFile (infHandle);
  4471. }
  4472. }
  4473. return b;
  4474. }
  4475. BOOL
  4476. pProcessUpginfs (
  4477. IN PCTSTR UpginfsCab,
  4478. IN BOOL ClientInstall
  4479. )
  4480. {
  4481. FILEPATTERNREC_ENUM e;
  4482. TCHAR upginfsSourceDir[MAX_PATH];
  4483. TCHAR upginfsDir[MAX_PATH];
  4484. TCHAR upginfsFile[MAX_PATH];
  4485. TCHAR origSubPath[MAX_PATH];
  4486. TCHAR origFileName[MAX_PATH];
  4487. TCHAR origFilePath[MAX_PATH];
  4488. TCHAR destFilePath[MAX_PATH];
  4489. TCHAR buffer[MAX_PATH];
  4490. PTSTR p;
  4491. BOOL b = TRUE;
  4492. if (!BuildPath (upginfsSourceDir, g_DynUpdtStatus->DynamicUpdatesSource, S_SUBDIRNAME_UPGINFS)) {
  4493. return FALSE;
  4494. }
  4495. if (ClientInstall) {
  4496. if (!DoesDirectoryExist (upginfsSourceDir)) {
  4497. return TRUE;
  4498. }
  4499. } else {
  4500. //
  4501. // expand it in the corresponding subdir
  4502. //
  4503. if (!pNonemptyFilePresent (UpginfsCab)) {
  4504. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("Package %1 is not present"), 0, UpginfsCab);
  4505. return TRUE;
  4506. }
  4507. DynUpdtDebugLog (
  4508. DynUpdtLogLevel,
  4509. TEXT("Analyzing package %1..."),
  4510. 0,
  4511. UpginfsCab
  4512. );
  4513. //
  4514. // expand CAB in this dir
  4515. // make sure dir is initially empty
  4516. //
  4517. MyDelnode (upginfsSourceDir);
  4518. if (CreateMultiLevelDirectory (upginfsSourceDir) != ERROR_SUCCESS) {
  4519. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to create dir %1"), 0, upginfsSourceDir);
  4520. return FALSE;
  4521. }
  4522. if (!MySetupIterateCabinet (UpginfsCab, 0, pExpandCabInDir, (PVOID)upginfsSourceDir)) {
  4523. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to expand cabinet %1"), 0, UpginfsCab);
  4524. return FALSE;
  4525. }
  4526. //
  4527. // ISSUE: the patching support is currently not available for platforms other than x86
  4528. //
  4529. #if defined(_X86_)
  4530. //
  4531. // now let's look for any patches
  4532. //
  4533. if (EnumFirstFilePatternRecursive (&e, upginfsSourceDir, S_PATCH_FILE_EXT, 0)) {
  4534. do {
  4535. BOOL bDeleteTempFile = FALSE;
  4536. if (g_DynUpdtStatus->Cancelled) {
  4537. SetLastError (ERROR_CANCELLED);
  4538. b = FALSE;
  4539. break;
  4540. }
  4541. if (e.FindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  4542. continue;
  4543. }
  4544. DynUpdtDebugLog (
  4545. DynUpdtLogLevel,
  4546. TEXT("pProcessUpginfs: found patch %1"),
  4547. 0,
  4548. e.FullPath
  4549. );
  4550. //
  4551. // get the original file from the sources location
  4552. // the filename is obtained cutting the ._p1 extension
  4553. //
  4554. MYASSERT(ARRAYSIZE(origFileName) == ARRAYSIZE(e.FileName));
  4555. lstrcpy (origFileName, e.FileName);
  4556. p = GetFileExtension (origFileName);
  4557. if (!p) {
  4558. MYASSERT (FALSE);
  4559. continue;
  4560. }
  4561. *p = 0;
  4562. MYASSERT(ARRAYSIZE(origSubPath) == ARRAYSIZE(e.SubPath));
  4563. lstrcpy (origSubPath, e.SubPath);
  4564. p = GetFileExtension (origSubPath);
  4565. if (!p) {
  4566. MYASSERT (FALSE);
  4567. continue;
  4568. }
  4569. *p = 0;
  4570. if (!BuildPath (origFilePath, NativeSourcePaths[0], origSubPath)) {
  4571. b = FALSE;
  4572. break;
  4573. }
  4574. //
  4575. // now check if this file (in it's compressed form or not) actually exists
  4576. //
  4577. if (!pDoesFileExist (origFilePath)) {
  4578. //
  4579. // try the compressed form
  4580. //
  4581. p = _tcschr (origFilePath, 0);
  4582. MYASSERT (p);
  4583. if (!p) {
  4584. continue;
  4585. }
  4586. p = _tcsdec (origFilePath, p);
  4587. MYASSERT (p);
  4588. if (!p) {
  4589. continue;
  4590. }
  4591. *p = TEXT('_');
  4592. if (!pDoesFileExist (origFilePath)) {
  4593. DynUpdtDebugLog (
  4594. Winnt32LogError,
  4595. TEXT("pProcessUpginfs: Unable to find original file %1 to apply the patch"),
  4596. 0,
  4597. origSubPath
  4598. );
  4599. b = FALSE;
  4600. break;
  4601. }
  4602. //
  4603. // expand the file to the temp dir
  4604. //
  4605. if (!BuildPath (buffer, g_DynUpdtStatus->TempDir, origSubPath)) {
  4606. b = FALSE;
  4607. break;
  4608. }
  4609. p = _tcsrchr (buffer, TEXT('\\'));
  4610. MYASSERT (p);
  4611. if (!p) {
  4612. continue;
  4613. }
  4614. *p = 0;
  4615. if (CreateMultiLevelDirectory (buffer) != ERROR_SUCCESS) {
  4616. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpginfs: Unable to create dir %1"), 0, buffer);
  4617. b = FALSE;
  4618. break;
  4619. }
  4620. if (!MySetupIterateCabinet (origFilePath, 0, pExpandCabInDir, buffer)) {
  4621. DynUpdtDebugLog (
  4622. Winnt32LogError,
  4623. TEXT("pProcessUpginfs: Unable to expand original file %1 to dir %2"),
  4624. 0,
  4625. origFilePath,
  4626. buffer
  4627. );
  4628. b = FALSE;
  4629. break;
  4630. }
  4631. *p = TEXT('\\');
  4632. MYASSERT(ARRAYSIZE(origFilePath) == ARRAYSIZE(buffer));
  4633. lstrcpy (origFilePath, buffer);
  4634. bDeleteTempFile = TRUE;
  4635. }
  4636. //
  4637. // even if this fails, we don't care; the file will just have a shorter name
  4638. //
  4639. BuildPath (destFilePath, upginfsSourceDir, TEXT("$$temp$$.~~~"));
  4640. //
  4641. // now really apply the patch
  4642. //
  4643. if (!ApplyPatchToFile (e.FullPath, origFilePath, destFilePath, 0)) {
  4644. DynUpdtDebugLog (
  4645. Winnt32LogError,
  4646. TEXT("pProcessUpginfs: ApplyPatchToFile failed to apply patch %1 to file %2"),
  4647. 0,
  4648. e.FullPath,
  4649. origFilePath
  4650. );
  4651. b = FALSE;
  4652. break;
  4653. }
  4654. //
  4655. // success! now move the file to the real destination
  4656. //
  4657. if (!BuildPath (buffer, upginfsSourceDir, origFileName)) {
  4658. b = FALSE;
  4659. break;
  4660. }
  4661. if (pDoesFileExist (buffer)) {
  4662. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpginfs: duplicate file found %1"), 0, origFileName);
  4663. b = FALSE;
  4664. break;
  4665. }
  4666. //
  4667. // all patches MUST be .rep files; change extension from .inf to .rep
  4668. //
  4669. p = GetFileExtension (buffer);
  4670. if (!p || lstrcmpi (p, TEXT(".inf"))) {
  4671. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpginfs: Unexpected file extension in %1"), 0, buffer);
  4672. b = FALSE;
  4673. break;
  4674. }
  4675. //
  4676. // we know we have space, p points to ".inf"
  4677. //
  4678. MYASSERT(ARRAYSIZE(".rep") == ARRAYSIZE(".inf"));
  4679. lstrcpy (p, TEXT(".rep"));
  4680. SetFileAttributes (buffer, FILE_ATTRIBUTE_NORMAL);
  4681. DeleteFile (buffer);
  4682. if (!MoveFile (destFilePath, buffer)) {
  4683. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpginfs: Unable to move file %1 to final dest %2"), 0, destFilePath, buffer);
  4684. b = FALSE;
  4685. break;
  4686. }
  4687. DynUpdtDebugLog (
  4688. DynUpdtLogLevel,
  4689. TEXT("pProcessUpginfs: successfully applied patch %1 to file %2; the new file was renamed %3"),
  4690. 0,
  4691. e.FullPath,
  4692. origFilePath,
  4693. buffer
  4694. );
  4695. //
  4696. // now remove the patch file
  4697. //
  4698. SetFileAttributes (e.FullPath, FILE_ATTRIBUTE_NORMAL);
  4699. DeleteFile (e.FullPath);
  4700. if (bDeleteTempFile) {
  4701. SetFileAttributes (origFilePath, FILE_ATTRIBUTE_NORMAL);
  4702. DeleteFile (origFilePath);
  4703. }
  4704. } while (EnumNextFilePatternRecursive (&e));
  4705. AbortEnumFilePatternRecursive (&e);
  4706. if (!b) {
  4707. goto exit;
  4708. }
  4709. }
  4710. SetFileAttributes (UpginfsCab, FILE_ATTRIBUTE_NORMAL);
  4711. DeleteFile (UpginfsCab);
  4712. #endif
  4713. }
  4714. if (!b) {
  4715. goto exit;
  4716. }
  4717. if (!g_DynUpdtStatus->PrepareWinnt32) {
  4718. //
  4719. // only do file installation on Win9x platforms
  4720. //
  4721. OSVERSIONINFO vi;
  4722. vi.dwOSVersionInfoSize = sizeof (vi);
  4723. GetVersionEx (&vi);
  4724. if (vi.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) {
  4725. DynUpdtDebugLog (
  4726. DynUpdtLogLevel,
  4727. TEXT("Package %1 ignored on NT platforms"),
  4728. 0,
  4729. UpginfsCab
  4730. );
  4731. return TRUE;
  4732. }
  4733. //
  4734. // prepare the target directory (%windir%\upginfs)
  4735. //
  4736. if (!MyGetWindowsDirectory (upginfsDir, MAX_PATH)) {
  4737. return FALSE;
  4738. }
  4739. if (!ConcatenatePaths (upginfsDir, S_SUBDIRNAME_UPGINFS, MAX_PATH)) {
  4740. return FALSE;
  4741. }
  4742. if (!CreateDir (upginfsDir)) {
  4743. return FALSE;
  4744. }
  4745. //
  4746. // copy relevant files to %windir%\Upginfs
  4747. //
  4748. if (EnumFirstFilePatternRecursive (&e, upginfsSourceDir, TEXT("*.add"), 0)) {
  4749. do {
  4750. if (g_DynUpdtStatus->Cancelled) {
  4751. SetLastError (ERROR_CANCELLED);
  4752. b = FALSE;
  4753. break;
  4754. }
  4755. if (e.FindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  4756. continue;
  4757. }
  4758. if (!e.FindData->nFileSizeLow) {
  4759. DynUpdtDebugLog (Winnt32LogWarning, TEXT("File %1 has size 0 and will be ignored"), 0, e.FullPath);
  4760. continue;
  4761. }
  4762. if (!BuildPath (upginfsFile, upginfsDir, e.FileName)) {
  4763. b = FALSE;
  4764. break;
  4765. }
  4766. SetFileAttributes (upginfsFile, FILE_ATTRIBUTE_NORMAL);
  4767. if (!CopyFile (e.FullPath, upginfsFile, FALSE)) {
  4768. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpginfs: Error copying %1 to %2"), 0, e.FullPath, upginfsFile);
  4769. b = FALSE;
  4770. break;
  4771. }
  4772. //
  4773. // let w95upg.dll know about the new files
  4774. //
  4775. UpginfsUpdated = TRUE;
  4776. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("pProcessUpginfs: INF %1 successfully copied to %2"), 0, e.FullPath, upginfsFile);
  4777. } while (EnumNextFilePatternRecursive (&e));
  4778. AbortEnumFilePatternRecursive (&e);
  4779. }
  4780. if (b) {
  4781. if (EnumFirstFilePatternRecursive (&e, upginfsSourceDir, TEXT("*.rep"), 0)) {
  4782. do {
  4783. if (g_DynUpdtStatus->Cancelled) {
  4784. SetLastError (ERROR_CANCELLED);
  4785. b = FALSE;
  4786. break;
  4787. }
  4788. if (e.FindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  4789. continue;
  4790. }
  4791. if (!e.FindData->nFileSizeLow) {
  4792. DynUpdtDebugLog (Winnt32LogWarning, TEXT("File %1 has size 0 and will be ignored"), 0, e.FullPath);
  4793. continue;
  4794. }
  4795. if (!BuildPath (upginfsFile, upginfsDir, e.FileName)) {
  4796. b = FALSE;
  4797. break;
  4798. }
  4799. SetFileAttributes (upginfsFile, FILE_ATTRIBUTE_NORMAL);
  4800. if (!CopyFile (e.FullPath, upginfsFile, FALSE)) {
  4801. DynUpdtDebugLog (Winnt32LogError, TEXT("pProcessUpginfs: Error copying %1 to %2"), 0, e.FullPath, upginfsFile);
  4802. b = FALSE;
  4803. break;
  4804. }
  4805. //
  4806. // let w95upg.dll know about the new files
  4807. //
  4808. UpginfsUpdated = TRUE;
  4809. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("pProcessUpginfs: INF %1 successfully copied to %2"), 0, e.FullPath, upginfsFile);
  4810. } while (EnumNextFilePatternRecursive (&e));
  4811. AbortEnumFilePatternRecursive (&e);
  4812. }
  4813. }
  4814. }
  4815. exit:
  4816. return b;
  4817. }
  4818. #ifdef _X86_
  4819. BOOL
  4820. pProcessMigdlls (
  4821. IN PCTSTR MigdllsCab,
  4822. IN BOOL ClientInstall
  4823. )
  4824. {
  4825. FILEPATTERN_ENUM e;
  4826. TCHAR migdllsLocalDir[MAX_PATH];
  4827. TCHAR dirName[MAX_PATH];
  4828. DWORD rc;
  4829. HKEY key;
  4830. BOOL migdlls = FALSE;
  4831. BOOL b = TRUE;
  4832. if (ISNT ()) {
  4833. return TRUE;
  4834. }
  4835. if (!pNonemptyFilePresent (MigdllsCab)) {
  4836. return TRUE;
  4837. }
  4838. if (g_DynUpdtStatus->PrepareWinnt32) {
  4839. DynUpdtDebugLog (DynUpdtLogLevel, TEXT("pProcessMigdlls: Skipping it due to /%1 switch"), 0, WINNT_U_DYNAMICUPDATESPREPARE);
  4840. return TRUE;
  4841. }
  4842. DynUpdtDebugLog (
  4843. DynUpdtLogLevel,
  4844. TEXT("Analyzing package %1..."),
  4845. 0,
  4846. MigdllsCab
  4847. );
  4848. if (!BuildPath (migdllsLocalDir, g_DynUpdtStatus->WorkingDir, S_SUBDIRNAME_MIGDLLS)) {
  4849. return FALSE;
  4850. }
  4851. //
  4852. // expand CAB in this dir
  4853. //
  4854. MyDelnode (migdllsLocalDir);
  4855. if (CreateMultiLevelDirectory (migdllsLocalDir) != ERROR_SUCCESS) {
  4856. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to create dir %1"), 0, migdllsLocalDir);
  4857. return FALSE;
  4858. }
  4859. if (!MySetupIterateCabinet (MigdllsCab, 0, pExpandCabInDir, (PVOID)migdllsLocalDir)) {
  4860. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to expand cabinet %1"), 0, MigdllsCab);
  4861. return FALSE;
  4862. }
  4863. //
  4864. // look for CAB files and expand each one in its own subdir
  4865. //
  4866. if (EnumFirstFilePattern (&e, migdllsLocalDir, TEXT("*.cab"))) {
  4867. do {
  4868. if (g_DynUpdtStatus->Cancelled) {
  4869. SetLastError (ERROR_CANCELLED);
  4870. b = FALSE;
  4871. break;
  4872. }
  4873. if (e.FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  4874. continue;
  4875. }
  4876. if (!e.FindData.nFileSizeLow) {
  4877. DynUpdtDebugLog (Winnt32LogWarning, TEXT("File %1 has size 0 and will be ignored"), 0, e.FullPath);
  4878. continue;
  4879. }
  4880. pGetAutoSubdirName (e.FullPath, dirName, ARRAYSIZE(dirName));
  4881. if (CreateMultiLevelDirectory (dirName) != ERROR_SUCCESS) {
  4882. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to create dir %1; skipping it"), 0, dirName);
  4883. continue;
  4884. }
  4885. //
  4886. // expand CAB in this dir
  4887. //
  4888. if (!MySetupIterateCabinet (e.FullPath, 0, pExpandCabInDir, (PVOID)dirName)) {
  4889. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to expand cabinet %1; skipping it"), 0, e.FullPath);
  4890. continue;
  4891. }
  4892. migdlls = TRUE;
  4893. } while (EnumNextFilePattern (&e));
  4894. }
  4895. if (b && migdlls) {
  4896. //
  4897. // register them
  4898. //
  4899. rc = RegCreateKey (HKEY_LOCAL_MACHINE, S_REGKEY_MIGRATION_DLLS_WIN9X, &key);
  4900. if (rc == ERROR_SUCCESS) {
  4901. rc = RegSetValueEx (key, S_REGVALUE_DYNUPDT, 0, REG_SZ, (CONST BYTE*)migdllsLocalDir, (lstrlen (migdllsLocalDir) + 1) * sizeof (TCHAR));
  4902. }
  4903. if (rc != ERROR_SUCCESS) {
  4904. DynUpdtDebugLog (Winnt32LogError, TEXT("Unable to register downloaded migdlls (rc=%1!u!)"), 0, rc);
  4905. b = FALSE;
  4906. }
  4907. }
  4908. return b;
  4909. }
  4910. #endif
  4911. BOOL
  4912. ProcessDownloadedFiles (
  4913. OUT PBOOL StopSetup
  4914. )
  4915. {
  4916. TCHAR cabName[MAX_PATH];
  4917. BOOL bClientInstall = FALSE;
  4918. if (g_DynUpdtStatus->UserSpecifiedUpdates && !g_DynUpdtStatus->PrepareWinnt32) {
  4919. bClientInstall = TRUE;
  4920. }
  4921. DynUpdtDebugLog (
  4922. DynUpdtLogLevel,
  4923. TEXT("Source=%1"),
  4924. 0,
  4925. g_DynUpdtStatus->UserSpecifiedUpdates ? g_DynUpdtStatus->DynamicUpdatesSource : TEXT("Windows Update")
  4926. );
  4927. if (!g_DynUpdtStatus->HwdbInitialize) {
  4928. if (CreateMultiLevelDirectory (g_DynUpdtStatus->TempDir) != ERROR_SUCCESS ||
  4929. !pInitializeSupport (S_HWDB_DLL, pLoadHwdbLib, FALSE) ||
  4930. !g_DynUpdtStatus->HwdbInitialize (g_DynUpdtStatus->TempDir)
  4931. ) {
  4932. return FALSE;
  4933. }
  4934. }
  4935. if (!Winnt32Restarted ()) {
  4936. if (!BuildPath (cabName, g_DynUpdtStatus->DynamicUpdatesSource, S_CABNAME_WINNT32)) {
  4937. return FALSE;
  4938. }
  4939. if (!pProcessWinnt32Files (cabName, bClientInstall, StopSetup)) {
  4940. return FALSE;
  4941. }
  4942. if (g_DynUpdtStatus->RestartWinnt32) {
  4943. MYASSERT (!g_DynUpdtStatus->PrepareWinnt32);
  4944. return TRUE;
  4945. }
  4946. }
  4947. if (!BuildPath (cabName, g_DynUpdtStatus->DynamicUpdatesSource, S_CABNAME_UPDATES)) {
  4948. return FALSE;
  4949. }
  4950. if (!pProcessUpdates (cabName, bClientInstall, StopSetup)) {
  4951. if (g_DynUpdtStatus->PrepareWinnt32) {
  4952. MessageBoxFromMessage (
  4953. g_DynUpdtStatus->ProgressWindow,
  4954. MSG_ERROR_PROCESSING_UPDATES,
  4955. FALSE,
  4956. AppTitleStringId,
  4957. MB_OK | MB_ICONERROR | MB_TASKMODAL,
  4958. GetLastError (),
  4959. cabName
  4960. );
  4961. }
  4962. return FALSE;
  4963. }
  4964. //
  4965. // process New Assemblies on WU
  4966. //
  4967. if (BuildPath (cabName, g_DynUpdtStatus->DynamicUpdatesSource, S_CABNAME_DUASMS)) {
  4968. if (!pProcessDuasms (cabName, bClientInstall)) {
  4969. //
  4970. // don't fail DU if we didn't install them
  4971. //
  4972. }
  4973. }
  4974. if (!BuildPath (cabName, g_DynUpdtStatus->DynamicUpdatesSource, S_CABNAME_UPGINFS)) {
  4975. return FALSE;
  4976. }
  4977. if (!pProcessUpginfs (cabName, bClientInstall)) {
  4978. return FALSE;
  4979. }
  4980. #ifdef _X86_
  4981. if (!BuildPath (cabName, g_DynUpdtStatus->DynamicUpdatesSource, S_CABNAME_MIGDLLS)) {
  4982. return FALSE;
  4983. }
  4984. if (!pProcessMigdlls (cabName, bClientInstall)) {
  4985. return FALSE;
  4986. }
  4987. #endif
  4988. if (!pProcessNewdrvs (g_DynUpdtStatus->DynamicUpdatesSource, bClientInstall)) {
  4989. return FALSE;
  4990. }
  4991. return TRUE;
  4992. }
  4993. BOOL
  4994. Winnt32Restarted (
  4995. VOID
  4996. )
  4997. {
  4998. return g_DynUpdtStatus->Winnt32Restarted;
  4999. }
  5000. BOOL
  5001. Winnt32RestartedWithAF (
  5002. VOID
  5003. )
  5004. {
  5005. return g_DynUpdtStatus->RestartAnswerFile[0];
  5006. }
  5007. VOID
  5008. pLogWininetError (
  5009. IN DWORD Error
  5010. )
  5011. {
  5012. HMODULE hWinInet = LoadLibraryEx (TEXT("wininet.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE);
  5013. if (hWinInet) {
  5014. HLOCAL msg = NULL;
  5015. if (FormatMessage (
  5016. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
  5017. hWinInet,
  5018. Error,
  5019. 0,
  5020. (LPTSTR)&msg,
  5021. 0,
  5022. NULL
  5023. ) &&
  5024. msg != NULL
  5025. ) {
  5026. DynUpdtDebugLog (Winnt32LogError, TEXT("Failure with wininet error code %1!u!: \"%2\""), 0, Error, msg);
  5027. LocalFree (msg);
  5028. }
  5029. FreeLibrary (hWinInet);
  5030. } else {
  5031. MYASSERT (FALSE);
  5032. }
  5033. }
  5034. VOID
  5035. pLogStandardError (
  5036. IN DWORD Error
  5037. )
  5038. {
  5039. HLOCAL msg = NULL;
  5040. if (FormatMessage (
  5041. FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
  5042. NULL,
  5043. Error,
  5044. 0,
  5045. (LPTSTR)&msg,
  5046. 0,
  5047. NULL
  5048. ) &&
  5049. msg != NULL
  5050. ) {
  5051. DynUpdtDebugLog (Winnt32LogError, TEXT("Failure with standard error code %1!u!:\r\n%2"), 0, Error, msg);
  5052. LocalFree (msg);
  5053. }
  5054. }
  5055. VOID
  5056. pUpdateDUStatus (
  5057. IN DWORD Error
  5058. )
  5059. {
  5060. MYASSERT (Error != ERROR_SUCCESS);
  5061. if (Error == ERROR_SUCCESS) {
  5062. g_DynUpdtStatus->DUStatus = DUS_ERROR;
  5063. return;
  5064. }
  5065. switch (Error) {
  5066. case ERROR_CONNECTION_UNAVAIL:
  5067. //
  5068. // ask for manual connection
  5069. //
  5070. MYASSERT (g_DynUpdtStatus->DUStatus == DUS_PREPARING);
  5071. g_DynUpdtStatus->DUStatus = DUS_PREPARING_CONNECTIONUNAVAILABLE;
  5072. break;
  5073. case ERROR_INTERNET_INVALID_URL:
  5074. case ERROR_INTERNET_NAME_NOT_RESOLVED:
  5075. //
  5076. // site not available; ask user if they want to retry
  5077. //
  5078. MYASSERT (g_DynUpdtStatus->DUStatus == DUS_PREPARING);
  5079. g_DynUpdtStatus->DUStatus = DUS_PREPARING_INVALIDURL;
  5080. break;
  5081. case ERROR_INVALID_PARAMETER:
  5082. case ERROR_NOT_ENOUGH_MEMORY:
  5083. case ERROR_OLD_WIN_VERSION:
  5084. case ERROR_OUTOFMEMORY:
  5085. case ERROR_NO_MORE_ITEMS:
  5086. case ERROR_FILE_NOT_FOUND:
  5087. case ERROR_INVALID_DATA:
  5088. case ERROR_UNSUPPORTED_TYPE:
  5089. case ERROR_INVALID_HANDLE:
  5090. pLogStandardError (Error);
  5091. g_DynUpdtStatus->DUStatus = DUS_ERROR;
  5092. break;
  5093. case DU_ERROR_MISSING_DLL:
  5094. case DU_NOT_INITIALIZED:
  5095. DynUpdtDebugLog (Winnt32LogError, TEXT("Failure with custom error code %1!u!"), 0, Error);
  5096. g_DynUpdtStatus->DUStatus = DUS_ERROR;
  5097. break;
  5098. case ERROR_INTERNET_NO_CONTEXT:
  5099. pLogWininetError (Error);
  5100. g_DynUpdtStatus->DUStatus = DUS_ERROR;
  5101. break;
  5102. default:
  5103. if (Error > INTERNET_ERROR_BASE) {
  5104. pLogWininetError (Error);
  5105. } else {
  5106. pLogStandardError (Error);
  5107. }
  5108. }
  5109. }
  5110. DWORD
  5111. WINAPI
  5112. DoDynamicUpdate (
  5113. LPVOID Parameter
  5114. )
  5115. {
  5116. #define MIN_INTERVAL_BETWEEN_TASKS 3000
  5117. HWND hUIWindow = (HWND)Parameter;
  5118. DWORD rc = ERROR_SUCCESS;
  5119. LONG ticks;
  5120. LONG sleep;
  5121. DWORD estTime, estSize;
  5122. TCHAR drive[4];
  5123. DWORD sectorsPerCluster;
  5124. DWORD bytesPerSector;
  5125. ULARGE_INTEGER freeClusters = {0, 0};
  5126. ULARGE_INTEGER totalClusters = {0, 0};
  5127. DWORD clusterSize;
  5128. ULONGLONG availableBytes;
  5129. HANDLE hEvent;
  5130. BOOL bStopSetup;
  5131. BOOL bContinue = TRUE;
  5132. hEvent = OpenEvent (EVENT_ALL_ACCESS, FALSE, S_DU_SYNC_EVENT_NAME);
  5133. if (!hEvent) {
  5134. DynUpdtDebugLog (
  5135. Winnt32LogError,
  5136. TEXT("OpenEvent(%1) failed"),
  5137. 0,
  5138. S_DU_SYNC_EVENT_NAME
  5139. );
  5140. g_DynUpdtStatus->DUStatus = DUS_ERROR;
  5141. goto exit;
  5142. }
  5143. while (bContinue) {
  5144. if (g_DynUpdtStatus->Cancelled) {
  5145. g_DynUpdtStatus->DUStatus = DUS_CANCELLED;
  5146. rc = ERROR_CANCELLED;
  5147. DynamicUpdateUninitialize ();
  5148. break;
  5149. }
  5150. switch (g_DynUpdtStatus->DUStatus) {
  5151. case DUS_INITIAL:
  5152. if (Winnt32Restarted () || g_DynUpdtStatus->UserSpecifiedUpdates) {
  5153. g_DynUpdtStatus->DUStatus = DUS_PROCESSING;
  5154. break;
  5155. }
  5156. g_DynUpdtStatus->DUStatus = DUS_PREPARING;
  5157. SendMessage (hUIWindow, WMX_SETUPUPDATE_PREPARING, 0, 0);
  5158. break;
  5159. case DUS_PREPARING:
  5160. ticks = GetTickCount ();
  5161. if (!DynamicUpdateInitDownload (hUIWindow)) {
  5162. DynUpdtDebugLog (
  5163. Winnt32LogError,
  5164. TEXT("DynamicUpdateInitDownload failed"),
  5165. 0
  5166. );
  5167. pUpdateDUStatus (GetLastError ());
  5168. if (g_DynUpdtStatus->DUStatus != DUS_SKIP &&
  5169. g_DynUpdtStatus->DUStatus != DUS_ERROR) {
  5170. //
  5171. // the UI thread will decide what the next state will be
  5172. // based on user's selection
  5173. //
  5174. PostMessage (hUIWindow, WMX_SETUPUPDATE_INIT_RETRY, 0, 0);
  5175. rc = WaitForSingleObject (hEvent, INFINITE);
  5176. if (rc != WAIT_OBJECT_0) {
  5177. DynUpdtDebugLog (
  5178. Winnt32LogError,
  5179. TEXT("WaitForSingleObject failed (%1!u!)"),
  5180. 0,
  5181. rc
  5182. );
  5183. g_DynUpdtStatus->DUStatus = DUS_ERROR;
  5184. break;
  5185. }
  5186. }
  5187. break;
  5188. }
  5189. sleep = ticks + MIN_INTERVAL_BETWEEN_TASKS - (LONG)GetTickCount ();
  5190. if (sleep > 0 && sleep <= MIN_INTERVAL_BETWEEN_TASKS) {
  5191. Sleep (sleep);
  5192. }
  5193. g_DynUpdtStatus->DUStatus = DUS_DOWNLOADING;
  5194. break;
  5195. case DUS_DOWNLOADING:
  5196. ticks = GetTickCount ();
  5197. estSize = estTime = 0;
  5198. if (!DynamicUpdateStart (&estTime, &estSize)) {
  5199. g_DynUpdtStatus->DUStatus = DUS_ERROR;
  5200. break;
  5201. }
  5202. //
  5203. // check if there is enough disk space available for this operation
  5204. //
  5205. MYASSERT(ARRAYSIZE(drive) >= 4);
  5206. lstrcpyn (drive, g_DynUpdtStatus->WorkingDir, 4);
  5207. if (Winnt32GetDiskFreeSpaceNew (
  5208. drive,
  5209. &sectorsPerCluster,
  5210. &bytesPerSector,
  5211. &freeClusters,
  5212. &totalClusters
  5213. )) {
  5214. clusterSize = bytesPerSector * sectorsPerCluster;
  5215. availableBytes = (ULONGLONG)clusterSize * freeClusters.QuadPart;
  5216. //
  5217. // assume the average-worst case where each file occupies 1/2 cluster
  5218. // then the space required is the double of estimated space
  5219. //
  5220. if (availableBytes < (ULONGLONG)estSize * 2) {
  5221. DynUpdtDebugLog (
  5222. Winnt32LogError,
  5223. TEXT("DoDynamicUpdate: not enough free space on drive %1 to perform download (available=%2!u! MB, needed=%3!u! MB)"),
  5224. 0,
  5225. drive,
  5226. (DWORD)(availableBytes >> 20),
  5227. (DWORD)(estSize >> 20)
  5228. );
  5229. g_DynUpdtStatus->DUStatus = DUS_ERROR;
  5230. DynamicUpdateCancel ();
  5231. //
  5232. // wait for the UI thread to signal the event, no more than about a minute
  5233. //
  5234. rc = WaitForSingleObject (hEvent, 66000);
  5235. if (rc == WAIT_TIMEOUT) {
  5236. //
  5237. // why?
  5238. //
  5239. MYASSERT (FALSE);
  5240. } else if (rc != WAIT_OBJECT_0) {
  5241. DynUpdtDebugLog (
  5242. Winnt32LogError,
  5243. TEXT("WaitForSingleObject failed (%1!u!)"),
  5244. 0,
  5245. rc
  5246. );
  5247. }
  5248. break;
  5249. }
  5250. }
  5251. SendMessage (hUIWindow, WMX_SETUPUPDATE_DOWNLOADING, estTime, estSize);
  5252. rc = WaitForSingleObject (hEvent, INFINITE);
  5253. if (rc != WAIT_OBJECT_0) {
  5254. DynUpdtDebugLog (
  5255. Winnt32LogError,
  5256. TEXT("WaitForSingleObject failed (%1!u!)"),
  5257. 0,
  5258. rc
  5259. );
  5260. g_DynUpdtStatus->DUStatus = DUS_ERROR;
  5261. break;
  5262. }
  5263. sleep = ticks + MIN_INTERVAL_BETWEEN_TASKS - (LONG)GetTickCount ();
  5264. if (sleep > 0 && sleep <= MIN_INTERVAL_BETWEEN_TASKS) {
  5265. Sleep (sleep);
  5266. }
  5267. //
  5268. // the UI thread has already set the next state,
  5269. // based on the result of download
  5270. //
  5271. break;
  5272. case DUS_PROCESSING:
  5273. ticks = GetTickCount ();
  5274. SendMessage (hUIWindow, WMX_SETUPUPDATE_PROCESSING, 0, 0);
  5275. if (!g_DynUpdtStatus->UserSpecifiedUpdates) {
  5276. MYASSERT(ARRAYSIZE(g_DynUpdtStatus->DynamicUpdatesSource) == ARRAYSIZE(g_DynUpdtStatus->WorkingDir));
  5277. lstrcpy (g_DynUpdtStatus->DynamicUpdatesSource, g_DynUpdtStatus->WorkingDir);
  5278. }
  5279. bStopSetup = FALSE;
  5280. if (!DynamicUpdateProcessFiles (&bStopSetup)) {
  5281. g_DynUpdtStatus->DUStatus = bStopSetup ? DUS_FATALERROR : DUS_ERROR;
  5282. break;
  5283. }
  5284. sleep = ticks + MIN_INTERVAL_BETWEEN_TASKS - (LONG)GetTickCount ();
  5285. if (sleep > 0 && sleep <= MIN_INTERVAL_BETWEEN_TASKS) {
  5286. Sleep (sleep);
  5287. }
  5288. g_DynUpdtStatus->DUStatus = DUS_SUCCESSFUL;
  5289. break;
  5290. case DUS_SUCCESSFUL:
  5291. if (CheckUpgradeOnly && !g_DynUpdtStatus->RestartWinnt32 && !g_DynUpdtStatus->UserSpecifiedUpdates) {
  5292. if (pSaveLastDownloadInfo ()) {
  5293. g_DynUpdtStatus->PreserveWorkingDir = TRUE;
  5294. }
  5295. }
  5296. //
  5297. // notify the upgrade module that DU completed with success
  5298. //
  5299. g_DynUpdtStatus->Successful = TRUE;
  5300. //
  5301. // fall through
  5302. //
  5303. case DUS_ERROR:
  5304. case DUS_FATALERROR:
  5305. case DUS_SKIP:
  5306. //
  5307. // always make sure to uninitialize DU
  5308. // if the user had a modem connection active, this should close
  5309. // the connection
  5310. // DynamicUpdateUninitialize () will not reset any DU data
  5311. // in case the processing was successful
  5312. //
  5313. DynamicUpdateUninitialize ();
  5314. bContinue = FALSE;
  5315. break;
  5316. default:
  5317. MYASSERT (FALSE);
  5318. }
  5319. }
  5320. CloseHandle (hEvent);
  5321. exit:
  5322. //
  5323. // always notify the UI thread before exiting
  5324. //
  5325. PostMessage (hUIWindow, WMX_SETUPUPDATE_THREAD_DONE, 0, 0);
  5326. return rc;
  5327. }