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.

249 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. migwin95.c
  5. Abstract:
  6. This file contains the syssetup hooks for win9x->Nt5.0 migration. Most functions
  7. call out to the w95upgnt.dll where the real work is done.
  8. Author:
  9. Jaime Sasson 30-Aug-1995
  10. Revision History:
  11. 29-Ian-1998 calinn Added RemoveFiles_x86
  12. 24-Jul-1997 marcw Minor bug cleanup.
  13. 03-Oct-1996 jimschm Changed over to use migration DLLs
  14. 22-Jan-1997 jimschm Added Win95MigrationFileRemoval
  15. 28-Feb-1997 jimschm Added SourceDir to MIGRATE fn
  16. 3-Apr-1997 jimschm Added PreWin9xMigration
  17. --*/
  18. #include "setupp.h"
  19. #pragma hdrstop
  20. #define S_UNDO_INF L"SF_UNDO.INF"
  21. #define S_UNDO_PROFILESPATH L"PROFILESPATH"
  22. #define S_UNDO_MOVEDFILES L"MOVEDFILES"
  23. typedef BOOL (WINAPI *MIGRATE) (HWND WizardParentWnd, LPCWSTR UnattendFile, LPCWSTR SourceDir);
  24. typedef BOOL (WINAPI *FILEREMOVAL) (void);
  25. static HANDLE g_Win95UpgNTLib;
  26. BOOL
  27. SpCreateSpoolerKey (
  28. VOID
  29. )
  30. {
  31. HKEY SpoolerKey;
  32. LONG rc;
  33. DWORD DontCare;
  34. static DWORD NinetyFive = 95;
  35. //
  36. // For spooler: write an upgrade flag that will automatically be removed
  37. //
  38. rc = RegCreateKeyEx (
  39. HKEY_LOCAL_MACHINE,
  40. WINNT_WIN95UPG_SPOOLER,
  41. 0,
  42. NULL,
  43. 0,
  44. KEY_WRITE,
  45. NULL,
  46. &SpoolerKey,
  47. &DontCare
  48. );
  49. if (rc != ERROR_SUCCESS) {
  50. return FALSE;
  51. }
  52. rc = RegSetValueEx (
  53. SpoolerKey,
  54. WINNT_WIN95UPG_UPGRADE_VAL,
  55. 0,
  56. REG_DWORD,
  57. (LPBYTE) &NinetyFive,
  58. sizeof (NinetyFive)
  59. );
  60. RegCloseKey (SpoolerKey);
  61. return rc == ERROR_SUCCESS;
  62. }
  63. BOOL
  64. PreWin9xMigration(
  65. VOID
  66. )
  67. {
  68. BOOL b;
  69. BEGIN_SECTION(TEXT("PreWin9xMigration"));
  70. b = SpCreateSpoolerKey();
  71. if(!b){
  72. SetupDebugPrint(TEXT("SpCreateSpoolerKey failed"));
  73. }
  74. END_SECTION(TEXT("PreWin9xMigration"));
  75. return b;
  76. }
  77. BOOL
  78. MigrateWin95Settings(
  79. IN HWND hwndWizardParent,
  80. IN LPCWSTR UnattendFile
  81. )
  82. /*++
  83. Routine Description:
  84. Loads w95upgnt.dll and calls W95UpgNt_Migrate. This function
  85. transfers all Win9x settings to the new NT installation, and
  86. is completely restartable.
  87. Arguments:
  88. hwndWizardParent Handle to the wizard window, used for (rare) UI
  89. UnattendFile The full Win32 path to the unattend file, to be
  90. opened via Setup APIs
  91. Return Value:
  92. Returns TRUE if the module was successful, or FALSE otherwise.
  93. GetLastError() holds a Win32 error code if not successful.
  94. --*/
  95. {
  96. MIGRATE Migrate;
  97. BOOL b = FALSE;
  98. WCHAR buffer[2048];
  99. g_Win95UpgNTLib = NULL;
  100. //
  101. // See if there is a replacement path for the w95upgnt.dll.
  102. //
  103. GetPrivateProfileStringW (
  104. WINNT_WIN95UPG_95_DIR_W,
  105. WINNT_WIN95UPG_NTKEY_W,
  106. L"",
  107. buffer,
  108. sizeof(buffer)/sizeof(WCHAR),
  109. UnattendFile
  110. );
  111. if (*buffer) {
  112. //
  113. // We have a replacement dll to load.
  114. //
  115. g_Win95UpgNTLib = LoadLibrary (buffer);
  116. }
  117. if (!g_Win95UpgNTLib) {
  118. //
  119. // Either there was not a replacement, or loading that replacement failed.
  120. //
  121. g_Win95UpgNTLib = LoadLibrary (L"w95upgnt.dll");
  122. }
  123. if (!g_Win95UpgNTLib) {
  124. return FALSE;
  125. }
  126. Migrate = (MIGRATE) GetProcAddress (g_Win95UpgNTLib, "W95UpgNt_Migrate");
  127. if (Migrate) {
  128. b = Migrate (hwndWizardParent, UnattendFile, SourcePath);
  129. }
  130. return b;
  131. }
  132. BOOL
  133. Win95MigrationFileRemoval(
  134. void
  135. )
  136. /*++
  137. Routine Description:
  138. Loads w95upgnt.dll and calls W95UpgNt_FileRemoval. This function
  139. deletes all Win9x-specific files and removes temporary files including
  140. all migration DLLs. It is NOT restartable.
  141. Arguments:
  142. none
  143. Return Value:
  144. Returns TRUE if the module was successful, or FALSE otherwise.
  145. GetLastError() holds a Win32 error code if not successful.
  146. --*/
  147. {
  148. FILEREMOVAL FileRemoval;
  149. BOOL b = FALSE;
  150. FileRemoval = (FILEREMOVAL) GetProcAddress (g_Win95UpgNTLib, "W95UpgNt_FileRemoval");
  151. if (FileRemoval)
  152. b = FileRemoval();
  153. FreeLibrary (g_Win95UpgNTLib);
  154. return b;
  155. }
  156. #define SIF_REMOVEFILESX86 L"RemoveFiles.x86"
  157. BOOL
  158. RemoveFiles_X86 (
  159. IN HINF InfHandle
  160. )
  161. {
  162. WCHAR fullPath[MAX_PATH],fileName[MAX_PATH];
  163. INFCONTEXT lineContext;
  164. if (InfHandle == INVALID_HANDLE_VALUE) {
  165. return TRUE;
  166. }
  167. if (SetupFindFirstLine (
  168. InfHandle,
  169. SIF_REMOVEFILESX86,
  170. NULL,
  171. &lineContext
  172. )) {
  173. do {
  174. if ((SetupGetStringField (&lineContext, 1, fileName, MAX_PATH, NULL)) &&
  175. (GetWindowsDirectory (fullPath, MAX_PATH)) &&
  176. (pSetupConcatenatePaths (fullPath, fileName, MAX_PATH, NULL)) &&
  177. (SetFileAttributes (fullPath, FILE_ATTRIBUTE_NORMAL))
  178. ) {
  179. DeleteFile (fullPath);
  180. }
  181. }
  182. while (SetupFindNextLine (&lineContext, &lineContext));
  183. }
  184. return TRUE;
  185. }