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.

428 lines
7.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. ocm.c
  5. Abstract:
  6. OC Manager implementation for intergratation with NT base setup
  7. Author:
  8. Ted Miller (tedm) 20 May 1997
  9. Revision History:
  10. --*/
  11. #include "setupp.h"
  12. #pragma hdrstop
  13. #include <ocmanage.h>
  14. #include <ocmgrlib.h>
  15. // Returns TRUE if ASR is enabled. Otherwise, FALSE is returned.
  16. BOOL
  17. AsrIsEnabled(VOID);
  18. VOID
  19. OcFillInSetupDataW(
  20. OUT PSETUP_DATAW SetupData
  21. );
  22. VOID
  23. OcFillInSetupDataA(
  24. OUT PSETUP_DATAA SetupData
  25. );
  26. VOID
  27. OcSetReboot(
  28. VOID
  29. );
  30. INT
  31. OcLogError(
  32. IN OcErrorLevel Level,
  33. IN LPCWSTR FormatString,
  34. ...
  35. );
  36. OCM_CLIENT_CALLBACKS OcManagerImplementationCallbackRoutines = {
  37. OcFillInSetupDataA,
  38. OcLogError,
  39. OcSetReboot,
  40. OcFillInSetupDataW,
  41. ShowHideWizardPage,
  42. Billboard_Progress_Callback,
  43. Billboard_Set_Progress_Text,
  44. pSetupDebugPrint
  45. };
  46. PVOID
  47. FireUpOcManager(
  48. VOID
  49. )
  50. /*++
  51. Routine Description:
  52. Initialize OC Manager, generating an OC Manager context.
  53. The master oc inf is assumed to be %windir%\system32\SYSOC.INF.
  54. Arguments:
  55. None.
  56. Return Value:
  57. OC Manager context handle.
  58. --*/
  59. {
  60. PWSTR MasterOcInf;
  61. WCHAR SystemDir[MAX_PATH];
  62. WCHAR DirSave[MAX_PATH];
  63. BOOL ShowErr;
  64. PVOID OcManagerContext;
  65. //
  66. // save the current directory
  67. //
  68. GetCurrentDirectory( sizeof(DirSave)/sizeof(WCHAR), DirSave );
  69. //
  70. // get the system directory
  71. //
  72. GetSystemDirectory( SystemDir, MAX_PATH );
  73. //
  74. // set the current dir to the master oc inf path
  75. // so that OcInitialize can find the component DLLs
  76. //
  77. SetCurrentDirectory( SystemDir );
  78. //
  79. // create a valid path to the master oc inf
  80. //
  81. if( !MiniSetup ) {
  82. if (!AsrIsEnabled()) {
  83. MasterOcInf = L"SYSOC.INF";
  84. }
  85. else {
  86. MasterOcInf = L"ASROC.INF";
  87. }
  88. } else {
  89. MasterOcInf = L"MINIOC.INF";
  90. }
  91. //
  92. // initialize the oc manager
  93. //
  94. BEGIN_SECTION(L"Initializing the OC manager");
  95. OcManagerContext = OcInitialize(
  96. &OcManagerImplementationCallbackRoutines,
  97. MasterOcInf,
  98. OCINIT_FORCENEWINF,
  99. &ShowErr,
  100. NULL
  101. );
  102. END_SECTION(L"Initializing the OC manager");
  103. //
  104. // restore the current directory
  105. //
  106. SetCurrentDirectory( DirSave );
  107. //
  108. // return the oc manager handle
  109. //
  110. return OcManagerContext;
  111. }
  112. VOID
  113. KillOcManager(
  114. PVOID OcManagerContext
  115. )
  116. /*++
  117. Routine Description:
  118. Terminate OC Manager
  119. Arguments:
  120. OC Manager context handle.
  121. Return Value:
  122. none
  123. --*/
  124. {
  125. MYASSERT(OcManagerContext);
  126. if (OcManagerContext)
  127. OcTerminate(&OcManagerContext);
  128. }
  129. VOID
  130. OcFillInSetupDataW(
  131. OUT PSETUP_DATAW SetupData
  132. )
  133. /*++
  134. Routine Description:
  135. "Glue" routine called by the OC Manager to request that the
  136. implementation fill in setup data to be passed to OC Manager
  137. component DLLs that expect Unicode data.
  138. Arguments:
  139. SetupData - recieves setup data expected by OC components.
  140. Return Value:
  141. None.
  142. --*/
  143. {
  144. //
  145. // It's not possible to be any more specific than this because
  146. // the mode page hasn't been shown yet.
  147. //
  148. SetupData->SetupMode = SETUPMODE_UNKNOWN;
  149. SetupData->ProductType = ProductType;
  150. lstrcpy(SetupData->SourcePath,SourcePath);
  151. SetupData->OperationFlags = 0;
  152. if(Win31Upgrade) {
  153. SetupData->OperationFlags |= SETUPOP_WIN31UPGRADE;
  154. }
  155. if(Win95Upgrade) {
  156. SetupData->OperationFlags |= SETUPOP_WIN95UPGRADE;
  157. }
  158. if(Upgrade) {
  159. SetupData->OperationFlags |= SETUPOP_NTUPGRADE;
  160. }
  161. if(UnattendMode > UAM_PROVIDEDEFAULT) {
  162. SetupData->OperationFlags |= SETUPOP_BATCH;
  163. lstrcpy(SetupData->UnattendFile,AnswerFile);
  164. }
  165. //
  166. // Which files are available?
  167. //
  168. #if defined(_AMD64_)
  169. SetupData->OperationFlags |= SETUPOP_X86_FILES_AVAIL | SETUPOP_AMD64_FILES_AVAIL;
  170. #elif defined(_X86_)
  171. SetupData->OperationFlags |= SETUPOP_X86_FILES_AVAIL;
  172. #elif defined(_IA64_)
  173. SetupData->OperationFlags |= SETUPOP_X86_FILES_AVAIL | SETUPOP_IA64_FILES_AVAIL;
  174. #else
  175. #pragma message( "*** Warning! No architecture defined!")
  176. #endif
  177. }
  178. VOID
  179. OcFillInSetupDataA(
  180. OUT PSETUP_DATAA SetupData
  181. )
  182. /*++
  183. Routine Description:
  184. "Glue" routine called by the OC Manager to request that the
  185. implementation fill in setup data to be passed to OC Manager
  186. component DLLs that expect ANSI data.
  187. Arguments:
  188. SetupData - recieves setup data expected by OC components.
  189. Return Value:
  190. None.
  191. --*/
  192. {
  193. SETUP_DATAW setupdata;
  194. OcFillInSetupDataW(&setupdata);
  195. SetupData->SetupMode = setupdata.SetupMode;
  196. SetupData->ProductType = setupdata.ProductType;
  197. SetupData->OperationFlags = setupdata.OperationFlags;
  198. WideCharToMultiByte(
  199. CP_ACP,
  200. 0,
  201. setupdata.SourcePath,
  202. -1,
  203. SetupData->SourcePath,
  204. sizeof(SetupData->SourcePath),
  205. NULL,
  206. NULL
  207. );
  208. WideCharToMultiByte(
  209. CP_ACP,
  210. 0,
  211. setupdata.UnattendFile,
  212. -1,
  213. SetupData->UnattendFile,
  214. sizeof(SetupData->UnattendFile),
  215. NULL,
  216. NULL
  217. );
  218. }
  219. VOID
  220. OcSetReboot(
  221. VOID
  222. )
  223. /*++
  224. Routine Description:
  225. "Glue" routine called by the OC Manager when a reboot is deemed
  226. necessary by an OC Manager component.
  227. For this integrated version of OC Manager, this does nothing;
  228. the system is rebooted at the end of text mode.
  229. Arguments:
  230. None.
  231. Return Value:
  232. None.
  233. --*/
  234. {
  235. return;
  236. }
  237. INT
  238. OcLogError(
  239. IN OcErrorLevel Level,
  240. IN LPCWSTR FormatString,
  241. ...
  242. )
  243. {
  244. TCHAR str[4096];
  245. va_list arglist;
  246. UINT Icon;
  247. UINT lev;
  248. va_start(arglist,FormatString);
  249. wvsprintf(str,FormatString,arglist);
  250. va_end(arglist);
  251. if (Level & OcErrLevWarning)
  252. lev = LogSevWarning;
  253. else if (Level & OcErrLevError)
  254. lev = LogSevError;
  255. else if (Level & OcErrLevFatal)
  256. lev = LogSevError;
  257. else
  258. lev = LogSevInformation;
  259. #if DBG
  260. if (lev != LogSevInformation) {
  261. SetupDebugPrint(str);
  262. }
  263. #endif
  264. SetuplogError(lev, str, 0, NULL, NULL);
  265. return NO_ERROR;
  266. }
  267. HWND
  268. ShowHideWizardPage(
  269. IN BOOL bShow
  270. )
  271. {
  272. HWND hwnd = GetBBhwnd();
  273. if (hwnd)
  274. {
  275. SendMessage(WizardHandle, WMX_BBTEXT, (WPARAM)!bShow, 0);
  276. }
  277. // If we show the wizard again, return the wizard hwnd
  278. if (bShow)
  279. {
  280. // Should hide the progress bar, the wizard page is showing.
  281. BB_ShowProgressGaugeWnd(SW_HIDE);
  282. hwnd = WizardHandle;
  283. }
  284. return hwnd;
  285. }
  286. LRESULT
  287. Billboard_Progress_Callback(
  288. IN UINT Msg,
  289. IN WPARAM wParam,
  290. IN LPARAM lParam
  291. )
  292. {
  293. LRESULT lResult;
  294. if ((Msg == PBM_SETRANGE) || (Msg == PBM_SETRANGE32))
  295. {
  296. // Also enable the progress bar
  297. // Note: No hiding of the progress this way.
  298. BB_ShowProgressGaugeWnd(SW_SHOW);
  299. lResult = ProgressGaugeMsgWrapper(Msg, wParam, lParam);
  300. }
  301. else
  302. {
  303. lResult = ProgressGaugeMsgWrapper(Msg, wParam, lParam);
  304. }
  305. return lResult;
  306. }
  307. VOID Billboard_Set_Progress_Text(LPCTSTR Text)
  308. {
  309. BB_SetProgressText(Text);
  310. }