[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.

svn path=/trunk/; revision=70309
This commit is contained in:
Eric Kohl 2015-12-08 15:57:47 +00:00
parent 4ed942b77e
commit 75fe25183f
2 changed files with 105 additions and 71 deletions

View file

@ -56,6 +56,8 @@ typedef struct _SETUPDATA
DWORD TimeZoneIndex;
DWORD DisableAutoDaylightTimeSet;
LCID LocaleID;
HINF hUnattendedInf;
} SETUPDATA, *PSETUPDATA;
typedef struct _ADMIN_INFO
@ -67,7 +69,6 @@ typedef struct _ADMIN_INFO
extern HINSTANCE hDllInstance;
extern HINF hSysSetupInf;
extern SETUPDATA SetupData;
extern ADMIN_INFO AdminInfo;
BOOL RegisterTypeLibraries (HINF hinf, LPCWSTR szSection);

View file

@ -45,10 +45,6 @@ typedef struct _REGISTRATIONDATA
PVOID DefaultContext;
} REGISTRATIONDATA, *PREGISTRATIONDATA;
/* GLOBALS ******************************************************************/
SETUPDATA SetupData;
/* FUNCTIONS ****************************************************************/
@ -224,16 +220,20 @@ WelcomeDlgProc(HWND hwndDlg,
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 @@ WelcomeDlgProc(HWND hwndDlg,
SendDlgItemMessage(hwndDlg,
IDC_WELCOMETITLE,
WM_SETFONT,
(WPARAM)SetupData->hTitleFont,
(WPARAM)pSetupData->hTitleFont,
(LPARAM)TRUE);
}
break;
@ -268,7 +268,7 @@ WelcomeDlgProc(HWND hwndDlg,
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 @@ WelcomeDlgProc(HWND hwndDlg,
break;
case PSN_WIZBACK:
SetupData.UnattendSetup = FALSE;
pSetupData->UnattendSetup = FALSE;
break;
default:
@ -303,11 +303,17 @@ AckPageDlgProc(HWND hwndDlg,
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 @@ AckPageDlgProc(HWND hwndDlg,
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 @@ AckPageDlgProc(HWND hwndDlg,
break;
case PSN_WIZBACK:
SetupData.UnattendSetup = FALSE;
pSetupData->UnattendSetup = FALSE;
break;
default:
@ -450,11 +456,17 @@ OwnerPageDlgProc(HWND hwndDlg,
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 @@ OwnerPageDlgProc(HWND hwndDlg,
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 @@ OwnerPageDlgProc(HWND hwndDlg,
}
case PSN_WIZBACK:
SetupData.UnattendSetup = FALSE;
pSetupData->UnattendSetup = FALSE;
break;
default:
@ -661,6 +673,9 @@ ComputerPageDlgProc(HWND hwndDlg,
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 @@ ComputerPageDlgProc(HWND hwndDlg,
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 @@ ComputerPageDlgProc(HWND hwndDlg,
/* Set focus to computer name */
SetFocus(GetDlgItem(hwndDlg, IDC_COMPUTERNAME));
if (SetupData.UnattendSetup)
if (pSetupData->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);
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 @@ ComputerPageDlgProc(HWND hwndDlg,
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 @@ ComputerPageDlgProc(HWND hwndDlg,
break;
case PSN_WIZBACK:
SetupData.UnattendSetup = FALSE;
pSetupData->UnattendSetup = FALSE;
break;
default:
@ -2091,8 +2109,9 @@ FinishDlgProc(HWND hwndDlg,
}
BOOL
ProcessUnattendInf(HINF hUnattendedInf)
VOID
ProcessUnattendInf(
PSETUPDATA pSetupData)
{
INFCONTEXT InfContext;
WCHAR szName[256];
@ -2100,13 +2119,13 @@ ProcessUnattendInf(HINF hUnattendedInf)
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,25 +2135,26 @@ ProcessUnattendInf(HINF hUnattendedInf)
&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;
return;
}
if (!SetupFindFirstLineW(hUnattendedInf,
pSetupData->UnattendSetup = TRUE;
if (!SetupFindFirstLineW(pSetupData->hUnattendedInf,
L"Unattend",
NULL,
&InfContext))
{
DPRINT1("Error: SetupFindFirstLine failed %d\n", GetLastError());
return FALSE;
return;
}
do
{
if (!SetupGetStringFieldW(&InfContext,
@ -2144,7 +2164,7 @@ ProcessUnattendInf(HINF hUnattendedInf)
&LineLength))
{
DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError());
return FALSE;
return;
}
if (!SetupGetStringFieldW(&InfContext,
@ -2154,62 +2174,63 @@ ProcessUnattendInf(HINF hUnattendedInf)
&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)
if ((sizeof(pSetupData->OwnerName) / sizeof(TCHAR)) > LineLength)
{
wcscpy(SetupData.OwnerName, szValue);
wcscpy(pSetupData->OwnerName, szValue);
}
}
else if (!wcscmp(szName, L"OrgName"))
{
if ((sizeof(SetupData.OwnerOrganization) / sizeof(WCHAR)) > LineLength)
if ((sizeof(pSetupData->OwnerOrganization) / sizeof(WCHAR)) > LineLength)
{
wcscpy(SetupData.OwnerOrganization, szValue);
wcscpy(pSetupData->OwnerOrganization, szValue);
}
}
else if (!wcscmp(szName, L"ComputerName"))
{
if ((sizeof(SetupData.ComputerName) / sizeof(WCHAR)) > LineLength)
if ((sizeof(pSetupData->ComputerName) / sizeof(WCHAR)) > LineLength)
{
wcscpy(SetupData.ComputerName, szValue);
wcscpy(pSetupData->ComputerName, szValue);
}
}
else if (!wcscmp(szName, L"AdminPassword"))
{
if ((sizeof(SetupData.AdminPassword) / sizeof(WCHAR)) > LineLength)
if ((sizeof(pSetupData->AdminPassword) / sizeof(WCHAR)) > LineLength)
{
wcscpy(SetupData.AdminPassword, szValue);
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 @@ ProcessUnattendInf(HINF hUnattendedInf)
&hKey) != ERROR_SUCCESS)
{
DPRINT1("Error: failed to open HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce\n");
return TRUE;
return;
}
if (SetupFindFirstLineW(hUnattendedInf,
if (SetupFindFirstLineW(pSetupData->hUnattendedInf,
L"GuiRunOnce",
NULL,
&InfContext))
@ -2258,7 +2278,6 @@ ProcessUnattendInf(HINF hUnattendedInf)
}
RegCloseKey(hKey);
return TRUE;
}
/*
@ -2308,10 +2327,10 @@ GetRosInstallCD(WCHAR *pwszPath, DWORD cchPathMax)
VOID
ProcessUnattendSetup(VOID)
ProcessUnattendSetup(
PSETUPDATA pSetupData)
{
WCHAR szPath[MAX_PATH];
HINF hUnattendedInf;
DWORD dwLength;
if (!GetRosInstallCD(szPath, MAX_PATH))
@ -2331,15 +2350,13 @@ ProcessUnattendSetup(VOID)
wcscat(szPath, L"reactos\\unattend.inf");
hUnattendedInf = SetupOpenInfFileW(szPath,
NULL,
INF_STYLE_OLDNT,
NULL);
if (hUnattendedInf != INVALID_HANDLE_VALUE)
pSetupData->hUnattendedInf = SetupOpenInfFileW(szPath,
NULL,
INF_STYLE_OLDNT,
NULL);
if (pSetupData->hUnattendedInf != INVALID_HANDLE_VALUE)
{
SetupData.UnattendSetup = ProcessUnattendInf(hUnattendedInf);
SetupCloseInfFile(hUnattendedInf);
ProcessUnattendInf(pSetupData);
}
}
@ -2353,17 +2370,29 @@ InstallWizard(VOID)
UINT nPages = 0;
HWND hWnd;
MSG msg;
PSETUPDATA pSetupData = NULL;
/* Clear setup data */
ZeroMemory(&SetupData, sizeof(SETUPDATA));
/* 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;
}
ProcessUnattendSetup();
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 @@ InstallWizard(VOID)
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 @@ InstallWizard(VOID)
}
}
DeleteObject(SetupData.hTitleFont);
if (pSetupData->hUnattendedInf != INVALID_HANDLE_VALUE)
SetupCloseInfFile(pSetupData->hUnattendedInf);
DeleteObject(pSetupData->hTitleFont);
HeapFree(GetProcessHeap(), 0, pSetupData);
}
/* EOF */