mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +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 "settings.h"
|
||||
|
||||
#define SETTINGSSUBKEY L"Software\\ReactOS\\" RAPPS_NAME
|
||||
|
||||
class SettingsField
|
||||
{
|
||||
|
@ -109,7 +110,7 @@ class SettingsFieldString : public SettingsField
|
|||
LPCWSTR m_RegName; // key name in registery
|
||||
};
|
||||
|
||||
void
|
||||
static void
|
||||
AddInfoFields(ATL::CAtlList<SettingsField *> &infoFields, SETTINGS_INFO &settings)
|
||||
{
|
||||
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 SettingsFieldBool(&(settings.bUseSource), L"bUseSource"));
|
||||
infoFields.AddTail(new SettingsFieldString((settings.szSourceURL), INTERNET_MAX_URL_LENGTH, L"SourceURL"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL
|
||||
static BOOL
|
||||
SaveAllSettings(CRegKey &key, SETTINGS_INFO &settings)
|
||||
{
|
||||
BOOL bAllSuccess = TRUE;
|
||||
|
@ -153,10 +152,10 @@ SaveAllSettings(CRegKey &key, SETTINGS_INFO &settings)
|
|||
return bAllSuccess;
|
||||
}
|
||||
|
||||
BOOL
|
||||
static BOOL
|
||||
LoadAllSettings(CRegKey &key, SETTINGS_INFO &settings)
|
||||
{
|
||||
BOOL bAllSuccess = TRUE;
|
||||
BOOL bLoadedAny = FALSE;
|
||||
ATL::CAtlList<SettingsField *> infoFields;
|
||||
|
||||
AddInfoFields(infoFields, settings);
|
||||
|
@ -165,27 +164,18 @@ LoadAllSettings(CRegKey &key, SETTINGS_INFO &settings)
|
|||
while (InfoListPosition)
|
||||
{
|
||||
SettingsField *Info = infoFields.GetNext(InfoListPosition);
|
||||
if (!Info->Load(key))
|
||||
{
|
||||
bAllSuccess = FALSE;
|
||||
// TODO: error log
|
||||
}
|
||||
if (Info->Load(key))
|
||||
bLoadedAny = TRUE;
|
||||
//else
|
||||
// TODO: error log
|
||||
delete Info;
|
||||
}
|
||||
return bAllSuccess;
|
||||
return bLoadedAny;
|
||||
}
|
||||
|
||||
VOID
|
||||
FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
|
||||
static void
|
||||
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))))
|
||||
{
|
||||
szDownloadDir.ReleaseBuffer();
|
||||
|
@ -201,29 +191,68 @@ FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
|
|||
|
||||
PathAppendW(szDownloadDir.GetBuffer(MAX_PATH), L"\\RAPPS Downloads");
|
||||
szDownloadDir.ReleaseBuffer();
|
||||
}
|
||||
|
||||
CStringW::CopyChars(
|
||||
pSettingsInfo->szDownloadDir, _countof(pSettingsInfo->szDownloadDir), szDownloadDir.GetString(),
|
||||
szDownloadDir.GetLength() + 1);
|
||||
static VOID
|
||||
ValidateStringSettings(PSETTINGS_INFO pSettingsInfo)
|
||||
{
|
||||
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->Maximized = FALSE;
|
||||
pSettingsInfo->Left = CW_USEDEFAULT;
|
||||
pSettingsInfo->Top = CW_USEDEFAULT;
|
||||
pSettingsInfo->Width = 680;
|
||||
pSettingsInfo->Height = 450;
|
||||
|
||||
ValidateStringSettings(pSettingsInfo);
|
||||
}
|
||||
|
||||
BOOL
|
||||
LoadSettings(PSETTINGS_INFO pSettingsInfo)
|
||||
{
|
||||
BOOL bLoadedAny = FALSE;
|
||||
|
||||
FillDefaultSettings(pSettingsInfo);
|
||||
|
||||
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
|
||||
|
@ -245,8 +274,8 @@ SaveSettings(HWND hwnd, PSETTINGS_INFO pSettingsInfo)
|
|||
(wp.showCmd == SW_MAXIMIZE || (wp.showCmd == SW_SHOWMINIMIZED && (wp.flags & WPF_RESTORETOMAXIMIZED)));
|
||||
}
|
||||
|
||||
if (RegKey.Create(HKEY_CURRENT_USER, L"Software\\ReactOS\\" RAPPS_NAME, NULL,
|
||||
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL) != ERROR_SUCCESS)
|
||||
if (RegKey.Create(HKEY_CURRENT_USER, SETTINGSSUBKEY, NULL, REG_OPTION_NON_VOLATILE,
|
||||
KEY_WRITE, NULL, NULL) != ERROR_SUCCESS)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -40,12 +40,7 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nSh
|
|||
}
|
||||
|
||||
hInst = hInstance;
|
||||
|
||||
BOOL bIsFirstLaunch = !LoadSettings(&SettingsInfo);
|
||||
if (bIsFirstLaunch)
|
||||
{
|
||||
FillDefaultSettings(&SettingsInfo);
|
||||
}
|
||||
|
||||
InitLogs();
|
||||
InitCommonControls();
|
||||
|
|
Loading…
Reference in a new issue