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.

380 lines
11 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // load.c
  8. //
  9. // Description:
  10. //
  11. // This file implements LoadAllAnswers() which is called by the
  12. // NewOrEdit page.
  13. //
  14. // When LoadAllAnswers is called, the NewOrEdit page passes whether
  15. // we should load settings from an existing answer file, from the
  16. // registry on the current machine, or whether we should reset to
  17. // true defaults.
  18. //
  19. // The global variables GenSettings, WizGlobals and NetSettings
  20. // are populated and the wizard pages init from there and scribble
  21. // into there.
  22. //
  23. //----------------------------------------------------------------------------
  24. #include "pch.h"
  25. #include "allres.h"
  26. //
  27. // External functions we call
  28. //
  29. BOOL ReadSettingsFromAnswerFile(HWND hwnd); // loadfile.c
  30. VOID ResetAnswersToDefaults(HWND hwnd, int iOrigin); // reset.c
  31. VOID LoadOriginalSettingsLowHalScsi(HWND hwnd,
  32. LPTSTR lpFileName,
  33. QUEUENUM dwWhichQueue);
  34. //
  35. // Local prototypes
  36. //
  37. VOID LoadOriginalSettingsLow(HWND hwnd,
  38. LPTSTR lpFileName,
  39. QUEUENUM dwWhichQueue);
  40. static BOOL IsOkToLoadFile(HWND hwnd, LPTSTR lpAnswerFileName);
  41. static VOID LoadOriginalSettings(HWND hwnd);
  42. static VOID RemoveNotPreservedSettings( VOID );
  43. //----------------------------------------------------------------------------
  44. //
  45. // Function: LoadAllAnswers
  46. //
  47. // Purpose: This is the entry for setting all the answers in our globals
  48. // called by the NewEdit page.
  49. //
  50. // NewEdit calls us with one of the following 3 flags depending
  51. // on the radio button the user selected.
  52. //
  53. // LOAD_NEWSCRIPT_DEFAULTS
  54. // Reset all controls and and answer file settings to defaults.
  55. //
  56. // LOAD_FROM_ANSWER_FILE
  57. // Reset all controls and answer file settings to defaults,
  58. // then load answers from an existing answer file.
  59. //
  60. // Arguments: HWND hwnd
  61. //
  62. // Returns: BOOL
  63. //
  64. //----------------------------------------------------------------------------
  65. BOOL LoadAllAnswers(HWND hwnd, LOAD_TYPES iOrigin)
  66. {
  67. TCHAR szTxtSetupPathAndFileName[MAX_PATH + 1] = _T("");
  68. //
  69. // Call into common\reset.c
  70. //
  71. ResetAnswersToDefaults(hwnd, iOrigin);
  72. //
  73. // If editing an answer file, load all of the original settings onto
  74. // a SettingQueue.
  75. //
  76. // Then call into common\loadfile.c to set init the globals vars.
  77. //
  78. if ( iOrigin == LOAD_FROM_ANSWER_FILE ) {
  79. if ( ! IsOkToLoadFile(hwnd, FixedGlobals.ScriptName) )
  80. return FALSE;
  81. LoadOriginalSettings(hwnd);
  82. RemoveNotPreservedSettings();
  83. ReadSettingsFromAnswerFile(hwnd);
  84. //
  85. // If a txtsetup.oem exists, load it into its queue
  86. //
  87. if( WizGlobals.DistFolder[0] != _T('\0') ) {
  88. ConcatenatePaths( szTxtSetupPathAndFileName,
  89. WizGlobals.DistFolder,
  90. _T("\\$oem$\\Textmode\\txtsetup.oem"),
  91. NULL );
  92. if( DoesFileExist( szTxtSetupPathAndFileName ) ) {
  93. LoadOriginalSettingsLowHalScsi(hwnd,
  94. szTxtSetupPathAndFileName,
  95. SETTING_QUEUE_TXTSETUP_OEM);
  96. }
  97. }
  98. }
  99. //
  100. // Detemine if it is sysprep
  101. //
  102. if ( LSTRCMPI( MyGetFullPath( FixedGlobals.ScriptName ), _T("sysprep.inf") ) == 0 )
  103. {
  104. WizGlobals.iProductInstall = PRODUCT_SYSPREP;
  105. }
  106. return TRUE;
  107. }
  108. //----------------------------------------------------------------------------
  109. //
  110. // Function: IsOkToLoadFile
  111. //
  112. // Purpose: Checks to see if the file was created by SetupMgr before the
  113. // caller attempts to load settings from it. If the file was not
  114. // created by SetupMgr, it gives the user a chance to say "Load
  115. // it anyway. The given filename must be a full pathname.
  116. //
  117. //----------------------------------------------------------------------------
  118. static BOOL IsOkToLoadFile(HWND hwnd,
  119. LPTSTR lpAnswerFileName)
  120. {
  121. TCHAR Buffer[MAX_INILINE_LEN];
  122. BOOL bLoadIt = TRUE;
  123. FILE *fp = My_fopen( FixedGlobals.ScriptName, _T("r") );
  124. if ( fp == NULL ) {
  125. ReportErrorId(hwnd,
  126. MSGTYPE_ERR,
  127. IDS_ERR_CANNOT_FIND_ANSWER_FILE,
  128. FixedGlobals.ScriptName);
  129. return FALSE;
  130. }
  131. //
  132. // If we can't find ;SetupMgrTag on the first line of this answer file,
  133. // then Setup Manager didn't create this file.
  134. //
  135. // In that case, ask the user if they want to load it anyway.
  136. //
  137. if ( My_fgets(Buffer, MAX_INILINE_LEN - 1, fp) == NULL ||
  138. lstrcmp(Buffer, _T(";SetupMgrTag\n") ) != 0 ) {
  139. INT iRet;
  140. iRet = ReportErrorId(hwnd,
  141. MSGTYPE_YESNO,
  142. IDS_ERR_FILE_NOT_SETUPMGR,
  143. FixedGlobals.ScriptName);
  144. if ( iRet == IDNO )
  145. bLoadIt = FALSE;
  146. }
  147. My_fclose(fp);
  148. return bLoadIt;
  149. }
  150. //----------------------------------------------------------------------------
  151. //
  152. // Function: LoadOriginalSettings
  153. //
  154. // Purpose: Stub that loads the orginal settings of the answer file
  155. // and the .udf
  156. //
  157. //----------------------------------------------------------------------------
  158. static
  159. VOID
  160. LoadOriginalSettings(HWND hwnd)
  161. {
  162. LoadOriginalSettingsLow(hwnd,
  163. FixedGlobals.ScriptName,
  164. SETTING_QUEUE_ORIG_ANSWERS);
  165. LoadOriginalSettingsLow(hwnd,
  166. FixedGlobals.UdfFileName,
  167. SETTING_QUEUE_ORIG_UDF);
  168. }
  169. //----------------------------------------------------------------------------
  170. //
  171. // Function: LoadOriginalSettingsLow
  172. //
  173. // Purpose:
  174. //
  175. //----------------------------------------------------------------------------
  176. VOID
  177. LoadOriginalSettingsLow(HWND hwnd,
  178. LPTSTR lpFileName,
  179. QUEUENUM dwWhichQueue)
  180. {
  181. TCHAR Buffer[MAX_INILINE_LEN];
  182. FILE *fp;
  183. TCHAR SectionName[MAX_ININAME_LEN + 1] = _T("");
  184. TCHAR KeyName[MAX_ININAME_LEN + 1] = _T("");
  185. TCHAR *pValue;
  186. //
  187. // Open the answer file for reading
  188. //
  189. if ( (fp = My_fopen( lpFileName, _T("r") )) == NULL )
  190. return;
  191. //
  192. // Read each line
  193. //
  194. while ( My_fgets(Buffer, MAX_INILINE_LEN - 1, fp) != NULL ) {
  195. BOOL bSectionLine = FALSE;
  196. BOOL bSettingLine = FALSE;
  197. BOOL bCreatedPriorSection = FALSE;
  198. TCHAR *p;
  199. TCHAR *pEqual;
  200. //
  201. // A semicolon(;) denotes that the rest of the line is a comment.
  202. // Thus, if a semicolon(;) exists in the Buffer, place a null char
  203. // there and send the Buffer on for further processing.
  204. //
  205. // ISSUE-2002/02/28-stelo - but if the ; is in a string, that is OK so we need to watch
  206. // for quotes as well
  207. for( p = Buffer; *p != _T('\0') && *p != _T(';'); p++ )
  208. ; // purposely do nothing
  209. if( *p == _T(';') ) {
  210. *p = _T('\0');
  211. }
  212. //
  213. // Look for [SectionName]
  214. //
  215. if ( Buffer[0] == _T('[') ) {
  216. for ( p=Buffer+1; *p && *p != _T(']'); p++ )
  217. ;
  218. if ( p ) {
  219. *p = _T('\0');
  220. bSectionLine = TRUE;
  221. }
  222. }
  223. //
  224. // If this line has [SectionName], be sure we made a section node
  225. // on the setting queue before overwriting SectionName buffer. This
  226. // is the only way to get the SettingQueueFlush routine to write
  227. // out an empty section. The user had an empty section originally,
  228. // so we'll preserve it.
  229. //
  230. if ( bSectionLine ) {
  231. if ( ! bCreatedPriorSection && SectionName[0] ) {
  232. SettingQueue_AddSetting(SectionName,
  233. _T(""),
  234. _T(""),
  235. dwWhichQueue);
  236. }
  237. lstrcpyn(SectionName, Buffer+1, AS(SectionName));
  238. bSectionLine = FALSE;
  239. bCreatedPriorSection = FALSE;
  240. }
  241. //
  242. // Look for a key=value line, if it is one, add the setting.
  243. //
  244. // Adding a setting to the setting queue has the effect of creating
  245. // the section node if needed.
  246. //
  247. if ( (pEqual = lstrchr( Buffer, _T('=') )) != NULL ) {
  248. p = CleanLeadSpace(Buffer);
  249. lstrcpyn(KeyName, p, (UINT)(pEqual - p + 1));
  250. CleanTrailingSpace( KeyName );
  251. pValue = pEqual + 1;
  252. p = CleanSpaceAndQuotes(pValue);
  253. //
  254. // Strip the quotes but leave the spaces in
  255. // An example of where this is needed is for SCSI and HAL section
  256. //
  257. StripQuotes( KeyName );
  258. SettingQueue_AddSetting(SectionName,
  259. KeyName,
  260. p,
  261. dwWhichQueue);
  262. bCreatedPriorSection = TRUE;
  263. }
  264. }
  265. My_fclose(fp);
  266. return;
  267. }
  268. //----------------------------------------------------------------------------
  269. //
  270. // Function: RemoveNotPreservedSettings
  271. //
  272. // Purpose: To removed sections from the answer queue that are not preserved
  273. // on an edit.
  274. //
  275. //----------------------------------------------------------------------------
  276. static VOID
  277. RemoveNotPreservedSettings( VOID ) {
  278. // ISSUE-2002/02/28-stelo - all of these should be string should be made constants and put in a header file
  279. //
  280. // Do not preserve any of the SCSI drivers from the previous script
  281. //
  282. SettingQueue_RemoveSection( _T("MassStorageDrivers"),
  283. SETTING_QUEUE_ORIG_ANSWERS );
  284. //
  285. // The OEM Boot files get generated depending on the users choices on the
  286. // SCSI and HAL pages so there is no need to preserve it.
  287. //
  288. SettingQueue_RemoveSection( _T("OEMBootFiles"),
  289. SETTING_QUEUE_ORIG_ANSWERS );
  290. //
  291. // Do not preserve any IE Favorites from the previous script, they get
  292. // written out from the in-memory settings.
  293. //
  294. SettingQueue_RemoveSection( _T("FavoritesEx"),
  295. SETTING_QUEUE_ORIG_ANSWERS );
  296. }