2011-11-24 06:56:57 +00:00
|
|
|
/* windows.c */
|
|
|
|
/* implements Windows specific functions */
|
|
|
|
#include "display-gtk.h"
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
static HKEY hkey;
|
|
|
|
|
|
|
|
static int get_from_registry(HKEY hkey, const char *key)
|
|
|
|
{
|
|
|
|
DWORD value;
|
|
|
|
DWORD len = 4;
|
|
|
|
LONG success;
|
|
|
|
|
2011-11-26 04:09:01 +00:00
|
|
|
success = RegQueryValueEx(hkey, (LPCTSTR)TEXT(key), NULL, NULL,
|
|
|
|
(LPBYTE) &value, (LPDWORD)&len );
|
2011-11-24 06:56:57 +00:00
|
|
|
if (success != ERROR_SUCCESS)
|
|
|
|
return FALSE; /* that's what happens the first time we start */
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void subsurface_open_conf(void)
|
|
|
|
{
|
|
|
|
LONG success;
|
|
|
|
|
2011-11-26 04:09:01 +00:00
|
|
|
success = RegCreateKeyEx(HKEY_CURRENT_USER, (LPCTSTR)TEXT("Software\\subsurface"),
|
2011-11-26 03:48:53 +00:00
|
|
|
0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
|
|
|
|
NULL, &hkey, NULL);
|
|
|
|
if (success != ERROR_SUCCESS)
|
|
|
|
printf("CreateKey Software\\subsurface failed %ld\n", success);
|
2011-11-24 06:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void subsurface_set_conf(char *name, pref_type_t type, const void *value)
|
|
|
|
{
|
2011-11-26 04:09:01 +00:00
|
|
|
/* since we are using the pointer 'value' as both an actual
|
|
|
|
* pointer to the string setting and as a way to pass the
|
|
|
|
* numbers 0 and 1 to this function for booleans, one of the
|
|
|
|
* calls to RegSetValueEx needs to pass &value (when we want
|
|
|
|
* to pass the boolean value), the other one passes value (the
|
|
|
|
* address of the string. */
|
2011-11-24 06:56:57 +00:00
|
|
|
switch (type) {
|
|
|
|
case PREF_BOOL:
|
|
|
|
/* we simply store the value as DWORD */
|
2011-11-26 04:09:01 +00:00
|
|
|
RegSetValueEx(hkey, (LPCTSTR)TEXT(name), 0, REG_DWORD, (const BYTE *)&value, 4);
|
2011-11-24 06:56:57 +00:00
|
|
|
break;
|
|
|
|
case PREF_STRING:
|
2011-11-26 04:09:01 +00:00
|
|
|
RegSetValueEx(hkey, (LPCTSTR)TEXT(name), 0, REG_SZ, (const BYTE *)value, strlen(value));
|
2011-11-24 06:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const void *subsurface_get_conf(char *name, pref_type_t type)
|
|
|
|
{
|
2011-11-25 06:32:10 +00:00
|
|
|
LONG success;
|
2011-11-24 06:56:57 +00:00
|
|
|
char *string;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case PREF_BOOL:
|
|
|
|
return get_from_registry(hkey, name) ? (void *) 1 : NULL;
|
|
|
|
case PREF_STRING:
|
|
|
|
string = malloc(80);
|
|
|
|
len = 80;
|
2011-11-26 04:09:01 +00:00
|
|
|
success = RegQueryValueEx(hkey, (LPCTSTR)TEXT(name), NULL, NULL,
|
2011-11-25 06:32:10 +00:00
|
|
|
(LPBYTE) string, (LPDWORD)&len );
|
2011-11-24 06:56:57 +00:00
|
|
|
if (success != ERROR_SUCCESS) {
|
|
|
|
/* that's what happens the first time we start - just return NULL */
|
|
|
|
free(string);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
/* we shouldn't get here */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void subsurface_close_conf(void)
|
|
|
|
{
|
|
|
|
if (RegFlushKey(hkey) != ERROR_SUCCESS)
|
2011-11-25 06:32:10 +00:00
|
|
|
printf("RegFlushKey failed \n");
|
2011-11-24 06:56:57 +00:00
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|