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.

666 lines
23 KiB

  1. /*-----------------------------------------------------------------------------
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name: ckcnv.cxx
  4. Abstract:
  5. Upgrades cookies to present urlcache format by enumerating cookie files in the
  6. cache cookies directory and creates cookie cache index entries in the format of
  7. the current wininet.dll.
  8. Author:
  9. Adriaan Canter (adriaanc) 09-Jan-1997
  10. Created
  11. Adriaan Canter (adriaanc) 01-Feb-1997
  12. Modified for per-user caches. The class CCookieLoader definition
  13. can now be pasted into the urlcache build without re-definition
  14. and work correctly, as long as the HKLM and HKCU cache keys are
  15. not modified. BUGBUG - do this.
  16. -----------------------------------------------------------------------------*/
  17. #include <windows.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <wininet.h>
  21. #include "cachedef.h"
  22. #define INET_ASSERT(condition) Assert(condition)
  23. /*-----------------------------------------------------------------------------
  24. GetHKLMHistoryDirectory
  25. ----------------------------------------------------------------------------*/
  26. DWORD GetHKLMHistoryDirectory(CHAR *szHistoryDirectory)
  27. {
  28. HKEY hKey = (HKEY) INVALID_HANDLE_VALUE;
  29. DWORD dwError, dwKeyType, cbKeyLen = MAX_PATH;
  30. // Skip the level of indirection for url history.
  31. if (dwError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  32. "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Url History",
  33. NULL, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  34. goto exit;
  35. if (dwError = RegQueryValueEx(hKey, CACHE_DIRECTORY_VALUE, NULL, &dwKeyType,
  36. (LPBYTE) szHistoryDirectory, &cbKeyLen) != ERROR_SUCCESS)
  37. goto exit;
  38. exit:
  39. if (hKey != INVALID_HANDLE_VALUE)
  40. CloseHandle(hKey);
  41. return dwError;
  42. }
  43. /*-----------------------------------------------------------------------------
  44. GetHKCUHistoryDirectory
  45. ----------------------------------------------------------------------------*/
  46. DWORD GetHKCUHistoryDirectory(CHAR *szHistoryDirectory)
  47. {
  48. HKEY hKey = (HKEY) INVALID_HANDLE_VALUE;
  49. DWORD dwError, dwKeyType, cbKeyLen = MAX_PATH;
  50. CHAR szHistoryDirRegKey[MAX_PATH];
  51. strcpy(szHistoryDirRegKey, OLD_CACHE_KEY);
  52. strcat(szHistoryDirRegKey, "\\");
  53. strcat(szHistoryDirRegKey, HISTORY_PATH_KEY);
  54. if (dwError = RegOpenKeyEx(HKEY_CURRENT_USER,
  55. szHistoryDirRegKey, NULL, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  56. goto exit;
  57. if (dwError = RegQueryValueEx(hKey, CACHE_PATH_VALUE, NULL, &dwKeyType,
  58. (LPBYTE) szHistoryDirectory, &cbKeyLen) != ERROR_SUCCESS)
  59. goto exit;
  60. exit:
  61. if (hKey != INVALID_HANDLE_VALUE)
  62. CloseHandle(hKey);
  63. return dwError;
  64. }
  65. /*-----------------------------------------------------------------------------
  66. GetHKLMCookiesDirectory
  67. ----------------------------------------------------------------------------*/
  68. DWORD GetHKLMCookiesDirectory(CHAR *szCookiesDirectory)
  69. {
  70. HKEY hKey = (HKEY) INVALID_HANDLE_VALUE;
  71. DWORD dwError, dwKeyType, cbKeyLen = MAX_PATH;
  72. CHAR szCookiesDirRegKey[MAX_PATH];
  73. strcpy(szCookiesDirRegKey, OLD_CACHE_KEY);
  74. strcat(szCookiesDirRegKey, "\\");
  75. strcat(szCookiesDirRegKey, CACHE_SPECIAL_PATHS_KEY);
  76. strcat(szCookiesDirRegKey, "\\");
  77. strcat(szCookiesDirRegKey, COOKIE_PATH_KEY);
  78. if (dwError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  79. szCookiesDirRegKey, NULL, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  80. goto exit;
  81. if (dwError = RegQueryValueEx(hKey, CACHE_DIRECTORY_VALUE, NULL, &dwKeyType,
  82. (LPBYTE) szCookiesDirectory, &cbKeyLen) != ERROR_SUCCESS)
  83. goto exit;
  84. exit:
  85. if (hKey != INVALID_HANDLE_VALUE)
  86. CloseHandle(hKey);
  87. return dwError;
  88. }
  89. /*-----------------------------------------------------------------------------
  90. GetHKCUCookiesDirectory
  91. ----------------------------------------------------------------------------*/
  92. DWORD GetHKCUCookiesDirectory(CHAR *szCookiesDirectory)
  93. {
  94. HKEY hKey = (HKEY) INVALID_HANDLE_VALUE;
  95. DWORD dwError, dwKeyType, cbKeyLen = MAX_PATH;
  96. CHAR szCookiesDirRegKey[MAX_PATH];
  97. strcpy(szCookiesDirRegKey, OLD_CACHE_KEY);
  98. strcat(szCookiesDirRegKey, "\\");
  99. strcat(szCookiesDirRegKey, COOKIE_PATH_KEY);
  100. if (dwError = RegOpenKeyEx(HKEY_CURRENT_USER,
  101. szCookiesDirRegKey, NULL, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  102. goto exit;
  103. if (dwError = RegQueryValueEx(hKey, CACHE_PATH_VALUE, NULL, &dwKeyType,
  104. (LPBYTE) szCookiesDirectory, &cbKeyLen) != ERROR_SUCCESS)
  105. goto exit;
  106. exit:
  107. if (hKey != INVALID_HANDLE_VALUE)
  108. CloseHandle(hKey);
  109. return dwError;
  110. }
  111. /*-----------------------------------------------------------------------------
  112. GetHKLMContentDirectory
  113. ----------------------------------------------------------------------------*/
  114. DWORD GetHKLMContentDirectory(CHAR *szContentDirectory)
  115. {
  116. HKEY hKey = (HKEY) INVALID_HANDLE_VALUE;
  117. DWORD dwError, dwKeyType, cbKeyLen = MAX_PATH;
  118. CHAR szContentDirRegKey[MAX_PATH];
  119. strcpy(szContentDirRegKey, CACHE_PATHS_FULL_KEY);
  120. if (dwError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  121. szContentDirRegKey, NULL, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  122. goto exit;
  123. if (dwError = RegQueryValueEx(hKey, CACHE_DIRECTORY_VALUE, NULL, &dwKeyType,
  124. (LPBYTE) szContentDirectory, &cbKeyLen) != ERROR_SUCCESS)
  125. goto exit;
  126. exit:
  127. if (hKey != INVALID_HANDLE_VALUE)
  128. CloseHandle(hKey);
  129. return dwError;
  130. }
  131. /*-----------------------------------------------------------------------------
  132. GetHKCUContentDirectory
  133. ----------------------------------------------------------------------------*/
  134. DWORD GetHKCUContentDirectory(CHAR *szContentDirectory)
  135. {
  136. HKEY hKey = (HKEY) INVALID_HANDLE_VALUE;
  137. DWORD dwError, dwKeyType, cbKeyLen = MAX_PATH;
  138. CHAR szContentDirRegKey[MAX_PATH];
  139. strcpy(szContentDirRegKey, OLD_CACHE_KEY);
  140. strcat(szContentDirRegKey, "\\");
  141. strcat(szContentDirRegKey, CONTENT_PATH_KEY);
  142. if (dwError = RegOpenKeyEx(HKEY_CURRENT_USER,
  143. szContentDirRegKey, NULL, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
  144. goto exit;
  145. if (dwError = RegQueryValueEx(hKey, CACHE_PATH_VALUE, NULL, &dwKeyType,
  146. (LPBYTE) szContentDirectory, &cbKeyLen) != ERROR_SUCCESS)
  147. goto exit;
  148. exit:
  149. if (hKey != INVALID_HANDLE_VALUE)
  150. CloseHandle(hKey);
  151. return dwError;
  152. }
  153. /*-----------------------------------------------------------------------------
  154. class CCookieLoader
  155. Class used to perform cookie conversion
  156. ----------------------------------------------------------------------------*/
  157. class CCookieLoader
  158. {
  159. public:
  160. CHAR* ParseNextCookie(CHAR*, CHAR**, FILETIME*, FILETIME*);
  161. DWORD LoadCookies(BOOL);
  162. };
  163. // Debug assert code.
  164. #if DBG
  165. #define Assert(Predicate) \
  166. { \
  167. if (!(Predicate)) \
  168. AssertFailed( #Predicate, __FILE__, __LINE__, NULL ); \
  169. }
  170. VOID
  171. AssertFailed(
  172. LPSTR FailedAssertion,
  173. LPSTR FileName,
  174. DWORD LineNumber,
  175. LPSTR Message
  176. )
  177. {
  178. printf("Assert @ %s \n", FailedAssertion );
  179. printf("Assert Filename, %s \n", FileName );
  180. printf("Line Num. = %ld.\n", LineNumber );
  181. printf("Message is %s\n", Message );
  182. DebugBreak();
  183. }
  184. #else
  185. #define Assert(_x_)
  186. #endif // DBG
  187. /*-----------------------------------------------------------------------------
  188. CCookieLoader::ParseNextCookie
  189. Upgrades cookies from Cache Version 3.2 to Cache Version 4.0
  190. ----------------------------------------------------------------------------*/
  191. CHAR* CCookieLoader::ParseNextCookie(CHAR* ptr, CHAR** ppszHash,
  192. FILETIME* pftExpire, FILETIME* pftLast)
  193. {
  194. CHAR *pszName, *pszValue, *pszFlags,
  195. *pszExpireTimeLow, *pszExpireTimeHigh,
  196. *pszLastTimeHigh, *pszLastTimeLow,
  197. *pszDelimiter, *pszNextCookie;
  198. __try
  199. {
  200. // Get the first token (cookie name).
  201. pszName = strtok(ptr, "\n");
  202. if (!pszName) // Cookie name.
  203. {
  204. // Normal termination of the parse.
  205. pszNextCookie = 0;
  206. goto exit;
  207. }
  208. // Parse the rest of the cookie
  209. pszValue = strtok(NULL, "\n"); // Cookie value.
  210. *ppszHash = strtok(NULL, "\n"); // Combo of domain and path.
  211. pszFlags = strtok(NULL, "\n"); // Cookie flags.
  212. pszExpireTimeLow = strtok(NULL, "\n"); // Expire time.
  213. pszExpireTimeHigh = strtok(NULL, "\n");
  214. pszLastTimeLow = strtok(NULL, "\n"); // Last Modified time.
  215. pszLastTimeHigh = strtok(NULL, "\n");
  216. pszDelimiter = strtok(NULL, "\n"); // Delimiter should be "*"
  217. // Abnormal termination of parse.
  218. if (!pszDelimiter || pszDelimiter[0] != '*')
  219. {
  220. INET_ASSERT(FALSE);
  221. pszNextCookie = 0;
  222. goto exit;
  223. }
  224. // Set the times.
  225. pftExpire->dwLowDateTime = atoi(pszExpireTimeLow);
  226. pftExpire->dwHighDateTime = atoi(pszExpireTimeHigh);
  227. pftLast->dwLowDateTime = atoi(pszLastTimeLow);
  228. pftLast->dwHighDateTime = atoi(pszLastTimeHigh);
  229. pszNextCookie = pszDelimiter+2;
  230. }
  231. __except(EXCEPTION_EXECUTE_HANDLER)
  232. {
  233. INET_ASSERT(FALSE);
  234. pszNextCookie = 0;
  235. goto exit;
  236. }
  237. exit:
  238. return pszNextCookie;
  239. }
  240. /*-----------------------------------------------------------------------------
  241. CCookieLoader::LoadCookies
  242. ----------------------------------------------------------------------------*/
  243. DWORD CCookieLoader::LoadCookies(BOOL fConvertToPerUser)
  244. {
  245. HANDLE hFind = INVALID_HANDLE_VALUE;
  246. HANDLE hFile = INVALID_HANDLE_VALUE;
  247. FILETIME ftExpire, ftLast;
  248. CHAR szCookieFileName [MAX_PATH],
  249. szCookieFileNamePattern [MAX_PATH],
  250. szHKLMCookiesPath [MAX_PATH],
  251. szHKCUCookiesPath [MAX_PATH],
  252. szCookieName [MAX_PATH],
  253. szHKLMCookieFileName [MAX_PATH],
  254. szHKCUCookieFileName [MAX_PATH];
  255. CHAR *pszHash, *ptr, *pszCookiesPath,
  256. *pszCurrentCookie, *szBuffer;
  257. WIN32_FIND_DATA FindData;
  258. BOOL bReturn;
  259. DWORD cbRead = 0, dwError = ERROR_SUCCESS;
  260. // Data for a single cookie should fit in 2 pages.
  261. BYTE bCacheEntryInfoBuffer[2 * PAGE_SIZE];
  262. INTERNET_CACHE_ENTRY_INFO *pCacheEntryInfo;
  263. DWORD cbCacheEntryInfoBuffer;
  264. // Strictly enforced syntax: requires this to be initialized
  265. // before the try block is entered.
  266. szBuffer = 0;
  267. __try
  268. {
  269. // Check to see if we are upgrading cookies
  270. // from local machine to per user.
  271. if (fConvertToPerUser)
  272. {
  273. DWORD cb = MAX_PATH;
  274. CHAR szUserName[MAX_PATH];
  275. // We are converting cookies from HKLM to HKCU.
  276. // This is done by enumerating the user's cookies
  277. // files and copying them to the per-user diretory.
  278. // Once this is accomplished, cookie converting will
  279. // proceed normally.
  280. // Get the cookies directory as specified by HKLM.
  281. if (dwError = GetHKLMCookiesDirectory(szHKLMCookiesPath) != ERROR_SUCCESS)
  282. {
  283. INET_ASSERT(FALSE);
  284. goto exit;
  285. }
  286. strcpy(szCookieFileNamePattern, szHKLMCookiesPath);
  287. // Get the cookies directory as specified by HKCU.
  288. if (dwError = GetHKCUCookiesDirectory(szHKCUCookiesPath) != ERROR_SUCCESS)
  289. {
  290. INET_ASSERT(FALSE);
  291. goto exit;
  292. }
  293. // Get the current user name.
  294. GetUserName(szUserName, &cb);
  295. // szCookieFileNamePattern will look like c:\winnt\cookies\joeuser@*.txt
  296. strcat(szCookieFileNamePattern, "\\");
  297. strcat(szCookieFileNamePattern, szUserName);
  298. strcat(szCookieFileNamePattern, "@*.txt");
  299. // Enumerate the users cache files
  300. hFind = FindFirstFile(szCookieFileNamePattern, &FindData);
  301. if (hFind == INVALID_HANDLE_VALUE)
  302. {
  303. // OK, No cookie files to upgrade.
  304. dwError = ERROR_SUCCESS;
  305. goto exit;
  306. }
  307. // One or more cookie files exist.
  308. do
  309. {
  310. // Construct absolute path from HKLM to cookies file.
  311. strcpy(szHKLMCookieFileName, szHKLMCookiesPath);
  312. strcat(szHKLMCookieFileName, "\\");
  313. strcat(szHKLMCookieFileName, FindData.cFileName);
  314. // Construct absolute path from HKCU to cookies file.
  315. strcpy(szHKCUCookieFileName, szHKCUCookiesPath);
  316. strcat(szHKCUCookieFileName, "\\");
  317. strcat(szHKCUCookieFileName, FindData.cFileName);
  318. // Copy the file to the per-user directory.
  319. CopyFile(szHKLMCookieFileName, szHKCUCookieFileName, TRUE);
  320. } while (FindNextFile(hFind, &FindData));
  321. // Close the Find handle.
  322. if (hFind != INVALID_HANDLE_VALUE)
  323. {
  324. FindClose(hFind);
  325. hFind = INVALID_HANDLE_VALUE;
  326. }
  327. } // Per-user upgrade.
  328. else
  329. {
  330. // No per-user upgrade. szCookieFileNamePattern will look like
  331. // c:\winnt\cookies\*@*.txt or c:\winnt\profiles\joeuser\cookies\*@*.txt.
  332. GetHKLMCookiesDirectory(szHKLMCookiesPath);
  333. strcpy(szCookieFileNamePattern, szHKLMCookiesPath);
  334. strcat(szCookieFileNamePattern, "\\*@*.txt");
  335. }
  336. // We now have the appropriate cookie filename pattern, also need a copy
  337. // of the cookies directory associated with the current user.
  338. pszCookiesPath = (fConvertToPerUser ? szHKCUCookiesPath : szHKLMCookiesPath);
  339. // Enumerate the cache files.
  340. hFind = FindFirstFile(szCookieFileNamePattern, &FindData);
  341. if (hFind == INVALID_HANDLE_VALUE)
  342. {
  343. // OK, No cookies files to upgrade.
  344. // BUGBUG - should we verify this?
  345. dwError = ERROR_SUCCESS;
  346. goto exit;
  347. }
  348. // One or more cookie files exist.
  349. do
  350. {
  351. // Construct absolute path to cookie file.
  352. strcpy(szCookieFileName, pszCookiesPath);
  353. strcat(szCookieFileName, "\\");
  354. strcat(szCookieFileName, FindData.cFileName);
  355. // Open the cookie file.
  356. hFile = CreateFile(
  357. szCookieFileName, // Absolute path to cookies file.
  358. GENERIC_READ, // Read only.
  359. FILE_SHARE_READ, // Share.
  360. 0, // Security Attribute (ignored in W95).
  361. OPEN_EXISTING, // Fail if doesn't exist.
  362. FILE_ATTRIBUTE_NORMAL, // No special attributes.
  363. 0 // Attribute template.
  364. );
  365. // File handle must be valid.
  366. if (hFile != INVALID_HANDLE_VALUE)
  367. {
  368. // Allocate memory for cookie file contents.
  369. // BUGBUG - put an upper limit on this? ->
  370. // 300 cookies * 4k/cookie = 1200k plus sundry.
  371. szBuffer = new CHAR[FindData.nFileSizeLow + 1];
  372. if (!szBuffer)
  373. {
  374. dwError = ERROR_NOT_ENOUGH_MEMORY;
  375. goto exit;
  376. }
  377. // Read the file into memory.
  378. bReturn = ReadFile(hFile, szBuffer, FindData.nFileSizeLow, &cbRead, NULL);
  379. // ReadFile must be successful.
  380. INET_ASSERT(bReturn);
  381. if (bReturn)
  382. {
  383. // Null terminate buffer.
  384. szBuffer[cbRead] = '\0';
  385. // Parse each cookie out of the buffer.
  386. pszCurrentCookie = szBuffer;
  387. while (pszCurrentCookie = ParseNextCookie(pszCurrentCookie,
  388. &pszHash, &ftExpire, &ftLast))
  389. {
  390. // Construct the cookie name from the following strings:
  391. // FindData.cFileName is like "[email protected]"
  392. // pszHash is like "foobar.com/"
  393. // szCookieName should then be "Cookie:[email protected]/"
  394. strcpy(szCookieName, COOKIE_PREFIX);
  395. strcat(szCookieName, FindData.cFileName);
  396. ptr = strstr(szCookieName, "@");
  397. strcpy(ptr+1, pszHash);
  398. // Check to see if an earlier version of this cookie
  399. // has already been added to the cache index file.
  400. BOOL fAddToCache = TRUE;
  401. pCacheEntryInfo = (INTERNET_CACHE_ENTRY_INFO*) bCacheEntryInfoBuffer;
  402. cbCacheEntryInfoBuffer = sizeof(bCacheEntryInfoBuffer);
  403. dwError = GetUrlCacheEntryInfo(szCookieName, pCacheEntryInfo,
  404. &cbCacheEntryInfoBuffer);
  405. if (dwError == ERROR_SUCCESS
  406. && CompareFileTime(&pCacheEntryInfo->LastModifiedTime, &ftLast) > 0)
  407. fAddToCache = FALSE;
  408. if (fAddToCache)
  409. {
  410. // Either this cookie was not found in the index file or
  411. // it was found and the last modified time on it is
  412. // less than the currently parsed cookie. Proceed
  413. // to add this cookie to the index file.
  414. BOOL bCommit;
  415. bCommit = CommitUrlCacheEntry(
  416. szCookieName, // cookie:[email protected].
  417. szCookieFileName, // c:\winnt\cookies\[email protected].
  418. ftExpire, // Expire time.
  419. ftLast, // Last modified time.
  420. 0, // CacheEntryType.
  421. 0, // HeaderInfo.
  422. 0, // HeaderSize.
  423. 0, // FileExtension.
  424. 0); // Reserved.
  425. INET_ASSERT(bCommit);
  426. }
  427. } // Successful next cookie field.
  428. } // Successful read.
  429. // Done with this cookie file. Delete the buffer.
  430. delete [] szBuffer;
  431. // And close the file
  432. CloseHandle(hFile);
  433. hFile = INVALID_HANDLE_VALUE;
  434. } // File handle is valid.
  435. } while (FindNextFile(hFind, &FindData));
  436. // No more cookie files or an error occured.
  437. if ((dwError = GetLastError()) != ERROR_NO_MORE_FILES)
  438. goto exit;
  439. // Normal termination.
  440. dwError = ERROR_SUCCESS;
  441. exit:
  442. // Close the file handle.
  443. if (hFile != INVALID_HANDLE_VALUE)
  444. CloseHandle(hFile);
  445. // Close the Find handle.
  446. if (hFind != INVALID_HANDLE_VALUE)
  447. FindClose(hFind);
  448. return dwError;
  449. } // try
  450. __except(EXCEPTION_EXECUTE_HANDLER)
  451. {
  452. // Cleanup.
  453. delete [] szBuffer;
  454. if (hFind != INVALID_HANDLE_VALUE)
  455. FindClose(hFind);
  456. if (hFile != INVALID_HANDLE_VALUE)
  457. CloseHandle(hFile);
  458. INET_ASSERT(FALSE);
  459. dwError = ERROR_EXCEPTION_IN_SERVICE;
  460. return dwError;
  461. }
  462. }
  463. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  464. {
  465. DWORD dwError;
  466. CHAR szFilename[MAX_PATH];
  467. CHAR szHistoryIndexFile[MAX_PATH];
  468. CHAR szCookiesIndexFile[MAX_PATH];
  469. CHAR szContentIndexFile[MAX_PATH];
  470. CCookieLoader cc;
  471. __try
  472. {
  473. // Convert cookies. Note, for ckcnv, we never
  474. // upgrade to per-user.
  475. dwError = cc.LoadCookies(FALSE);
  476. // Nuke all index.dat files so that re-installations will init properly.
  477. // Take care of HKLM entries only.
  478. // Content
  479. if (GetHKLMContentDirectory(szContentIndexFile) == ERROR_SUCCESS)
  480. {
  481. strcat(szContentIndexFile, "\\");
  482. strcat(szContentIndexFile, MEMMAP_FILE_NAME);
  483. DeleteFile(szContentIndexFile);
  484. }
  485. // Cookies
  486. if (GetHKLMCookiesDirectory(szCookiesIndexFile) == ERROR_SUCCESS)
  487. {
  488. strcat(szCookiesIndexFile, "\\");
  489. strcat(szCookiesIndexFile, MEMMAP_FILE_NAME);
  490. DeleteFile(szCookiesIndexFile);
  491. }
  492. // History
  493. if (GetHKLMHistoryDirectory(szHistoryIndexFile) == ERROR_SUCCESS)
  494. {
  495. strcat(szHistoryIndexFile, "\\");
  496. strcat(szHistoryIndexFile, MEMMAP_FILE_NAME);
  497. DeleteFile(szHistoryIndexFile);
  498. }
  499. // See if we're supposed to delete this
  500. // executable after the user reboots.
  501. if (!_strnicmp(lpCmdLine, "/D", sizeof("/D")))
  502. {
  503. // Got this filename?
  504. if (GetModuleFileName(NULL, szFilename, MAX_PATH))
  505. {
  506. OSVERSIONINFO osVersionInfo;
  507. osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  508. if (GetVersionEx(&osVersionInfo))
  509. {
  510. // Two different methods of deleting this file
  511. // depending on the platform ID.
  512. if (osVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
  513. {
  514. // Platform is Windows NT.
  515. MoveFileEx(szFilename, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
  516. }
  517. else
  518. {
  519. // Platform is Windows 95.
  520. CHAR szString[MAX_PATH];
  521. strcpy(szString, "NUL=");
  522. strcat(szString, szFilename);
  523. WritePrivateProfileSection("Rename", szString, "wininit.ini");
  524. }
  525. }
  526. }
  527. }
  528. }
  529. __except(EXCEPTION_EXECUTE_HANDLER)
  530. {
  531. INET_ASSERT(FALSE);
  532. dwError = ERROR_EXTENDED_ERROR;
  533. }
  534. return (dwError == ERROR_SUCCESS ? 0 : 1);
  535. }