Author: ekohl Date: Tue Dec 8 15:57:47 2015 New Revision: 70309
URL: http://svn.reactos.org/svn/reactos?rev=70309&view=rev Log: [SYSSETUP] - Get rid of the global SetupData variable. Allocate the setup data struct from heap instead and pass its pointer to all wizard pages. - Keep the setup data pointer in all wizard pages where it is needed. - Keep the handle to the unattended.inf file open as long as the setup wizard exists.
Modified: trunk/reactos/dll/win32/syssetup/globals.h trunk/reactos/dll/win32/syssetup/wizard.c
Modified: trunk/reactos/dll/win32/syssetup/globals.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/syssetup/globals.... ============================================================================== --- trunk/reactos/dll/win32/syssetup/globals.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/syssetup/globals.h [iso-8859-1] Tue Dec 8 15:57:47 2015 @@ -56,6 +56,8 @@ DWORD TimeZoneIndex; DWORD DisableAutoDaylightTimeSet; LCID LocaleID; + + HINF hUnattendedInf; } SETUPDATA, *PSETUPDATA;
typedef struct _ADMIN_INFO @@ -67,7 +69,6 @@
extern HINSTANCE hDllInstance; extern HINF hSysSetupInf; -extern SETUPDATA SetupData; extern ADMIN_INFO AdminInfo;
BOOL RegisterTypeLibraries (HINF hinf, LPCWSTR szSection);
Modified: trunk/reactos/dll/win32/syssetup/wizard.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/syssetup/wizard.c... ============================================================================== --- trunk/reactos/dll/win32/syssetup/wizard.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/syssetup/wizard.c [iso-8859-1] Tue Dec 8 15:57:47 2015 @@ -45,10 +45,6 @@ PVOID DefaultContext; } REGISTRATIONDATA, *PREGISTRATIONDATA;
-/* GLOBALS ******************************************************************/ - -SETUPDATA SetupData; -
/* FUNCTIONS ****************************************************************/
@@ -224,16 +220,20 @@ WPARAM wParam, LPARAM lParam) { + PSETUPDATA pSetupData; + + pSetupData = (PSETUPDATA)GetWindowLongPtr(hwndDlg, DWLP_USER); + switch (uMsg) { case WM_INITDIALOG: { - PSETUPDATA SetupData; HWND hwndControl; DWORD dwStyle;
/* Get pointer to the global setup data */ - SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam; + pSetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam; + SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pSetupData);
hwndControl = GetParent(hwndDlg);
@@ -253,7 +253,7 @@ SendDlgItemMessage(hwndDlg, IDC_WELCOMETITLE, WM_SETFONT, - (WPARAM)SetupData->hTitleFont, + (WPARAM)pSetupData->hTitleFont, (LPARAM)TRUE); } break; @@ -268,7 +268,7 @@ case PSN_SETACTIVE: /* Enable the Next button */ PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT); - if (SetupData.UnattendSetup) + if (pSetupData->UnattendSetup) { SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_ACKPAGE); return TRUE; @@ -276,7 +276,7 @@ break;
case PSN_WIZBACK: - SetupData.UnattendSetup = FALSE; + pSetupData->UnattendSetup = FALSE; break;
default: @@ -303,11 +303,17 @@ PWCHAR Projects; PWCHAR End, CurrentProject; INT ProjectsSize, ProjectsCount; + PSETUPDATA pSetupData; + + pSetupData = (PSETUPDATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
switch (uMsg) { case WM_INITDIALOG: { + pSetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam; + SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pSetupData); + Projects = NULL; ProjectsSize = 256; do @@ -370,7 +376,7 @@ case PSN_SETACTIVE: /* Enable the Back and Next buttons */ PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT); - if (SetupData.UnattendSetup) + if (pSetupData->UnattendSetup) { SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_LOCALEPAGE); return TRUE; @@ -378,7 +384,7 @@ break;
case PSN_WIZBACK: - SetupData.UnattendSetup = FALSE; + pSetupData->UnattendSetup = FALSE; break;
default: @@ -450,11 +456,17 @@ WCHAR Title[64]; WCHAR ErrorName[256]; LPNMHDR lpnm; + PSETUPDATA pSetupData; + + pSetupData = (PSETUPDATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
switch (uMsg) { case WM_INITDIALOG: { + pSetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam; + SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pSetupData); + /* set a localized ('Owner') placeholder string as default */ if (LoadStringW(hDllInstance, IDS_MACHINE_OWNER_NAME, OwnerName, _countof(OwnerName))) { @@ -482,11 +494,11 @@ case PSN_SETACTIVE: /* Enable the Back and Next buttons */ PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT); - if (SetupData.UnattendSetup) + if (pSetupData->UnattendSetup) { - SendMessage(GetDlgItem(hwndDlg, IDC_OWNERNAME), WM_SETTEXT, 0, (LPARAM)SetupData.OwnerName); - SendMessage(GetDlgItem(hwndDlg, IDC_OWNERORGANIZATION), WM_SETTEXT, 0, (LPARAM)SetupData.OwnerOrganization); - if (WriteOwnerSettings(SetupData.OwnerName, SetupData.OwnerOrganization)) + SendMessage(GetDlgItem(hwndDlg, IDC_OWNERNAME), WM_SETTEXT, 0, (LPARAM)pSetupData->OwnerName); + SendMessage(GetDlgItem(hwndDlg, IDC_OWNERORGANIZATION), WM_SETTEXT, 0, (LPARAM)pSetupData->OwnerOrganization); + if (WriteOwnerSettings(pSetupData->OwnerName, pSetupData->OwnerOrganization)) { SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_COMPUTERPAGE); return TRUE; @@ -525,7 +537,7 @@ }
case PSN_WIZBACK: - SetupData.UnattendSetup = FALSE; + pSetupData->UnattendSetup = FALSE; break;
default: @@ -661,6 +673,9 @@ WCHAR Title[64]; WCHAR EmptyComputerName[256], NotMatchPassword[256], WrongPassword[256]; LPNMHDR lpnm; + PSETUPDATA pSetupData; + + pSetupData = (PSETUPDATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
if (0 == LoadStringW(hDllInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0]))) { @@ -670,6 +685,9 @@ switch (uMsg) { case WM_INITDIALOG: + pSetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam; + SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pSetupData); + /* Generate a new pseudo-random computer name */ GenerateComputerName(ComputerName);
@@ -683,17 +701,17 @@
/* Set focus to computer name */ SetFocus(GetDlgItem(hwndDlg, IDC_COMPUTERNAME)); - if (SetupData.UnattendSetup) - { - SendMessage(GetDlgItem(hwndDlg, IDC_COMPUTERNAME), WM_SETTEXT, 0, (LPARAM)SetupData.ComputerName); - SendMessage(GetDlgItem(hwndDlg, IDC_ADMINPASSWORD1), WM_SETTEXT, 0, (LPARAM)SetupData.AdminPassword); - SendMessage(GetDlgItem(hwndDlg, IDC_ADMINPASSWORD2), WM_SETTEXT, 0, (LPARAM)SetupData.AdminPassword); - WriteComputerSettings(SetupData.ComputerName, NULL); - SetAdministratorPassword(SetupData.AdminPassword); + if (pSetupData->UnattendSetup) + { + SendMessage(GetDlgItem(hwndDlg, IDC_COMPUTERNAME), WM_SETTEXT, 0, (LPARAM)pSetupData->ComputerName); + SendMessage(GetDlgItem(hwndDlg, IDC_ADMINPASSWORD1), WM_SETTEXT, 0, (LPARAM)pSetupData->AdminPassword); + SendMessage(GetDlgItem(hwndDlg, IDC_ADMINPASSWORD2), WM_SETTEXT, 0, (LPARAM)pSetupData->AdminPassword); + WriteComputerSettings(pSetupData->ComputerName, NULL); + SetAdministratorPassword(pSetupData->AdminPassword); }
/* Store the administrator account name as the default user name */ - WriteDefaultLogonData(SetupData.ComputerName); + WriteDefaultLogonData(pSetupData->ComputerName); break;
@@ -706,7 +724,7 @@ case PSN_SETACTIVE: /* Enable the Back and Next buttons */ PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT); - if (SetupData.UnattendSetup && WriteComputerSettings(SetupData.ComputerName, hwndDlg)) + if (pSetupData->UnattendSetup && WriteComputerSettings(pSetupData->ComputerName, hwndDlg)) { SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_DATETIMEPAGE); return TRUE; @@ -791,7 +809,7 @@ break;
case PSN_WIZBACK: - SetupData.UnattendSetup = FALSE; + pSetupData->UnattendSetup = FALSE; break;
default: @@ -2091,8 +2109,9 @@ }
-BOOL -ProcessUnattendInf(HINF hUnattendedInf) +VOID +ProcessUnattendInf( + PSETUPDATA pSetupData) { INFCONTEXT InfContext; WCHAR szName[256]; @@ -2100,13 +2119,13 @@ DWORD LineLength; HKEY hKey;
- if (!SetupFindFirstLineW(hUnattendedInf, + if (!SetupFindFirstLineW(pSetupData->hUnattendedInf, L"Unattend", L"UnattendSetupEnabled", &InfContext)) { DPRINT1("Error: Cant find UnattendSetupEnabled Key! %d\n", GetLastError()); - return FALSE; + return; }
if (!SetupGetStringFieldW(&InfContext, @@ -2116,24 +2135,25 @@ &LineLength)) { DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError()); - return FALSE; + return; }
if (wcscmp(szValue, L"yes") != 0) { DPRINT("Unattend setup was disabled by UnattendSetupEnabled key.\n"); - return FALSE; - } - - if (!SetupFindFirstLineW(hUnattendedInf, + return; + } + + pSetupData->UnattendSetup = TRUE; + + if (!SetupFindFirstLineW(pSetupData->hUnattendedInf, L"Unattend", NULL, &InfContext)) { DPRINT1("Error: SetupFindFirstLine failed %d\n", GetLastError()); - return FALSE; - } - + return; + }
do { @@ -2144,7 +2164,7 @@ &LineLength)) { DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError()); - return FALSE; + return; }
if (!SetupGetStringFieldW(&InfContext, @@ -2154,62 +2174,63 @@ &LineLength)) { DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError()); - return FALSE; + return; } DPRINT1("Name %S Value %S\n", szName, szValue); if (!wcscmp(szName, L"FullName")) { - if ((sizeof(SetupData.OwnerName) / sizeof(TCHAR)) > LineLength) - { - wcscpy(SetupData.OwnerName, szValue); + if ((sizeof(pSetupData->OwnerName) / sizeof(TCHAR)) > LineLength) + { + wcscpy(pSetupData->OwnerName, szValue); } } else if (!wcscmp(szName, L"OrgName")) { - if ((sizeof(SetupData.OwnerOrganization) / sizeof(WCHAR)) > LineLength) - { - wcscpy(SetupData.OwnerOrganization, szValue); + if ((sizeof(pSetupData->OwnerOrganization) / sizeof(WCHAR)) > LineLength) + { + wcscpy(pSetupData->OwnerOrganization, szValue); } } else if (!wcscmp(szName, L"ComputerName")) { - if ((sizeof(SetupData.ComputerName) / sizeof(WCHAR)) > LineLength) - { - wcscpy(SetupData.ComputerName, szValue); + if ((sizeof(pSetupData->ComputerName) / sizeof(WCHAR)) > LineLength) + { + wcscpy(pSetupData->ComputerName, szValue); } } else if (!wcscmp(szName, L"AdminPassword")) { - if ((sizeof(SetupData.AdminPassword) / sizeof(WCHAR)) > LineLength) - { - wcscpy(SetupData.AdminPassword, szValue); + if ((sizeof(pSetupData->AdminPassword) / sizeof(WCHAR)) > LineLength) + { + wcscpy(pSetupData->AdminPassword, szValue); } } else if (!wcscmp(szName, L"TimeZoneIndex")) { - SetupData.TimeZoneIndex = _wtoi(szValue); + pSetupData->TimeZoneIndex = _wtoi(szValue); } else if (!wcscmp(szName, L"DisableAutoDaylightTimeSet")) { - SetupData.DisableAutoDaylightTimeSet = _wtoi(szValue); + pSetupData->DisableAutoDaylightTimeSet = _wtoi(szValue); } else if (!wcscmp(szName, L"DisableVmwInst")) { if(!wcscmp(szValue, L"yes")) - SetupData.DisableVmwInst = 1; + pSetupData->DisableVmwInst = 1; else - SetupData.DisableVmwInst = 0; + pSetupData->DisableVmwInst = 0; } else if (!wcscmp(szName, L"DisableGeckoInst")) { if(!wcscmp(szValue, L"yes")) - SetupData.DisableGeckoInst = 1; + pSetupData->DisableGeckoInst = 1; else - SetupData.DisableGeckoInst = 0; + pSetupData->DisableGeckoInst = 0; }
} while (SetupFindNextLine(&InfContext, &InfContext)); + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", 0, @@ -2217,11 +2238,10 @@ &hKey) != ERROR_SUCCESS) { DPRINT1("Error: failed to open HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce\n"); - return TRUE; - } - - - if (SetupFindFirstLineW(hUnattendedInf, + return; + } + + if (SetupFindFirstLineW(pSetupData->hUnattendedInf, L"GuiRunOnce", NULL, &InfContext)) @@ -2258,7 +2278,6 @@ }
RegCloseKey(hKey); - return TRUE; }
/* @@ -2308,10 +2327,10 @@
VOID -ProcessUnattendSetup(VOID) +ProcessUnattendSetup( + PSETUPDATA pSetupData) { WCHAR szPath[MAX_PATH]; - HINF hUnattendedInf; DWORD dwLength;
if (!GetRosInstallCD(szPath, MAX_PATH)) @@ -2331,15 +2350,13 @@
wcscat(szPath, L"reactos\unattend.inf");
- hUnattendedInf = SetupOpenInfFileW(szPath, - NULL, - INF_STYLE_OLDNT, - NULL); - - if (hUnattendedInf != INVALID_HANDLE_VALUE) - { - SetupData.UnattendSetup = ProcessUnattendInf(hUnattendedInf); - SetupCloseInfFile(hUnattendedInf); + pSetupData->hUnattendedInf = SetupOpenInfFileW(szPath, + NULL, + INF_STYLE_OLDNT, + NULL); + if (pSetupData->hUnattendedInf != INVALID_HANDLE_VALUE) + { + ProcessUnattendInf(pSetupData); } }
@@ -2353,17 +2370,29 @@ UINT nPages = 0; HWND hWnd; MSG msg; - - /* Clear setup data */ - ZeroMemory(&SetupData, sizeof(SETUPDATA)); - - ProcessUnattendSetup(); + PSETUPDATA pSetupData = NULL; + + /* Allocate setup data */ + pSetupData = HeapAlloc(GetProcessHeap(), + HEAP_ZERO_MEMORY, + sizeof(SETUPDATA)); + if (pSetupData == NULL) + { + MessageBoxW(NULL, + L"Setup failed to allocate global data!", + L"ReactOS Setup", + MB_ICONERROR | MB_OK); + return; + } + + pSetupData->hUnattendedInf = INVALID_HANDLE_VALUE; + ProcessUnattendSetup(pSetupData);
/* Create the Welcome page */ psp.dwSize = sizeof(PROPSHEETPAGE); psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER; psp.hInstance = hDllInstance; - psp.lParam = (LPARAM)&SetupData; + psp.lParam = (LPARAM)pSetupData; psp.pfnDlgProc = WelcomeDlgProc; psp.pszTemplate = MAKEINTRESOURCE(IDD_WELCOMEPAGE); ahpsp[nPages++] = CreatePropertySheetPage(&psp); @@ -2438,7 +2467,7 @@ psh.pszbmHeader = MAKEINTRESOURCE(IDB_HEADER);
/* Create title font */ - SetupData.hTitleFont = CreateTitleFont(); + pSetupData->hTitleFont = CreateTitleFont();
/* Display the wizard */ hWnd = (HWND)PropertySheet(&psh); @@ -2453,7 +2482,11 @@ } }
- DeleteObject(SetupData.hTitleFont); + if (pSetupData->hUnattendedInf != INVALID_HANDLE_VALUE) + SetupCloseInfFile(pSetupData->hUnattendedInf); + + DeleteObject(pSetupData->hTitleFont); + HeapFree(GetProcessHeap(), 0, pSetupData); }
/* EOF */