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.

289 lines
8.0 KiB

  1. #include "pch.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "loader.h"
  5. #include "resource.h"
  6. #include "cab.h"
  7. // Constants
  8. typedef enum _MIGWIZLOC
  9. {
  10. MWL_EXISTING,
  11. MWL_UNPACKED
  12. } MIGWIZLOC;
  13. // Globals
  14. HWND g_hWndParent = NULL;
  15. HINSTANCE g_hInstParent = NULL;
  16. static LPSTR g_lpCmdLine = NULL;
  17. VOID
  18. HandleError( ERRORCODE ecValue, LPARAM lpszExtra )
  19. {
  20. if (ecValue != E_OK)
  21. {
  22. SendMessage( g_hWndParent, WM_USER_THREAD_ERROR, (WPARAM)ecValue, lpszExtra );
  23. }
  24. }
  25. BOOL
  26. pIsIE4Installed (
  27. VOID
  28. )
  29. {
  30. LONG hResult;
  31. HKEY ieKey = NULL;
  32. DWORD valueType = REG_SZ;
  33. DWORD valueSize = 0;
  34. PTSTR valueData = NULL;
  35. PTSTR numPtr = NULL;
  36. PTSTR dotPtr = NULL;
  37. INT major = 0;
  38. INT minor = 0;
  39. TCHAR saved;
  40. BOOL result = FALSE;
  41. hResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Internet Explorer"), 0, KEY_QUERY_VALUE, &ieKey);
  42. if ((hResult == ERROR_SUCCESS) &&
  43. ieKey
  44. ) {
  45. hResult = RegQueryValueEx (ieKey, TEXT("Version"), NULL, &valueType, NULL, &valueSize);
  46. if ((hResult == ERROR_SUCCESS) || (hResult == ERROR_MORE_DATA)) {
  47. valueData = (PTSTR)HeapAlloc (GetProcessHeap (), 0, valueSize * 2);
  48. if (valueData) {
  49. hResult = RegQueryValueEx (ieKey, TEXT("Version"), NULL, &valueType, (PBYTE)valueData, &valueSize);
  50. if ((hResult == ERROR_SUCCESS) && (valueType == REG_SZ)) {
  51. // let's see if it the version is the correct one
  52. numPtr = valueData;
  53. dotPtr = _tcschr (numPtr, TEXT('.'));
  54. if (dotPtr) {
  55. saved = *dotPtr;
  56. *dotPtr = 0;
  57. major = atoi (numPtr);
  58. *dotPtr = saved;
  59. } else {
  60. major = atoi (numPtr);
  61. }
  62. if (dotPtr) {
  63. numPtr = _tcsinc (dotPtr);
  64. dotPtr = _tcschr (numPtr, TEXT('.'));
  65. if (dotPtr) {
  66. saved = *dotPtr;
  67. *dotPtr = 0;
  68. minor = atoi (numPtr);
  69. *dotPtr = saved;
  70. } else {
  71. minor = atoi (numPtr);
  72. }
  73. }
  74. if ((major >= 5) ||
  75. ((major == 4) && (minor >= 71))
  76. ) {
  77. result = TRUE;
  78. }
  79. }
  80. HeapFree (GetProcessHeap (), 0, valueData);
  81. valueData = NULL;
  82. }
  83. }
  84. }
  85. if (ieKey) {
  86. RegCloseKey (ieKey);
  87. ieKey = NULL;
  88. }
  89. return result;
  90. }
  91. ERRORCODE
  92. CheckSystemRequirements( VOID )
  93. {
  94. ERRORCODE dwRetval = E_OK;
  95. DWORD dwArraySize;
  96. DWORD x;
  97. HMODULE hDll;
  98. PSTR lpszDllListA[] = REQUIRED_DLLSA;
  99. PWSTR lpszDllListW[] = REQUIRED_DLLSW;
  100. DWORD dwVersion;
  101. //
  102. // Check OS version. Disallow Win32s and NT < 4.00
  103. //
  104. dwVersion = GetVersion();
  105. if((dwVersion & 0xff) < 4)
  106. {
  107. HandleError( E_OLD_OS_VERSION, 0 );
  108. return E_OLD_OS_VERSION;
  109. }
  110. // let's check to see if IE4 is installed on this machine
  111. if (!pIsIE4Installed ())
  112. {
  113. HandleError( E_OLD_OS_VERSION, 0 );
  114. return E_OLD_OS_VERSION;
  115. }
  116. // check if required DLLS exist
  117. if (g_VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
  118. // WinNT
  119. dwArraySize = sizeof(lpszDllListW) / sizeof(PWSTR);
  120. for (x=0; x<dwArraySize; x++)
  121. {
  122. hDll = LoadLibraryW( lpszDllListW[x] );
  123. if (!hDll)
  124. {
  125. dwRetval = E_DLL_NOT_FOUND;
  126. HandleError( E_DLL_NOT_FOUND, (LPARAM)lpszDllListW[x] );
  127. break;
  128. }
  129. FreeLibrary( hDll );
  130. }
  131. } else {
  132. // Win9x
  133. dwArraySize = sizeof(lpszDllListA) / sizeof(PSTR);
  134. for (x=0; x<dwArraySize; x++)
  135. {
  136. hDll = LoadLibraryA( lpszDllListA[x] );
  137. if (!hDll)
  138. {
  139. dwRetval = E_DLL_NOT_FOUND;
  140. HandleError( E_DLL_NOT_FOUND, (LPARAM)lpszDllListA[x] );
  141. break;
  142. }
  143. FreeLibrary( hDll );
  144. }
  145. }
  146. if (InitLanguageDetection ()) {
  147. if (!g_IsLanguageMatched) {
  148. HandleError( E_WRONG_LANGUAGE, 0 );
  149. return E_WRONG_LANGUAGE;
  150. }
  151. }
  152. return dwRetval;
  153. }
  154. ERRORCODE
  155. StartMigwiz( MIGWIZLOC mwlLocation )
  156. {
  157. PTSTR lpszPath = NULL;
  158. PTSTR lpszMigwiz = NULL;
  159. PTSTR lpszFullName = NULL;
  160. STARTUPINFO startInfo;
  161. PROCESS_INFORMATION procInfo;
  162. ERRORCODE ecResult = E_OK;
  163. if (mwlLocation == MWL_EXISTING)
  164. {
  165. lpszPath = GetModulePath();
  166. }
  167. else // mwlLocation == MWL_UNPACKED
  168. {
  169. lpszPath = GetDestPath();
  170. }
  171. if (lpszPath == NULL)
  172. {
  173. return E_INVALID_PATH;
  174. }
  175. lpszMigwiz = GetResourceString( g_hInstParent, IDS_MIGWIZFILENAME );
  176. if (lpszMigwiz != NULL)
  177. {
  178. lpszFullName = JoinPaths( lpszPath, lpszMigwiz );
  179. FREE( lpszMigwiz );
  180. }
  181. if (lpszFullName)
  182. {
  183. if (GetFileAttributes( lpszFullName ) != -1)
  184. {
  185. PTSTR lpszCommand = NULL;
  186. ZeroMemory( &startInfo, sizeof(STARTUPINFO) );
  187. startInfo.cb = sizeof(STARTUPINFO);
  188. if (g_lpCmdLine)
  189. {
  190. PTSTR lpszQuotedName;
  191. lpszQuotedName = ALLOC( (lstrlen(lpszFullName) + 3) * sizeof(TCHAR) );
  192. if (lpszQuotedName)
  193. {
  194. lpszQuotedName[0] = TEXT('"');
  195. lstrcpy( (lpszQuotedName+1), lpszFullName );
  196. lstrcat( lpszQuotedName, TEXT("\"") );
  197. lpszCommand = JoinText( lpszQuotedName, g_lpCmdLine, TEXT(' ') );
  198. FREE( lpszQuotedName );
  199. }
  200. }
  201. if (CreateProcess( NULL,
  202. lpszCommand ? lpszCommand : lpszFullName,
  203. NULL,
  204. NULL,
  205. FALSE,
  206. DETACHED_PROCESS,
  207. NULL,
  208. NULL,
  209. &startInfo,
  210. &procInfo ))
  211. {
  212. SendMessage( g_hWndParent, WM_USER_SUBTHREAD_CREATED, (WPARAM)NULL, (LPARAM)procInfo.dwThreadId );
  213. WaitForSingleObject( procInfo.hProcess, INFINITE );
  214. }
  215. else
  216. {
  217. ecResult = E_PROCESS_CREATION_FAILED;
  218. }
  219. FREE( lpszCommand );
  220. }
  221. else
  222. {
  223. ecResult = E_FILE_DOES_NOT_EXIST;
  224. }
  225. FREE( lpszFullName );
  226. }
  227. else
  228. {
  229. ecResult = E_INVALID_FILENAME;
  230. }
  231. return ecResult;
  232. }
  233. DWORD
  234. WINAPI
  235. UnpackThread(
  236. IN LPVOID lpParameter
  237. )
  238. {
  239. ERRORCODE ecResult = E_OK;
  240. g_hWndParent = ((LPTHREADSTARTUPINFO)lpParameter)->hWnd;
  241. g_hInstParent = ((LPTHREADSTARTUPINFO)lpParameter)->hInstance;
  242. g_lpCmdLine = ((LPTHREADSTARTUPINFO)lpParameter)->lpCmdLine;
  243. ecResult = CheckSystemRequirements();
  244. if (ecResult == E_OK)
  245. {
  246. // Don't worry if this StartMigwiz fails. It's not an error yet
  247. if (StartMigwiz( MWL_EXISTING ) != E_OK)
  248. {
  249. ecResult = Unpack();
  250. if (ecResult == E_OK)
  251. {
  252. ecResult = StartMigwiz( MWL_UNPACKED );
  253. CleanupTempFiles();
  254. }
  255. HandleError( ecResult, 0 );
  256. }
  257. }
  258. UtilFree();
  259. SendMessage( g_hWndParent, WM_USER_THREAD_COMPLETE, (WPARAM)NULL, (LPARAM)ecResult );
  260. ExitThread( ecResult );
  261. }