mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 16:36:33 +00:00
[RAPPS] Respect partial settings configuration (#7247)
Instead of defaulting all settings if any setting is missing, respect any setting that is already set and default the rest.
This commit is contained in:
parent
d734bd784c
commit
301675c112
2 changed files with 59 additions and 35 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include "rapps.h"
|
#include "rapps.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
|
#define SETTINGSSUBKEY L"Software\\ReactOS\\" RAPPS_NAME
|
||||||
|
|
||||||
class SettingsField
|
class SettingsField
|
||||||
{
|
{
|
||||||
|
@ -109,7 +110,7 @@ class SettingsFieldString : public SettingsField
|
||||||
LPCWSTR m_RegName; // key name in registery
|
LPCWSTR m_RegName; // key name in registery
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
static void
|
||||||
AddInfoFields(ATL::CAtlList<SettingsField *> &infoFields, SETTINGS_INFO &settings)
|
AddInfoFields(ATL::CAtlList<SettingsField *> &infoFields, SETTINGS_INFO &settings)
|
||||||
{
|
{
|
||||||
infoFields.AddTail(new SettingsFieldBool(&(settings.bSaveWndPos), L"bSaveWndPos"));
|
infoFields.AddTail(new SettingsFieldBool(&(settings.bSaveWndPos), L"bSaveWndPos"));
|
||||||
|
@ -127,11 +128,9 @@ AddInfoFields(ATL::CAtlList<SettingsField *> &infoFields, SETTINGS_INFO &setting
|
||||||
infoFields.AddTail(new SettingsFieldString((settings.szNoProxyFor), MAX_PATH, L"NoProxyFor"));
|
infoFields.AddTail(new SettingsFieldString((settings.szNoProxyFor), MAX_PATH, L"NoProxyFor"));
|
||||||
infoFields.AddTail(new SettingsFieldBool(&(settings.bUseSource), L"bUseSource"));
|
infoFields.AddTail(new SettingsFieldBool(&(settings.bUseSource), L"bUseSource"));
|
||||||
infoFields.AddTail(new SettingsFieldString((settings.szSourceURL), INTERNET_MAX_URL_LENGTH, L"SourceURL"));
|
infoFields.AddTail(new SettingsFieldString((settings.szSourceURL), INTERNET_MAX_URL_LENGTH, L"SourceURL"));
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
static BOOL
|
||||||
SaveAllSettings(CRegKey &key, SETTINGS_INFO &settings)
|
SaveAllSettings(CRegKey &key, SETTINGS_INFO &settings)
|
||||||
{
|
{
|
||||||
BOOL bAllSuccess = TRUE;
|
BOOL bAllSuccess = TRUE;
|
||||||
|
@ -153,10 +152,10 @@ SaveAllSettings(CRegKey &key, SETTINGS_INFO &settings)
|
||||||
return bAllSuccess;
|
return bAllSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
static BOOL
|
||||||
LoadAllSettings(CRegKey &key, SETTINGS_INFO &settings)
|
LoadAllSettings(CRegKey &key, SETTINGS_INFO &settings)
|
||||||
{
|
{
|
||||||
BOOL bAllSuccess = TRUE;
|
BOOL bLoadedAny = FALSE;
|
||||||
ATL::CAtlList<SettingsField *> infoFields;
|
ATL::CAtlList<SettingsField *> infoFields;
|
||||||
|
|
||||||
AddInfoFields(infoFields, settings);
|
AddInfoFields(infoFields, settings);
|
||||||
|
@ -165,27 +164,18 @@ LoadAllSettings(CRegKey &key, SETTINGS_INFO &settings)
|
||||||
while (InfoListPosition)
|
while (InfoListPosition)
|
||||||
{
|
{
|
||||||
SettingsField *Info = infoFields.GetNext(InfoListPosition);
|
SettingsField *Info = infoFields.GetNext(InfoListPosition);
|
||||||
if (!Info->Load(key))
|
if (Info->Load(key))
|
||||||
{
|
bLoadedAny = TRUE;
|
||||||
bAllSuccess = FALSE;
|
//else
|
||||||
// TODO: error log
|
// TODO: error log
|
||||||
}
|
|
||||||
delete Info;
|
delete Info;
|
||||||
}
|
}
|
||||||
return bAllSuccess;
|
return bLoadedAny;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
static void
|
||||||
FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
|
GetDefaultDownloadDirectory(CStringW &szDownloadDir)
|
||||||
{
|
{
|
||||||
CStringW szDownloadDir;
|
|
||||||
ZeroMemory(pSettingsInfo, sizeof(SETTINGS_INFO));
|
|
||||||
|
|
||||||
pSettingsInfo->bSaveWndPos = TRUE;
|
|
||||||
pSettingsInfo->bUpdateAtStart = FALSE;
|
|
||||||
pSettingsInfo->bLogEnabled = TRUE;
|
|
||||||
pSettingsInfo->bUseSource = FALSE;
|
|
||||||
|
|
||||||
if (FAILED(SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, szDownloadDir.GetBuffer(MAX_PATH))))
|
if (FAILED(SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, szDownloadDir.GetBuffer(MAX_PATH))))
|
||||||
{
|
{
|
||||||
szDownloadDir.ReleaseBuffer();
|
szDownloadDir.ReleaseBuffer();
|
||||||
|
@ -201,29 +191,68 @@ FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
|
||||||
|
|
||||||
PathAppendW(szDownloadDir.GetBuffer(MAX_PATH), L"\\RAPPS Downloads");
|
PathAppendW(szDownloadDir.GetBuffer(MAX_PATH), L"\\RAPPS Downloads");
|
||||||
szDownloadDir.ReleaseBuffer();
|
szDownloadDir.ReleaseBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
CStringW::CopyChars(
|
static VOID
|
||||||
pSettingsInfo->szDownloadDir, _countof(pSettingsInfo->szDownloadDir), szDownloadDir.GetString(),
|
ValidateStringSettings(PSETTINGS_INFO pSettingsInfo)
|
||||||
szDownloadDir.GetLength() + 1);
|
{
|
||||||
|
if (!pSettingsInfo->szDownloadDir[0])
|
||||||
|
{
|
||||||
|
CStringW szDownloadDir;
|
||||||
|
GetDefaultDownloadDirectory(szDownloadDir);
|
||||||
|
|
||||||
|
CStringW::CopyChars(pSettingsInfo->szDownloadDir, _countof(pSettingsInfo->szDownloadDir),
|
||||||
|
szDownloadDir.GetString(), szDownloadDir.GetLength() + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID
|
||||||
|
FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
|
||||||
|
{
|
||||||
|
ZeroMemory(pSettingsInfo, sizeof(*pSettingsInfo));
|
||||||
|
|
||||||
|
pSettingsInfo->bSaveWndPos = TRUE;
|
||||||
|
pSettingsInfo->bUpdateAtStart = FALSE;
|
||||||
|
pSettingsInfo->bLogEnabled = TRUE;
|
||||||
|
pSettingsInfo->bUseSource = FALSE;
|
||||||
pSettingsInfo->bDelInstaller = FALSE;
|
pSettingsInfo->bDelInstaller = FALSE;
|
||||||
pSettingsInfo->Maximized = FALSE;
|
pSettingsInfo->Maximized = FALSE;
|
||||||
pSettingsInfo->Left = CW_USEDEFAULT;
|
pSettingsInfo->Left = CW_USEDEFAULT;
|
||||||
pSettingsInfo->Top = CW_USEDEFAULT;
|
pSettingsInfo->Top = CW_USEDEFAULT;
|
||||||
pSettingsInfo->Width = 680;
|
pSettingsInfo->Width = 680;
|
||||||
pSettingsInfo->Height = 450;
|
pSettingsInfo->Height = 450;
|
||||||
|
|
||||||
|
ValidateStringSettings(pSettingsInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
LoadSettings(PSETTINGS_INFO pSettingsInfo)
|
LoadSettings(PSETTINGS_INFO pSettingsInfo)
|
||||||
{
|
{
|
||||||
|
BOOL bLoadedAny = FALSE;
|
||||||
|
|
||||||
|
FillDefaultSettings(pSettingsInfo);
|
||||||
|
|
||||||
ATL::CRegKey RegKey;
|
ATL::CRegKey RegKey;
|
||||||
if (RegKey.Open(HKEY_CURRENT_USER, L"Software\\ReactOS\\" RAPPS_NAME, KEY_READ) != ERROR_SUCCESS)
|
if (RegKey.Open(HKEY_CURRENT_USER, SETTINGSSUBKEY, KEY_READ) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
return FALSE;
|
bLoadedAny = LoadAllSettings(RegKey, *pSettingsInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
return LoadAllSettings(RegKey, *pSettingsInfo);
|
ValidateStringSettings(pSettingsInfo); // Handles the case where a REG_SZ is present but empty
|
||||||
|
|
||||||
|
if (!bLoadedAny)
|
||||||
|
{
|
||||||
|
// This the first launch, write at least one item so ParseCmdAndExecute() does not
|
||||||
|
// trigger another DB update in another process instance between now and SaveSettings().
|
||||||
|
ATL::CRegKey RegKey;
|
||||||
|
if (RegKey.Create(HKEY_CURRENT_USER, SETTINGSSUBKEY, NULL, REG_OPTION_NON_VOLATILE,
|
||||||
|
KEY_WRITE, NULL, NULL) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
SettingsFieldBool field(&(pSettingsInfo->bUpdateAtStart), L"bUpdateAtStart");
|
||||||
|
field.Save(RegKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bLoadedAny;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
|
@ -245,8 +274,8 @@ SaveSettings(HWND hwnd, PSETTINGS_INFO pSettingsInfo)
|
||||||
(wp.showCmd == SW_MAXIMIZE || (wp.showCmd == SW_SHOWMINIMIZED && (wp.flags & WPF_RESTORETOMAXIMIZED)));
|
(wp.showCmd == SW_MAXIMIZE || (wp.showCmd == SW_SHOWMINIMIZED && (wp.flags & WPF_RESTORETOMAXIMIZED)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RegKey.Create(HKEY_CURRENT_USER, L"Software\\ReactOS\\" RAPPS_NAME, NULL,
|
if (RegKey.Create(HKEY_CURRENT_USER, SETTINGSSUBKEY, NULL, REG_OPTION_NON_VOLATILE,
|
||||||
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL) != ERROR_SUCCESS)
|
KEY_WRITE, NULL, NULL) != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,12 +40,7 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nSh
|
||||||
}
|
}
|
||||||
|
|
||||||
hInst = hInstance;
|
hInst = hInstance;
|
||||||
|
|
||||||
BOOL bIsFirstLaunch = !LoadSettings(&SettingsInfo);
|
BOOL bIsFirstLaunch = !LoadSettings(&SettingsInfo);
|
||||||
if (bIsFirstLaunch)
|
|
||||||
{
|
|
||||||
FillDefaultSettings(&SettingsInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
InitLogs();
|
InitLogs();
|
||||||
InitCommonControls();
|
InitCommonControls();
|
||||||
|
|
Loading…
Reference in a new issue