From 0fc089c66941b6799dce9fbb6e3ccd51ede2b65d Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Fri, 1 Mar 2013 02:45:32 +0200 Subject: 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 Signed-off-by: Dirk Hohndel --- windows.c | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) (limited to 'windows.c') 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) -- cgit v1.2.3-70-g09d2