1 /* 2 * PROJECT: ReactOS On-Screen Keyboard 3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) 4 * PURPOSE: Settings file for warning dialog on startup 5 * COPYRIGHT: Copyright 2018 Bișoc George (fraizeraust99 at gmail dot com) 6 */ 7 8 /* INCLUDES *******************************************************************/ 9 10 #include "osk.h" 11 #include "settings.h" 12 13 /* FUNCTIONS *******************************************************************/ 14 15 BOOL LoadDataFromRegistry() 16 { 17 HKEY hKey; 18 LONG lResult; 19 DWORD dwShowWarningData, dwLayout, dwSoundOnClick; 20 DWORD cbData = sizeof(DWORD); 21 22 /* Set the structure members to TRUE (and the bSoundClick member to FALSE) */ 23 Globals.bShowWarning = TRUE; 24 Globals.bIsEnhancedKeyboard = TRUE; 25 Globals.bSoundClick = FALSE; 26 27 /* Open the key, so that we can query it */ 28 lResult = RegOpenKeyExW(HKEY_CURRENT_USER, 29 L"Software\\Microsoft\\osk", 30 0, 31 KEY_READ, 32 &hKey); 33 34 if (lResult != ERROR_SUCCESS) 35 { 36 /* Bail out and return FALSE if we fail */ 37 return FALSE; 38 } 39 40 /* Query the key */ 41 lResult = RegQueryValueExW(hKey, 42 L"ShowWarning", 43 0, 44 0, 45 (BYTE *)&dwShowWarningData, 46 &cbData); 47 48 if (lResult != ERROR_SUCCESS) 49 { 50 /* Bail out and return FALSE if we fail */ 51 RegCloseKey(hKey); 52 return FALSE; 53 } 54 55 /* Load the data value (it can be either FALSE or TRUE depending on the data itself) */ 56 Globals.bShowWarning = (dwShowWarningData != 0); 57 58 /* Query the key */ 59 lResult = RegQueryValueExW(hKey, 60 L"IsEnhancedKeyboard", 61 0, 62 0, 63 (BYTE *)&dwLayout, 64 &cbData); 65 66 if (lResult != ERROR_SUCCESS) 67 { 68 /* Bail out and return FALSE if we fail */ 69 RegCloseKey(hKey); 70 return FALSE; 71 } 72 73 /* Load the dialog layout value */ 74 Globals.bIsEnhancedKeyboard = (dwLayout != 0); 75 76 /* Query the key */ 77 lResult = RegQueryValueExW(hKey, 78 L"OnSoundClick", 79 0, 80 0, 81 (BYTE *)&dwSoundOnClick, 82 &cbData); 83 84 if (lResult != ERROR_SUCCESS) 85 { 86 /* Bail out and return FALSE if we fail */ 87 RegCloseKey(hKey); 88 return FALSE; 89 } 90 91 /* Load the sound on click value event */ 92 Globals.bSoundClick = (dwSoundOnClick != 0); 93 94 /* If we're here then we succeed, close the key and return TRUE */ 95 RegCloseKey(hKey); 96 return TRUE; 97 } 98 99 BOOL SaveDataToRegistry() 100 { 101 HKEY hKey; 102 LONG lResult; 103 DWORD dwShowWarningData, dwLayout, dwSoundOnClick; 104 105 /* If no key has been made, create one */ 106 lResult = RegCreateKeyExW(HKEY_CURRENT_USER, 107 L"Software\\Microsoft\\osk", 108 0, 109 NULL, 110 0, 111 KEY_WRITE, 112 NULL, 113 &hKey, 114 NULL); 115 116 if (lResult != ERROR_SUCCESS) 117 { 118 /* Bail out and return FALSE if we fail */ 119 return FALSE; 120 } 121 122 /* The data value of the subkey will be appended to the warning dialog switch */ 123 dwShowWarningData = Globals.bShowWarning; 124 125 lResult = RegSetValueExW(hKey, 126 L"ShowWarning", 127 0, 128 REG_DWORD, 129 (BYTE *)&dwShowWarningData, 130 sizeof(dwShowWarningData)); 131 132 if (lResult != ERROR_SUCCESS) 133 { 134 /* Bail out and return FALSE if we fail */ 135 RegCloseKey(hKey); 136 return FALSE; 137 } 138 139 /* The value will be appended to the layout dialog */ 140 dwLayout = Globals.bIsEnhancedKeyboard; 141 142 lResult = RegSetValueExW(hKey, 143 L"IsEnhancedKeyboard", 144 0, 145 REG_DWORD, 146 (BYTE *)&dwLayout, 147 sizeof(dwLayout)); 148 149 if (lResult != ERROR_SUCCESS) 150 { 151 /* Bail out and return FALSE if we fail */ 152 RegCloseKey(hKey); 153 return FALSE; 154 } 155 156 /* The value will be appended to the sound on click event */ 157 dwSoundOnClick = Globals.bSoundClick; 158 159 lResult = RegSetValueExW(hKey, 160 L"OnSoundClick", 161 0, 162 REG_DWORD, 163 (BYTE *)&dwSoundOnClick, 164 sizeof(dwSoundOnClick)); 165 166 if (lResult != ERROR_SUCCESS) 167 { 168 /* Bail out and return FALSE if we fail */ 169 RegCloseKey(hKey); 170 return FALSE; 171 } 172 173 /* If we're here then we succeed, close the key and return TRUE */ 174 RegCloseKey(hKey); 175 return TRUE; 176 } 177