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.

1436 lines
46 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // loadfile.c
  8. //
  9. // Description:
  10. //
  11. // This file implements ReadSettingsFromAnswerFile(). It is called
  12. // from load.c only if the user chose to edit an existing answer file.
  13. //
  14. // We call GetPrivateProfileString repeatedly to figure out how to
  15. // initialize GenSettings WizGlobals and NetSettings global vars.
  16. //
  17. // WARNING:
  18. // This function is called after reset.c in the case we're editting
  19. // an answer file. Be very careful how you call GetPrivateProfileString()
  20. // because if the setting is not present, you do not want to change
  21. // the default already set in reset.c. Numerous examples below.
  22. //
  23. //----------------------------------------------------------------------------
  24. #include "pch.h"
  25. #include "allres.h"
  26. //
  27. // Misc constants (declared as vars to save space)
  28. //
  29. static WCHAR *StrConstYes = _T("Yes");
  30. static WCHAR *StrConstNo = _T("No");
  31. static WCHAR *StrConstStar = _T("*");
  32. extern BOOL GetCommaDelimitedEntry( OUT TCHAR szIPString[],
  33. IN OUT TCHAR **pBuffer );
  34. // ISSUE-2002/02/28-stelo- make constants for each key and use them both in the save file and in this load file
  35. const TCHAR c_szFAVORITESEX[] = _T("FavoritesEx");
  36. //
  37. // Local prototypes
  38. //
  39. static VOID ReadRegionalSettings( VOID );
  40. static VOID ReadTapiSettings( VOID );
  41. static VOID ReadIeSettings( VOID );
  42. static VOID ReadIeFavorites( VOID );
  43. static VOID ParseAddressAndPort( LPTSTR pszBufferForProxyAddressAndPort,
  44. LPTSTR pszAddress,
  45. DWORD cbAddressLen,
  46. LPTSTR pszPort,
  47. DWORD cbPortLen);
  48. //
  49. // Call out to loadnet.c to load the network settings
  50. //
  51. extern VOID ReadNetworkSettings( HWND );
  52. //----------------------------------------------------------------------------
  53. //
  54. // Function: ReadSettingsFromAnswerFile
  55. //
  56. // Purpose: This function does all of the GetPrivateProfile*() stuff
  57. // to load up our in-memory settings.
  58. //
  59. // Arguments: VOID
  60. //
  61. // Returns: VOID
  62. //
  63. //----------------------------------------------------------------------------
  64. BOOL ReadSettingsFromAnswerFile(HWND hwnd)
  65. {
  66. INT temp;
  67. TCHAR Buffer[MAX_INILINE_LEN];
  68. //
  69. // Get the UnattendMode. In case there is garbage in the answer file,
  70. // let the answer be UMODE_PROVIDE_DEFAULT.
  71. //
  72. temp = StrBuffSize(Buffer);
  73. GetPrivateProfileString(_T("Unattended"),
  74. _T("UnattendMode"),
  75. _T(""),
  76. Buffer,
  77. temp,
  78. FixedGlobals.ScriptName);
  79. if ( LSTRCMPI(Buffer, _T("GuiAttended")) == 0 )
  80. GenSettings.iUnattendMode = UMODE_GUI_ATTENDED;
  81. else if ( LSTRCMPI(Buffer, _T("DefaultHide")) == 0 )
  82. GenSettings.iUnattendMode = UMODE_DEFAULT_HIDE;
  83. else if ( LSTRCMPI(Buffer, _T("Readonly")) == 0 )
  84. GenSettings.iUnattendMode = UMODE_READONLY;
  85. else if ( LSTRCMPI(Buffer, _T("FullUnattended")) == 0 )
  86. GenSettings.iUnattendMode = UMODE_FULL_UNATTENDED;
  87. else
  88. GenSettings.iUnattendMode = UMODE_PROVIDE_DEFAULT;
  89. //
  90. // Get the HAL
  91. //
  92. GetPrivateProfileString(_T("Unattended"),
  93. _T("ComputerType"),
  94. _T(""),
  95. Buffer,
  96. StrBuffSize(Buffer),
  97. FixedGlobals.ScriptName);
  98. //
  99. // Have to read in HAL and SCSI drivers a little
  100. // differently because of the quotes on the left for the SCSI drivers
  101. // and the different formatting with the HAL
  102. //
  103. {
  104. HINF hUnattendTxt;
  105. INFCONTEXT UnattendTxtContext;
  106. BOOL bKeepReading = TRUE;
  107. BOOL bHalFound = FALSE;
  108. TCHAR szTempBuffer[MAX_INILINE_LEN];
  109. hUnattendTxt = SetupOpenInfFile( FixedGlobals.ScriptName,
  110. NULL,
  111. INF_STYLE_OLDNT | INF_STYLE_WIN4,
  112. NULL );
  113. if( hUnattendTxt == INVALID_HANDLE_VALUE ) {
  114. // ISSUE-2002/02/28-stelo - alert an error that we couldn't open the file or just
  115. // skip over in this case?
  116. //return;
  117. }
  118. UnattendTxtContext.Inf = hUnattendTxt;
  119. UnattendTxtContext.CurrentInf = hUnattendTxt;
  120. bKeepReading = SetupFindFirstLine( hUnattendTxt,
  121. _T("Unattended"),
  122. NULL,
  123. &UnattendTxtContext );
  124. //
  125. // Look for the ComputerType key to set which HAL to use
  126. //
  127. while( bKeepReading && ! bHalFound ) {
  128. SetupGetStringField( &UnattendTxtContext,
  129. 0,
  130. szTempBuffer,
  131. MAX_INILINE_LEN,
  132. NULL );
  133. if( LSTRCMPI( szTempBuffer, _T("ComputerType") ) == 0 ) {
  134. SetupGetStringField( &UnattendTxtContext,
  135. 1,
  136. GenSettings.szHalFriendlyName,
  137. MAX_INILINE_LEN,
  138. NULL );
  139. bHalFound = TRUE;
  140. }
  141. //
  142. // move to the next line of the answer file
  143. //
  144. bKeepReading = SetupFindNextLine( &UnattendTxtContext, &UnattendTxtContext );
  145. }
  146. //
  147. // Read in the SCSI drivers
  148. //
  149. bKeepReading = SetupFindFirstLine( hUnattendTxt,
  150. _T("MassStorageDrivers"),
  151. NULL,
  152. &UnattendTxtContext );
  153. //
  154. // For each MassStorageDriver entry, add it to the MassStorageDriver
  155. // namelist
  156. //
  157. while( bKeepReading ) {
  158. TCHAR szScsiFriendlyName[MAX_INILINE_LEN];
  159. SetupGetStringField( &UnattendTxtContext,
  160. 0,
  161. szScsiFriendlyName,
  162. MAX_INILINE_LEN,
  163. NULL );
  164. //
  165. // Don't allow the adding of a blank name (protection against a bad input file)
  166. //
  167. if( szScsiFriendlyName[0] != _T('\0') ) {
  168. AddNameToNameList( &GenSettings.MassStorageDrivers,
  169. szScsiFriendlyName );
  170. }
  171. //
  172. // move to the next line of the answer file
  173. //
  174. bKeepReading = SetupFindNextLine( &UnattendTxtContext, &UnattendTxtContext );
  175. }
  176. SetupCloseInfFile( hUnattendTxt );
  177. }
  178. //
  179. // Not reading from the [OEMBootFiles] section because this gets
  180. // generated from whatever SCSI and HAL selections they make so
  181. // it is not necessary to read it in.
  182. //
  183. //
  184. // Get OEM Ads data
  185. //
  186. GetPrivateProfileString(_T("OEM_Ads"),
  187. _T("Logo"),
  188. GenSettings.lpszLogoBitmap,
  189. GenSettings.lpszLogoBitmap,
  190. StrBuffSize(GenSettings.lpszLogoBitmap),
  191. FixedGlobals.ScriptName);
  192. GetPrivateProfileString(_T("OEM_Ads"),
  193. _T("Background"),
  194. GenSettings.lpszBackgroundBitmap,
  195. GenSettings.lpszBackgroundBitmap,
  196. StrBuffSize(GenSettings.lpszBackgroundBitmap),
  197. FixedGlobals.ScriptName);
  198. //
  199. // Get the product ID
  200. //
  201. {
  202. TCHAR *pStart = Buffer, *pEnd;
  203. BOOL bStop = FALSE;
  204. int CurField = 0;
  205. GetPrivateProfileString(_T("UserData"),
  206. _T("ProductKey"),
  207. NULLSTR,
  208. Buffer,
  209. StrBuffSize(Buffer),
  210. FixedGlobals.ScriptName);
  211. // We did not have a ProductKey, check for the old ProductID
  212. //
  213. if ( Buffer[0] == NULLCHR )
  214. {
  215. GetPrivateProfileString(_T("UserData"),
  216. _T("ProductID"),
  217. _T("-"),
  218. Buffer,
  219. StrBuffSize(Buffer),
  220. FixedGlobals.ScriptName);
  221. }
  222. //
  223. // Have to parse out the pid1-pid2-pid3-pid4-pid5.
  224. //
  225. do {
  226. if ( (pEnd = wcschr(pStart, _T('-'))) == NULL )
  227. bStop = TRUE;
  228. else
  229. *pEnd++ = _T('\0');
  230. lstrcpyn(GenSettings.ProductId[CurField++],
  231. pStart,
  232. MAX_PID_FIELD + 1);
  233. pStart = pEnd;
  234. } while ( ! bStop && CurField < NUM_PID_FIELDS );
  235. }
  236. //
  237. // Get the license mode for server. If we find this section, we
  238. // force on iProductInstall to be Server.
  239. //
  240. GetPrivateProfileString(_T("LicenseFilePrintData"),
  241. _T("AutoMode"),
  242. _T(""),
  243. Buffer,
  244. StrBuffSize(Buffer),
  245. FixedGlobals.ScriptName);
  246. if ( Buffer[0] != _T('\0') ) {
  247. WizGlobals.iProductInstall = PRODUCT_UNATTENDED_INSTALL;
  248. WizGlobals.iPlatform = PLATFORM_SERVER;
  249. if ( LSTRCMPI(Buffer, _T("PerSeat")) == 0 ) {
  250. GenSettings.bPerSeat = TRUE;
  251. } else {
  252. GenSettings.bPerSeat = FALSE;
  253. GenSettings.NumConnections =
  254. GetPrivateProfileInt(_T("LicenseFilePrintData"),
  255. _T("AutoUsers"),
  256. GenSettings.NumConnections,
  257. FixedGlobals.ScriptName);
  258. }
  259. }
  260. //
  261. // Get name&org
  262. //
  263. GetPrivateProfileString(_T("UserData"),
  264. _T("FullName"),
  265. GenSettings.UserName,
  266. GenSettings.UserName,
  267. StrBuffSize(GenSettings.UserName),
  268. FixedGlobals.ScriptName);
  269. GetPrivateProfileString(_T("UserData"),
  270. _T("OrgName"),
  271. GenSettings.Organization,
  272. GenSettings.Organization,
  273. StrBuffSize(GenSettings.Organization),
  274. FixedGlobals.ScriptName);
  275. //
  276. // Get the computer names. It can be:
  277. // 1. ComputerName=*
  278. // 2. ComputerName=some_name
  279. // 3. not specified at all
  280. // 4. multiple computer names
  281. //
  282. // In case #4, we wrote out a .UDF, but we won't read the .UDF. Instead,
  283. // we get the list from here:
  284. //
  285. // [SetupMgr]
  286. // ComputerName0=some_name
  287. // ComputerName1=another_name
  288. //
  289. {
  290. ResetNameList(&GenSettings.ComputerNames);
  291. GetPrivateProfileString(_T("UserData"),
  292. _T("ComputerName"),
  293. _T(""),
  294. Buffer,
  295. StrBuffSize(Buffer),
  296. FixedGlobals.ScriptName);
  297. if( Buffer[0] != _T('\0') )
  298. {
  299. if( lstrcmpi(Buffer, StrConstStar) == 0 )
  300. {
  301. //
  302. // if ComputerName=*, it is either the auto generate case
  303. // or the UDF case
  304. //
  305. GetPrivateProfileString(_T("SetupMgr"),
  306. _T("ComputerName0"),
  307. _T(""),
  308. Buffer,
  309. StrBuffSize(Buffer),
  310. FixedGlobals.ScriptName);
  311. if( Buffer[0] == _T('\0') )
  312. {
  313. GenSettings.bAutoComputerName = TRUE;
  314. }
  315. else
  316. {
  317. int i;
  318. TCHAR Buffer2[MAX_INILINE_LEN];
  319. HRESULT hrPrintf;
  320. GenSettings.bAutoComputerName = FALSE;
  321. for( i = 0; TRUE; i++ )
  322. {
  323. hrPrintf=StringCchPrintf(Buffer2, AS(Buffer2),_T("ComputerName%d"), i);
  324. GetPrivateProfileString(_T("SetupMgr"),
  325. Buffer2,
  326. _T(""),
  327. Buffer,
  328. StrBuffSize(Buffer),
  329. FixedGlobals.ScriptName);
  330. if ( Buffer[0] == _T('\0') )
  331. break;
  332. AddNameToNameList(&GenSettings.ComputerNames, Buffer);
  333. }
  334. }
  335. }
  336. else
  337. {
  338. GenSettings.bAutoComputerName = FALSE;
  339. AddNameToNameList(&GenSettings.ComputerNames, Buffer);
  340. }
  341. }
  342. }
  343. //
  344. // Get the IE settings
  345. //
  346. ReadIeSettings();
  347. //
  348. // Get the targetpath
  349. //
  350. GetPrivateProfileString(_T("Unattended"),
  351. _T("TargetPath"),
  352. _T(""),
  353. Buffer,
  354. StrBuffSize(Buffer),
  355. FixedGlobals.ScriptName);
  356. if ( lstrcmpi(Buffer, StrConstStar) == 0 ) {
  357. GenSettings.iTargetPath = TARGPATH_AUTO;
  358. GenSettings.TargetPath[0] = _T('\0');
  359. }
  360. else if ( lstrcmpi(Buffer, _T("")) == 0 ) {
  361. GenSettings.iTargetPath = TARGPATH_WINNT;
  362. GenSettings.TargetPath[0] = _T('\0');
  363. }
  364. else {
  365. GenSettings.iTargetPath = TARGPATH_SPECIFY;
  366. lstrcpyn(GenSettings.TargetPath, Buffer, MAX_TARGPATH + 1);
  367. }
  368. //
  369. // Get the administrator password.
  370. //
  371. // AdminPassword == * means bSpecifyPassword to blank
  372. // AdminPassword[0] == '\0' means !bSpecifyPassword
  373. //
  374. // Always set ConfirmPassword == AdminPassword on an edit so that
  375. // the user can breeze past this page.
  376. //
  377. // Check to see if the password is encrypted
  378. GetPrivateProfileString(_T("GuiUnattended"),
  379. _T("EncryptedAdminPassword"),
  380. _T(""),
  381. Buffer,
  382. StrBuffSize(Buffer),
  383. FixedGlobals.ScriptName);
  384. if (lstrcmpi(Buffer, StrConstYes) == 0)
  385. {
  386. // If it is encrypted, don't bother reading it, just blank it out
  387. GenSettings.AdminPassword[0] = _T('\0');
  388. GenSettings.bSpecifyPassword = TRUE;
  389. }
  390. else
  391. {
  392. GetPrivateProfileString(_T("GuiUnattended"),
  393. _T("AdminPassword"),
  394. GenSettings.AdminPassword,
  395. GenSettings.AdminPassword,
  396. StrBuffSize(GenSettings.AdminPassword),
  397. FixedGlobals.ScriptName);
  398. if ( GenSettings.AdminPassword[0] == _T('\0') )
  399. GenSettings.bSpecifyPassword = FALSE;
  400. else
  401. GenSettings.bSpecifyPassword = TRUE;
  402. if ( lstrcmpi(GenSettings.AdminPassword, StrConstStar) == 0 )
  403. GenSettings.AdminPassword[0] = _T('\0');
  404. }
  405. lstrcpyn(GenSettings.ConfirmPassword, GenSettings.AdminPassword, AS(GenSettings.ConfirmPassword));
  406. GetPrivateProfileString(_T("GuiUnattended"),
  407. _T("AutoLogon"),
  408. _T(""),
  409. Buffer,
  410. StrBuffSize(Buffer),
  411. FixedGlobals.ScriptName);
  412. if ( lstrcmpi(Buffer, StrConstYes) == 0 )
  413. GenSettings.bAutoLogon = TRUE;
  414. else
  415. GenSettings.bAutoLogon = FALSE;
  416. GenSettings.nAutoLogonCount = GetPrivateProfileInt(_T("GuiUnattended"),
  417. _T("AutoLogonCount"),
  418. GenSettings.nAutoLogonCount,
  419. FixedGlobals.ScriptName);
  420. GetPrivateProfileString(_T("GuiUnattended"),
  421. _T("OEMDuplicatorstring"),
  422. GenSettings.szOemDuplicatorString,
  423. GenSettings.szOemDuplicatorString,
  424. StrBuffSize(GenSettings.szOemDuplicatorString),
  425. FixedGlobals.ScriptName);
  426. //
  427. // Get the display settings.
  428. //
  429. GenSettings.DisplayColorBits = GetPrivateProfileInt(
  430. _T("Display"),
  431. _T("BitsPerPel"),
  432. GenSettings.DisplayColorBits,
  433. FixedGlobals.ScriptName);
  434. GenSettings.DisplayXResolution = GetPrivateProfileInt(
  435. _T("Display"),
  436. _T("XResolution"),
  437. GenSettings.DisplayXResolution,
  438. FixedGlobals.ScriptName);
  439. GenSettings.DisplayYResolution = GetPrivateProfileInt(
  440. _T("Display"),
  441. _T("YResolution"),
  442. GenSettings.DisplayYResolution,
  443. FixedGlobals.ScriptName);
  444. GenSettings.DisplayRefreshRate = GetPrivateProfileInt(
  445. _T("Display"),
  446. _T("Vrefresh"),
  447. GenSettings.DisplayRefreshRate,
  448. FixedGlobals.ScriptName);
  449. //
  450. // Get the runonce commands. They are listed like this:
  451. //
  452. // [GuiRunOnce]
  453. // Command0=some_cmd
  454. // Command0=another_cmd
  455. //
  456. // ISSUE-2002/02/28-stelo -Need to investigate this biz about running these commands
  457. // in sequence or in parrallel.
  458. //
  459. {
  460. int i;
  461. TCHAR Buffer2[MAX_INILINE_LEN];
  462. HRESULT hrPrintf;
  463. ResetNameList(&GenSettings.RunOnceCmds);
  464. for ( i=0; TRUE; i++ ) {
  465. hrPrintf=StringCchPrintf(Buffer2, AS(Buffer2),_T("Command%d"), i);
  466. GetPrivateProfileString(_T("GuiRunOnce"),
  467. Buffer2,
  468. _T(""),
  469. Buffer,
  470. StrBuffSize(Buffer),
  471. FixedGlobals.ScriptName);
  472. if ( Buffer[0] == _T('\0') )
  473. break;
  474. AddNameToNameList(&GenSettings.RunOnceCmds, Buffer);
  475. }
  476. }
  477. //
  478. // Loop through the commands and parse out any add printer commands
  479. //
  480. //
  481. // NOTE: This code works if the user never edits the commands.
  482. // However, the user might want to modify it and put
  483. // different switches on it on the RunOnce page. The
  484. // parsing below could be more robust.
  485. //
  486. // If /n means 'name', then it should parse for /n then
  487. // the next arg is the printer name no matter what switches
  488. // the user added or re-ordered.
  489. //
  490. {
  491. int i, NumCmds;
  492. TCHAR *pName;
  493. TCHAR PrinterName[MAX_PRINTERNAME + 1];
  494. NumCmds = GetNameListSize(&GenSettings.RunOnceCmds);
  495. for ( i=0; i<NumCmds; i++ )
  496. {
  497. pName = GetNameListName(&GenSettings.RunOnceCmds, i);
  498. PrinterName[0] = _T('\0');
  499. if ( ( swscanf(pName,
  500. _T("rundll32 printui.dll,PrintUIEntry /in /n %s"),
  501. PrinterName) > 0 ) &&
  502. ( PrinterName[0] ) )
  503. {
  504. AddNameToNameList(&GenSettings.PrinterNames, PrinterName);
  505. }
  506. }
  507. }
  508. //
  509. // Get the timezone
  510. //
  511. GetPrivateProfileString( _T("GuiUnattended"),
  512. _T("TimeZone"),
  513. _T(""),
  514. Buffer,
  515. StrBuffSize(Buffer),
  516. FixedGlobals.ScriptName );
  517. if ( LSTRCMPI(Buffer, _T("%TIMEZONE%")) == 0 )
  518. {
  519. GenSettings.TimeZoneIdx = TZ_IDX_SETSAMEASSERVER;
  520. }
  521. else if ( ( Buffer[0] == _T('\0') ) ||
  522. ( swscanf(Buffer, _T("%d"), &GenSettings.TimeZoneIdx) <= 0 ) )
  523. {
  524. GenSettings.TimeZoneIdx = TZ_IDX_DONOTSPECIFY;
  525. }
  526. //
  527. // Init the settings for the 2 Distribution Folder pages. OemPreInstall
  528. // indicates whether the script is stand-alone or not. The others are
  529. // saved in the [SetupMgr] section.
  530. //
  531. GetPrivateProfileString(_T("Unattended"),
  532. _T("OemPreInstall"),
  533. _T(""),
  534. Buffer,
  535. StrBuffSize(Buffer),
  536. FixedGlobals.ScriptName );
  537. if ( lstrcmpi(Buffer, StrConstYes) == 0 )
  538. WizGlobals.bStandAloneScript = FALSE;
  539. else
  540. WizGlobals.bStandAloneScript = TRUE;
  541. GetPrivateProfileString(_T("SetupMgr"),
  542. _T("DistFolder"),
  543. WizGlobals.DistFolder,
  544. WizGlobals.DistFolder,
  545. StrBuffSize(WizGlobals.DistFolder),
  546. FixedGlobals.ScriptName);
  547. GetPrivateProfileString(_T("SetupMgr"),
  548. _T("DistShare"),
  549. WizGlobals.DistShareName,
  550. WizGlobals.DistShareName,
  551. StrBuffSize(WizGlobals.DistShareName),
  552. FixedGlobals.ScriptName);
  553. WizGlobals.bCreateNewDistFolder = FALSE;
  554. //
  555. // Get tapi & regional settings
  556. //
  557. ReadTapiSettings();
  558. ReadRegionalSettings();
  559. //
  560. // Purposely grabbing the JoinWorkgroup key twice. Once to determine if
  561. // there a value for the key and once to set the value for the global
  562. // NetSettings.WorkGroupName string.
  563. //
  564. GetPrivateProfileString(_T("Identification"),
  565. _T("JoinWorkgroup"),
  566. _T(""),
  567. Buffer,
  568. StrBuffSize(Buffer),
  569. FixedGlobals.ScriptName);
  570. GetPrivateProfileString(_T("Identification"),
  571. _T("JoinWorkgroup"),
  572. NetSettings.WorkGroupName,
  573. NetSettings.WorkGroupName,
  574. StrBuffSize(NetSettings.WorkGroupName),
  575. FixedGlobals.ScriptName);
  576. GetPrivateProfileString(_T("Identification"),
  577. _T("JoinDomain"),
  578. NetSettings.DomainName,
  579. NetSettings.DomainName,
  580. StrBuffSize(NetSettings.DomainName),
  581. FixedGlobals.ScriptName);
  582. //
  583. // If they didn't specify a workgroup in the answerfile and they did
  584. // specify a domain, chose to Join a Domain (i.e. not join a workgroup)
  585. //
  586. if( Buffer[0] == _T('\0') &&
  587. NetSettings.DomainName[0] != _T('\0') )
  588. {
  589. NetSettings.bWorkgroup = FALSE;
  590. }
  591. if( lstrcmp( NetSettings.DomainName, _T("%MACHINEDOMAIN%") ) == 0 )
  592. {
  593. WizGlobals.iProductInstall = PRODUCT_REMOTEINSTALL;
  594. }
  595. GetPrivateProfileString(_T("Identification"),
  596. _T("DomainAdmin"),
  597. NetSettings.DomainAccount,
  598. NetSettings.DomainAccount,
  599. StrBuffSize(NetSettings.DomainAccount),
  600. FixedGlobals.ScriptName);
  601. GetPrivateProfileString(_T("Identification"),
  602. _T("DomainAdminPassword"),
  603. NetSettings.DomainPassword,
  604. NetSettings.DomainPassword,
  605. StrBuffSize(NetSettings.DomainPassword),
  606. FixedGlobals.ScriptName);
  607. if( NetSettings.DomainAccount[0] == _T('\0') )
  608. {
  609. NetSettings.bCreateAccount = FALSE;
  610. }
  611. else
  612. {
  613. NetSettings.bCreateAccount = TRUE;
  614. }
  615. //
  616. // Make the domain password and the confirm the same so user can
  617. // breeze past the page if they want to
  618. //
  619. lstrcpyn( NetSettings.ConfirmPassword, NetSettings.DomainPassword ,AS(NetSettings.ConfirmPassword));
  620. //
  621. // Read in the Network settings
  622. //
  623. ReadNetworkSettings( hwnd );
  624. return( TRUE );
  625. }
  626. //----------------------------------------------------------------------------
  627. //
  628. // Function: ReadTapiSettings
  629. //
  630. // Purpose: Read the tapi settings keys from the answerfile.
  631. //
  632. // Arguments: VOID
  633. //
  634. // Returns: VOID
  635. //
  636. //----------------------------------------------------------------------------
  637. static VOID
  638. ReadTapiSettings( VOID ) {
  639. TCHAR Buffer[MAX_INILINE_LEN] = _T("");
  640. //
  641. // Note: if it doesn't find the CountryCode key then it defaults to
  642. // "Don't specify setting"
  643. //
  644. GenSettings.dwCountryCode = GetPrivateProfileInt(_T("TapiLocation"),
  645. _T("CountryCode"),
  646. DONTSPECIFYSETTING,
  647. FixedGlobals.ScriptName);
  648. GetPrivateProfileString(_T("TapiLocation"),
  649. _T("Dialing"),
  650. _T(""),
  651. Buffer,
  652. StrBuffSize(Buffer),
  653. FixedGlobals.ScriptName);
  654. if ( LSTRCMPI(Buffer, _T("Tone")) == 0 )
  655. GenSettings.iDialingMethod = TONE;
  656. else if ( LSTRCMPI(Buffer, _T("Pulse")) == 0 )
  657. GenSettings.iDialingMethod = PULSE;
  658. else
  659. GenSettings.iDialingMethod = DONTSPECIFYSETTING;
  660. GetPrivateProfileString(_T("TapiLocation"),
  661. _T("AreaCode"),
  662. GenSettings.szAreaCode,
  663. GenSettings.szAreaCode,
  664. StrBuffSize(GenSettings.szAreaCode),
  665. FixedGlobals.ScriptName);
  666. GetPrivateProfileString(_T("TapiLocation"),
  667. _T("LongDistanceAccess"),
  668. GenSettings.szOutsideLine,
  669. GenSettings.szOutsideLine,
  670. StrBuffSize(GenSettings.szOutsideLine),
  671. FixedGlobals.ScriptName);
  672. }
  673. //----------------------------------------------------------------------------
  674. //
  675. // Function: ReadRegionalSettings
  676. //
  677. // Purpose: Read the regional settings keys from the answerfile.
  678. //
  679. // Arguments: VOID
  680. //
  681. // Returns: VOID
  682. //
  683. //----------------------------------------------------------------------------
  684. static VOID
  685. ReadRegionalSettings( VOID ) {
  686. TCHAR Buffer[MAX_INILINE_LEN] = _T("");
  687. TCHAR OemSkipBuffer[MAX_INILINE_LEN] = _T("");
  688. TCHAR szLanguageGroup[MAX_INILINE_LEN] = _T("");
  689. TCHAR *pLanguageGroup = NULL;
  690. DWORD dwOemSkipSize = 0;
  691. DWORD dwLanguageSize = 0;
  692. DWORD dwSystemSize = 0;
  693. DWORD dwNumberSize = 0;
  694. DWORD dwKeyboardSize = 0;
  695. dwOemSkipSize = GetPrivateProfileString(_T("RegionalSettings"),
  696. _T("OEMSkipRegionalSettings"),
  697. _T(""),
  698. OemSkipBuffer,
  699. StrBuffSize(OemSkipBuffer),
  700. FixedGlobals.ScriptName);
  701. GetPrivateProfileString(_T("RegionalSettings"),
  702. _T("LanguageGroup"),
  703. _T(""),
  704. Buffer,
  705. StrBuffSize(Buffer),
  706. FixedGlobals.ScriptName);
  707. //
  708. // Loop grabbing the Language Groups and inserting them into
  709. // the NameList
  710. //
  711. pLanguageGroup = Buffer;
  712. while( GetCommaDelimitedEntry( szLanguageGroup, &pLanguageGroup ) ) {
  713. AddNameToNameList( &GenSettings.LanguageGroups,
  714. szLanguageGroup );
  715. }
  716. dwLanguageSize = GetPrivateProfileString(_T("RegionalSettings"),
  717. _T("Language"),
  718. _T(""),
  719. GenSettings.szLanguage,
  720. StrBuffSize(GenSettings.szLanguage),
  721. FixedGlobals.ScriptName);
  722. dwSystemSize = GetPrivateProfileString(_T("RegionalSettings"),
  723. _T("SystemLocale"),
  724. _T(""),
  725. GenSettings.szMenuLanguage,
  726. StrBuffSize(GenSettings.szMenuLanguage),
  727. FixedGlobals.ScriptName);
  728. dwNumberSize = GetPrivateProfileString(_T("RegionalSettings"),
  729. _T("UserLocale"),
  730. _T(""),
  731. GenSettings.szNumberLanguage,
  732. StrBuffSize(GenSettings.szNumberLanguage),
  733. FixedGlobals.ScriptName);
  734. dwKeyboardSize = GetPrivateProfileString(_T("RegionalSettings"),
  735. _T("InputLocale"),
  736. _T(""),
  737. GenSettings.szKeyboardLayout,
  738. StrBuffSize(GenSettings.szKeyboardLayout),
  739. FixedGlobals.ScriptName);
  740. //
  741. // If the OEMSkipRegionalSettings was specified in the answerfile, set
  742. // its value and return. Else set the language locales appropriately.
  743. //
  744. if( dwOemSkipSize > 0 ) {
  745. if( lstrcmp( OemSkipBuffer, _T("0") ) == 0 ) {
  746. GenSettings.iRegionalSettings = REGIONAL_SETTINGS_SKIP;
  747. }
  748. else if( lstrcmp( OemSkipBuffer, _T("1") ) == 0 ) {
  749. GenSettings.iRegionalSettings = REGIONAL_SETTINGS_DEFAULT;
  750. }
  751. else {
  752. // if it was set to some strange settings, just set it to use default
  753. GenSettings.iRegionalSettings = REGIONAL_SETTINGS_DEFAULT;
  754. }
  755. }
  756. else {
  757. if( dwLanguageSize != 0 ) {
  758. GenSettings.iRegionalSettings = REGIONAL_SETTINGS_SPECIFY;
  759. }
  760. else if( dwSystemSize != 0 || dwNumberSize != 0 || dwKeyboardSize != 0 ) {
  761. GenSettings.iRegionalSettings = REGIONAL_SETTINGS_SPECIFY;
  762. GenSettings.bUseCustomLocales = TRUE;
  763. }
  764. else {
  765. //
  766. // If no keys were specified, set it to not specified
  767. //
  768. GenSettings.iRegionalSettings = REGIONAL_SETTINGS_NOT_SPECIFIED;
  769. }
  770. }
  771. }
  772. //----------------------------------------------------------------------------
  773. //
  774. // Function: ReadIeSettings
  775. //
  776. // Purpose: Read the IE settings keys from the answerfile and store them in
  777. // the global structs.
  778. //
  779. // Arguments: VOID
  780. //
  781. // Returns: VOID
  782. //
  783. //----------------------------------------------------------------------------
  784. static VOID
  785. ReadIeSettings( VOID )
  786. {
  787. TCHAR szBufferForProxyAddressAndPort[2048 + 1];
  788. TCHAR szAddress[MAX_PROXY_LEN];
  789. TCHAR szPort[MAX_PROXY_PORT_LEN];
  790. TCHAR Buffer[MAX_INILINE_LEN];
  791. TCHAR *pLocalString;
  792. GetPrivateProfileString(_T("Branding"),
  793. _T("IEBrandingFile"),
  794. GenSettings.szInsFile,
  795. GenSettings.szInsFile,
  796. StrBuffSize(GenSettings.szInsFile),
  797. FixedGlobals.ScriptName);
  798. if( GenSettings.szInsFile[0] != _T('\0') )
  799. {
  800. GenSettings.IeCustomizeMethod = IE_USE_BRANDING_FILE;
  801. }
  802. else
  803. {
  804. GenSettings.IeCustomizeMethod = IE_SPECIFY_SETTINGS;
  805. }
  806. GetPrivateProfileString(_T("URL"),
  807. _T("AutoConfig"),
  808. _T("1"),
  809. Buffer,
  810. StrBuffSize(Buffer),
  811. FixedGlobals.ScriptName);
  812. if( lstrcmpi( Buffer, _T("1") ) == 0 )
  813. {
  814. GenSettings.bUseAutoConfigScript = TRUE;
  815. }
  816. else
  817. {
  818. GenSettings.bUseAutoConfigScript = FALSE;
  819. }
  820. GetPrivateProfileString(_T("URL"),
  821. _T("AutoConfigURL"),
  822. GenSettings.szAutoConfigUrl,
  823. GenSettings.szAutoConfigUrl,
  824. StrBuffSize(GenSettings.szAutoConfigUrl),
  825. FixedGlobals.ScriptName);
  826. GetPrivateProfileString(_T("URL"),
  827. _T("AutoConfigJSURL"),
  828. GenSettings.szAutoConfigUrlJscriptOrPac,
  829. GenSettings.szAutoConfigUrlJscriptOrPac,
  830. StrBuffSize(GenSettings.szAutoConfigUrlJscriptOrPac),
  831. FixedGlobals.ScriptName);
  832. if( GenSettings.szAutoConfigUrl[0] != _T('\0') ||
  833. GenSettings.szAutoConfigUrlJscriptOrPac[0] != _T('\0') )
  834. {
  835. GenSettings.bUseAutoConfigScript = TRUE;
  836. }
  837. else
  838. {
  839. GenSettings.bUseAutoConfigScript = FALSE;
  840. }
  841. GetPrivateProfileString(_T("Proxy"),
  842. _T("Use_Same_Proxy"),
  843. _T("0"),
  844. Buffer,
  845. StrBuffSize(Buffer),
  846. FixedGlobals.ScriptName);
  847. if( lstrcmpi( Buffer, _T("1") ) == 0 )
  848. {
  849. GenSettings.bUseSameProxyForAllProtocols = TRUE;
  850. }
  851. else
  852. {
  853. GenSettings.bUseSameProxyForAllProtocols = FALSE;
  854. }
  855. //
  856. // Get the HTTP Proxy server
  857. //
  858. GetPrivateProfileString(_T("Proxy"),
  859. _T("HTTP_Proxy_Server"),
  860. _T(""),
  861. szBufferForProxyAddressAndPort,
  862. StrBuffSize(szBufferForProxyAddressAndPort),
  863. FixedGlobals.ScriptName);
  864. ParseAddressAndPort( szBufferForProxyAddressAndPort, szAddress, AS(szAddress), szPort, AS(szPort));
  865. lstrcpyn( GenSettings.szHttpProxyAddress, szAddress, AS(GenSettings.szHttpProxyAddress) );
  866. lstrcpyn( GenSettings.szHttpProxyPort, szPort, AS(GenSettings.szHttpProxyPort) );
  867. if( GenSettings.szHttpProxyAddress[0] != _T('\0') )
  868. {
  869. GenSettings.bUseProxyServer = TRUE;
  870. }
  871. else
  872. {
  873. GenSettings.bUseProxyServer = FALSE;
  874. }
  875. //
  876. // Get the Secure Proxy server
  877. //
  878. GetPrivateProfileString(_T("Proxy"),
  879. _T("Secure_Proxy_Server"),
  880. _T(""),
  881. szBufferForProxyAddressAndPort,
  882. StrBuffSize(szBufferForProxyAddressAndPort),
  883. FixedGlobals.ScriptName);
  884. ParseAddressAndPort( szBufferForProxyAddressAndPort, szAddress, AS(szAddress), szPort, AS(szAddress) );
  885. lstrcpyn( GenSettings.szSecureProxyAddress, szAddress, AS(GenSettings.szSecureProxyAddress) );
  886. lstrcpyn( GenSettings.szSecureProxyPort, szPort, AS(GenSettings.szSecureProxyPort) );
  887. //
  888. // Get the FTP Proxy server
  889. //
  890. GetPrivateProfileString(_T("Proxy"),
  891. _T("FTP_Proxy_Server"),
  892. _T(""),
  893. szBufferForProxyAddressAndPort,
  894. StrBuffSize(szBufferForProxyAddressAndPort),
  895. FixedGlobals.ScriptName);
  896. ParseAddressAndPort( szBufferForProxyAddressAndPort, szAddress, AS(szAddress), szPort, AS(szPort) );
  897. lstrcpyn( GenSettings.szFtpProxyAddress, szAddress, AS(GenSettings.szFtpProxyAddress) );
  898. lstrcpyn( GenSettings.szFtpProxyPort, szPort, AS(GenSettings.szFtpProxyPort) );
  899. //
  900. // Get the Gopher Proxy server
  901. //
  902. GetPrivateProfileString(_T("Proxy"),
  903. _T("Gopher_Proxy_Server"),
  904. _T(""),
  905. szBufferForProxyAddressAndPort,
  906. StrBuffSize(szBufferForProxyAddressAndPort),
  907. FixedGlobals.ScriptName);
  908. ParseAddressAndPort( szBufferForProxyAddressAndPort, szAddress, AS(szAddress), szPort, AS(szPort) );
  909. lstrcpyn( GenSettings.szGopherProxyAddress, szAddress, AS(GenSettings.szGopherProxyAddress) );
  910. lstrcpyn( GenSettings.szGopherProxyPort, szPort, AS(GenSettings.szGopherProxyPort) );
  911. //
  912. // Get the Socks Proxy server
  913. //
  914. GetPrivateProfileString(_T("Proxy"),
  915. _T("Socks_Proxy_Server"),
  916. _T(""),
  917. szBufferForProxyAddressAndPort,
  918. StrBuffSize(szBufferForProxyAddressAndPort),
  919. FixedGlobals.ScriptName);
  920. ParseAddressAndPort( szBufferForProxyAddressAndPort, szAddress, AS(szAddress), szPort, AS(szPort) );
  921. lstrcpyn( GenSettings.szSocksProxyAddress, szAddress, AS(GenSettings.szSocksProxyAddress) );
  922. lstrcpyn( GenSettings.szSocksProxyPort, szPort, AS(GenSettings.szSocksProxyPort) );
  923. GetPrivateProfileString(_T("Proxy"),
  924. _T("Proxy_Override"),
  925. _T(""),
  926. GenSettings.szProxyExceptions,
  927. StrBuffSize(GenSettings.szProxyExceptions),
  928. FixedGlobals.ScriptName);
  929. pLocalString = _tcsstr( GenSettings.szProxyExceptions, _T("<local>") );
  930. // Initialize the GenSettings Proxy Bypass boolean value...
  931. //
  932. GenSettings.bBypassProxyForLocalAddresses = FALSE;
  933. if( pLocalString != NULL )
  934. {
  935. TCHAR *pChar;
  936. TCHAR *pEndLocal;
  937. LPTSTR lpszExceptionBuffer;
  938. DWORD cbExceptionBufferLen;
  939. //
  940. // Remove the false entry, so it doesn't get added to the exception edit box
  941. //
  942. pEndLocal = pLocalString + lstrlen( _T("<local>") );
  943. //
  944. // Allocate the exception buffer...
  945. //
  946. cbExceptionBufferLen= lstrlen(pEndLocal)+1;
  947. lpszExceptionBuffer = MALLOC( cbExceptionBufferLen * sizeof(TCHAR) );
  948. if ( lpszExceptionBuffer )
  949. {
  950. GenSettings.bBypassProxyForLocalAddresses = TRUE;
  951. //
  952. // strcpy is undefined if source and dest overlap so I have to go through
  953. // an intermediate buffer
  954. //
  955. lstrcpyn( lpszExceptionBuffer, pEndLocal, cbExceptionBufferLen);
  956. lstrcpyn( pLocalString, lpszExceptionBuffer,
  957. AS(GenSettings.szProxyExceptions)-
  958. (int)(pLocalString-GenSettings.szProxyExceptions) );
  959. //
  960. // If the first or last char is a semicolon(;) then remove it.
  961. //
  962. pChar = GenSettings.szProxyExceptions;
  963. if( *pChar == _T(';') )
  964. {
  965. lstrcpyn( lpszExceptionBuffer, GenSettings.szProxyExceptions, cbExceptionBufferLen);
  966. pChar = lpszExceptionBuffer;
  967. pChar++;
  968. lstrcpyn( GenSettings.szProxyExceptions, pChar, AS(GenSettings.szProxyExceptions) );
  969. }
  970. pChar = GenSettings.szProxyExceptions + lstrlen( GenSettings.szProxyExceptions );
  971. pChar--;
  972. if( *pChar == _T(';') )
  973. {
  974. *pChar = _T('\0');
  975. }
  976. FREE( lpszExceptionBuffer );
  977. }
  978. }
  979. GetPrivateProfileString(_T("URL"),
  980. _T("Home_Page"),
  981. _T(""),
  982. GenSettings.szHomePage,
  983. StrBuffSize(GenSettings.szHomePage),
  984. FixedGlobals.ScriptName);
  985. GetPrivateProfileString(_T("URL"),
  986. _T("Help_Page"),
  987. _T(""),
  988. GenSettings.szHelpPage,
  989. StrBuffSize(GenSettings.szHelpPage),
  990. FixedGlobals.ScriptName);
  991. GetPrivateProfileString(_T("URL"),
  992. _T("Search_Page"),
  993. _T(""),
  994. GenSettings.szSearchPage,
  995. StrBuffSize(GenSettings.szSearchPage),
  996. FixedGlobals.ScriptName);
  997. ReadIeFavorites();
  998. }
  999. //----------------------------------------------------------------------------
  1000. //
  1001. // Function: ReadIeFavorites
  1002. //
  1003. // Purpose:
  1004. //
  1005. // Arguments: VOID
  1006. //
  1007. // Returns: VOID
  1008. //
  1009. //----------------------------------------------------------------------------
  1010. static VOID
  1011. ReadIeFavorites( VOID )
  1012. {
  1013. const TCHAR c_szTITLE[] = _T("Title");
  1014. const TCHAR c_szURL[] = _T("URL");
  1015. const INT c_nMAX_URLS = 1000;
  1016. INT i = 1;
  1017. TCHAR szTitle[MAX_INILINE_LEN + 1];
  1018. TCHAR szUrl[MAX_INILINE_LEN + 1];
  1019. TCHAR szNumberBuffer[10];
  1020. TCHAR szFavoriteFriendlyName[MAX_INILINE_LEN + 1];
  1021. TCHAR szFavoriteAddress[MAX_INILINE_LEN + 1];
  1022. TCHAR *pszDotUrl;
  1023. HRESULT hrCat;
  1024. //
  1025. // We really always should hit the break to exit the loop. The max count
  1026. // is just to avoid a infinite loop for some strange reason.
  1027. //
  1028. while( i < c_nMAX_URLS )
  1029. {
  1030. _itot( i, szNumberBuffer, 10 );
  1031. i++;
  1032. lstrcpyn( szTitle, c_szTITLE, AS(szTitle) );
  1033. hrCat=StringCchCat( szTitle, AS(szTitle), szNumberBuffer);
  1034. lstrcpyn( szUrl, c_szURL, AS(szUrl) );
  1035. hrCat=StringCchCat( szUrl, AS(szUrl), szNumberBuffer );
  1036. GetPrivateProfileString( c_szFAVORITESEX,
  1037. szTitle,
  1038. _T(""),
  1039. szFavoriteFriendlyName,
  1040. StrBuffSize( szFavoriteFriendlyName ),
  1041. FixedGlobals.ScriptName );
  1042. if( szFavoriteFriendlyName[0] != _T('\0') )
  1043. {
  1044. //
  1045. // Strip off the .url portion of the title
  1046. //
  1047. pszDotUrl = _tcsstr( szFavoriteFriendlyName, _T(".url") );
  1048. if( pszDotUrl != NULL )
  1049. {
  1050. *pszDotUrl = _T('\0');
  1051. }
  1052. else
  1053. {
  1054. // skip it if it is a malformed title
  1055. continue;
  1056. }
  1057. GetPrivateProfileString( c_szFAVORITESEX,
  1058. szUrl,
  1059. _T(""),
  1060. szFavoriteAddress,
  1061. StrBuffSize( szFavoriteAddress ),
  1062. FixedGlobals.ScriptName );
  1063. AddNameToNameList( &GenSettings.Favorites,
  1064. szFavoriteFriendlyName );
  1065. AddNameToNameList( &GenSettings.Favorites,
  1066. szFavoriteAddress );
  1067. }
  1068. else
  1069. {
  1070. break;
  1071. }
  1072. }
  1073. }
  1074. //----------------------------------------------------------------------------
  1075. //
  1076. // Function: ParseAddressAndPort
  1077. //
  1078. // Purpose: LPTCSTR pszBufferForProxyAddressAndPort - the string to parse the
  1079. // web address and port from
  1080. // LPTSTR pszAddress - web address returned in this string
  1081. // DWORD cbAddressLen - length of adress buffer
  1082. // LPTSTR pszPort - web port returned in this string
  1083. // DWORD cbPortLen - length of port buffer
  1084. //
  1085. // Arguments: VOID
  1086. //
  1087. // Returns: VOID
  1088. //
  1089. //----------------------------------------------------------------------------
  1090. static VOID
  1091. ParseAddressAndPort( LPTSTR pszBufferForProxyAddressAndPort,
  1092. LPTSTR pszAddress,
  1093. DWORD cbAddressLen,
  1094. LPTSTR pszPort,
  1095. DWORD cbPortLen)
  1096. {
  1097. INT i;
  1098. INT iStrLen;
  1099. BOOL bColonFound = FALSE;
  1100. lstrcpyn( pszAddress, _T(""), cbAddressLen);
  1101. lstrcpyn( pszPort, _T(""), cbPortLen);
  1102. iStrLen = lstrlen( pszBufferForProxyAddressAndPort );
  1103. for( i = 0; i < iStrLen; i++ )
  1104. {
  1105. if( pszBufferForProxyAddressAndPort[i] == _T(':') )
  1106. {
  1107. //
  1108. // We have found the colon(:) separating the address and the port
  1109. // if the next char is a digit. This prevents the colon in
  1110. // http://www.someaddress.com from looking like the port.
  1111. //
  1112. if( _istdigit( pszBufferForProxyAddressAndPort[i + 1] ) )
  1113. {
  1114. bColonFound = TRUE;
  1115. break;
  1116. }
  1117. }
  1118. }
  1119. if( bColonFound )
  1120. {
  1121. LPTSTR pPortSection;
  1122. pszBufferForProxyAddressAndPort[i] = _T('\0');
  1123. pPortSection = &( pszBufferForProxyAddressAndPort[i + 1] );
  1124. lstrcpyn( pszAddress, pszBufferForProxyAddressAndPort, cbAddressLen);
  1125. lstrcpyn( pszPort, pPortSection, cbPortLen);
  1126. }
  1127. else
  1128. {
  1129. //
  1130. // it doesn't contain a colon so it doesn't have a port, the whole
  1131. // string is the address
  1132. //
  1133. lstrcpyn( pszAddress, pszBufferForProxyAddressAndPort, cbAddressLen);
  1134. }
  1135. }