https://git.reactos.org/?p=reactos.git;a=commitdiff;h=14ebc0ba3d169fb253a36d...
commit 14ebc0ba3d169fb253a36d961654fd3e58f92f2b Author: Bișoc George fraizeraust99@gmail.com AuthorDate: Thu Dec 12 00:25:55 2019 +0100 Commit: Katayama Hirofumi MZ katayama.hirofumi.mz@gmail.com CommitDate: Thu Dec 12 08:25:55 2019 +0900
[OSK] Refactor the registry configuration code (#2096)
Rewrite LoadDataFromRegistry() and SaveDataToRegistry() as function helpers. With these, we'll be able to load and save data to registry on our choice. --- base/applications/osk/main.c | 14 +- base/applications/osk/precomp.h | 12 +- base/applications/osk/settings.c | 303 +++++++++++++-------------------------- 3 files changed, 113 insertions(+), 216 deletions(-)
diff --git a/base/applications/osk/main.c b/base/applications/osk/main.c index 7994571dfee..1dc36eae705 100644 --- a/base/applications/osk/main.c +++ b/base/applications/osk/main.c @@ -257,7 +257,7 @@ int OSK_DlgInitDialog(HWND hDlg) */ VOID OSK_RestoreDlgPlacement(HWND hDlg) { - LoadDataFromRegistry(); + LoadSettings(); SetWindowPos(hDlg, (Globals.bAlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST), Globals.PosX, Globals.PosY, 0, 0, SWP_NOSIZE); }
@@ -282,8 +282,8 @@ int OSK_DlgClose(void) /* delete GDI objects */ if (Globals.hBrushGreenLed) DeleteObject(Globals.hBrushGreenLed);
- /* Save the settings to the registry hive */ - SaveDataToRegistry(); + /* Save the application's settings on registry */ + SaveSettings();
return TRUE; } @@ -633,7 +633,7 @@ INT_PTR APIENTRY OSK_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) */ Globals.bIsEnhancedKeyboard = TRUE; EndDialog(hDlg, FALSE); - SaveDataToRegistry(); + SaveSettings();
/* Change the condition of enhanced keyboard item menu to checked */ CheckMenuItem(GetMenu(hDlg), IDM_ENHANCED_KB, MF_BYCOMMAND | MF_CHECKED); @@ -666,7 +666,7 @@ INT_PTR APIENTRY OSK_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) */ Globals.bIsEnhancedKeyboard = FALSE; EndDialog(hDlg, FALSE); - SaveDataToRegistry(); + SaveSettings();
/* Change the condition of standard keyboard item menu to checked */ CheckMenuItem(GetMenu(hDlg), IDM_ENHANCED_KB, MF_BYCOMMAND | MF_UNCHECKED); @@ -805,8 +805,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, ZeroMemory(&Globals, sizeof(Globals)); Globals.hInstance = hInstance;
- /* Load the settings from the registry hive */ - LoadDataFromRegistry(); + /* Load the application's settings from the registry */ + LoadSettings();
/* If the member of the struct (bShowWarning) is set then display the dialog box */ if (Globals.bShowWarning) diff --git a/base/applications/osk/precomp.h b/base/applications/osk/precomp.h index e2503f787e4..1b71c5860cc 100644 --- a/base/applications/osk/precomp.h +++ b/base/applications/osk/precomp.h @@ -68,11 +68,17 @@ LRESULT APIENTRY OSK_ThemeHandler(HWND hDlg, NMCUSTOMDRAW *pNmDraw); int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int); VOID OSK_RestoreDlgPlacement(HWND hDlg); VOID OSK_RefreshLEDKeys(VOID); +INT_PTR CALLBACK OSK_WarningProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
/* settings.c */ -BOOL LoadDataFromRegistry(VOID); -BOOL SaveDataToRegistry(VOID); -INT_PTR CALLBACK OSK_WarningProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam); +LONG LoadDataFromRegistry(IN LPCWSTR lpValueDataName, + OUT PDWORD pdwValueData); + +LONG SaveDataToRegistry(IN LPCWSTR lpValueDataName, + IN DWORD dwValueData); + +VOID LoadSettings(VOID); +VOID SaveSettings(VOID);
/* DEFINES ********************************************************************/
diff --git a/base/applications/osk/settings.c b/base/applications/osk/settings.c index 1f4d9c94800..c674984994b 100644 --- a/base/applications/osk/settings.c +++ b/base/applications/osk/settings.c @@ -11,24 +11,18 @@
/* FUNCTIONS *******************************************************************/
-BOOL LoadDataFromRegistry(VOID) +LONG LoadDataFromRegistry(IN LPCWSTR lpValueDataName, + OUT PDWORD pdwValueData) { HKEY hKey; LONG lResult; DWORD dwValue; DWORD cbData = sizeof(dwValue);
- /* Initialize the registry application settings */ - Globals.bShowWarning = TRUE; - Globals.bIsEnhancedKeyboard = TRUE; - Globals.bSoundClick = FALSE; - Globals.bAlwaysOnTop = TRUE; - - /* Set the coordinate values to default */ - Globals.PosX = CW_USEDEFAULT; - Globals.PosY = CW_USEDEFAULT; + /* Initialize the pointer parameter to default */ + *pdwValueData = 0;
- /* Open the key, so that we can query it */ + /* Open our application's key in order to load its configuration data */ lResult = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\Microsoft\Osk", 0, @@ -37,133 +31,49 @@ BOOL LoadDataFromRegistry(VOID)
if (lResult != ERROR_SUCCESS) { - /* Bail out and return FALSE if we fail */ - return FALSE; - } - - /* Query the key */ - lResult = RegQueryValueExW(hKey, - L"ShowWarning", - 0, - 0, - (BYTE *)&dwValue, - &cbData); - - if (lResult != ERROR_SUCCESS || cbData != sizeof(dwValue)) - { - /* Bail out and return FALSE if we fail */ - RegCloseKey(hKey); - return FALSE; - } - - /* Load the data value (it can be either FALSE or TRUE depending on the data itself) */ - Globals.bShowWarning = (dwValue != 0); - - /* Query the key */ - lResult = RegQueryValueExW(hKey, - L"IsEnhancedKeyboard", - 0, - 0, - (BYTE *)&dwValue, - &cbData); - - if (lResult != ERROR_SUCCESS || cbData != sizeof(dwValue)) - { - /* Bail out and return FALSE if we fail */ - RegCloseKey(hKey); - return FALSE; - } - - /* Load the dialog layout value */ - Globals.bIsEnhancedKeyboard = (dwValue != 0); - - /* Query the key */ - lResult = RegQueryValueExW(hKey, - L"ClickSound", - 0, - 0, - (BYTE *)&dwValue, - &cbData); - - if (lResult != ERROR_SUCCESS || cbData != sizeof(dwValue)) - { - /* Bail out and return FALSE if we fail */ - RegCloseKey(hKey); - return FALSE; + /* Bail out */ + DPRINT("LoadDataFromRegistry(): Failed to open the application's key! (Error - %li)\n", lResult); + return lResult; }
- /* Load the sound on click value event */ - Globals.bSoundClick = (dwValue != 0); - - /* Query the key */ + /* Load the specific value based on the parameter caller, lpValueDataName */ lResult = RegQueryValueExW(hKey, - L"WindowLeft", + lpValueDataName, 0, 0, (BYTE *)&dwValue, &cbData);
- if (lResult != ERROR_SUCCESS || cbData != sizeof(dwValue)) + if (lResult != ERROR_SUCCESS) { - /* Bail out and return FALSE if we fail */ - RegCloseKey(hKey); - return FALSE; - }
- /* Load the X value data of the dialog's coordinate */ - Globals.PosX = dwValue; - - lResult = RegQueryValueExW(hKey, - L"WindowTop", - 0, - 0, - (BYTE *)&dwValue, - &cbData); - - if (lResult != ERROR_SUCCESS || cbData != sizeof(dwValue)) - { - /* Bail out and return FALSE if we fail */ + /* Bail out */ + DPRINT("LoadDataFromRegistry(): Failed to load the following value - "%S". (Error - %li)\n", lpValueDataName, lResult); RegCloseKey(hKey); - return FALSE; + return lResult; }
- /* Load the Y value data of the dialog's coordinate */ - Globals.PosY = dwValue; - - lResult = RegQueryValueExW(hKey, - L"AlwaysOnTop", - 0, - 0, - (BYTE *)&dwValue, - &cbData); - - if (lResult != ERROR_SUCCESS || cbData != sizeof(dwValue)) + /* Is the buffer's size too small to query the required data? */ + if (cbData != sizeof(dwValue)) { - /* Bail out and return FALSE if we fail */ + /* It is therefore bail out */ + DPRINT("LoadDataFromRegistry(): The buffer is too small to hold the data!\n"); RegCloseKey(hKey); - return FALSE; + return ERROR_MORE_DATA; }
- /* Load the window state value data */ - Globals.bAlwaysOnTop = (dwValue != 0); - - /* If we're here then we succeed, close the key and return TRUE */ + *pdwValueData = dwValue; RegCloseKey(hKey); - return TRUE; + return lResult; }
-BOOL SaveDataToRegistry(VOID) +LONG SaveDataToRegistry(IN LPCWSTR lpValueDataName, + IN DWORD dwValueData) { HKEY hKey; LONG lResult; - DWORD dwValue; - WINDOWPLACEMENT wp;
- /* Set the structure length and retrieve the dialog's placement */ - wp.length = sizeof(WINDOWPLACEMENT); - GetWindowPlacement(Globals.hMainWnd, &wp); - - /* If no key has been made, create one */ + /* Set up the application's key in case it has not been made yet */ lResult = RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\Microsoft\Osk", 0, @@ -176,119 +86,100 @@ BOOL SaveDataToRegistry(VOID)
if (lResult != ERROR_SUCCESS) { - /* Bail out and return FALSE if we fail */ - return FALSE; - } - - /* The data value of the subkey will be appended to the warning dialog switch */ - dwValue = Globals.bShowWarning; - - /* Welcome warning box value key */ - lResult = RegSetValueExW(hKey, - L"ShowWarning", - 0, - REG_DWORD, - (BYTE *)&dwValue, - sizeof(dwValue)); - - if (lResult != ERROR_SUCCESS) - { - /* Bail out and return FALSE if we fail */ - RegCloseKey(hKey); - return FALSE; + /* Bail out */ + DPRINT("SaveDataToRegistry(): Failed to create the application's key! (Error - %li)\n", lResult); + return lResult; }
- /* The value will be appended to the layout dialog */ - dwValue = Globals.bIsEnhancedKeyboard; - - /* Keyboard dialog switcher */ + /* Save the data into the registry value */ lResult = RegSetValueExW(hKey, - L"IsEnhancedKeyboard", + lpValueDataName, 0, REG_DWORD, - (BYTE *)&dwValue, - sizeof(dwValue)); + (BYTE *)&dwValueData, + sizeof(dwValueData));
if (lResult != ERROR_SUCCESS) { - /* Bail out and return FALSE if we fail */ + /* Bail out */ + DPRINT("SaveDataToRegistry(): Failed to save the following value - "%S". (Error - %li)\n", lpValueDataName, lResult); RegCloseKey(hKey); - return FALSE; + return lResult; }
- /* The value will be appended to the sound on click event */ - dwValue = Globals.bSoundClick; + RegCloseKey(hKey); + return lResult; +}
- /* "Sound on Click" switcher value key */ - lResult = RegSetValueExW(hKey, - L"ClickSound", - 0, - REG_DWORD, - (BYTE *)&dwValue, - sizeof(dwValue)); +VOID LoadSettings(VOID) +{ + DWORD dwValue; + LONG lResult;
- if (lResult != ERROR_SUCCESS) - { - /* Bail out and return FALSE if we fail */ - RegCloseKey(hKey); - return FALSE; - } + /* Initialize the registry application settings */ + Globals.bShowWarning = TRUE; + Globals.bIsEnhancedKeyboard = TRUE; + Globals.bAlwaysOnTop = TRUE; + Globals.bSoundClick = FALSE;
- /* The value will be appended to the X coordination dialog's placement */ - dwValue = wp.rcNormalPosition.left; + /* Set the coordinate values to default */ + Globals.PosX = CW_USEDEFAULT; + Globals.PosY = CW_USEDEFAULT;
- /* Position X coordination of dialog's placement value key */ - lResult = RegSetValueExW(hKey, - L"WindowLeft", - 0, - REG_DWORD, - (BYTE *)&dwValue, - sizeof(dwValue)); + /* Warning dialog registry setting */ + lResult = LoadDataFromRegistry(L"ShowWarning", &dwValue); + if (lResult == NO_ERROR) + Globals.bShowWarning = (dwValue != 0); + + /* Enhanced keyboard switch dialog registry setting */ + lResult = LoadDataFromRegistry(L"IsEnhancedKeyboard", &dwValue); + if (lResult == NO_ERROR) + Globals.bIsEnhancedKeyboard = (dwValue != 0); + + /* Sound on click event registry setting */ + lResult = LoadDataFromRegistry(L"ClickSound", &dwValue); + if (lResult == NO_ERROR) + Globals.bSoundClick = (dwValue != 0); + + /* X coordinate dialog placement registry setting */ + lResult = LoadDataFromRegistry(L"WindowLeft", &dwValue); + if (lResult == NO_ERROR) + Globals.PosX = dwValue; + + /* Y coordinate dialog placement registry setting */ + lResult = LoadDataFromRegistry(L"WindowTop", &dwValue); + if (lResult == NO_ERROR) + Globals.PosY = dwValue; + + /* Top window state registry setting */ + lResult = LoadDataFromRegistry(L"AlwaysOnTop", &dwValue); + if (lResult == NO_ERROR) + Globals.bAlwaysOnTop = (dwValue != 0); +}
- if (lResult != ERROR_SUCCESS) - { - /* Bail out and return FALSE if we fail */ - RegCloseKey(hKey); - return FALSE; - } +VOID SaveSettings(VOID) +{ + WINDOWPLACEMENT wp;
- /* The value will be appended to the Y coordination dialog's placement */ - dwValue = wp.rcNormalPosition.top; + /* Initialize the window placement structure */ + wp.length = sizeof(WINDOWPLACEMENT); + GetWindowPlacement(Globals.hMainWnd, &wp);
- /* Position Y coordination of dialog's placement value key */ - lResult = RegSetValueExW(hKey, - L"WindowTop", - 0, - REG_DWORD, - (BYTE *)&dwValue, - sizeof(dwValue)); + /* Warning dialog registry setting */ + SaveDataToRegistry(L"ShowWarning", Globals.bShowWarning);
- if (lResult != ERROR_SUCCESS) - { - /* Bail out and return FALSE if we fail */ - RegCloseKey(hKey); - return FALSE; - } + /* Enhanced keyboard switch dialog registry setting */ + SaveDataToRegistry(L"IsEnhancedKeyboard", Globals.bIsEnhancedKeyboard);
- /* Window top state value */ - dwValue = Globals.bAlwaysOnTop; + /* Sound on click event registry setting */ + SaveDataToRegistry(L"ClickSound", Globals.bSoundClick);
- /* "Always on Top" state value key */ - lResult = RegSetValueExW(hKey, - L"AlwaysOnTop", - 0, - REG_DWORD, - (BYTE *)&dwValue, - sizeof(dwValue)); + /* X coordinate dialog placement registry setting */ + SaveDataToRegistry(L"WindowLeft", wp.rcNormalPosition.left);
- if (lResult != ERROR_SUCCESS) - { - /* Bail out and return FALSE if we fail */ - RegCloseKey(hKey); - return FALSE; - } + /* Y coordinate dialog placement registry setting */ + SaveDataToRegistry(L"WindowTop", wp.rcNormalPosition.top);
- /* If we're here then we succeed, close the key and return TRUE */ - RegCloseKey(hKey); - return TRUE; + /* Top window state registry setting */ + SaveDataToRegistry(L"AlwaysOnTop", Globals.bAlwaysOnTop); }