[WELCOME]: Follow-up to r73590: Load a "welcome.ini" configuration file inside the path of the welcome.exe application, if present, that specifies few default values to use for the interface, as well as the path (possibly relative) to a subdirectory containing ini files specifying localized resources for the interface.

[BOOTDATA]: Add a default "welcome.ini" file to the build, only for hybrid-cds. The ini files containing the localized resources are automatically converted to UTF-16 prior to inclusion in the hybridcd.

svn path=/trunk/; revision=73656
This commit is contained in:
Hermès Bélusca-Maïto 2017-02-01 03:12:56 +00:00
parent 229958ea1d
commit 9ffcd6f25a
3 changed files with 91 additions and 18 deletions

View file

@ -71,8 +71,7 @@ HBITMAP hDefaultTopicBitmap = NULL;
HWND hWndCloseButton = NULL;
HWND hWndCheckButton = NULL;
/* TODO: Retrieve the preferences from a configuration file */
BOOL bDisplayCheckBox = FALSE; // FIXME!
BOOL bDisplayCheckBox = FALSE; // FIXME: We should also repaint the OS version correctly!
BOOL bDisplayExitBtn = TRUE;
#define BUFFER_SIZE 1024
@ -121,7 +120,7 @@ MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
/* FUNCTIONS ****************************************************************/
INT GetLocaleName(LCID Locale, LPTSTR lpLCData, SIZE_T cchData)
INT GetLocaleName(IN LCID Locale, OUT LPTSTR lpLCData, IN SIZE_T cchData)
{
INT ret, ret2;
@ -197,7 +196,8 @@ VOID TranslateEscapes(IN OUT LPTSTR lpString)
}
}
BOOL LoadTopicsFromINI(LCID Locale)
static BOOL
LoadTopicsFromINI(LCID Locale, LPTSTR lpResPath)
{
DWORD dwRet;
DWORD dwSize;
@ -215,7 +215,7 @@ BOOL LoadTopicsFromINI(LCID Locale)
}
/* Build the INI file name */
GetCurrentDirectory(ARRAYSIZE(szIniPath), szIniPath);
StringCchCopy(szIniPath, ARRAYSIZE(szIniPath), lpResPath);
StringCchCat(szIniPath, ARRAYSIZE(szIniPath), TEXT("\\"));
StringCchCat(szIniPath, ARRAYSIZE(szIniPath), szBuffer);
StringCchCat(szIniPath, ARRAYSIZE(szIniPath), TEXT(".ini"));
@ -225,7 +225,7 @@ BOOL LoadTopicsFromINI(LCID Locale)
{
StringCchCopy(szBuffer, ARRAYSIZE(szBuffer), TEXT("en-US"));
GetCurrentDirectory(ARRAYSIZE(szIniPath), szIniPath);
StringCchCopy(szIniPath, ARRAYSIZE(szIniPath), lpResPath);
StringCchCat(szIniPath, ARRAYSIZE(szIniPath), TEXT("\\"));
StringCchCat(szIniPath, ARRAYSIZE(szIniPath), szBuffer);
StringCchCat(szIniPath, ARRAYSIZE(szIniPath), TEXT(".ini"));
@ -324,7 +324,8 @@ BOOL LoadTopicsFromINI(LCID Locale)
return TRUE;
}
BOOL LoadTopics(VOID)
static BOOL
LoadTopics(LPTSTR lpResPath)
{
#define MAX_NUMBER_INTERNAL_TOPICS 3
@ -344,7 +345,7 @@ BOOL LoadTopics(VOID)
*szDefaultDesc = 0;
/* Try to load the topics from INI file */
if (LoadTopicsFromINI(LOCALE_USER_DEFAULT))
if (*lpResPath && LoadTopicsFromINI(LOCALE_USER_DEFAULT, lpResPath))
return TRUE;
/* We failed, fall back to internal (localized) resource */
@ -379,7 +380,8 @@ BOOL LoadTopics(VOID)
return TRUE;
}
VOID FreeTopics(VOID)
static VOID
FreeTopics(VOID)
{
if (!pTopics)
return;
@ -394,6 +396,50 @@ VOID FreeTopics(VOID)
dwNumberTopics = 0;
}
static BOOL
LoadConfiguration(VOID)
{
TCHAR szAppPath[MAX_PATH];
TCHAR szIniPath[MAX_PATH];
TCHAR szResPath[MAX_PATH];
/* Retrieve the full path to this application */
GetModuleFileName(NULL, szAppPath, ARRAYSIZE(szAppPath));
if (*szAppPath)
{
LPTSTR lpFileName = _tcsrchr(szAppPath, _T('\\'));
if (lpFileName)
*lpFileName = 0;
else
*szAppPath = 0;
}
/* Build the full INI file path name */
StringCchCopy(szIniPath, ARRAYSIZE(szIniPath), szAppPath);
StringCchCat(szIniPath, ARRAYSIZE(szIniPath), TEXT("\\welcome.ini"));
/* Verify that the file exists, otherwise use the default configuration */
if (GetFileAttributes(szIniPath) == INVALID_FILE_ATTRIBUTES)
{
/* Use the default configuration and retrieve the default topics */
return LoadTopics(TEXT(""));
}
/* Load the settings from the INI configuration file */
bDisplayCheckBox = !!GetPrivateProfileInt(TEXT("Welcome"), TEXT("DisplayCheckBox"), FALSE /* default */, szIniPath);
bDisplayExitBtn = !!GetPrivateProfileInt(TEXT("Welcome"), TEXT("DisplayExitButton"), TRUE /* default */, szIniPath);
if (!GetPrivateProfileString(TEXT("Welcome"), TEXT("ResourceDir"), NULL /* default */,
szResPath, ARRAYSIZE(szResPath), szIniPath))
{
*szResPath = 0;
}
/* Set the current directory to the one of this application, and retrieve the topics */
SetCurrentDirectory(szAppPath);
return LoadTopics(szResPath);
}
#if 0
static VOID
ShowLastWin32Error(HWND hWnd)
@ -513,7 +559,8 @@ _tWinMain(HINSTANCE hInst,
if (!LoadString(hInstance, IDS_APPTITLE, szAppTitle, ARRAYSIZE(szAppTitle)))
StringCchCopy(szAppTitle, ARRAYSIZE(szAppTitle), TEXT("ReactOS Welcome"));
LoadTopics();
/* Load the configuration and the topics */
LoadConfiguration();
/* Create main window */
hWndMain = CreateWindow(szFrameClass,
@ -544,6 +591,7 @@ _tWinMain(HINSTANCE hInst,
DispatchMessage(&msg);
}
/* Cleanup */
FreeTopics();
return msg.wParam;

View file

@ -1,7 +1,7 @@
add_subdirectory(packages)
#common hives
# Common hives
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/txtsetup.sif DESTINATION reactos NO_CAB FOR bootcd regtest)
@ -14,31 +14,51 @@ add_registry_inf(
hivebcd.inf)
#regtest
# Regtest
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/bootcdregtest/regtest.cmd DESTINATION reactos/bin FOR all)
#autorun.inf
# autorun.inf
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/autorun-bootcd.inf DESTINATION root NO_CAB NOT_IN_HYBRIDCD NAME_ON_CD autorun.inf FOR bootcd)
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/autorun-livecd.inf DESTINATION root NO_CAB NOT_IN_HYBRIDCD NAME_ON_CD autorun.inf FOR livecd)
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/autorun-hybridcd.inf DESTINATION root NO_CAB NOT_IN_HYBRIDCD NAME_ON_CD autorun.inf FOR hybridcd)
#icon.ico
# icon.ico
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/icon.ico DESTINATION root NO_CAB NOT_IN_HYBRIDCD FOR all hybridcd)
#readme.txt
# readme.txt
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/readme.txt DESTINATION root NO_CAB NOT_IN_HYBRIDCD FOR all hybridcd)
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/readme.txt DESTINATION reactos FOR all)
#freeldr.ini
# Welcome.exe optional custom configuration (only for HybridCD)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/welcome_config/)
# Copy the main configuration file
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/welcome_config/welcome.ini DESTINATION bootcd/reactos NO_CAB FOR hybridcd)
# Convert the translation files (name format: xx-YY.ini) into UTF-16
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/welcome_config)
file(GLOB I18N_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/welcome_config/ ${CMAKE_CURRENT_SOURCE_DIR}/welcome_config/*-*.ini)
foreach(_file ${I18N_FILES})
set(_converted_file ${CMAKE_CURRENT_BINARY_DIR}/welcome_config/${_file})
set(_source_file ${CMAKE_CURRENT_SOURCE_DIR}/welcome_config/${_file})
add_custom_command(OUTPUT "${_converted_file}"
COMMAND native-utf16le "${_source_file}" "${_converted_file}"
DEPENDS native-utf16le "${_source_file}")
add_cd_file(TARGET converted_welcome_i18n_files FILE ${_converted_file} DESTINATION bootcd/reactos/welcome NO_CAB NAME_ON_CD ${_file} FOR hybridcd)
list(APPEND _converted_welcome_i18n_files ${_converted_file})
endforeach(_file)
add_custom_target(converted_welcome_i18n_files DEPENDS ${_converted_welcome_i18n_files})
endif()
# freeldr.ini
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/bootcd.ini DESTINATION root NO_CAB NOT_IN_HYBRIDCD NAME_ON_CD freeldr.ini FOR bootcd regtest)
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/livecd.ini DESTINATION root NOT_IN_HYBRIDCD NAME_ON_CD freeldr.ini FOR livecd)
add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/hybridcd.ini DESTINATION root NAME_ON_CD freeldr.ini FOR hybridcd)
#unattend
# 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)
#LiveCD shortcuts
# LiveCD shortcuts
macro(add_livecd_shortcut name app dest)
add_link(NAME ${name} CMD_LINE_ARGS ${app} ICON ${app} PATH livecd_start.cmd GUID "{450D8FBA-AD25-11D0-98A8-0800361B1103}" MINIMIZE)
list(APPEND LIVECD_SHORTCUTS "${CMAKE_CURRENT_BINARY_DIR}/${name}.lnk")

View file

@ -0,0 +1,5 @@
[Welcome]
DisplayCheckBox = 0
DisplayExitButton = 1
ResourceDir = welcome\