[PATCH] windows.c: Added support for "int" configuration storage

Lubomir I. Ivanov neolit123 at gmail.com
Thu Feb 28 16:45:32 PST 2013


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

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 at gmail.com>
---
 windows.c | 44 ++++++++++++++------------------------------
 1 file changed, 14 insertions(+), 30 deletions(-)

diff --git a/windows.c b/windows.c
index 948b1f7..de1c905 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)
--
1.7.11.msysgit.0



More information about the subsurface mailing list