AutoDownload.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /*-------------------------------------------------------------------------
  2. * clintlib\AutoDownload.h
  3. *
  4. *
  5. * Owner:
  6. *
  7. * Copyright 1986-2000 Microsoft Corporation, All Rights Reserved
  8. *-----------------------------------------------------------------------*/
  9. #include "regkey.h"
  10. class IAutoUpdateSink;
  11. /* AutoDownload incepts the logon ack, delaying it until the download
  12. * is complete. Use this to tell Autodown what to Ack with, once the
  13. * transfer is complete.
  14. */
  15. class IAutoDownload
  16. {
  17. public:
  18. /*-------------------------------------------------------------------------
  19. * SetFTPSite()
  20. *-------------------------------------------------------------------------
  21. * Purpose:
  22. * Set the site info so we know what sever to connect to.
  23. */
  24. virtual void SetFTPSite(const char * szFTPSite, const char * szInitialDirectory, const char * szUsername, const char * szPassword) = 0;
  25. /*-------------------------------------------------------------------------
  26. * SetOfficialFileListAttributes()
  27. *-------------------------------------------------------------------------
  28. * Purpose:
  29. * Set the CRC we can verify that the FTP site has the correct FileList.txt
  30. *
  31. * Parameters:
  32. * nCRC: official CRC for filelist.txt at FTP site
  33. * nFileSize: size of filelist.txt at FTP Site
  34. */
  35. virtual void SetOfficialFileListAttributes(int nCRC, unsigned nFileSize) = 0;
  36. /*-------------------------------------------------------------------------
  37. * SetOfficialTime()
  38. *-------------------------------------------------------------------------
  39. */
  40. virtual void SetArtPath(const char * pArtPath) = 0;
  41. /*-------------------------------------------------------------------------
  42. * SetFilelistSubDir()
  43. * Since the filename Filelist.txt is hardcoded everywhere, and sometimes
  44. * we want differentiate between two filelists, we have this.
  45. * This is the sub dir of where the filelist is downloaded from; if not
  46. * set, then the regular base directory is used.
  47. *-------------------------------------------------------------------------
  48. */
  49. virtual void SetFilelistSubDir(const char * pszPath) = 0;
  50. /*-------------------------------------------------------------------------
  51. * BeginUpdate()
  52. *-------------------------------------------------------------------------
  53. * Purpose:
  54. * Setup variables and download the file list.
  55. *
  56. * Parameters:
  57. * pSink: pointer to the object receiving events about the download
  58. * bForceCRCCheck: if true, file times are ignored and CRC are always checked
  59. * bSkipReloader: if true, then reloader is not launch: an error is displayed
  60. */
  61. virtual void BeginUpdate(IAutoUpdateSink * pSink, bool bForceCRCCheck, bool bSkipReloader) = 0;
  62. /*-------------------------------------------------------------------------
  63. * HandleAutoDownload()
  64. *-------------------------------------------------------------------------
  65. * Parameters:
  66. * dwTimeAlloted: time slice that we have to get or process data.
  67. * HandleAutoDownload() will usually take AT LEAST this much
  68. * time, and on rare occasions less.
  69. * Purpose:
  70. * Check to see if AutoUpdate is done from within the main thread. If so,
  71. * restart or relogon as needed.
  72. *
  73. * Remarks:
  74. * This is intended to be called periodically during the download.
  75. */
  76. virtual void HandleAutoDownload(DWORD dwTimeAlloted) = 0;
  77. /*-------------------------------------------------------------------------
  78. * Abort()
  79. *-------------------------------------------------------------------------
  80. * Purpose:
  81. * Abort the autodownload.
  82. */
  83. virtual void Abort() = 0;
  84. };
  85. IAutoDownload * CreateAutoDownload();
  86. /*---------------------------------------------------------------------------------
  87. IAutoUpdateSink:
  88. This receives events about the Autodownload system
  89. ---------------------------------------------------------------------------------*/
  90. class IAutoUpdateSink :
  91. public IHTTPSessionSink
  92. {
  93. public:
  94. virtual void OnBeginRetrievingFileList() {}
  95. virtual void OnRetrievingFileListProgress(unsigned long nFileSize, unsigned long cCurrentBytes) {}
  96. // once we've got the right filelist, we begin analysis of local files
  97. virtual void OnBeginAnalysis() {}
  98. virtual void OnAnalysisProgress(float fPercentDone) {}
  99. virtual bool ShouldFilterFile(const char * szFileName) // szFileName is base filename (not including path)
  100. {
  101. return false; // if returns true, then file is not downloaded
  102. }
  103. virtual void OnProgress(unsigned long cTotalBytes, const char* szCurrentFile, unsigned long cCurrentFileBytes, unsigned cEstimatedSecondsLeft) {}
  104. virtual void OnBeginDownloadProgressBar(unsigned cTotalBytes, int cFiles) {}
  105. virtual void OnUserAbort() {}
  106. /*-------------------------------------------------------------------------
  107. * SetErrorFunction()
  108. *-------------------------------------------------------------------------
  109. * Purpose:
  110. * Set a callback function for when an error occurs during moving files.
  111. *
  112. * Returns: true if the autoupdate system should try again
  113. */
  114. virtual bool OnMoveError(char * szErrorMsg)
  115. {
  116. return false;
  117. }
  118. // returns true if file should be registered
  119. virtual bool ShouldRegister(char * szFullFileName) // path is included in szFullFileName
  120. {
  121. return false;
  122. }
  123. // returns registration exit code (0 means success)
  124. virtual int RegisterFile(char * szFullFileName) // path is included in szFullFileName
  125. {
  126. return -1;
  127. }
  128. // this is called in the AutoUpdate system destructor
  129. virtual void OnAutoUpdateSystemTermination(bool bErrorOccurred, bool bRestarting) {}
  130. };
  131. class CAutoDownloadUtil // Shared between Reloader.exe and IAutoDownload's privates
  132. {
  133. public:
  134. /*-------------------------------------------------------------------------
  135. * MoveFiles()
  136. *-------------------------------------------------------------------------
  137. * Purpose:
  138. * Copies temp files into ArtPath. There's a hardcoded check for
  139. * Allegiance.exe. Assumes current folder is where Allegiance.exe
  140. * should go (not ArtPath).
  141. *
  142. * Paramters:
  143. * szTempPath: where the all the files come from
  144. * szArtPath: where the art files go
  145. * bSkipSharingViolation: if true then we don't quit when a sharing violation occurs.
  146. * if false then we quit with error on such cases.
  147. * pbFilesWereSkipped: is used at only if bSkipSharingViolation is true -AND- pbFilesWereSkipped != NULL.
  148. * *pbFilesWereSkipped is set to true if files were indeed skipped due to a
  149. * sharing violation.
  150. * bNoRegistryWrite: do not update registry
  151. * pSink : AutoUpdate sink where move errors are reported
  152. * Returns:
  153. * true only on success
  154. */
  155. static bool MoveFiles(const char * szTempPath, const char * szArtPath_, bool bSkipSharingViolation,
  156. bool * pbFilesWereSkipped, bool bNoRegistryWrite, char * szErrorMsg, IAutoUpdateSink * pSink)
  157. {
  158. WIN32_FIND_DATA finddata;
  159. HANDLE hsearchFiles = 0;
  160. char szSourceSpec[MAX_PATH+20];
  161. char szArtPath[MAX_PATH+20];
  162. strcpy(szSourceSpec, szTempPath);
  163. strcat(szSourceSpec, "*.*");
  164. strcpy(szArtPath, szArtPath_);
  165. int cLen = strlen(szArtPath);
  166. if (cLen == 0 || szArtPath[cLen-1] != '\\')
  167. {
  168. szArtPath[cLen++] = '\\';
  169. szArtPath[cLen] = 0;
  170. }
  171. bool bFilesWereSkipped = false;
  172. // count the files in the file path
  173. hsearchFiles = FindFirstFile(szSourceSpec, &finddata);
  174. if (INVALID_HANDLE_VALUE == hsearchFiles)
  175. {
  176. return false;
  177. }
  178. char szSource[MAX_PATH+20];
  179. char szDest[MAX_PATH+20];
  180. while (INVALID_HANDLE_VALUE != hsearchFiles)
  181. {
  182. // skip directory listings "." and ".."; and filelist (filelist is moved last)
  183. if (finddata.cFileName[0] != '.' &&
  184. _stricmp(finddata.cFileName, "filelist.txt") != 0 &&
  185. (!pSink || !pSink->ShouldFilterFile(finddata.cFileName)))
  186. {
  187. // setup move paths
  188. strcpy(szSource, szTempPath);
  189. strcat(szSource, finddata.cFileName);
  190. GetFileNameWithPath(szDest, finddata.cFileName, szArtPath, ".\\");
  191. // Move files to their dest
  192. if (!MoveFilePrivate(szSource, szDest, bSkipSharingViolation, &bFilesWereSkipped, szErrorMsg, pSink))
  193. return false;
  194. // consider registering special files
  195. if(pSink && pSink->ShouldRegister(szDest))
  196. {
  197. int nExitCode = pSink->RegisterFile(szDest);
  198. if (nExitCode != 0)
  199. {
  200. // registration failed; move file back so autoupdate attempts to register later; then abort
  201. MoveFile(szDest, szSource);
  202. if (szErrorMsg)
  203. sprintf(szErrorMsg, "Failed to Register file %s; registration exit code(%d)", finddata.cFileName, nExitCode);
  204. return false;
  205. }
  206. }
  207. }
  208. if (!FindNextFile(hsearchFiles, &finddata))
  209. {
  210. FindClose(hsearchFiles);
  211. hsearchFiles = INVALID_HANDLE_VALUE;
  212. }
  213. }
  214. //
  215. // finish off with moving the filelist; if no files were skipped; if files were skipped, then reloader
  216. // needs to move the filelist
  217. //
  218. if(!bFilesWereSkipped)
  219. {
  220. strcpy(szSource, szTempPath);
  221. strcat(szSource, "filelist.txt");
  222. if (CAutoDownloadUtil::GetFileLength(szSource) != -1) // check for existance
  223. {
  224. GetFileNameWithPath(szDest, "filelist.txt", szArtPath, ".\\");
  225. if (!MoveFilePrivate(szSource, szDest, bSkipSharingViolation, &bFilesWereSkipped, szErrorMsg, pSink))
  226. return false;
  227. }
  228. }
  229. FindClose(hsearchFiles);
  230. if (bSkipSharingViolation && pbFilesWereSkipped)
  231. *pbFilesWereSkipped = bFilesWereSkipped;
  232. if (!bFilesWereSkipped && !bNoRegistryWrite)
  233. {
  234. // Set registry's MoveInProgress to zero, meaning move is complete
  235. HKEY hKey;
  236. DWORD dwValue = 0;
  237. if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT, 0, KEY_WRITE, &hKey))
  238. {
  239. ::RegSetValueEx(hKey, "MoveInProgress", NULL, REG_DWORD, (unsigned char*)&dwValue, sizeof(DWORD));
  240. }
  241. }
  242. return true;
  243. }
  244. static char * GetEXEFileName(int nIndex)
  245. {
  246. static char * pszEXEFiles[] =
  247. {
  248. "CliConfig.exe",
  249. "fsmon.exe",
  250. "readme.txt",
  251. "patcher.exe",
  252. "FileList.txt",
  253. "Reloader.exe",
  254. "msrgbits.inf",
  255. "msrgtran.dll",
  256. "msrgip.dll"
  257. // the file muse be at least 8 characters (including ext) For example: fsmon.exe
  258. // increment g_cEXEFiles, if you add to this
  259. };
  260. #define g_cEXEFiles 9
  261. return pszEXEFiles[nIndex];
  262. }
  263. /*-------------------------------------------------------------------------
  264. * GetFileNameWithPath()
  265. *-------------------------------------------------------------------------
  266. * Returns:
  267. * The full path of where the file belongs.
  268. */
  269. static void GetFileNameWithPath(OUT char * szFileNameWithPath,
  270. IN const char * szRawFileName,
  271. IN const char * szArtPath,
  272. IN const char * szEXEPath)
  273. {
  274. //
  275. // Move special files to current directory
  276. //
  277. //
  278. // NOTE: if you add special files, try adding them to the GetEXEFileName()
  279. // list to ensure get special care for the PC Gamer Build (Beta 1) bug.
  280. // ///////////////////////////////////////////////////////
  281. if (_stricmp(szRawFileName, "AllegianceRetail.exe") == 0 ||
  282. _stricmp(szRawFileName, "AllegianceDebug.exe") == 0 ||
  283. _stricmp(szRawFileName, "AllegianceTest.exe") == 0 ||
  284. _stricmp(szRawFileName, "Allegiance.exe") == 0)
  285. {
  286. strcpy(szFileNameWithPath, szEXEPath);
  287. strcat(szFileNameWithPath, "Allegiance.exe");
  288. }
  289. else
  290. if (_stricmp(szRawFileName, "AllegianceRetail.pdb") == 0 ||
  291. _stricmp(szRawFileName, "AllegianceDebug.pdb") == 0 ||
  292. _stricmp(szRawFileName, "AllegianceTest.pdb") == 0 ||
  293. _stricmp(szRawFileName, "Allegiance.pdb") == 0)
  294. {
  295. strcpy(szFileNameWithPath, szEXEPath);
  296. strcat(szFileNameWithPath, "Allegiance.pdb");
  297. }
  298. else
  299. if (_stricmp(szRawFileName, "AllegianceRetail.sym") == 0 ||
  300. _stricmp(szRawFileName, "AllegianceDebug.sym") == 0 ||
  301. _stricmp(szRawFileName, "AllegianceTest.sym") == 0 ||
  302. _stricmp(szRawFileName, "Allegiance.sym") == 0)
  303. {
  304. strcpy(szFileNameWithPath, szEXEPath);
  305. strcat(szFileNameWithPath, "Allegiance.sym");
  306. }
  307. else
  308. if (_stricmp(szRawFileName, "AllegianceRetail.map") == 0 ||
  309. _stricmp(szRawFileName, "AllegianceDebug.map") == 0 ||
  310. _stricmp(szRawFileName, "AllegianceTest.map") == 0 ||
  311. _stricmp(szRawFileName, "Allegiance.map") == 0)
  312. {
  313. strcpy(szFileNameWithPath, szEXEPath);
  314. strcat(szFileNameWithPath, "Allegiance.map");
  315. }
  316. else ///////////////////////////////////////////////////////
  317. if (_stricmp(szRawFileName, "AllSrvRetail.exe") == 0 ||
  318. _stricmp(szRawFileName, "AllSrvDebug.exe") == 0 ||
  319. _stricmp(szRawFileName, "AllSrvTest.exe") == 0 ||
  320. _stricmp(szRawFileName, "AllSrv.exe") == 0)
  321. {
  322. strcpy(szFileNameWithPath, szEXEPath);
  323. strcat(szFileNameWithPath, "AllSrv.exe");
  324. }
  325. else
  326. if (_stricmp(szRawFileName, "AllSrvRetail.pdb") == 0 ||
  327. _stricmp(szRawFileName, "AllSrvDebug.pdb") == 0 ||
  328. _stricmp(szRawFileName, "AllSrvTest.pdb") == 0 ||
  329. _stricmp(szRawFileName, "AllSrv.pdb") == 0)
  330. {
  331. strcpy(szFileNameWithPath, szEXEPath);
  332. strcat(szFileNameWithPath, "AllSrv.pdb");
  333. }
  334. else
  335. if (_stricmp(szRawFileName, "AllSrvRetail.sym") == 0 ||
  336. _stricmp(szRawFileName, "AllSrvDebug.sym") == 0 ||
  337. _stricmp(szRawFileName, "AllSrvTest.sym") == 0 ||
  338. _stricmp(szRawFileName, "AllSrv.sym") == 0)
  339. {
  340. strcpy(szFileNameWithPath, szEXEPath);
  341. strcat(szFileNameWithPath, "AllSrv.sym");
  342. }
  343. else
  344. if (_stricmp(szRawFileName, "AllSrvRetail.map") == 0 ||
  345. _stricmp(szRawFileName, "AllSrvDebug.map") == 0 ||
  346. _stricmp(szRawFileName, "AllSrvTest.map") == 0 ||
  347. _stricmp(szRawFileName, "AllSrv.map") == 0)
  348. {
  349. strcpy(szFileNameWithPath, szEXEPath);
  350. strcat(szFileNameWithPath, "AllSrv.map");
  351. }
  352. else ///////////////////////////////////////////////////////
  353. if (_stricmp(szRawFileName, "AllSrv32Retail.exe") == 0 ||
  354. _stricmp(szRawFileName, "AllSrv32Debug.exe") == 0 ||
  355. _stricmp(szRawFileName, "AllSrv32Test.exe") == 0 ||
  356. _stricmp(szRawFileName, "AllSrv32.exe") == 0)
  357. {
  358. strcpy(szFileNameWithPath, szEXEPath);
  359. strcat(szFileNameWithPath, "AllSrv32.exe");
  360. }
  361. else
  362. if (_stricmp(szRawFileName, "AllSrv32Retail.pdb") == 0 ||
  363. _stricmp(szRawFileName, "AllSrv32Debug.pdb") == 0 ||
  364. _stricmp(szRawFileName, "AllSrv32Test.pdb") == 0 ||
  365. _stricmp(szRawFileName, "AllSrv32.pdb") == 0)
  366. {
  367. strcpy(szFileNameWithPath, szEXEPath);
  368. strcat(szFileNameWithPath, "AllSrv32.pdb");
  369. }
  370. else
  371. if (_stricmp(szRawFileName, "AllSrv32Retail.sym") == 0 ||
  372. _stricmp(szRawFileName, "AllSrv32Debug.sym") == 0 ||
  373. _stricmp(szRawFileName, "AllSrv32Test.sym") == 0 ||
  374. _stricmp(szRawFileName, "AllSrv32.sym") == 0)
  375. {
  376. strcpy(szFileNameWithPath, szEXEPath);
  377. strcat(szFileNameWithPath, "AllSrv32.sym");
  378. }
  379. else
  380. if (_stricmp(szRawFileName, "AllSrv32Retail.map") == 0 ||
  381. _stricmp(szRawFileName, "AllSrv32Debug.map") == 0 ||
  382. _stricmp(szRawFileName, "AllSrv32Test.map") == 0 ||
  383. _stricmp(szRawFileName, "AllSrv32.map") == 0)
  384. {
  385. strcpy(szFileNameWithPath, szEXEPath);
  386. strcat(szFileNameWithPath, "AllSrv32.map");
  387. }
  388. else ///////////////////////////////////////////////////////
  389. if (_stricmp(szRawFileName, "AGCRetail.dll") == 0 ||
  390. _stricmp(szRawFileName, "AGCDebug.dll") == 0 ||
  391. _stricmp(szRawFileName, "AGCTest.dll") == 0 ||
  392. _stricmp(szRawFileName, "AGC.dll") == 0)
  393. {
  394. strcpy(szFileNameWithPath, szEXEPath);
  395. strcat(szFileNameWithPath, "AGC.dll");
  396. }
  397. else
  398. if (_stricmp(szRawFileName, "AGCRetail.pdb") == 0 ||
  399. _stricmp(szRawFileName, "AGCDebug.pdb") == 0 ||
  400. _stricmp(szRawFileName, "AGCTest.pdb") == 0 ||
  401. _stricmp(szRawFileName, "AGC.pdb") == 0)
  402. {
  403. strcpy(szFileNameWithPath, szEXEPath);
  404. strcat(szFileNameWithPath, "AGC.pdb");
  405. }
  406. else
  407. if (_stricmp(szRawFileName, "AGCRetail.sym") == 0 ||
  408. _stricmp(szRawFileName, "AGCDebug.sym") == 0 ||
  409. _stricmp(szRawFileName, "AGCTest.sym") == 0 ||
  410. _stricmp(szRawFileName, "AGC.sym") == 0)
  411. {
  412. strcpy(szFileNameWithPath, szEXEPath);
  413. strcat(szFileNameWithPath, "AGC.sym");
  414. }
  415. else
  416. if (_stricmp(szRawFileName, "AGCRetail.map") == 0 ||
  417. _stricmp(szRawFileName, "AGCDebug.map") == 0 ||
  418. _stricmp(szRawFileName, "AGCTest.map") == 0 ||
  419. _stricmp(szRawFileName, "AGC.map") == 0)
  420. {
  421. strcpy(szFileNameWithPath, szEXEPath);
  422. strcat(szFileNameWithPath, "AGC.map");
  423. }
  424. else ///////////////////////////////////////////////////////
  425. if (_stricmp(szRawFileName, "AllSrvUIRetail.exe") == 0 ||
  426. _stricmp(szRawFileName, "AllSrvUIDebug.exe") == 0 ||
  427. _stricmp(szRawFileName, "AllSrvUITest.exe") == 0 ||
  428. _stricmp(szRawFileName, "AllSrvUI.exe") == 0)
  429. {
  430. strcpy(szFileNameWithPath, szEXEPath);
  431. strcat(szFileNameWithPath, "AllSrvUI.exe");
  432. }
  433. else
  434. if (_stricmp(szRawFileName, "AllSrvUIRetail.pdb") == 0 ||
  435. _stricmp(szRawFileName, "AllSrvUIDebug.pdb") == 0 ||
  436. _stricmp(szRawFileName, "AllSrvUITest.pdb") == 0 ||
  437. _stricmp(szRawFileName, "AllSrvUI.pdb") == 0)
  438. {
  439. strcpy(szFileNameWithPath, szEXEPath);
  440. strcat(szFileNameWithPath, "AllSrvUI.pdb");
  441. }
  442. else
  443. if (_stricmp(szRawFileName, "AllSrvUIRetail.sym") == 0 ||
  444. _stricmp(szRawFileName, "AllSrvUIDebug.sym") == 0 ||
  445. _stricmp(szRawFileName, "AllSrvUITest.sym") == 0 ||
  446. _stricmp(szRawFileName, "AllSrvUI.sym") == 0)
  447. {
  448. strcpy(szFileNameWithPath, szEXEPath);
  449. strcat(szFileNameWithPath, "AllSrvUI.sym");
  450. }
  451. else
  452. if (_stricmp(szRawFileName, "AllSrvUIRetail.map") == 0 ||
  453. _stricmp(szRawFileName, "AllSrvUIDebug.map") == 0 ||
  454. _stricmp(szRawFileName, "AllSrvUITest.map") == 0 ||
  455. _stricmp(szRawFileName, "AllSrvUI.map") == 0)
  456. {
  457. strcpy(szFileNameWithPath, szEXEPath);
  458. strcat(szFileNameWithPath, "AllSrvUI.map");
  459. }
  460. else ///////////////////////////////////////////////////////
  461. if (_stricmp(szRawFileName, "AllSrvUI32Retail.exe") == 0 ||
  462. _stricmp(szRawFileName, "AllSrvUI32Debug.exe") == 0 ||
  463. _stricmp(szRawFileName, "AllSrvUI32Test.exe") == 0 ||
  464. _stricmp(szRawFileName, "AllSrvUI32.exe") == 0)
  465. {
  466. strcpy(szFileNameWithPath, szEXEPath);
  467. strcat(szFileNameWithPath, "AllSrvUI32.exe");
  468. }
  469. else
  470. if (_stricmp(szRawFileName, "AllSrvUI32Retail.pdb") == 0 ||
  471. _stricmp(szRawFileName, "AllSrvUI32Debug.pdb") == 0 ||
  472. _stricmp(szRawFileName, "AllSrvUI32Test.pdb") == 0 ||
  473. _stricmp(szRawFileName, "AllSrvUI32.pdb") == 0)
  474. {
  475. strcpy(szFileNameWithPath, szEXEPath);
  476. strcat(szFileNameWithPath, "AllSrvUI32.pdb");
  477. }
  478. else
  479. if (_stricmp(szRawFileName, "AllSrvUI32Retail.sym") == 0 ||
  480. _stricmp(szRawFileName, "AllSrvUI32Debug.sym") == 0 ||
  481. _stricmp(szRawFileName, "AllSrvUI32Test.sym") == 0 ||
  482. _stricmp(szRawFileName, "AllSrvUI32.sym") == 0)
  483. {
  484. strcpy(szFileNameWithPath, szEXEPath);
  485. strcat(szFileNameWithPath, "AllSrvUI32.sym");
  486. }
  487. else
  488. if (_stricmp(szRawFileName, "AllSrvUI32Retail.map") == 0 ||
  489. _stricmp(szRawFileName, "AllSrvUI32Debug.map") == 0 ||
  490. _stricmp(szRawFileName, "AllSrvUI32Test.map") == 0 ||
  491. _stricmp(szRawFileName, "AllSrvUI32.map") == 0)
  492. {
  493. strcpy(szFileNameWithPath, szEXEPath);
  494. strcat(szFileNameWithPath, "AllSrvUI32.map");
  495. }
  496. else ///////////////////////////////////////////////////////
  497. if (_stricmp(szRawFileName, "AutoUpdateRetail.exe") == 0 ||
  498. _stricmp(szRawFileName, "AutoUpdateDebug.exe") == 0 ||
  499. _stricmp(szRawFileName, "AutoUpdateTest.exe") == 0 ||
  500. _stricmp(szRawFileName, "AutoUpdate.exe") == 0)
  501. {
  502. strcpy(szFileNameWithPath, szEXEPath);
  503. strcat(szFileNameWithPath, "AutoUpdate.exe");
  504. }
  505. else
  506. if (_stricmp(szRawFileName, "AutoUpdateRetail.pdb") == 0 ||
  507. _stricmp(szRawFileName, "AutoUpdateDebug.pdb") == 0 ||
  508. _stricmp(szRawFileName, "AutoUpdateTest.pdb") == 0 ||
  509. _stricmp(szRawFileName, "AutoUpdate.pdb") == 0)
  510. {
  511. strcpy(szFileNameWithPath, szEXEPath);
  512. strcat(szFileNameWithPath, "AutoUpdate.pdb");
  513. }
  514. else
  515. if (_stricmp(szRawFileName, "AutoUpdateRetail.sym") == 0 ||
  516. _stricmp(szRawFileName, "AutoUpdateDebug.sym") == 0 ||
  517. _stricmp(szRawFileName, "AutoUpdateTest.sym") == 0 ||
  518. _stricmp(szRawFileName, "AutoUpdate.sym") == 0)
  519. {
  520. strcpy(szFileNameWithPath, szEXEPath);
  521. strcat(szFileNameWithPath, "AutoUpdate.sym");
  522. }
  523. else
  524. if (_stricmp(szRawFileName, "AutoUpdateRetail.map") == 0 ||
  525. _stricmp(szRawFileName, "AutoUpdateDebug.map") == 0 ||
  526. _stricmp(szRawFileName, "AutoUpdateTest.map") == 0 ||
  527. _stricmp(szRawFileName, "AutoUpdate.map") == 0)
  528. {
  529. strcpy(szFileNameWithPath, szEXEPath);
  530. strcat(szFileNameWithPath, "AutoUpdate.map");
  531. }
  532. else
  533. {
  534. for (int i = 0; i < g_cEXEFiles; ++i)
  535. {
  536. if (_stricmp(szRawFileName, GetEXEFileName(i)) == 0)
  537. {
  538. strcpy(szFileNameWithPath, szEXEPath);
  539. strcat(szFileNameWithPath, szRawFileName);
  540. return;
  541. }
  542. }
  543. //
  544. // Must be an ArtFile!
  545. //
  546. strcpy(szFileNameWithPath, szArtPath);
  547. strcat(szFileNameWithPath, szRawFileName);
  548. }
  549. }
  550. //////////////////////////////////////////////////////////////////////////
  551. static unsigned GetFileLength(char *szFileName)
  552. {
  553. HANDLE hFile = CreateFile(szFileName,
  554. 0/*GENERIC_READ*/, // 0 == query only
  555. FILE_SHARE_READ,
  556. NULL,
  557. OPEN_EXISTING,
  558. FILE_ATTRIBUTE_NORMAL,
  559. NULL);
  560. if (hFile == INVALID_HANDLE_VALUE)
  561. {
  562. return (unsigned)-1;
  563. }
  564. unsigned nSize = ::GetFileSize(hFile, NULL);
  565. ::CloseHandle(hFile);
  566. return nSize;
  567. }
  568. private:
  569. /*-------------------------------------------------------------------------
  570. * Move File considering bSkipSharingViolation
  571. *
  572. * returns false if error, true on success
  573. */
  574. static bool MoveFilePrivate(char * szSource, char * szDest, bool bSkipSharingViolation,
  575. bool * pbFilesWereSkipped, char * szErrorMsg, IAutoUpdateSink * pSink)
  576. {
  577. bool bErrorOccured;
  578. bool bTryAgain;
  579. do
  580. {
  581. ::DeleteFile(szDest);
  582. // Note: considered using MoveFileEx, but win95/98 doesn't support it
  583. BOOL bResult = ::MoveFile(szSource, szDest);
  584. if(!bResult)
  585. {
  586. if (bSkipSharingViolation)
  587. {
  588. int nErr = GetLastError();
  589. bool bSkip = (nErr == ERROR_ALREADY_EXISTS || nErr == ERROR_ACCESS_DENIED || nErr == ERROR_SHARING_VIOLATION);
  590. if (bSkip)
  591. {
  592. *pbFilesWereSkipped = true;
  593. bErrorOccured = false;
  594. }
  595. else
  596. bErrorOccured = true;
  597. }
  598. else
  599. {
  600. #ifdef _DEBUG
  601. char sz[40];
  602. sprintf(sz, "Moving Files Error: %d", GetLastError());
  603. ::OutputDebugString(sz);
  604. #endif
  605. bErrorOccured = true;
  606. }
  607. }
  608. else
  609. bErrorOccured = false;
  610. bTryAgain = false;
  611. if (bErrorOccured && (pSink || szErrorMsg))
  612. {
  613. char szErrorMessage[2*MAX_PATH+50];
  614. FormatErrorMessage(szErrorMessage, GetLastError());
  615. strcat(szErrorMessage, "\n\r\n\r Source: ");
  616. strcat(szErrorMessage, szSource);
  617. strcat(szErrorMessage, "\n\r\n\r Dest: ");
  618. strcat(szErrorMessage, szDest);
  619. if (szErrorMsg)
  620. strcpy(szErrorMsg, szErrorMessage);
  621. if (pSink)
  622. bTryAgain = pSink->OnMoveError(szErrorMessage);
  623. }
  624. } while(bTryAgain);
  625. return !bErrorOccured; // true if successful move
  626. }
  627. /*-------------------------------------------------------------------------
  628. * FormatErrorMessage()
  629. *-------------------------------------------------------------------------
  630. * Paramters:
  631. * dwErrorCode: take a dwErrorCode and print what it means as text
  632. *
  633. */
  634. static void FormatErrorMessage(char *szBuffer, DWORD dwErrorCode)
  635. {
  636. sprintf(szBuffer,"(%d) ", dwErrorCode);
  637. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
  638. FORMAT_MESSAGE_IGNORE_INSERTS,
  639. NULL,
  640. dwErrorCode,
  641. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  642. szBuffer + strlen(szBuffer),
  643. 128,
  644. NULL
  645. );
  646. }
  647. };
  648. bool LaunchReloaderAndExit(bool bReLaunchAllegianceAsMinimized);