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

198 lines
5.2 KiB

  1. #include <windows.h>
  2. #include "Global.h"
  3. #include "Resource.h"
  4. //////////////////////////////////////////////////////////////////////////////////////////////
  5. //
  6. // Global variables
  7. //
  8. //////////////////////////////////////////////////////////////////////////////////////////////
  9. HINSTANCE g_hInstance;
  10. DWORD g_dwOSVersion;
  11. BOOL g_fInstallDebug;
  12. DWORD g_dwSuccessCode;
  13. //////////////////////////////////////////////////////////////////////////////////////////////
  14. //
  15. // This is the global structure used by this applications state machine
  16. //
  17. //////////////////////////////////////////////////////////////////////////////////////////////
  18. COMPONENT_INFO g_sComponentInfo[COMPONENT_COUNT] =
  19. {
  20. { TEXT("AppMan.dll"), FALSE, TRUE, OS_VERSION_WIN9X, IDR_APPMAN_9X, 0, { 0 }, { 0 } },
  21. { TEXT("AppManD.dll"), TRUE, FALSE, OS_VERSION_WIN9X, IDR_APPMAND_9X, 0, { 0 }, { 0 } },
  22. { TEXT("AppManDp.dll"), FALSE, TRUE, OS_VERSION_WIN9X, IDR_APPMANDP_9X, 0, { 0 }, { 0 } },
  23. { TEXT("AppMan.dll"), FALSE, TRUE, OS_VERSION_WIN2K, IDR_APPMAN_2K, 0, { 0 }, { 0 } },
  24. { TEXT("AppManD.dll"), TRUE, FALSE, OS_VERSION_WIN2K, IDR_APPMAND_2K, 0, { 0 }, { 0 } },
  25. { TEXT("AppManDp.dll"), FALSE, TRUE, OS_VERSION_WIN2K, IDR_APPMANDP_2K, 0, { 0 }, { 0 } }
  26. };
  27. //////////////////////////////////////////////////////////////////////////////////////////////
  28. //
  29. //////////////////////////////////////////////////////////////////////////////////////////////
  30. BOOL FileExists(LPCTSTR strFilename)
  31. {
  32. BOOL fSuccess = TRUE;
  33. WIN32_FIND_DATA sFindFileInfo;
  34. HANDLE hFindFileHandle;
  35. hFindFileHandle = FindFirstFile(strFilename, &sFindFileInfo);
  36. if (INVALID_HANDLE_VALUE == hFindFileHandle)
  37. {
  38. fSuccess = FALSE;
  39. }
  40. else
  41. {
  42. FindClose(hFindFileHandle);
  43. }
  44. return fSuccess;
  45. }
  46. //////////////////////////////////////////////////////////////////////////////////////////////
  47. //
  48. //////////////////////////////////////////////////////////////////////////////////////////////
  49. DWORD GetOSVersion(void)
  50. {
  51. OSVERSIONINFOEX sOSVersionInfo;
  52. DWORD dwOSVersion = OS_VERSION_WIN32S;
  53. //
  54. // Try calling GetVersionEx using the OSVERSIONINFOEX structure,
  55. // which is supported on Windows 2000.
  56. //
  57. // If that fails, try using the OSVERSIONINFO structure.
  58. //
  59. ZeroMemory(&sOSVersionInfo, sizeof(OSVERSIONINFOEX));
  60. sOSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  61. if(!GetVersionEx((OSVERSIONINFO *) &sOSVersionInfo))
  62. {
  63. //
  64. // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
  65. //
  66. sOSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  67. if (!GetVersionEx((OSVERSIONINFO *) &sOSVersionInfo))
  68. {
  69. return OS_VERSION_WIN32S;
  70. }
  71. }
  72. //
  73. // What OS are we running
  74. //
  75. switch (sOSVersionInfo.dwPlatformId)
  76. {
  77. case VER_PLATFORM_WIN32_NT
  78. : if (5 == sOSVersionInfo.dwMajorVersion)
  79. {
  80. dwOSVersion = OS_VERSION_WIN2000;
  81. }
  82. else
  83. {
  84. dwOSVersion = OS_VERSION_WINNT;
  85. }
  86. break;
  87. case VER_PLATFORM_WIN32_WINDOWS
  88. : if ((4 < sOSVersionInfo.dwMajorVersion)||((4 == sOSVersionInfo.dwMajorVersion)&&(0 < sOSVersionInfo.dwMinorVersion)))
  89. {
  90. dwOSVersion = OS_VERSION_WIN98;
  91. }
  92. else
  93. {
  94. dwOSVersion = OS_VERSION_WIN95;
  95. }
  96. break;
  97. }
  98. return dwOSVersion;
  99. }
  100. //////////////////////////////////////////////////////////////////////////////////////////////
  101. //
  102. //////////////////////////////////////////////////////////////////////////////////////////////
  103. DWORD StrLen(LPCTSTR strString)
  104. {
  105. DWORD dwIndex;
  106. dwIndex = 0;
  107. while (0 != strString[dwIndex])
  108. {
  109. dwIndex++;
  110. }
  111. return dwIndex;
  112. }
  113. //////////////////////////////////////////////////////////////////////////////////////////////
  114. //
  115. //////////////////////////////////////////////////////////////////////////////////////////////
  116. BOOL GenerateUniqueFilename(LPCTSTR strRootPath, LPCTSTR strExtension, LPTSTR strFilename)
  117. {
  118. BOOL fSuccess = FALSE;
  119. DWORD dwTimeTick;
  120. DWORD dwIndex, dwRootPathLen;
  121. LPTSTR strAdjustedRootPath;
  122. //
  123. // Build strAdjustedRootPath
  124. //
  125. dwRootPathLen = StrLen(strRootPath) + 1;
  126. strAdjustedRootPath = new TCHAR [dwRootPathLen];
  127. if (NULL != strAdjustedRootPath)
  128. {
  129. #ifdef _UNICODE
  130. memcpy((LPVOID) strAdjustedRootPath, (LPVOID) strRootPath, (dwRootPathLen * 2));
  131. #else
  132. memcpy((LPVOID) strAdjustedRootPath, (LPVOID) strRootPath, dwRootPathLen);
  133. #endif
  134. //
  135. // If there is a trailing backslash at the end of strRootPath, remove it
  136. //
  137. dwIndex = 0;
  138. do
  139. {
  140. dwIndex++;
  141. if ((0 == strAdjustedRootPath[dwIndex])&&(92 == strAdjustedRootPath[dwIndex - 1]))
  142. {
  143. strAdjustedRootPath[dwIndex - 1] = 0;
  144. }
  145. }
  146. while (0 != strAdjustedRootPath[dwIndex]);
  147. //
  148. // Generate a temporary filename
  149. //
  150. do
  151. {
  152. dwTimeTick = GetTickCount();
  153. wsprintf(strFilename, TEXT("%s\\%08x.%s"), strAdjustedRootPath, dwTimeTick, strExtension);
  154. if (!FileExists(strFilename))
  155. {
  156. fSuccess = TRUE;
  157. }
  158. }
  159. while (!fSuccess);
  160. //
  161. // Dont forget to deallocate strAdjustedRootPath
  162. //
  163. delete [] strAdjustedRootPath;
  164. }
  165. return fSuccess;
  166. }