summaryrefslogtreecommitdiffstats
path: root/windows.c
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2013-03-01 02:45:32 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-28 19:56:37 -0800
commit0fc089c66941b6799dce9fbb6e3ccd51ede2b65d (patch)
tree3a6728775340e88907f30431bc27c42c97f8571b /windows.c
parentc0c88ba69d0fd7796d55258f8abbd41cdadf4b1e (diff)
downloadsubsurface-0fc089c66941b6799dce9fbb6e3ccd51ede2b65d.tar.gz
windows.c: Added support for "int" configuration storage
This patch addes body to the functions subsurface_get_conf_int() and subsurface_set_conf_int(). It also makes some small changes: - subsurface_get_conf_bool() now uses subsurface_get_conf_int() - for retrieving DWORDS we would only need RegQueryValueEx, thus the wchar_t conversations aren't really needed, unless we start storing integers in keys with UTF-8 characters in the name. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'windows.c')
-rw-r--r--windows.c44
1 files changed, 14 insertions, 30 deletions
diff --git a/windows.c b/windows.c
index 948b1f701..de1c905ea 100644
--- a/windows.c
+++ b/windows.c
@@ -9,20 +9,6 @@ const char system_divelist_default_font[] = "Sans 8";
static HKEY hkey;
-/* Return "boolean" 0/1, or -1 if nonexistent */
-static int get_from_registry(HKEY hkey, const char *key)
-{
- DWORD value;
- DWORD len = 4;
- LONG success;
-
- success = RegQueryValueEx(hkey, (LPCTSTR)TEXT(key), NULL, NULL,
- (LPBYTE) &value, (LPDWORD)&len);
- if (success != ERROR_SUCCESS)
- return -1;
- return value != 0;
-}
-
void subsurface_open_conf(void)
{
LONG success;
@@ -71,22 +57,14 @@ void subsurface_set_conf(char *name, const char *value)
free(wname);
}
-void subsurface_set_conf_bool(char *name, int value)
+void subsurface_set_conf_int(char *name, int value)
{
- wchar_t *wname;
-
- wname = (wchar_t *)g_utf8_to_utf16(name, -1, NULL, NULL, NULL);
- if (!wname)
- return;
-
- /* we simply store the value as DWORD */
- RegSetValueExW(hkey, (LPCWSTR)wname, 0, REG_DWORD, (const BYTE *)&value, 4);
- free(wname);
+ RegSetValueEx(hkey, (LPCTSTR)name, 0, REG_DWORD, (const BYTE *)&value, 4);
}
-void subsurface_set_conf_int(char *name, int value)
+void subsurface_set_conf_bool(char *name, int value)
{
- /* call to set registry key to value here? */
+ subsurface_set_conf_int(name, value);
}
const void *subsurface_get_conf(char *name)
@@ -127,14 +105,20 @@ const void *subsurface_get_conf(char *name)
return utf8_string;
}
-int subsurface_get_conf_bool(char *name)
+int subsurface_get_conf_int(char *name)
{
- return get_from_registry(hkey, name);
+ DWORD value = -1, len = 4;
+ RegQueryValueEx(hkey, (LPCTSTR)TEXT(name), NULL, NULL,
+ (LPBYTE)&value, (LPDWORD)&len);
+ return value;
}
-int subsurface_get_conf_int(char *name)
+int subsurface_get_conf_bool(char *name)
{
- return -1; /* windows registry call here? */
+ int ret = subsurface_get_conf_int(name);
+ if (ret == -1)
+ return 0;
+ return ret != 0;
}
void subsurface_flush_conf(void)