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.

441 lines
8.4 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. if(!GetCurrentDirectory(ARRAYSIZE(DirSave), DirSave)){
  69. MYASSERT(FALSE);
  70. return NULL;
  71. }
  72. //
  73. // get the system directory
  74. //
  75. if(!GetSystemDirectory(SystemDir, ARRAYSIZE(SystemDir))){
  76. MYASSERT(FALSE);
  77. return NULL;
  78. }
  79. //
  80. // set the current dir to the master oc inf path
  81. // so that OcInitialize can find the component DLLs
  82. //
  83. SetCurrentDirectory( SystemDir );
  84. //
  85. // create a valid path to the master oc inf
  86. //
  87. if( !MiniSetup ) {
  88. if (!AsrIsEnabled()) {
  89. MasterOcInf = L"SYSOC.INF";
  90. }
  91. else {
  92. MasterOcInf = L"ASROC.INF";
  93. }
  94. } else {
  95. MasterOcInf = L"MINIOC.INF";
  96. }
  97. //
  98. // initialize the oc manager
  99. //
  100. BEGIN_SECTION(L"Initializing the OC manager");
  101. OcManagerContext = OcInitialize(
  102. &OcManagerImplementationCallbackRoutines,
  103. MasterOcInf,
  104. OCINIT_FORCENEWINF,
  105. &ShowErr,
  106. NULL
  107. );
  108. END_SECTION(L"Initializing the OC manager");
  109. //
  110. // restore the current directory
  111. //
  112. SetCurrentDirectory( DirSave );
  113. //
  114. // return the oc manager handle
  115. //
  116. return OcManagerContext;
  117. }
  118. VOID
  119. KillOcManager(
  120. PVOID OcManagerContext
  121. )
  122. /*++
  123. Routine Description:
  124. Terminate OC Manager
  125. Arguments:
  126. OC Manager context handle.
  127. Return Value:
  128. none
  129. --*/
  130. {
  131. MYASSERT(OcManagerContext);
  132. if (OcManagerContext)
  133. OcTerminate(&OcManagerContext);
  134. }
  135. VOID
  136. OcFillInSetupDataW(
  137. OUT PSETUP_DATAW SetupData
  138. )
  139. /*++
  140. Routine Description:
  141. "Glue" routine called by the OC Manager to request that the
  142. implementation fill in setup data to be passed to OC Manager
  143. component DLLs that expect Unicode data.
  144. Arguments:
  145. SetupData - recieves setup data expected by OC components.
  146. Return Value:
  147. None.
  148. --*/
  149. {
  150. //
  151. // It's not possible to be any more specific than this because
  152. // the mode page hasn't been shown yet.
  153. //
  154. SetupData->SetupMode = SETUPMODE_UNKNOWN;
  155. SetupData->ProductType = ProductType;
  156. lstrcpy(SetupData->SourcePath,SourcePath);
  157. SetupData->OperationFlags = 0;
  158. if(Win31Upgrade) {
  159. SetupData->OperationFlags |= SETUPOP_WIN31UPGRADE;
  160. }
  161. if(Win95Upgrade) {
  162. SetupData->OperationFlags |= SETUPOP_WIN95UPGRADE;
  163. }
  164. if(Upgrade) {
  165. SetupData->OperationFlags |= SETUPOP_NTUPGRADE;
  166. }
  167. if(UnattendMode > UAM_PROVIDEDEFAULT) {
  168. SetupData->OperationFlags |= SETUPOP_BATCH;
  169. lstrcpy(SetupData->UnattendFile,AnswerFile);
  170. }
  171. //
  172. // Which files are available?
  173. //
  174. #if defined(_AMD64_)
  175. SetupData->OperationFlags |= SETUPOP_X86_FILES_AVAIL | SETUPOP_AMD64_FILES_AVAIL;
  176. #elif defined(_X86_)
  177. SetupData->OperationFlags |= SETUPOP_X86_FILES_AVAIL;
  178. #elif defined(_IA64_)
  179. SetupData->OperationFlags |= SETUPOP_X86_FILES_AVAIL | SETUPOP_IA64_FILES_AVAIL;
  180. #else
  181. #pragma message( "*** Warning! No architecture defined!")
  182. #endif
  183. }
  184. VOID
  185. OcFillInSetupDataA(
  186. OUT PSETUP_DATAA SetupData
  187. )
  188. /*++
  189. Routine Description:
  190. "Glue" routine called by the OC Manager to request that the
  191. implementation fill in setup data to be passed to OC Manager
  192. component DLLs that expect ANSI data.
  193. Arguments:
  194. SetupData - recieves setup data expected by OC components.
  195. Return Value:
  196. None.
  197. --*/
  198. {
  199. SETUP_DATAW setupdata;
  200. OcFillInSetupDataW(&setupdata);
  201. SetupData->SetupMode = setupdata.SetupMode;
  202. SetupData->ProductType = setupdata.ProductType;
  203. SetupData->OperationFlags = setupdata.OperationFlags;
  204. if(!WideCharToMultiByte(
  205. CP_ACP,
  206. 0,
  207. setupdata.SourcePath,
  208. -1,
  209. SetupData->SourcePath,
  210. sizeof(SetupData->SourcePath),
  211. NULL,
  212. NULL
  213. )){
  214. MYASSERT(FALSE);
  215. }
  216. if(!WideCharToMultiByte(
  217. CP_ACP,
  218. 0,
  219. setupdata.UnattendFile,
  220. -1,
  221. SetupData->UnattendFile,
  222. sizeof(SetupData->UnattendFile),
  223. NULL,
  224. NULL
  225. )){
  226. MYASSERT(FALSE);
  227. }
  228. }
  229. VOID
  230. OcSetReboot(
  231. VOID
  232. )
  233. /*++
  234. Routine Description:
  235. "Glue" routine called by the OC Manager when a reboot is deemed
  236. necessary by an OC Manager component.
  237. For this integrated version of OC Manager, this does nothing;
  238. the system is rebooted at the end of text mode.
  239. Arguments:
  240. None.
  241. Return Value:
  242. None.
  243. --*/
  244. {
  245. return;
  246. }
  247. INT
  248. OcLogError(
  249. IN OcErrorLevel Level,
  250. IN LPCWSTR FormatString,
  251. ...
  252. )
  253. {
  254. TCHAR str[4096];
  255. va_list arglist;
  256. UINT Icon;
  257. UINT lev;
  258. va_start(arglist,FormatString);
  259. _vsntprintf(str, ARRAYSIZE(str), FormatString, arglist);
  260. // null terminate string.
  261. str[ARRAYSIZE(str) - 1] = '\0';
  262. va_end(arglist);
  263. if (Level & OcErrLevWarning)
  264. lev = LogSevWarning;
  265. else if (Level & OcErrLevError)
  266. lev = LogSevError;
  267. else if (Level & OcErrLevFatal)
  268. lev = LogSevError;
  269. else
  270. lev = LogSevInformation;
  271. #if DBG
  272. if (lev != LogSevInformation) {
  273. SetupDebugPrint(str);
  274. }
  275. #endif
  276. SetuplogError(lev, str, 0, NULL, NULL);
  277. return NO_ERROR;
  278. }
  279. HWND
  280. ShowHideWizardPage(
  281. IN BOOL bShow
  282. )
  283. {
  284. HWND hwnd = GetBBhwnd();
  285. if (hwnd)
  286. {
  287. SendMessage(WizardHandle, WMX_BBTEXT, (WPARAM)!bShow, 0);
  288. }
  289. // If we show the wizard again, return the wizard hwnd
  290. if (bShow)
  291. {
  292. // Should hide the progress bar, the wizard page is showing.
  293. BB_ShowProgressGaugeWnd(SW_HIDE);
  294. hwnd = WizardHandle;
  295. }
  296. return hwnd;
  297. }
  298. LRESULT
  299. Billboard_Progress_Callback(
  300. IN UINT Msg,
  301. IN WPARAM wParam,
  302. IN LPARAM lParam
  303. )
  304. {
  305. LRESULT lResult;
  306. if ((Msg == PBM_SETRANGE) || (Msg == PBM_SETRANGE32))
  307. {
  308. // Also enable the progress bar
  309. // Note: No hiding of the progress this way.
  310. BB_ShowProgressGaugeWnd(SW_SHOW);
  311. lResult = ProgressGaugeMsgWrapper(Msg, wParam, lParam);
  312. }
  313. else
  314. {
  315. lResult = ProgressGaugeMsgWrapper(Msg, wParam, lParam);
  316. }
  317. return lResult;
  318. }
  319. VOID Billboard_Set_Progress_Text(LPCTSTR Text)
  320. {
  321. BB_SetProgressText(Text);
  322. }