33f8893d57c80000c7c5b4dca5c1ada8fbefadca
[reactos.git] / base / applications / osk / settings.c
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 dwData;
20 DWORD cbData = sizeof(DWORD);
21
22 /* Set the structure member to TRUE */
23 Globals.bShowWarning = TRUE;
24
25 /* Open the key, so that we can query it */
26 lResult = RegOpenKeyExW(HKEY_CURRENT_USER,
27 L"Software\\Microsoft\\osk",
28 0,
29 KEY_READ,
30 &hKey);
31
32 if (lResult != ERROR_SUCCESS)
33 {
34 /* Bail out and return FALSE if we fail */
35 return FALSE;
36 }
37
38 /* Query the key */
39 lResult = RegQueryValueExW(hKey,
40 L"ShowWarning",
41 0,
42 0,
43 (BYTE *)&dwData,
44 &cbData);
45
46 if (lResult != ERROR_SUCCESS)
47 {
48 /* Bail out and return FALSE if we fail */
49 RegCloseKey(hKey);
50 return FALSE;
51 }
52
53 /* Load the data value (it can be either FALSE or TRUE depending on the data itself) */
54 Globals.bShowWarning = (dwData != 0);
55
56 /* If we're here then we succeed, close the key and return TRUE */
57 RegCloseKey(hKey);
58 return TRUE;
59 }
60
61 BOOL SaveDataToRegistry()
62 {
63 HKEY hKey;
64 LONG lResult;
65 DWORD dwData;
66
67 /* If no key has been made, create one */
68 lResult = RegCreateKeyExW(HKEY_CURRENT_USER,
69 L"Software\\Microsoft\\osk",
70 0,
71 NULL,
72 0,
73 KEY_WRITE,
74 NULL,
75 &hKey,
76 NULL);
77
78 if (lResult != ERROR_SUCCESS)
79 {
80 /* Bail out and return FALSE if we fail */
81 return FALSE;
82 }
83
84 /* The data value of the subkey will be appended to the warning dialog switch */
85 dwData = Globals.bShowWarning;
86
87 lResult = RegSetValueExW(hKey,
88 L"ShowWarning",
89 0,
90 REG_DWORD,
91 (BYTE *)&dwData,
92 sizeof(dwData));
93
94 if (lResult != ERROR_SUCCESS)
95 {
96 /* Bail out and return FALSE if we fail */
97 RegCloseKey(hKey);
98 return FALSE;
99 }
100
101 /* If we're here then we succeed, close the key and return TRUE */
102 RegCloseKey(hKey);
103 return TRUE;
104 }