diff --git a/base/setup/lib/setuplib.c b/base/setup/lib/setuplib.c index 5bd9fa4f034..cb48fd3fa36 100644 --- a/base/setup/lib/setuplib.c +++ b/base/setup/lib/setuplib.c @@ -500,7 +500,6 @@ InitPaths: ERROR_NUMBER LoadSetupInf( - OUT HINF* SetupInf, IN OUT PUSETUP_DATA pSetupData) { INFCONTEXT Context; @@ -514,17 +513,18 @@ LoadSetupInf( DPRINT("SetupInf path: '%S'\n", FileNameBuffer); - *SetupInf = SetupOpenInfFileExW(FileNameBuffer, - NULL, - /* INF_STYLE_WIN4 | */ INF_STYLE_OLDNT, - pSetupData->LanguageId, - &ErrorLine); + pSetupData->SetupInf = + SetupOpenInfFileExW(FileNameBuffer, + NULL, + /* INF_STYLE_WIN4 | */ INF_STYLE_OLDNT, + pSetupData->LanguageId, + &ErrorLine); - if (*SetupInf == INVALID_HANDLE_VALUE) + if (pSetupData->SetupInf == INVALID_HANDLE_VALUE) return ERROR_LOAD_TXTSETUPSIF; /* Open 'Version' section */ - if (!SetupFindFirstLineW(*SetupInf, L"Version", L"Signature", &Context)) + if (!SetupFindFirstLineW(pSetupData->SetupInf, L"Version", L"Signature", &Context)) return ERROR_CORRUPT_TXTSETUPSIF; /* Get pointer 'Signature' key */ @@ -541,7 +541,7 @@ LoadSetupInf( INF_FreeData(Value); /* Open 'DiskSpaceRequirements' section */ - if (!SetupFindFirstLineW(*SetupInf, L"DiskSpaceRequirements", L"FreeSysPartDiskSpace", &Context)) + if (!SetupFindFirstLineW(pSetupData->SetupInf, L"DiskSpaceRequirements", L"FreeSysPartDiskSpace", &Context)) return ERROR_CORRUPT_TXTSETUPSIF; pSetupData->RequiredPartitionDiskSpace = ~0; @@ -553,12 +553,48 @@ LoadSetupInf( pSetupData->RequiredPartitionDiskSpace = (ULONG)IntValue; // - // TODO: Support "SetupSourceDevice" and "SetupSourcePath" in txtsetup.sif + // Support "SetupSourceDevice" and "SetupSourcePath" in txtsetup.sif // See CORE-9023 + // Support for that should also be added in setupldr. // + /* Update the Setup Source paths */ + if (SetupFindFirstLineW(pSetupData->SetupInf, L"SetupData", L"SetupSourceDevice", &Context)) + { + /* + * Get optional pointer 'SetupSourceDevice' key, its presence + * will dictate whether we also need 'SetupSourcePath'. + */ + if (INF_GetData(&Context, NULL, &Value)) + { + /* Free the old source root path string and create the new one */ + RtlFreeUnicodeString(&pSetupData->SourceRootPath); + RtlCreateUnicodeString(&pSetupData->SourceRootPath, Value); + INF_FreeData(Value); + + if (!SetupFindFirstLineW(pSetupData->SetupInf, L"SetupData", L"SetupSourcePath", &Context)) + { + /* The 'SetupSourcePath' value is mandatory! */ + return ERROR_CORRUPT_TXTSETUPSIF; + } + + /* Get pointer 'SetupSourcePath' key */ + if (!INF_GetData(&Context, NULL, &Value)) + { + /* The 'SetupSourcePath' value is mandatory! */ + return ERROR_CORRUPT_TXTSETUPSIF; + } + + /* Free the old source path string and create the new one */ + RtlFreeUnicodeString(&pSetupData->SourceRootDir); + RtlCreateUnicodeString(&pSetupData->SourceRootDir, Value); + INF_FreeData(Value); + } + } + /* Search for 'DefaultPath' in the 'SetupData' section */ - if (SetupFindFirstLineW(*SetupInf, L"SetupData", L"DefaultPath", &Context)) + pSetupData->InstallationDirectory[0] = 0; + if (SetupFindFirstLineW(pSetupData->SetupInf, L"SetupData", L"DefaultPath", &Context)) { /* Get pointer 'DefaultPath' key */ if (!INF_GetData(&Context, NULL, &Value)) @@ -574,6 +610,175 @@ LoadSetupInf( return ERROR_SUCCESS; } +NTSTATUS +InitDestinationPaths( + IN OUT PUSETUP_DATA pSetupData, + IN PCWSTR InstallationDir, + IN PDISKENTRY DiskEntry, // FIXME: HACK! + IN PPARTENTRY PartEntry) // FIXME: HACK! +{ + WCHAR PathBuffer[MAX_PATH]; + + // + // TODO: Check return status values of the functions! + // + + /* Create 'pSetupData->DestinationRootPath' string */ + RtlFreeUnicodeString(&pSetupData->DestinationRootPath); + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"\\Device\\Harddisk%lu\\Partition%lu\\", + DiskEntry->DiskNumber, + PartEntry->PartitionNumber); + RtlCreateUnicodeString(&pSetupData->DestinationRootPath, PathBuffer); + DPRINT("DestinationRootPath: %wZ\n", &pSetupData->DestinationRootPath); + +/** Equivalent of 'NTOS_INSTALLATION::SystemArcPath' **/ + /* Create 'pSetupData->DestinationArcPath' */ + RtlFreeUnicodeString(&pSetupData->DestinationArcPath); + RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"multi(0)disk(0)rdisk(%lu)partition(%lu)\\", + DiskEntry->BiosDiskNumber, + PartEntry->PartitionNumber); + ConcatPaths(PathBuffer, ARRAYSIZE(PathBuffer), 1, InstallationDir); + RtlCreateUnicodeString(&pSetupData->DestinationArcPath, PathBuffer); + +/** Equivalent of 'NTOS_INSTALLATION::SystemNtPath' **/ + /* Create 'pSetupData->DestinationPath' string */ + RtlFreeUnicodeString(&pSetupData->DestinationPath); + CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2, + pSetupData->DestinationRootPath.Buffer, InstallationDir); + RtlCreateUnicodeString(&pSetupData->DestinationPath, PathBuffer); + +/** Equivalent of 'NTOS_INSTALLATION::PathComponent' **/ + // FIXME: This is only temporary!! Must be removed later! + /***/RtlCreateUnicodeString(&pSetupData->InstallPath, InstallationDir);/***/ + + return STATUS_SUCCESS; +} + +// NTSTATUS +ERROR_NUMBER +InitializeSetup( + IN OUT PUSETUP_DATA pSetupData, + IN ULONG InitPhase) +{ + if (InitPhase == 0) + { + RtlZeroMemory(pSetupData, sizeof(*pSetupData)); + + // pSetupData->ComputerList = NULL; + // pSetupData->DisplayList = NULL; + // pSetupData->KeyboardList = NULL; + // pSetupData->LayoutList = NULL; + // pSetupData->LanguageList = NULL; + + /* Initialize global unicode strings */ + RtlInitUnicodeString(&pSetupData->SourcePath, NULL); + RtlInitUnicodeString(&pSetupData->SourceRootPath, NULL); + RtlInitUnicodeString(&pSetupData->SourceRootDir, NULL); + RtlInitUnicodeString(&pSetupData->DestinationArcPath, NULL); + RtlInitUnicodeString(&pSetupData->DestinationPath, NULL); + RtlInitUnicodeString(&pSetupData->DestinationRootPath, NULL); + RtlInitUnicodeString(&pSetupData->SystemRootPath, NULL); + + // FIXME: This is only temporary!! Must be removed later! + /***/RtlInitUnicodeString(&pSetupData->InstallPath, NULL);/***/ + + // + // TODO: Load and start SetupDD, and ask it for the information + // + + return ERROR_SUCCESS; + } + else + if (InitPhase == 1) + { + ERROR_NUMBER Error; + NTSTATUS Status; + + /* Get the source path and source root path */ + // + // NOTE: Sometimes the source path may not be in SystemRoot !! + // (and this is the case when using the 1st-stage GUI setup!) + // + Status = GetSourcePaths(&pSetupData->SourcePath, + &pSetupData->SourceRootPath, + &pSetupData->SourceRootDir); + if (!NT_SUCCESS(Status)) + { + DPRINT1("GetSourcePaths() failed (Status 0x%08lx)", Status); + return ERROR_NO_SOURCE_DRIVE; + } + /* + * Example of output: + * SourcePath: '\Device\CdRom0\I386' + * SourceRootPath: '\Device\CdRom0' + * SourceRootDir: '\I386' + */ + DPRINT1("SourcePath (1): '%wZ'\n", &pSetupData->SourcePath); + DPRINT1("SourceRootPath (1): '%wZ'\n", &pSetupData->SourceRootPath); + DPRINT1("SourceRootDir (1): '%wZ'\n", &pSetupData->SourceRootDir); + + /* Load 'txtsetup.sif' from the installation media */ + Error = LoadSetupInf(pSetupData); + if (Error != ERROR_SUCCESS) + { + DPRINT1("LoadSetupInf() failed (Error 0x%lx)", Error); + return Error; + } + DPRINT1("SourcePath (2): '%wZ'\n", &pSetupData->SourcePath); + DPRINT1("SourceRootPath (2): '%wZ'\n", &pSetupData->SourceRootPath); + DPRINT1("SourceRootDir (2): '%wZ'\n", &pSetupData->SourceRootDir); + + return ERROR_SUCCESS; + } + + return ERROR_SUCCESS; +} + +VOID +FinishSetup( + IN OUT PUSETUP_DATA pSetupData) +{ + /* Destroy the computer settings list */ + if (pSetupData->ComputerList != NULL) + { + DestroyGenericList(pSetupData->ComputerList, TRUE); + pSetupData->ComputerList = NULL; + } + + /* Destroy the display settings list */ + if (pSetupData->DisplayList != NULL) + { + DestroyGenericList(pSetupData->DisplayList, TRUE); + pSetupData->DisplayList = NULL; + } + + /* Destroy the keyboard settings list */ + if (pSetupData->KeyboardList != NULL) + { + DestroyGenericList(pSetupData->KeyboardList, TRUE); + pSetupData->KeyboardList = NULL; + } + + /* Destroy the keyboard layout list */ + if (pSetupData->LayoutList != NULL) + { + DestroyGenericList(pSetupData->LayoutList, TRUE); + pSetupData->LayoutList = NULL; + } + + /* Destroy the languages list */ + if (pSetupData->LanguageList != NULL) + { + DestroyGenericList(pSetupData->LanguageList, FALSE); + pSetupData->LanguageList = NULL; + } + + /* Close the Setup INF */ + SetupCloseInfFile(pSetupData->SetupInf); +} + /* * SIDEEFFECTS * Calls RegInitializeRegistry diff --git a/base/setup/lib/setuplib.h b/base/setup/lib/setuplib.h index 46c42f72a7a..a885d6d09d6 100644 --- a/base/setup/lib/setuplib.h +++ b/base/setup/lib/setuplib.h @@ -55,8 +55,16 @@ extern HANDLE ProcessHeap; /* TYPEDEFS *****************************************************************/ +struct _USETUP_DATA; + typedef struct _USETUP_DATA { +/* Setup INFs *****/ + HINF SetupInf; + +/* Installation *****/ + PVOID SetupFileQueue; // HSPFILEQ + /* SOURCE Paths *****/ UNICODE_STRING SourceRootPath; UNICODE_STRING SourceRootDir; @@ -79,17 +87,28 @@ typedef struct _USETUP_DATA UNICODE_STRING SystemRootPath; /* Path to the installation directory inside the ReactOS boot partition */ - UNICODE_STRING DestinationPath; /** Equivalent of 'NTOS_INSTALLATION::SystemNtPath' **/ UNICODE_STRING DestinationArcPath; /** Equivalent of 'NTOS_INSTALLATION::SystemArcPath' **/ + UNICODE_STRING DestinationPath; /** Equivalent of 'NTOS_INSTALLATION::SystemNtPath' **/ UNICODE_STRING DestinationRootPath; + // FIXME: This is only temporary!! Must be removed later! + UNICODE_STRING InstallPath; + LONG DestinationDiskNumber; LONG DestinationPartitionNumber; - LONG MBRInstallType; + LONG MBRInstallType; LONG FormatPartition; LONG AutoPartition; +/* Settings lists *****/ + PGENERIC_LIST ComputerList; + PGENERIC_LIST DisplayList; + PGENERIC_LIST KeyboardList; + PGENERIC_LIST LayoutList; + PGENERIC_LIST LanguageList; + +/* Other stuff *****/ WCHAR LocaleID[9]; LANGID LanguageId; @@ -119,7 +138,23 @@ GetSourcePaths( ERROR_NUMBER LoadSetupInf( - OUT HINF* SetupInf, + IN OUT PUSETUP_DATA pSetupData); + +NTSTATUS +InitDestinationPaths( + IN OUT PUSETUP_DATA pSetupData, + IN PCWSTR InstallationDir, + IN PDISKENTRY DiskEntry, // FIXME: HACK! + IN PPARTENTRY PartEntry); // FIXME: HACK! + +// NTSTATUS +ERROR_NUMBER +InitializeSetup( + IN OUT PUSETUP_DATA pSetupData, + IN ULONG InitPhase); + +VOID +FinishSetup( IN OUT PUSETUP_DATA pSetupData); diff --git a/base/setup/reactos/drivepage.c b/base/setup/reactos/drivepage.c index b8bc07f3ced..b58557cf1ee 100644 --- a/base/setup/reactos/drivepage.c +++ b/base/setup/reactos/drivepage.c @@ -70,7 +70,7 @@ MoreOptDlgProc(HWND hwndDlg, case IDOK: SendMessage(GetDlgItem(hwndDlg, IDC_PATH), WM_GETTEXT, - (WPARAM)sizeof(pSetupData->USetupData.InstallationDirectory) / sizeof(TCHAR), + (WPARAM)ARRAYSIZE(pSetupData->USetupData.InstallationDirectory), (LPARAM)pSetupData->USetupData.InstallationDirectory); EndDialog(hwndDlg, IDOK); diff --git a/base/setup/reactos/reactos.c b/base/setup/reactos/reactos.c index 7bc0581b9c7..261d5b2d4bc 100644 --- a/base/setup/reactos/reactos.c +++ b/base/setup/reactos/reactos.c @@ -555,16 +555,16 @@ DeviceDlgProc( SetWindowLongPtrW(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pSetupData); hList = GetDlgItem(hwndDlg, IDC_COMPUTER); - InitGenericComboList(hList, pSetupData->ComputerList, GetSettingDescription); + InitGenericComboList(hList, pSetupData->USetupData.ComputerList, GetSettingDescription); hList = GetDlgItem(hwndDlg, IDC_DISPLAY); - InitGenericComboList(hList, pSetupData->DisplayList, GetSettingDescription); + InitGenericComboList(hList, pSetupData->USetupData.DisplayList, GetSettingDescription); hList = GetDlgItem(hwndDlg, IDC_KEYBOARD); - InitGenericComboList(hList, pSetupData->KeyboardList, GetSettingDescription); + InitGenericComboList(hList, pSetupData->USetupData.KeyboardList, GetSettingDescription); // hList = GetDlgItem(hwndDlg, IDC_KEYBOARD_LAYOUT); - // InitGenericComboList(hList, pSetupData->LayoutList, GetSettingDescription); + // InitGenericComboList(hList, pSetupData->USetupData.LayoutList, GetSettingDescription); break; } @@ -808,11 +808,11 @@ BOOL LoadSetupData( /* Load the hardware, language and keyboard layout lists */ - pSetupData->ComputerList = CreateComputerTypeList(pSetupData->SetupInf); - pSetupData->DisplayList = CreateDisplayDriverList(pSetupData->SetupInf); - pSetupData->KeyboardList = CreateKeyboardDriverList(pSetupData->SetupInf); + pSetupData->USetupData.ComputerList = CreateComputerTypeList(pSetupData->USetupData.SetupInf); + pSetupData->USetupData.DisplayList = CreateDisplayDriverList(pSetupData->USetupData.SetupInf); + pSetupData->USetupData.KeyboardList = CreateKeyboardDriverList(pSetupData->USetupData.SetupInf); - pSetupData->LanguageList = CreateLanguageList(pSetupData->SetupInf, pSetupData->DefaultLanguage); + pSetupData->USetupData.LanguageList = CreateLanguageList(pSetupData->USetupData.SetupInf, pSetupData->DefaultLanguage); pSetupData->PartitionList = CreatePartitionList(); @@ -826,7 +826,7 @@ BOOL LoadSetupData( wcscpy(pSetupData->DefaultLanguage, pSetupData->USetupData.LocaleID); pSetupData->USetupData.LanguageId = (LANGID)(wcstol(pSetupData->SelectedLanguageId, NULL, 16) & 0xFFFF); - pSetupData->LayoutList = CreateKeyboardLayoutList(pSetupData->SetupInf, pSetupData->SelectedLanguageId, pSetupData->DefaultKBLayout); + pSetupData->USetupData.LayoutList = CreateKeyboardLayoutList(pSetupData->USetupData.SetupInf, pSetupData->SelectedLanguageId, pSetupData->DefaultKBLayout); #if 0 // get default for keyboard and language @@ -834,7 +834,7 @@ BOOL LoadSetupData( pSetupData->DefaultLang = -1; // TODO: get defaults from underlaying running system - if (SetupFindFirstLine(pSetupData->SetupInf, _T("NLS"), _T("DefaultLayout"), &InfContext)) + if (SetupFindFirstLine(pSetupData->USetupData.SetupInf, _T("NLS"), _T("DefaultLayout"), &InfContext)) { SetupGetStringField(&InfContext, 1, tmp, ARRAYSIZE(tmp), &LineLength); for (Count = 0; Count < pSetupData->KbLayoutCount; Count++) @@ -847,7 +847,7 @@ BOOL LoadSetupData( } } - if (SetupFindFirstLine(pSetupData->SetupInf, _T("NLS"), _T("DefaultLanguage"), &InfContext)) + if (SetupFindFirstLine(pSetupData->USetupData.SetupInf, _T("NLS"), _T("DefaultLanguage"), &InfContext)) { SetupGetStringField(&InfContext, 1, tmp, ARRAYSIZE(tmp), &LineLength); for (Count = 0; Count < pSetupData->LangCount; Count++) @@ -948,7 +948,6 @@ _tWinMain(HINSTANCE hInst, LPTSTR lpszCmdLine, int nCmdShow) { - NTSTATUS Status; ULONG Error; INITCOMMONCONTROLSEX iccx; PROPSHEETHEADER psh; @@ -958,41 +957,23 @@ _tWinMain(HINSTANCE hInst, ProcessHeap = GetProcessHeap(); - /* Initialize global unicode strings */ - RtlInitUnicodeString(&SetupData.USetupData.SourcePath, NULL); - RtlInitUnicodeString(&SetupData.USetupData.SourceRootPath, NULL); - RtlInitUnicodeString(&SetupData.USetupData.SourceRootDir, NULL); - // RtlInitUnicodeString(&InstallPath, NULL); - RtlInitUnicodeString(&SetupData.USetupData.DestinationPath, NULL); - RtlInitUnicodeString(&SetupData.USetupData.DestinationArcPath, NULL); - RtlInitUnicodeString(&SetupData.USetupData.DestinationRootPath, NULL); - RtlInitUnicodeString(&SetupData.USetupData.SystemRootPath, NULL); + /* Initialize Setup, phase 0 */ + InitializeSetup(&SetupData.USetupData, 0); - /* Get the source path and source root path */ - // - // NOTE: Sometimes the source path may not be in SystemRoot !! - // (and this is the case when using the 1st-stage GUI setup!) - // - Status = GetSourcePaths(&SetupData.USetupData.SourcePath, - &SetupData.USetupData.SourceRootPath, - &SetupData.USetupData.SourceRootDir); - if (!NT_SUCCESS(Status)) - { - DPRINT1("GetSourcePaths() failed (Status 0x%08lx)", Status); - // MUIDisplayError(ERROR_NO_SOURCE_DRIVE, Ir, POPUP_WAIT_ENTER); - MessageBoxW(NULL, L"GetSourcePaths failed!", L"Error", MB_ICONERROR); - goto Quit; - } - DPRINT1("SourcePath: '%wZ'\n", &SetupData.USetupData.SourcePath); - DPRINT1("SourceRootPath: '%wZ'\n", &SetupData.USetupData.SourceRootPath); - DPRINT1("SourceRootDir: '%wZ'\n", &SetupData.USetupData.SourceRootDir); - - /* Load 'txtsetup.sif' from the installation media */ - Error = LoadSetupInf(&SetupData.SetupInf, &SetupData.USetupData); + /* Initialize Setup, phase 1 */ + Error = InitializeSetup(&SetupData.USetupData, 1); if (Error != ERROR_SUCCESS) { - // MUIDisplayError(Error, Ir, POPUP_WAIT_ENTER); - DisplayError(NULL, IDS_CAPTION, IDS_NO_TXTSETUP_SIF); + // + // TODO: Write an error mapper (much like the MUIDisplayError of USETUP) + // + if (Error == ERROR_NO_SOURCE_DRIVE) + MessageBoxW(NULL, L"GetSourcePaths failed!", L"Error", MB_ICONERROR); + else if (Error == ERROR_LOAD_TXTSETUPSIF) + DisplayError(NULL, IDS_CAPTION, IDS_NO_TXTSETUP_SIF); + else // FIXME!! + MessageBoxW(NULL, L"Unknown error!", L"Error", MB_ICONERROR); + goto Quit; } @@ -1003,7 +984,7 @@ _tWinMain(HINSTANCE hInst, SetupData.hInstance = hInst; CheckUnattendedSetup(&SetupData.USetupData); - SetupData.bUnattend = IsUnattendedSetup; + SetupData.bUnattend = IsUnattendedSetup; // FIXME :-) /* Cache commonly-used strings */ LoadStringW(hInst, IDS_ABORTSETUP, SetupData.szAbortMessage, ARRAYSIZE(SetupData.szAbortMessage)); @@ -1124,9 +1105,9 @@ _tWinMain(HINSTANCE hInst, if (SetupData.hTitleFont) DeleteObject(SetupData.hTitleFont); - SetupCloseInfFile(SetupData.SetupInf); - Quit: + /* Setup has finished */ + FinishSetup(&SetupData.USetupData); #if 0 // NOTE: Disabled for testing purposes only! EnablePrivilege(SE_SHUTDOWN_NAME, TRUE); diff --git a/base/setup/reactos/reactos.h b/base/setup/reactos/reactos.h index 760b62708ab..508d9652c0d 100644 --- a/base/setup/reactos/reactos.h +++ b/base/setup/reactos/reactos.h @@ -55,7 +55,6 @@ /* Setup library headers */ // #include #include <../lib/setuplib.h> -// #include "errorcode.h" #if 0 typedef struct _KBLAYOUT @@ -79,7 +78,13 @@ typedef struct _SETUPDATA TCHAR szAbortTitle[64]; USETUP_DATA USetupData; - HINF SetupInf; + + BOOLEAN RepairUpdateFlag; // flag for update/repair an installed reactos + + PPARTLIST PartitionList; + PNTOS_INSTALLATION CurrentInstallation; + PGENERIC_LIST NtOsInstallsList; + /* Settings */ LONG DestPartSize; // if partition doesn't exist, size of partition @@ -92,9 +97,6 @@ typedef struct _SETUPDATA LONG SelectedDisplay; // selected display type (table index) LONG SelectedKeyboard; // selected keyboard type (table index) - BOOLEAN RepairUpdateFlag; // flag for update/repair an installed reactos - - /* txtsetup.sif data */ // LONG DefaultLang; // default language (table index) // LONG DefaultKBLayout; // default keyboard layout (table index) @@ -102,16 +104,6 @@ typedef struct _SETUPDATA WCHAR DefaultLanguage[20]; // Copy of string inside LanguageList WCHAR DefaultKBLayout[20]; // Copy of string inside KeyboardList - PGENERIC_LIST ComputerList; - PGENERIC_LIST DisplayList; - PGENERIC_LIST KeyboardList; - PGENERIC_LIST LayoutList; - PGENERIC_LIST LanguageList; - - PPARTLIST PartitionList; - PNTOS_INSTALLATION CurrentInstallation; - PGENERIC_LIST NtOsInstallsList; - } SETUPDATA, *PSETUPDATA; extern HANDLE ProcessHeap; diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index 1461528b88f..b544e207b36 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -40,15 +40,9 @@ /* GLOBALS & LOCALS *********************************************************/ HANDLE ProcessHeap; - BOOLEAN IsUnattendedSetup = FALSE; -static USETUP_DATA USetupData; -/* - * NOTE: Technically only used for the COPYCONTEXT InstallPath member - * for the filequeue functionality. - */ -static UNICODE_STRING InstallPath; +static USETUP_DATA USetupData; // FIXME: Is it really useful?? Just used for SetDefaultPagefile... static WCHAR DestinationDriveLetter; @@ -71,19 +65,9 @@ static FORMATMACHINESTATE FormatState = Start; /*****************************************************/ -static HINF SetupInf; - -static HSPFILEQ SetupFileQueue = NULL; - static PNTOS_INSTALLATION CurrentInstallation = NULL; static PGENERIC_LIST NtOsInstallsList = NULL; -static PGENERIC_LIST ComputerList = NULL; -static PGENERIC_LIST DisplayList = NULL; -static PGENERIC_LIST KeyboardList = NULL; -static PGENERIC_LIST LayoutList = NULL; -static PGENERIC_LIST LanguageList = NULL; - /* FUNCTIONS ****************************************************************/ @@ -404,10 +388,10 @@ UpdateKBLayout(VOID) pszNewLayout = MUIDefaultKeyboardLayout(SelectedLanguageId); - if (LayoutList == NULL) + if (USetupData.LayoutList == NULL) { - LayoutList = CreateKeyboardLayoutList(SetupInf, SelectedLanguageId, DefaultKBLayout); - if (LayoutList == NULL) + USetupData.LayoutList = CreateKeyboardLayoutList(USetupData.SetupInf, SelectedLanguageId, DefaultKBLayout); + if (USetupData.LayoutList == NULL) { /* FIXME: Handle error! */ return; @@ -417,12 +401,12 @@ UpdateKBLayout(VOID) /* Search for default layout (if provided) */ if (pszNewLayout != NULL) { - for (ListEntry = GetFirstListEntry(LayoutList); ListEntry; + for (ListEntry = GetFirstListEntry(USetupData.LayoutList); ListEntry; ListEntry = GetNextListEntry(ListEntry)) { if (!wcscmp(pszNewLayout, ((PGENENTRY)GetListEntryData(ListEntry))->Id)) { - SetCurrentListEntry(LayoutList, ListEntry); + SetCurrentListEntry(USetupData.LayoutList, ListEntry); break; } } @@ -491,10 +475,10 @@ LanguagePage(PINPUT_RECORD Ir) BOOL RefreshPage = FALSE; /* Initialize the computer settings list */ - if (LanguageList == NULL) + if (USetupData.LanguageList == NULL) { - LanguageList = CreateLanguageList(SetupInf, DefaultLanguage); - if (LanguageList == NULL) + USetupData.LanguageList = CreateLanguageList(USetupData.SetupInf, DefaultLanguage); + if (USetupData.LanguageList == NULL) { PopupError("Setup failed to initialize available translations", NULL, NULL, POPUP_WAIT_NONE); return WELCOME_PAGE; @@ -512,13 +496,13 @@ LanguagePage(PINPUT_RECORD Ir) * If there is no language or just a single one in the list, * skip the language selection process altogether. */ - if (GetNumberOfListEntries(LanguageList) <= 1) + if (GetNumberOfListEntries(USetupData.LanguageList) <= 1) { USetupData.LanguageId = (LANGID)(wcstol(SelectedLanguageId, NULL, 16) & 0xFFFF); return WELCOME_PAGE; } - InitGenericListUi(&ListUi, LanguageList, GetSettingDescription); + InitGenericListUi(&ListUi, USetupData.LanguageList, GetSettingDescription); DrawGenericList(&ListUi, 2, 18, xScreen - 3, @@ -566,10 +550,10 @@ LanguagePage(PINPUT_RECORD Ir) } else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x0D) /* ENTER */ { - ASSERT(GetNumberOfListEntries(LanguageList) >= 1); + ASSERT(GetNumberOfListEntries(USetupData.LanguageList) >= 1); SelectedLanguageId = - ((PGENENTRY)GetListEntryData(GetCurrentListEntry(LanguageList)))->Id; + ((PGENENTRY)GetListEntryData(GetCurrentListEntry(USetupData.LanguageList)))->Id; USetupData.LanguageId = (LANGID)(wcstol(SelectedLanguageId, NULL, 16) & 0xFFFF); @@ -592,10 +576,10 @@ LanguagePage(PINPUT_RECORD Ir) if (RefreshPage) { - ASSERT(GetNumberOfListEntries(LanguageList) >= 1); + ASSERT(GetNumberOfListEntries(USetupData.LanguageList) >= 1); NewLanguageId = - ((PGENENTRY)GetListEntryData(GetCurrentListEntry(LanguageList)))->Id; + ((PGENENTRY)GetListEntryData(GetCurrentListEntry(USetupData.LanguageList)))->Id; if (wcscmp(SelectedLanguageId, NewLanguageId)) { @@ -632,7 +616,7 @@ LanguagePage(PINPUT_RECORD Ir) * Init USetupData.SourcePath * Init USetupData.SourceRootPath * Init USetupData.SourceRootDir - * Init SetupInf + * Init USetupData.SetupInf * Init USetupData.RequiredPartitionDiskSpace * Init IsUnattendedSetup * If unattended, init *List and sets the Codepage @@ -645,29 +629,14 @@ LanguagePage(PINPUT_RECORD Ir) static PAGE_NUMBER SetupStartPage(PINPUT_RECORD Ir) { - NTSTATUS Status; ULONG Error; PGENERIC_LIST_ENTRY ListEntry; PCWSTR LocaleId; CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT)); - /* Get the source path and source root path */ - Status = GetSourcePaths(&USetupData.SourcePath, - &USetupData.SourceRootPath, - &USetupData.SourceRootDir); - if (!NT_SUCCESS(Status)) - { - CONSOLE_PrintTextXY(6, 15, "GetSourcePaths() failed (Status 0x%08lx)", Status); - MUIDisplayError(ERROR_NO_SOURCE_DRIVE, Ir, POPUP_WAIT_ENTER); - return QUIT_PAGE; - } - DPRINT1("SourcePath: '%wZ'\n", &USetupData.SourcePath); - DPRINT1("SourceRootPath: '%wZ'\n", &USetupData.SourceRootPath); - DPRINT1("SourceRootDir: '%wZ'\n", &USetupData.SourceRootDir); - - /* Load 'txtsetup.sif' from the installation media */ - Error = LoadSetupInf(&SetupInf, &USetupData); + /* Initialize Setup, phase 1 */ + Error = InitializeSetup(&USetupData, 1); if (Error != ERROR_SUCCESS) { MUIDisplayError(Error, Ir, POPUP_WAIT_ENTER); @@ -688,41 +657,41 @@ SetupStartPage(PINPUT_RECORD Ir) // TODO: Read options from inf /* Load the hardware, language and keyboard layout lists */ - ComputerList = CreateComputerTypeList(SetupInf); - DisplayList = CreateDisplayDriverList(SetupInf); - KeyboardList = CreateKeyboardDriverList(SetupInf); + USetupData.ComputerList = CreateComputerTypeList(USetupData.SetupInf); + USetupData.DisplayList = CreateDisplayDriverList(USetupData.SetupInf); + USetupData.KeyboardList = CreateKeyboardDriverList(USetupData.SetupInf); - LanguageList = CreateLanguageList(SetupInf, DefaultLanguage); + USetupData.LanguageList = CreateLanguageList(USetupData.SetupInf, DefaultLanguage); /* new part */ SelectedLanguageId = DefaultLanguage; wcscpy(DefaultLanguage, USetupData.LocaleID); USetupData.LanguageId = (LANGID)(wcstol(SelectedLanguageId, NULL, 16) & 0xFFFF); - LayoutList = CreateKeyboardLayoutList(SetupInf, SelectedLanguageId, DefaultKBLayout); + USetupData.LayoutList = CreateKeyboardLayoutList(USetupData.SetupInf, SelectedLanguageId, DefaultKBLayout); /* first we hack LanguageList */ - for (ListEntry = GetFirstListEntry(LanguageList); ListEntry; + for (ListEntry = GetFirstListEntry(USetupData.LanguageList); ListEntry; ListEntry = GetNextListEntry(ListEntry)) { LocaleId = ((PGENENTRY)GetListEntryData(ListEntry))->Id; if (!wcsicmp(USetupData.LocaleID, LocaleId)) { DPRINT("found %S in LanguageList\n", LocaleId); - SetCurrentListEntry(LanguageList, ListEntry); + SetCurrentListEntry(USetupData.LanguageList, ListEntry); break; } } /* now LayoutList */ - for (ListEntry = GetFirstListEntry(LayoutList); ListEntry; + for (ListEntry = GetFirstListEntry(USetupData.LayoutList); ListEntry; ListEntry = GetNextListEntry(ListEntry)) { LocaleId = ((PGENENTRY)GetListEntryData(ListEntry))->Id; if (!wcsicmp(USetupData.LocaleID, LocaleId)) { DPRINT("found %S in LayoutList\n", LocaleId); - SetCurrentListEntry(LayoutList, ListEntry); + SetCurrentListEntry(USetupData.LayoutList, ListEntry); break; } } @@ -1131,10 +1100,10 @@ OemDriverPage(PINPUT_RECORD Ir) * QuitPage * * SIDEEFFECTS - * Init ComputerList - * Init DisplayList - * Init KeyboardList - * Init LayoutList + * Init USetupData.ComputerList + * Init USetupData.DisplayList + * Init USetupData.KeyboardList + * Init USetupData.LayoutList * * RETURNS * Number of the next page. @@ -1145,10 +1114,10 @@ DeviceSettingsPage(PINPUT_RECORD Ir) static ULONG Line = 16; /* Initialize the computer settings list */ - if (ComputerList == NULL) + if (USetupData.ComputerList == NULL) { - ComputerList = CreateComputerTypeList(SetupInf); - if (ComputerList == NULL) + USetupData.ComputerList = CreateComputerTypeList(USetupData.SetupInf); + if (USetupData.ComputerList == NULL) { MUIDisplayError(ERROR_LOAD_COMPUTER, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; @@ -1156,10 +1125,10 @@ DeviceSettingsPage(PINPUT_RECORD Ir) } /* Initialize the display settings list */ - if (DisplayList == NULL) + if (USetupData.DisplayList == NULL) { - DisplayList = CreateDisplayDriverList(SetupInf); - if (DisplayList == NULL) + USetupData.DisplayList = CreateDisplayDriverList(USetupData.SetupInf); + if (USetupData.DisplayList == NULL) { MUIDisplayError(ERROR_LOAD_DISPLAY, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; @@ -1167,10 +1136,10 @@ DeviceSettingsPage(PINPUT_RECORD Ir) } /* Initialize the keyboard settings list */ - if (KeyboardList == NULL) + if (USetupData.KeyboardList == NULL) { - KeyboardList = CreateKeyboardDriverList(SetupInf); - if (KeyboardList == NULL) + USetupData.KeyboardList = CreateKeyboardDriverList(USetupData.SetupInf); + if (USetupData.KeyboardList == NULL) { MUIDisplayError(ERROR_LOAD_KEYBOARD, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; @@ -1178,10 +1147,10 @@ DeviceSettingsPage(PINPUT_RECORD Ir) } /* Initialize the keyboard layout list */ - if (LayoutList == NULL) + if (USetupData.LayoutList == NULL) { - LayoutList = CreateKeyboardLayoutList(SetupInf, SelectedLanguageId, DefaultKBLayout); - if (LayoutList == NULL) + USetupData.LayoutList = CreateKeyboardLayoutList(USetupData.SetupInf, SelectedLanguageId, DefaultKBLayout); + if (USetupData.LayoutList == NULL) { /* FIXME: report error */ MUIDisplayError(ERROR_LOAD_KBLAYOUT, Ir, POPUP_WAIT_ENTER); @@ -1197,10 +1166,10 @@ DeviceSettingsPage(PINPUT_RECORD Ir) MUIDisplayPage(DEVICE_SETTINGS_PAGE); - DrawGenericListCurrentItem(ComputerList, GetSettingDescription, 25, 11); - DrawGenericListCurrentItem(DisplayList , GetSettingDescription, 25, 12); - DrawGenericListCurrentItem(KeyboardList, GetSettingDescription, 25, 13); - DrawGenericListCurrentItem(LayoutList , GetSettingDescription, 25, 14); + DrawGenericListCurrentItem(USetupData.ComputerList, GetSettingDescription, 25, 11); + DrawGenericListCurrentItem(USetupData.DisplayList , GetSettingDescription, 25, 12); + DrawGenericListCurrentItem(USetupData.KeyboardList, GetSettingDescription, 25, 13); + DrawGenericListCurrentItem(USetupData.LayoutList , GetSettingDescription, 25, 14); CONSOLE_InvertTextXY(24, Line, 48, 1); @@ -1343,7 +1312,7 @@ ComputerSettingsPage(PINPUT_RECORD Ir) GENERIC_LIST_UI ListUi; MUIDisplayPage(COMPUTER_SETTINGS_PAGE); - InitGenericListUi(&ListUi, ComputerList, GetSettingDescription); + InitGenericListUi(&ListUi, USetupData.ComputerList, GetSettingDescription); DrawGenericList(&ListUi, 2, 18, xScreen - 3, @@ -1369,7 +1338,7 @@ DisplaySettingsPage(PINPUT_RECORD Ir) GENERIC_LIST_UI ListUi; MUIDisplayPage(DISPLAY_SETTINGS_PAGE); - InitGenericListUi(&ListUi, DisplayList, GetSettingDescription); + InitGenericListUi(&ListUi, USetupData.DisplayList, GetSettingDescription); DrawGenericList(&ListUi, 2, 18, xScreen - 3, @@ -1395,7 +1364,7 @@ KeyboardSettingsPage(PINPUT_RECORD Ir) GENERIC_LIST_UI ListUi; MUIDisplayPage(KEYBOARD_SETTINGS_PAGE); - InitGenericListUi(&ListUi, KeyboardList, GetSettingDescription); + InitGenericListUi(&ListUi, USetupData.KeyboardList, GetSettingDescription); DrawGenericList(&ListUi, 2, 18, xScreen - 3, @@ -1421,7 +1390,7 @@ LayoutSettingsPage(PINPUT_RECORD Ir) GENERIC_LIST_UI ListUi; MUIDisplayPage(LAYOUT_SETTINGS_PAGE); - InitGenericListUi(&ListUi, LayoutList, GetSettingDescription); + InitGenericListUi(&ListUi, USetupData.LayoutList, GetSettingDescription); DrawGenericList(&ListUi, 2, 18, xScreen - 3, @@ -3224,38 +3193,11 @@ BuildInstallPaths(PWSTR InstallDir, PDISKENTRY DiskEntry, PPARTENTRY PartEntry) { - WCHAR PathBuffer[MAX_PATH]; + NTSTATUS Status; -/** Equivalent of 'NTOS_INSTALLATION::PathComponent' **/ - /* Create 'InstallPath' string */ - RtlFreeUnicodeString(&InstallPath); - RtlCreateUnicodeString(&InstallPath, InstallDir); - - /* Create 'USetupData.DestinationRootPath' string */ - RtlFreeUnicodeString(&USetupData.DestinationRootPath); - RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), - L"\\Device\\Harddisk%lu\\Partition%lu\\", - DiskEntry->DiskNumber, - PartEntry->PartitionNumber); - RtlCreateUnicodeString(&USetupData.DestinationRootPath, PathBuffer); - DPRINT("DestinationRootPath: %wZ\n", &USetupData.DestinationRootPath); - -/** Equivalent of 'NTOS_INSTALLATION::SystemNtPath' **/ - /* Create 'USetupData.DestinationPath' string */ - RtlFreeUnicodeString(&USetupData.DestinationPath); - CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2, - USetupData.DestinationRootPath.Buffer, InstallDir); - RtlCreateUnicodeString(&USetupData.DestinationPath, PathBuffer); - -/** Equivalent of 'NTOS_INSTALLATION::SystemArcPath' **/ - /* Create 'USetupData.DestinationArcPath' */ - RtlFreeUnicodeString(&USetupData.DestinationArcPath); - RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), - L"multi(0)disk(0)rdisk(%lu)partition(%lu)\\", - DiskEntry->BiosDiskNumber, - PartEntry->PartitionNumber); - ConcatPaths(PathBuffer, ARRAYSIZE(PathBuffer), 1, InstallDir); - RtlCreateUnicodeString(&USetupData.DestinationArcPath, PathBuffer); + Status = InitDestinationPaths(&USetupData, InstallDir, DiskEntry, PartEntry); + // TODO: Check Status + UNREFERENCED_PARAMETER(Status); /* Initialize DestinationDriveLetter */ DestinationDriveLetter = (WCHAR)PartEntry->DriveLetter; @@ -3594,7 +3536,7 @@ AddSectionToCopyQueueCab(HINF InfFile, break; } - if (!SetupQueueCopy(SetupFileQueue, + if (!SetupQueueCopy(USetupData.SetupFileQueue, SourceCabinet, USetupData.SourceRootPath.Buffer, USetupData.SourceRootDir.Buffer, @@ -3728,7 +3670,7 @@ AddSectionToCopyQueue(HINF InfFile, DPRINT("RelativePath(2): '%S'\n", CompleteOrigDirName); } - if (!SetupQueueCopy(SetupFileQueue, + if (!SetupQueueCopy(USetupData.SetupFileQueue, SourceCabinet, USetupData.SourceRootPath.Buffer, CompleteOrigDirName, @@ -3767,7 +3709,7 @@ PrepareCopyPageInfFile(HINF InfFile, /* Add specific files depending of computer type */ if (SourceCabinet == NULL) { - if (!ProcessComputerFiles(InfFile, ComputerList, &AdditionalSectionName)) + if (!ProcessComputerFiles(InfFile, USetupData.ComputerList, &AdditionalSectionName)) return FALSE; if (AdditionalSectionName) @@ -3905,21 +3847,21 @@ PrepareCopyPage(PINPUT_RECORD Ir) MUIDisplayPage(PREPARE_COPY_PAGE); /* Create the file queue */ - SetupFileQueue = SetupOpenFileQueue(); - if (SetupFileQueue == NULL) + USetupData.SetupFileQueue = SetupOpenFileQueue(); + if (USetupData.SetupFileQueue == NULL) { MUIDisplayError(ERROR_COPY_QUEUE, Ir, POPUP_WAIT_ENTER); return QUIT_PAGE; } - if (!PrepareCopyPageInfFile(SetupInf, NULL, Ir)) + if (!PrepareCopyPageInfFile(USetupData.SetupInf, NULL, Ir)) { /* FIXME: show an error dialog */ return QUIT_PAGE; } /* Search for the 'Cabinets' section */ - if (!SetupFindFirstLineW(SetupInf, L"Cabinets", NULL, &CabinetsContext)) + if (!SetupFindFirstLineW(USetupData.SetupInf, L"Cabinets", NULL, &CabinetsContext)) { return FILE_COPY_PAGE; } @@ -4078,7 +4020,7 @@ FileCopyPage(PINPUT_RECORD Ir) /* Create context for the copy process */ CopyContext.DestinationRootPath = USetupData.DestinationRootPath.Buffer; - CopyContext.InstallPath = InstallPath.Buffer; + CopyContext.InstallPath = USetupData.InstallPath.Buffer; CopyContext.TotalOperations = 0; CopyContext.CompletedOperations = 0; @@ -4128,12 +4070,12 @@ FileCopyPage(PINPUT_RECORD Ir) /* Do the file copying */ SetupCommitFileQueueW(NULL, - SetupFileQueue, + USetupData.SetupFileQueue, FileCopyCallback, &CopyContext); /* If we get here, we're done, so cleanup the queue and progress bar */ - SetupCloseFileQueue(SetupFileQueue); + SetupCloseFileQueue(USetupData.SetupFileQueue); DestroyProgressBar(CopyContext.ProgressBar); DestroyProgressBar(CopyContext.MemoryBars[0]); DestroyProgressBar(CopyContext.MemoryBars[1]); @@ -4199,15 +4141,15 @@ RegistryPage(PINPUT_RECORD Ir) MUIDisplayPage(REGISTRY_PAGE); - Error = UpdateRegistry(SetupInf, + Error = UpdateRegistry(USetupData.SetupInf, &USetupData, RepairUpdateFlag, PartitionList, DestinationDriveLetter, SelectedLanguageId, - DisplayList, - LayoutList, - LanguageList, + USetupData.DisplayList, + USetupData.LayoutList, + USetupData.LanguageList, RegistryStatus); if (Error != ERROR_SUCCESS) { @@ -4794,6 +4736,7 @@ QuitPage(PINPUT_RECORD Ir) DestroyPartitionList(PartitionList); PartitionList = NULL; } + TempPartition = NULL; FormatState = Start; @@ -4804,41 +4747,6 @@ QuitPage(PINPUT_RECORD Ir) FileSystemList = NULL; } - /* Destroy the computer settings list */ - if (ComputerList != NULL) - { - DestroyGenericList(ComputerList, TRUE); - ComputerList = NULL; - } - - /* Destroy the display settings list */ - if (DisplayList != NULL) - { - DestroyGenericList(DisplayList, TRUE); - DisplayList = NULL; - } - - /* Destroy the keyboard settings list */ - if (KeyboardList != NULL) - { - DestroyGenericList(KeyboardList, TRUE); - KeyboardList = NULL; - } - - /* Destroy the keyboard layout list */ - if (LayoutList != NULL) - { - DestroyGenericList(LayoutList, TRUE); - LayoutList = NULL; - } - - /* Destroy the languages list */ - if (LanguageList != NULL) - { - DestroyGenericList(LanguageList, FALSE); - LanguageList = NULL; - } - CONSOLE_SetStatusText(MUIGetString(STRING_REBOOTCOMPUTER2)); /* Wait for maximum 15 seconds or an ENTER key before quitting */ @@ -4920,7 +4828,7 @@ RunUSetup(VOID) 0, 0, PnpEventThread, - &SetupInf, + &USetupData.SetupInf, &hPnpThread, NULL); if (!NT_SUCCESS(Status)) @@ -4936,15 +4844,8 @@ RunUSetup(VOID) return STATUS_APP_INIT_FAILURE; } - /* Initialize global unicode strings */ - RtlInitUnicodeString(&USetupData.SourcePath, NULL); - RtlInitUnicodeString(&USetupData.SourceRootPath, NULL); - RtlInitUnicodeString(&USetupData.SourceRootDir, NULL); - RtlInitUnicodeString(&InstallPath, NULL); - RtlInitUnicodeString(&USetupData.DestinationPath, NULL); - RtlInitUnicodeString(&USetupData.DestinationArcPath, NULL); - RtlInitUnicodeString(&USetupData.DestinationRootPath, NULL); - RtlInitUnicodeString(&USetupData.SystemRootPath, NULL); + /* Initialize Setup, phase 0 */ + InitializeSetup(&USetupData, 0); /* Hide the cursor */ CONSOLE_SetCursorType(TRUE, FALSE); @@ -5109,7 +5010,8 @@ RunUSetup(VOID) } } - SetupCloseInfFile(SetupInf); + /* Setup has finished */ + FinishSetup(&USetupData); if (Page == RECOVERY_PAGE) RecoveryConsole();