[USERINIT] Add unattend.inf functionality to livecd

This commit is contained in:
Mark Jansen 2020-05-03 20:18:30 +02:00
parent 1f3cb13fb9
commit a0e32d4f48
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B
5 changed files with 94 additions and 5 deletions

View file

@ -11,6 +11,13 @@ HWND hList;
HWND hLocaleList;
BOOL bSpain = FALSE;
typedef struct _LIVECD_UNATTEND
{
BOOL bEnabled;
LCID LocaleID;
} LIVECD_UNATTEND;
/*
* Taken and adapted from dll/cpl/sysdm/general.c
*/
@ -158,6 +165,7 @@ LocalesEnumProc(LPTSTR lpLocale)
if (!IsValidLocale(lcid, LCID_INSTALLED))
return TRUE;
// See http://archives.miloush.net/michkap/archive/2006/09/23/768178.html for why we handle spain differently
if (lcid == MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH), SORT_DEFAULT) ||
lcid == MAKELCID(MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MODERN), SORT_DEFAULT))
{
@ -194,17 +202,25 @@ LocalesEnumProc(LPTSTR lpLocale)
static VOID
CreateLanguagesList(HWND hwnd)
CreateLanguagesList(HWND hwnd, PSTATE pState)
{
WCHAR langSel[255];
LCID Locale = 0;
hList = hwnd;
bSpain = FALSE;
EnumSystemLocalesW(LocalesEnumProc, LCID_SUPPORTED);
if (pState->Unattend->bEnabled)
Locale = pState->Unattend->LocaleID;
if (!Locale)
{
/* Select current locale */
/* or should it be System and not user? */
GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_SLANGUAGE, langSel, ARRAYSIZE(langSel));
Locale = GetUserDefaultLCID();
}
GetLocaleInfoW(Locale, LOCALE_SLANGUAGE, langSel, ARRAYSIZE(langSel));
SendMessageW(hList,
CB_SELECTSTRING,
@ -618,8 +634,13 @@ LocaleDlgProc(
CenterWindow(hwndDlg);
/* Fill the language and keyboard layout lists */
CreateLanguagesList(GetDlgItem(hwndDlg, IDC_LANGUAGELIST));
CreateLanguagesList(GetDlgItem(hwndDlg, IDC_LANGUAGELIST), pState);
CreateKeyboardLayoutList(GetDlgItem(hwndDlg, IDC_LAYOUTLIST));
if (pState->Unattend->bEnabled)
{
// Advance to the next page
PostMessageW(hwndDlg, WM_COMMAND, MAKELONG(IDOK, BN_CLICKED), 0L);
}
return FALSE;
case WM_DRAWITEM:
@ -746,6 +767,13 @@ StartDlgProc(
/* Center the dialog window */
CenterWindow(hwndDlg);
if (pState->Unattend->bEnabled)
{
// Click on the 'Run' button
PostMessageW(hwndDlg, WM_COMMAND, MAKELONG(IDC_RUN, BN_CLICKED), 0L);
}
return FALSE;
case WM_DRAWITEM:
@ -805,13 +833,59 @@ StartDlgProc(
return FALSE;
}
VOID ParseUnattend(LPCWSTR UnattendInf, LIVECD_UNATTEND* pUnattend)
{
WCHAR Buffer[MAX_PATH];
pUnattend->bEnabled = FALSE;
if (!GetPrivateProfileStringW(L"Unattend", L"Signature", L"", Buffer, _countof(Buffer), UnattendInf))
{
ERR("Unable to parse Signature\n");
return;
}
if (_wcsicmp(Buffer, L"$ReactOS$") && _wcsicmp(Buffer, L"$Windows NT$"))
{
TRACE("Unknown signature: %S\n", Buffer);
return;
}
if (!GetPrivateProfileStringW(L"Unattend", L"UnattendSetupEnabled", L"", Buffer, _countof(Buffer), UnattendInf))
{
ERR("Unable to parse UnattendSetupEnabled\n");
return;
}
if (_wcsicmp(Buffer, L"yes"))
{
TRACE("Unattended setup is not enabled\n", Buffer);
return;
}
pUnattend->bEnabled = TRUE;
pUnattend->LocaleID = 0;
if (GetPrivateProfileStringW(L"Unattend", L"LocaleID", L"", Buffer, _countof(Buffer), UnattendInf) && Buffer[0])
{
pUnattend->LocaleID = wcstol(Buffer, NULL, 16);
}
}
VOID
RunLiveCD(
PSTATE pState)
{
LIVECD_UNATTEND Unattend = {0};
WCHAR UnattendInf[MAX_PATH];
InitLogo(&pState->ImageInfo, NULL);
GetWindowsDirectoryW(UnattendInf, _countof(UnattendInf));
wcscat(UnattendInf, L"\\unattend.inf");
ParseUnattend(UnattendInf, &Unattend);
pState->Unattend = &Unattend;
while (pState->NextPage != DONE)
{
switch (pState->NextPage)

View file

@ -58,6 +58,7 @@ typedef struct
PAGESTATE NextPage;
RUN Run;
IMGINFO ImageInfo;
struct _LIVECD_UNATTEND* Unattend;
} STATE, *PSTATE;

View file

@ -62,6 +62,7 @@ add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/hybridcd.ini DESTINATION root NAME_
# Unattend
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/bootcdregtest/unattend.inf DESTINATION reactos NO_CAB FOR regtest)
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/bootcd/unattend.inf DESTINATION reactos NO_CAB FOR bootcd)
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/livecd/unattend.inf DESTINATION reactos NO_CAB FOR livecd)
# LiveCD shortcuts
macro(add_livecd_shortcut name app dest)

View file

@ -0,0 +1,13 @@
[Unattend]
Signature = "$ReactOS$"
; Set UnattendSetupEnabled to yes in order to boot the livecd immediately to desktop
; yes - unattend setup enabled
; no - unattend setup disabled
UnattendSetupEnabled = no
; set this option to automatically
; specify language in the language setup
; see hivesys.inf for available languages
LocaleID = 409