]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
imported winuaesrc1450b9.zip
authorToni Wilen <twilen@winuae.net>
Sat, 10 Nov 2007 12:08:16 +0000 (14:08 +0200)
committerToni Wilen <twilen@winuae.net>
Mon, 22 Feb 2010 19:36:54 +0000 (21:36 +0200)
20 files changed:
custom.c
od-win32/avioutput.c
od-win32/bsdsock.c
od-win32/debug_win32.c
od-win32/hardfile_win32.c
od-win32/midi.c
od-win32/parser.c
od-win32/picasso96_win.c
od-win32/registry.c [new file with mode: 0644]
od-win32/registry.h [new file with mode: 0644]
od-win32/win32.c
od-win32/win32.h
od-win32/win32gfx.c
od-win32/win32gui.c
od-win32/win32gui.h
od-win32/win32gui_extra.c
od-win32/winuae_msvc/winuae_msvc.8.vcproj
od-win32/winuae_msvc/winuae_msvc.vcproj
od-win32/winuaechangelog.txt
od-win32/writelog.c

index 9b5a79f2539c8c2b3b895020f8afc238840decf1..2011d59e47acf99968a63bbc1f98155548444374 100644 (file)
--- a/custom.c
+++ b/custom.c
@@ -4668,7 +4668,7 @@ void customreset (int hardreset)
     int zero = 0;
 
     reset_all_systems ();
-    write_log ("Reset at %08.8X\n", m68k_getpc (&regs));
+    write_log ("Reset at %08X\n", m68k_getpc (&regs));
     memory_map_dump();
 
     hsync_counter = 0;
index fc9c72081f0d9454136fb4db2726f877ebdce43d..29464d3587de606429790a9f50d95cba8e9bc751 100644 (file)
@@ -32,6 +32,7 @@
 #include "xwin.h"
 #include "resource.h"
 #include "avioutput.h"
+#include "registry.h"
 
 #define MAX_AVI_SIZE (0x80000000 - 0x1000000)
 
@@ -79,6 +80,7 @@ static ACMFORMATCHOOSE acmopt;
 
 static WAVEFORMATEX wfxSrc; // source audio format
 static LPWAVEFORMATEX pwfxDst = NULL; // pointer to destination audio format
+static DWORD wfxMaxFmtSize;
 
 static FILE *wavfile;
 
@@ -95,51 +97,43 @@ static LPBITMAPINFOHEADER lpbi = NULL; // can also be used as LPBITMAPINFO becau
 static uae_u8 *lpVideo = NULL; // pointer to video data (bitmap bits)
 
 
-static HKEY openavikey(void)
+static UAEREG *openavikey(void)
 {
-    HKEY fkey = NULL;
-    RegCreateKeyEx(hWinUAEKey , "AVConfiguration", 0, NULL, REG_OPTION_NON_VOLATILE,
-       KEY_READ | KEY_WRITE, NULL, &fkey, NULL);
-    return fkey;
+    return regcreatetree (NULL, "AVConfiguration");
 }
 
-static void storesettings(HKEY avikey)
+static void storesettings(UAEREG *avikey)
 {
-    RegSetValueEx(avikey, "FrameLimiter", 0, REG_DWORD, (BYTE*)&avioutput_framelimiter, sizeof(DWORD));
-    RegSetValueEx(avikey, "NoSoundOutput", 0, REG_DWORD, (BYTE*)&avioutput_nosoundoutput, sizeof(DWORD));
-    RegSetValueEx(avikey, "FPS", 0, REG_DWORD, (BYTE*)&avioutput_fps, sizeof(DWORD));
+    regsetint (avikey, "FrameLimiter", avioutput_framelimiter);
+    regsetint (avikey, "NoSoundOutput", avioutput_nosoundoutput);
+    regsetint (avikey, "FPS", avioutput_fps);
 }
-static void getsettings(HKEY avikey)
+static void getsettings(UAEREG *avikey)
 {
     DWORD val;
-    DWORD ss = sizeof (DWORD);
-    if (RegQueryValueEx(avikey, "NoSoundOutput", 0, NULL, (BYTE*)&val, &ss) == ERROR_SUCCESS)
+    if (regqueryint (avikey, "NoSoundOutput", &val))
        avioutput_nosoundoutput = val;
-    ss = sizeof (DWORD);
-    if (RegQueryValueEx(avikey, "FrameLimiter", 0, NULL, (BYTE*)&val, &ss) == ERROR_SUCCESS)
+    if (regqueryint (avikey, "FrameLimiter", &val))
        avioutput_framelimiter = val;
     if (!avioutput_framelimiter)
        avioutput_nosoundoutput = 1;
-    ss = sizeof (DWORD);
-    if (RegQueryValueEx(avikey, "FPS", 0, NULL, (BYTE*)&val, &ss) == ERROR_SUCCESS)
+    if (regqueryint (avikey, "FPS", &val))
        avioutput_fps = val;
 }
 
 void AVIOutput_GetSettings(void)
 {
-    HKEY avikey = openavikey();
-    if (avikey) {
+    UAEREG *avikey = openavikey();
+    if (avikey)
        getsettings(avikey);
-       RegCloseKey(avikey);
-    }
+    regclosetree (avikey);
 }
 void AVIOutput_SetSettings(void)
 {
-    HKEY avikey = openavikey();
-    if (avikey) {
+    UAEREG *avikey = openavikey();
+    if (avikey)
        storesettings(avikey);
-       RegCloseKey(avikey);
-    }
+    regclosetree (avikey);
 }
 
 static UINT CALLBACK acmFilterChooseHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
@@ -190,7 +184,6 @@ static int AVIOutput_AudioAllocated(void)
 static int AVIOutput_AllocateAudio(void)
 {
     MMRESULT err;
-    DWORD wfxMaxFmtSize;
 
     AVIOutput_ReleaseAudio();
 
@@ -273,25 +266,22 @@ static int AVIOutput_GetAudioFromRegistry(WAVEFORMATEX *wft)
 {
     DWORD ss;
     int ok = 0;
-    HKEY avikey;
+    UAEREG *avikey;
 
     avikey = openavikey();
     if (!avikey)
        return 0;
     getsettings(avikey);
     if (wft) {
-       if (RegQueryValueEx(avikey, "AudioConfigurationVars", 0, NULL, NULL, &ss) == ERROR_SUCCESS) {
-           if (ss <= sizeof(WAVEFORMATEX) + wft->cbSize) {
-               if (RegQueryValueEx(avikey, "AudioConfigurationVars", 0, NULL, (BYTE*)wft, &ss) == ERROR_SUCCESS) {
-                   if (AVIOutput_ValidateAudio(wft, NULL, 0))
-                       ok = 1;
-               }
-           }
+       ss = wfxMaxFmtSize;
+       if (regquerydata (avikey, "AudioConfigurationVars", wft, &ss)) {
+           if (AVIOutput_ValidateAudio(wft, NULL, 0))
+               ok = 1;
        }
     }
     if (!ok)
-       RegDeleteValue(avikey, "AudioConfigurationVars");
-    RegCloseKey(avikey);
+       regdelete (avikey, "AudioConfigurationVars");
+    regclosetree (avikey);
     return ok;
 }
 
@@ -329,13 +319,13 @@ int AVIOutput_ChooseAudioCodec(HWND hwnd, char *s, int len)
     {
        case MMSYSERR_NOERROR:
        {
-           HKEY avikey;
+           UAEREG *avikey;
            strcpy (s, acmopt.szFormatTag);
            avikey = openavikey();
            if (avikey) {
-               RegSetValueEx(avikey, "AudioConfigurationVars", 0, REG_BINARY, (BYTE*)pwfxDst, pwfxDst->cbSize + sizeof(WAVEFORMATEX));
-               storesettings(avikey);
-               RegCloseKey(avikey);
+               regsetdata (avikey, "AudioConfigurationVars", pwfxDst, pwfxDst->cbSize + sizeof(WAVEFORMATEX));
+               storesettings (avikey);
+               regclosetree (avikey);
            }
            return 1;
        }
@@ -421,7 +411,7 @@ static void AVIOutput_FreeCOMPVARS(COMPVARS *pcv)
 
 static int AVIOutput_GetCOMPVARSFromRegistry(COMPVARS *pcv)
 {
-    HKEY avikey;
+    UAEREG *avikey;
     DWORD ss;
     int ok = 0;
 
@@ -432,14 +422,14 @@ static int AVIOutput_GetCOMPVARSFromRegistry(COMPVARS *pcv)
     if (pcv) {
        ss = pcv->cbSize;
        pcv->hic = 0;
-       if (RegQueryValueEx(avikey, "VideoConfigurationVars", 0, NULL, (BYTE*)pcv, &ss) == ERROR_SUCCESS) {
+       if (regquerydata (avikey, "VideoConfigurationVars", pcv, &ss)) {
            pcv->hic = 0;
            pcv->lpbiIn = pcv->lpbiOut = 0;
            pcv->cbState = 0;
-           if (RegQueryValueEx(avikey, "VideoConfigurationState", 0, NULL, NULL, &ss) == ERROR_SUCCESS) {
+           if (regquerydatasize (avikey, "VideoConfigurationState", &ss)) {
                if (ss > 0) {
                    LPBYTE state = xmalloc (ss);
-                   if (RegQueryValueEx(avikey, "VideoConfigurationState", 0, NULL, state, &ss) == ERROR_SUCCESS) {
+                   if (regquerydata (avikey, "VideoConfigurationState", state, &ss)) {
                        pcv->hic = ICOpen(pcv->fccType, pcv->fccHandler, ICMODE_COMPRESS);
                        if (pcv->hic) {
                            ok = 1;
@@ -454,10 +444,10 @@ static int AVIOutput_GetCOMPVARSFromRegistry(COMPVARS *pcv)
        }
     }
     if (!ok) {
-       RegDeleteValue(avikey, "VideoConfigurationVars");
-       RegDeleteValue(avikey, "VideoConfigurationState");
+       regdelete (avikey, "VideoConfigurationVars");
+       regdelete (avikey, "VideoConfigurationState");
     }
-    RegCloseKey(avikey);
+    regclosetree (avikey);
     return ok;
 }
 
@@ -512,7 +502,7 @@ int AVIOutput_ChooseVideoCodec(HWND hwnd, char *s, int len)
     pcompvars->dwFlags = 0;
 
     if(ICCompressorChoose(hwnd, ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME, lpbi, NULL, pcompvars, "Choose Video Codec") == TRUE) {
-       HKEY avikey;
+       UAEREG *avikey;
        int ss;
        uae_u8 *state;
 
@@ -533,10 +523,10 @@ int AVIOutput_ChooseVideoCodec(HWND hwnd, char *s, int len)
            state = xmalloc (1);
        avikey = openavikey();
        if (avikey) {
-           RegSetValueEx(avikey, "VideoConfigurationState", 0, REG_BINARY, state, ss);
-           RegSetValueEx(avikey, "VideoConfigurationVars", 0, REG_BINARY, (BYTE*)pcompvars, pcompvars->cbSize);
+           regsetdata (avikey, "VideoConfigurationState", state, ss);
+           regsetdata (avikey, "VideoConfigurationVars", pcompvars, pcompvars->cbSize);
            storesettings(avikey);
-           RegCloseKey(avikey);
+           regclosetree (avikey);
        }
        xfree (state);
        return AVIOutput_GetVideoCodecName(pcompvars, s, len);
index 803e1a9030ee5d0a90647ab50386f5af2a8fda2b..db79bb49be459ba9c85c02a6e4b09d3fcc88a1dc 100644 (file)
@@ -28,6 +28,7 @@
 #include "bsdsocket.h"
 
 #include "threaddep/thread.h"
+#include "registry.h"
 #include "native2amiga.h"
 #include "resource.h"
 #include "win32gui.h"
index 03f6a993d5804df07058570009999cf219ab448a..18d1f69b7eaccea9bdef9e309c2c4b93423d6a88 100644 (file)
@@ -24,6 +24,7 @@
 #include "savestate.h"
 #include "debug_win32.h"
 #include "win32.h"
+#include "registry.h"
 #include "win32gui.h"
 
 #include "uae.h"
@@ -1075,24 +1076,20 @@ static LRESULT CALLBACK DebuggerProc (HWND hDlg, UINT message, WPARAM wParam, LP
        {
            int newpos = 0;
            LONG x, y, w, h;
-           DWORD regkeytype;
-           DWORD regkeysize = sizeof(LONG);
            RECT rw;
            GetWindowRect(hDlg, &rw);
            dbgwnd_minx = rw.right - rw.left;
            dbgwnd_miny = rw.bottom - rw.top;
            GetClientRect(hDlg, &dlgRect);
-           if (hWinUAEKey) {
-               newpos = 1;
-               if (RegQueryValueEx (hWinUAEKey, "DebuggerPosX", 0, &regkeytype, (LPBYTE)&x, &regkeysize) != ERROR_SUCCESS)
-                   newpos = 0;
-               if (RegQueryValueEx (hWinUAEKey, "DebuggerPosY", 0, &regkeytype, (LPBYTE)&y, &regkeysize) != ERROR_SUCCESS)
-                   newpos = 0;
-               if (RegQueryValueEx (hWinUAEKey, "DebuggerPosW", 0, &regkeytype, (LPBYTE)&w, &regkeysize) != ERROR_SUCCESS)
-                   newpos = 0;
-               if (RegQueryValueEx (hWinUAEKey, "DebuggerPosH", 0, &regkeytype, (LPBYTE)&h, &regkeysize) != ERROR_SUCCESS)
-                   newpos = 0;
-           }
+           newpos = 1;
+           if (!regqueryint (NULL, "DebuggerPosX", &x))
+               newpos = 0;
+           if (!regqueryint (NULL, "DebuggerPosY", &y))
+               newpos = 0;
+           if (!regqueryint (NULL, "DebuggerPosW", &w))
+               newpos = 0;
+           if (!regqueryint (NULL, "DebuggerPosH", &h))
+               newpos = 0;
            if (newpos) {
                RECT rc;
                rc.left = x;
@@ -1118,13 +1115,13 @@ static LRESULT CALLBACK DebuggerProc (HWND hDlg, UINT message, WPARAM wParam, LP
        case WM_DESTROY:
        {
            RECT r;
-           if (GetWindowRect (hDlg, &r) && hWinUAEKey) {
+           if (GetWindowRect (hDlg, &r)) {
                r.right -= r.left;
                r.bottom -= r.top;
-               RegSetValueEx (hWinUAEKey, "DebuggerPosX", 0, REG_DWORD, (LPBYTE)&r.left, sizeof(LONG));
-               RegSetValueEx (hWinUAEKey, "DebuggerPosY", 0, REG_DWORD, (LPBYTE)&r.top, sizeof(LONG));
-               RegSetValueEx (hWinUAEKey, "DebuggerPosW", 0, REG_DWORD, (LPBYTE)&r.right, sizeof(LONG));
-               RegSetValueEx (hWinUAEKey, "DebuggerPosH", 0, REG_DWORD, (LPBYTE)&r.bottom, sizeof(LONG));
+               regsetint (NULL, "DebuggerPosX", r.left);
+               regsetint (NULL, "DebuggerPosY", r.top);
+               regsetint (NULL, "DebuggerPosW", r.right);
+               regsetint (NULL, "DebuggerPosH", r.bottom);
            }
            hDbgWnd = 0;
            PostQuitMessage(0);
index 45068e416e29c5777fb7074951d251447ed8d09a..a59b7080600328fc7fad89cf89162173b4063942 100644 (file)
@@ -10,6 +10,7 @@
 #include "threaddep/thread.h"
 #include "filesys.h"
 #include "blkdev.h"
+#include "registry.h"
 #include "win32gui.h"
 #include "zfile.h"
 
index 95f069c75699ed936ab5c2ea851eb9f5ee7d8d91..19f607aa7f301492b14b7a6a0ef4cbe0a09f2043 100644 (file)
@@ -31,6 +31,7 @@
 #include "options.h"
 #include "parser.h"
 #include "midi.h"
+#include "registry.h"
 #include "resource.h"
 #include "win32gui.h"
 
index 82ad46403708ce7d5b7f7663a981c389fc230a35..b2e92c49b778573e04bad949ac66e2decedbfb99 100644 (file)
@@ -33,6 +33,7 @@
 #include "autoconf.h"
 #include "newcpu.h"
 #include "traps.h"
+#include "registry.h"
 #include "od-win32/win32gui.h"
 #include "od-win32/parser.h"
 #include "od-win32/midi.h"
index 6750fc5bcceb317bb178f8b6fc12943b632d61eb..3f44ae6ed8fd1b623fa3035cf40fc581b52ebf32 100644 (file)
@@ -46,6 +46,7 @@
 
 #if defined(PICASSO96)
 
+#include "registry.h"
 #include "dxwrap.h"
 #include "picasso96_win.h"
 #include "win32gfx.h"
diff --git a/od-win32/registry.c b/od-win32/registry.c
new file mode 100644 (file)
index 0000000..c626132
--- /dev/null
@@ -0,0 +1,429 @@
+
+#include "sysconfig.h"
+#include "sysdeps.h"
+
+#include <windows.h>
+#include "win32.h"
+#include <shlwapi.h>
+#include "registry.h"
+#include "crc32.h"
+
+static int inimode = 0;
+static char *inipath;
+#define PUPPA "eitätäoo"
+
+static HKEY gr (UAEREG *root)
+{
+    if (!root)
+       return hWinUAEKey;
+    return root->fkey;
+}
+static char *gs (UAEREG *root)
+{
+    if (!root)
+       return "WinUAE";
+    return root->inipath;
+}
+static char *gsn (UAEREG *root, const char *name)
+{
+    char *r, *s;
+    if (!root)
+       return my_strdup (name);
+    r = gs (root);
+    s = xmalloc (strlen (r) + 1 + strlen (name) + 1);
+    sprintf (s, "%s/%s", r, name);
+    return s;
+}
+
+int regsetstr (UAEREG *root, const char *name, const char *str)
+{
+    if (inimode) {
+       DWORD ret;
+       ret = WritePrivateProfileString (gs (root), name, str, inipath);
+       return ret;
+    } else {
+       HKEY rk = gr (root);
+       if (!rk)
+           return 0;
+       return RegSetValueEx (rk, name, 0, REG_SZ, (CONST BYTE *)str, strlen (str) + 1) == ERROR_SUCCESS;
+    }
+}
+
+int regsetint (UAEREG *root, const char *name, int val)
+{
+    if (inimode) {
+       DWORD ret;
+       char tmp[100];
+       sprintf (tmp, "%d", val);
+       ret = WritePrivateProfileString (gs (root), name, tmp, inipath);
+       return ret;
+    } else {
+       DWORD v = val;
+       HKEY rk = gr (root);
+       if (!rk)
+           return 0;
+       return RegSetValueEx(rk, name, 0, REG_DWORD, (CONST BYTE*)&v, sizeof (DWORD)) == ERROR_SUCCESS;
+    }
+}
+
+int regqueryint (UAEREG *root, const char *name, int *val)
+{
+    if (inimode) {
+       int ret = 0;
+       char tmp[100];
+       GetPrivateProfileString (gs (root), name, PUPPA, tmp, sizeof (tmp), inipath);
+       if (strcmp (tmp, PUPPA)) {
+           *val = atol (tmp);
+           ret = 1;
+       }
+       return ret;
+    } else {
+       DWORD dwType = REG_DWORD;
+       DWORD size = sizeof (int);
+       HKEY rk = gr (root);
+       if (!rk)
+           return 0;
+       return RegQueryValueEx (rk, name, 0, &dwType, (LPBYTE)val, &size) == ERROR_SUCCESS;
+    }
+}
+
+int regquerystr (UAEREG *root, const char *name, char *str, int *size)
+{
+    if (inimode) {
+       int ret = 0;
+       char *tmp = xmalloc ((*size) + 1);
+       GetPrivateProfileString (gs (root), name, PUPPA, tmp, *size, inipath);
+       if (strcmp (tmp, PUPPA)) {
+           strcpy (str, tmp);
+           ret = 1;
+       }
+       xfree (tmp);
+       return ret;
+    } else {
+       HKEY rk = gr (root);
+       if (!rk)
+           return 0;
+       return RegQueryValueEx (rk, name, 0, NULL, str, size) == ERROR_SUCCESS;
+    }
+}
+
+int regenumstr (UAEREG *root, int idx, char *name, int *nsize, char *str, int *size)
+{
+    if (inimode) {
+       int ret = 0;
+       int tmpsize = 65536;
+       char *tmp = xmalloc (tmpsize);
+       if (GetPrivateProfileSection (gs (root), tmp, tmpsize, inipath) > 0) {
+           int i;
+           char *p = tmp, *p2;
+           for (i = 0; i < idx; i++) {
+               if (p[0] == 0)
+                   break;
+               p += strlen (p) + 1;
+           }
+           if (p[0]) {
+               p2 = strchr (p, '=');
+               *p2++ = 0;
+               strcpy_s (name, *nsize, p);
+               strcpy_s (str, *size, p2);
+               ret = 1;
+           }
+       }
+       xfree (tmp);
+       return ret;
+    } else {
+       HKEY rk = gr (root);
+       if (!rk)
+           return 0;
+       return RegEnumValue (rk, idx, name, nsize, NULL, NULL, str, size) == ERROR_SUCCESS;
+    }
+}
+
+int regquerydatasize (UAEREG *root, const char *name, int *size)
+{
+    if (inimode) {
+       int ret = 0;
+       int csize = 65536;
+       char *tmp = xmalloc (csize);
+       if (regquerystr (root, name, tmp, &csize)) {
+           *size = strlen (tmp) / 2;
+           ret = 1;
+       }
+       xfree (tmp);
+        return ret;
+    } else {
+       HKEY rk = gr (root);
+       if (!rk)
+           return 0;
+       return RegQueryValueEx(rk, name, 0, NULL, NULL, size) == ERROR_SUCCESS;
+    }
+}
+
+int regsetdata (UAEREG *root, const char *name, void *str, int size)
+{
+    if (inimode) {
+       uae_u8 *in = str;
+       DWORD ret;
+       int i;
+       char *tmp = xmalloc (size * 2 + 1);
+       for (i = 0; i < size; i++)
+           sprintf (tmp + i * 2, "%02X", in[i]); 
+       ret = WritePrivateProfileString (gs (root), name, tmp, inipath);
+       xfree (tmp);
+       return ret;
+    } else {
+       HKEY rk = gr (root);
+       if (!rk)
+           return 0;
+       return RegSetValueEx(rk, name, 0, REG_BINARY, (BYTE*)str, size) == ERROR_SUCCESS;
+    }
+}
+int regquerydata (UAEREG *root, const char *name, void *str, int *size)
+{
+    if (inimode) {
+       int csize = (*size) * 2 + 1;
+       int i, j;
+       int ret = 0;
+       char *tmp = xmalloc (csize);
+       uae_u8 *out = str;
+
+       if (!regquerystr (root, name, tmp, &csize))
+           goto err;
+       j = 0;
+       for (i = 0; i < strlen (tmp); i += 2) {
+           char c1 = toupper(tmp[i + 0]);
+           char c2 = toupper(tmp[i + 1]);
+           if (c1 >= 'A')
+               c1 -= 'A' - 10;
+           else if (c1 >= '0')
+               c1 -= '0';
+           if (c1 > 15)
+               goto err;
+           if (c2 >= 'A')
+               c2 -= 'A' - 10;
+           else if (c2 >= '0')
+               c2 -= '0';
+           if (c2 > 15)
+               goto err;
+           out[j++] = c1 * 16 + c2;
+       }
+       ret = 1;
+    err:
+       xfree (tmp);
+       return ret;
+    } else {
+       HKEY rk = gr (root);
+       if (!rk)
+           return 0;
+       return RegQueryValueEx(rk, name, 0, NULL, str, size) == ERROR_SUCCESS;
+    }
+}
+
+int regdelete (UAEREG *root, const char *name)
+{
+    if (inimode) {
+       WritePrivateProfileString (gs (root), name, NULL, inipath);
+       return 1;
+    } else {
+       HKEY rk = gr (root);
+       if (!rk)
+           return 0;
+       return RegDeleteValue (rk, name) == ERROR_SUCCESS;
+    }
+}
+
+int regexists (UAEREG *root, const char *name)
+{
+    if (inimode) {
+       int ret = 1;
+       char *tmp = xmalloc (strlen (PUPPA) + 1);
+       int size = strlen (PUPPA) + 1;
+       GetPrivateProfileString (gs (root), name, PUPPA, tmp, size, inipath);
+       if (!strcmp (tmp, PUPPA))
+           ret = 0;
+       xfree (tmp);
+       return ret;
+    } else {
+       HKEY rk = gr (root);
+       if (!rk)
+           return 0;
+       return RegQueryValueEx(rk, name, 0, NULL, NULL, NULL) == ERROR_SUCCESS;
+    }
+}
+
+void regdeletetree (UAEREG *root, const char *name)
+{
+    if (inimode) {
+       char *s = gsn (root, name);
+       if (!s)
+           return;
+       WritePrivateProfileSection (s, "", inipath);
+       xfree (s);
+    } else {
+       HKEY rk = gr (root);
+       if (!rk)
+           return;
+       SHDeleteKey (rk, name);
+    }
+}
+
+int regexiststree (UAEREG *root, const char *name)
+{
+    if (inimode) {
+       int ret = 0;
+       int tmpsize = 65536;
+       char *p, *tmp;
+       char *s = gsn (root, name);
+       if (!s)
+           return 0;
+       tmp = xmalloc (tmpsize);
+       tmp[0] = 0;
+       GetPrivateProfileSectionNames (tmp, tmpsize, inipath);
+       p = tmp;
+       while (p[0]) {
+           if (!strcmp (p, name)) {
+               ret = 1;
+               break;
+           }
+           p += strlen (p) + 1;
+       }
+       xfree (tmp);
+       xfree (s);
+       return ret;
+    } else {
+       int ret = 0;
+       HKEY k = NULL;
+       HKEY rk = gr (root);
+       if (!rk)
+           return 0;
+       if (RegOpenKeyEx (rk , name, 0, KEY_READ, &k) == ERROR_SUCCESS)
+           ret = 1;
+       if (k)
+           RegCloseKey (k);
+       return ret;
+    }
+}
+
+
+UAEREG *regcreatetree (UAEREG *root, const char *name)
+{
+    UAEREG *fkey;
+    HKEY rkey;
+
+    if (inimode) {
+       char *ininame;
+       if (!root) {
+           if (!name)
+               ininame = my_strdup (gs (NULL));
+           else
+               ininame = my_strdup (name);
+       } else {
+           ininame = xmalloc (strlen (root->inipath) + 1 + strlen (name) + 1);
+           sprintf (ininame, "%s/%s", root->inipath, name);
+       }
+       fkey = xcalloc (sizeof (UAEREG), 1);
+       fkey->inipath = ininame;
+    } else {
+       HKEY rk = gr (root);
+       if (!rk) {
+           rk = HKEY_CURRENT_USER;
+           name = "Software\\Arabuusimiehet\\WinUAE";
+       }
+       if (RegCreateKeyEx(rk, name, 0, NULL, REG_OPTION_NON_VOLATILE,
+           KEY_READ | KEY_WRITE, NULL, &rkey, NULL) != ERROR_SUCCESS)
+           return 0;
+       fkey = xcalloc (sizeof (UAEREG), 1);
+       fkey->fkey = rkey;
+    }
+    return fkey;
+}
+
+void regclosetree (UAEREG *key)
+{
+    if (!key)
+       return;
+    if (key->fkey)
+       RegCloseKey (key->fkey);
+    xfree (key->inipath);
+    xfree (key);
+}
+
+static uae_u8 crcok[20] = { 0xD3,0x34,0xDE,0x75,0x31,0x2B,0x44,0x51,0xA2,0xB8,0x8D,0xC3,0x52,0xFB,0x65,0x8F,0x95,0xCB,0x0C,0xF2 };
+
+int reginitializeinit (const char *ppath)
+{
+    UAEREG *r = NULL;
+    char tmp1[1000];
+    uae_u8 crc[20];
+    int s, v1, v2, v3;
+    char path[MAX_DPATH], fpath[MAX_PATH];
+
+    if (!ppath) {
+       char *posn;
+       strcpy (path, _pgmptr);
+       if((posn = strrchr (path, '\\')))
+           posn[1] = 0;
+       strcat (path, "winuae.ini");
+       if (GetFileAttributes (path) == INVALID_FILE_ATTRIBUTES)
+           return 0;
+    } else {
+       strcpy (path, ppath);
+    }
+
+    fpath[0] = 0;
+    GetFullPathName (path, sizeof fpath, fpath, NULL);
+    if (strlen (fpath) < 5 || stricmp (fpath + strlen (fpath) - 4, ".ini"))
+       return 0;
+
+    inimode = 1;
+    inipath = my_strdup (fpath);
+    if (!regexists (NULL, "Version"))
+       goto fail;
+    r = regcreatetree (NULL, "Warning");
+    if (!r)
+       goto fail;
+    memset (tmp1, 0, sizeof tmp1);
+    s = 200;
+    if (!regquerystr (r, "info1", tmp1, &s))
+       goto fail;
+    if (!regquerystr (r, "info2", tmp1 + 200, &s))
+       goto fail;
+    get_sha1 (tmp1, sizeof tmp1, crc);
+    if (memcmp (crc, crcok, sizeof crcok))
+       goto fail;
+    v1 = v2 = -1;
+    regsetint (r, "check", 1);
+    regqueryint (r, "check", &v1);
+    regsetint (r, "check", 3);
+    regqueryint (r, "check", &v2);
+    regdelete (r, "check");
+    if (regqueryint (r, "check", &v3))
+       goto fail;
+    if (v1 != 1 || v2 != 3)
+       goto fail;
+    regclosetree (r);
+    return 1;
+fail:
+    regclosetree (r);
+    if (GetFileAttributes (path) != INVALID_FILE_ATTRIBUTES)
+       DeleteFile (path);
+    if (GetFileAttributes (path) != INVALID_FILE_ATTRIBUTES)
+       goto end;
+    r = regcreatetree (NULL, "Warning");
+    if (!r)
+       goto end;
+    regsetstr (r, "info1", "This is unsupported file. Compatibility between versions is not guaranteed.");
+    regsetstr (r, "info2", "Incompatible ini-files may be re-created from scratch!");
+    regclosetree (r);
+    return 1;
+end:
+    inimode = 0;
+    xfree (inipath);
+    return 0;
+}
+
+void regstatus (void)
+{
+    if (inimode)
+       write_log ("WARNING: Unsupported '%s' enabled\n", inipath);
+}
diff --git a/od-win32/registry.h b/od-win32/registry.h
new file mode 100644 (file)
index 0000000..ac2845a
--- /dev/null
@@ -0,0 +1,30 @@
+
+
+typedef struct UAEREG {
+    HKEY fkey;
+    char *inipath;
+} UAEREG;
+
+extern int reginitializeinit (const char *path);
+extern void regstatus (void);
+
+extern int regsetstr (UAEREG*, const char *name, const char *str);
+extern int regsetint (UAEREG*, const char *name, int val);
+extern int regqueryint (UAEREG*, const char *name, int *val);
+extern int regquerystr (UAEREG*, const char *name, char *str, int *size);
+
+extern int regdelete (UAEREG*, const char *name);
+extern void regdeletetree (UAEREG*, const char *name);
+
+extern int regexists (UAEREG*, const char *name);
+extern int regexiststree (UAEREG *, const char *name);
+
+extern int regquerydatasize (UAEREG *root, const char *name, int *size);
+extern int regsetdata (UAEREG*, const char *name, const void *str, int size);
+extern int regquerydata (UAEREG *root, const char *name, void *str, int *size);
+
+extern int regenumstr (UAEREG*, int idx, char *name, int *nsize, char *str, int *size);
+
+extern UAEREG *regcreatetree (UAEREG*, const char *name);
+extern void regclosetree (UAEREG *key);
+
index dbb16c35c9f1c22a82fffb668d2c82bc8e591165..e6aea3889ab47d2a35933836fb87eca84f3b58b6 100644 (file)
@@ -49,6 +49,7 @@
 #include "bsdsocket.h"
 #include "win32.h"
 #include "win32gfx.h"
+#include "registry.h"
 #include "win32gui.h"
 #include "resource.h"
 #include "autoconf.h"
@@ -1295,9 +1296,9 @@ static LRESULT CALLBACK MainWindowProc (HWND hWnd, UINT message, WPARAM wParam,
                                    rc2.right - rc2.left, rc2.bottom - rc2.top, TRUE);
 
                    }
-                   if (hWinUAEKey && store_xy++) {
-                       RegSetValueEx(hWinUAEKey, "MainPosX", 0, REG_DWORD, (LPBYTE)&left, sizeof(LONG));
-                       RegSetValueEx(hWinUAEKey, "MainPosY", 0, REG_DWORD, (LPBYTE)&top, sizeof(LONG));
+                   if (store_xy++) {
+                       regsetint (NULL, "MainPosX", left);
+                       regsetint (NULL, "MainPosY", top);
                    }
                    changed_prefs.gfx_size_win.x = left;
                    changed_prefs.gfx_size_win.y = top;
@@ -1662,12 +1663,11 @@ static void pritransla (void)
 
 static void WIN32_InitLang(void)
 {
+    int lid;
     WORD langid = -1;
-    if (hWinUAEKey) {
-       DWORD regkeytype;
-       DWORD regkeysize = sizeof(langid);
-       RegQueryValueEx (hWinUAEKey, "Language", 0, &regkeytype, (LPBYTE)&langid, &regkeysize);
-    }
+
+    if (regqueryint (NULL, "Language", &lid))
+       langid = (WORD)lid;
     hUIDLL = language_load(langid);
     pritransla ();
 }
@@ -1762,6 +1762,7 @@ void logging_init(void)
               "\nEnd+F1 changes floppy 0, End+F2 changes floppy 1, etc."
               "\n");
     write_log ("EXE: '%s', DATA: '%s'\n", start_path_exe, start_path_data);
+    regstatus ();
 }
 
 void logging_cleanup( void )
@@ -2121,13 +2122,13 @@ void fetch_path (char *name, char *out, int size)
        strcat (out, "..\\shared\\rom\\");
     if (!strcmp (name, "ConfigurationPath"))
        strcat (out, "Configurations\\");
-    if (hWinUAEKey && start_data >= 0)
-       RegQueryValueEx (hWinUAEKey, name, 0, NULL, out, &size);
+    if (start_data >= 0)
+       regquerystr (NULL, name, out, &size); 
     if (out[0] == '\\' && (strlen(out) >= 2 && out[1] != '\\')) { /* relative? */
        strcpy (out, start_path_data);
-       if (hWinUAEKey && start_data >= 0) {
+       if (start_data >= 0) {
            size2 -= strlen (out);
-           RegQueryValueEx (hWinUAEKey, name, 0, NULL, out + strlen (out) - 1, &size2);
+           regquerystr (NULL, name, out, &size2);
        }
     }
     strip_slashes (out);
@@ -2244,16 +2245,12 @@ void set_path (char *name, char *path)
        }
     }
     fixtrailing (tmp);
-
-    if (hWinUAEKey)
-       RegSetValueEx (hWinUAEKey, name, 0, REG_SZ, (CONST BYTE *)tmp, strlen (tmp) + 1);
+    regsetstr (NULL, name, tmp);
 }
 
 static void initpath (char *name, char *path)
 {
-    if (!hWinUAEKey)
-       return;
-    if (RegQueryValueEx(hWinUAEKey, name, 0, NULL, NULL, NULL) == ERROR_SUCCESS)
+    if (regexists (NULL, name) == 0)
        return;
     set_path (name, NULL);
 }
@@ -2262,31 +2259,26 @@ extern int scan_roms (int);
 void read_rom_list (void)
 {
     char tmp2[1000];
-    DWORD size2;
     int idx, idx2;
-    HKEY fkey;
+    UAEREG *fkey;
     char tmp[1000];
-    DWORD size, disp;
+    int size, size2, exists;
 
     romlist_clear ();
-    if (!hWinUAEKey)
-       return;
-    RegCreateKeyEx(hWinUAEKey , "DetectedROMs", 0, NULL, REG_OPTION_NON_VOLATILE,
-       KEY_READ | KEY_WRITE, NULL, &fkey, &disp);
+    exists = regexiststree (NULL, "DetectedROMs");
+    fkey = regcreatetree (NULL, "DetectedROMs");
     if (fkey == NULL)
        return;
-    if (disp == REG_CREATED_NEW_KEY || forceroms) {
+    if (!exists || forceroms) {
        load_keyring (NULL, NULL);
        scan_roms (forceroms ? 0 : 1);
     }
     forceroms = 0;
     idx = 0;
     for (;;) {
-       int err;
        size = sizeof (tmp);
        size2 = sizeof (tmp2);
-       err = RegEnumValue(fkey, idx, tmp, &size, NULL, NULL, tmp2, &size2);
-       if (err != ERROR_SUCCESS)
+       if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2))
            break;
        if (strlen (tmp) == 6) {
            idx2 = atol (tmp + 3);
@@ -2298,6 +2290,7 @@ void read_rom_list (void)
        }
        idx++;
     }
+    regclosetree (fkey);
 }
 
 static int parseversion (char **vs)
@@ -2344,7 +2337,6 @@ static void WIN32_HandleRegistryStuff(void)
     char path[MAX_DPATH] = "";
     char version[100];
     HKEY hWinUAEKeyLocal = NULL;
-    HKEY fkey;
     HKEY rkey;
     char rpath1[MAX_DPATH], rpath2[MAX_DPATH], rpath3[MAX_DPATH];
 
@@ -2371,7 +2363,7 @@ static void WIN32_HandleRegistryStuff(void)
        // commands in.  This way, we're always up to date.
 
        /* Set our (default) sub-key to point to the "WinUAE" key, which we then create */
-       RegSetValueEx(hWinUAEKey, "", 0, REG_SZ, (CONST BYTE *)"WinUAE", strlen( "WinUAE" ) + 1);
+       RegSetValueEx(hWinUAEKey, "", 0, REG_SZ, (CONST BYTE *)"WinUAE", strlen("WinUAE") + 1);
 
        if((RegCreateKeyEx(rkey, rpath2, 0, "", REG_OPTION_NON_VOLATILE,
                              KEY_WRITE | KEY_READ, NULL, &hWinUAEKeyLocal, &disposition) == ERROR_SUCCESS))
@@ -2395,49 +2387,50 @@ static void WIN32_HandleRegistryStuff(void)
     hWinUAEKey = NULL;
 
     /* Create/Open the hWinUAEKey which points our config-info */
-    if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Arabuusimiehet\\WinUAE", 0, "", REG_OPTION_NON_VOLATILE,
-                         KEY_WRITE | KEY_READ, NULL, &hWinUAEKey, &disposition) == ERROR_SUCCESS)
-    {
-       initpath ("FloppyPath", start_path_data);
-       initpath ("KickstartPath", start_path_data);
-       initpath ("hdfPath", start_path_data);
-       initpath ("ConfigurationPath", start_path_data);
-       initpath ("ScreenshotPath", start_path_data);
-       initpath ("StatefilePath", start_path_data);
-       initpath ("SaveimagePath", start_path_data);
-       initpath ("VideoPath", start_path_data);
-       initpath ("InputPath", start_path_data);
-       if (disposition == REG_CREATED_NEW_KEY) {
-           /* Create and initialize all our sub-keys to the default values */
-           RegSetValueEx(hWinUAEKey, "MainPosX", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof(colortype));
-           RegSetValueEx(hWinUAEKey, "MainPosY", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof(colortype));
-           RegSetValueEx(hWinUAEKey, "GUIPosX", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof(colortype));
-           RegSetValueEx(hWinUAEKey, "GUIPosY", 0, REG_DWORD, (CONST BYTE *)&colortype, sizeof(colortype));
-       }
-       size = sizeof (version);
-       dwType = REG_SZ;
-       if (RegQueryValueEx (hWinUAEKey, "Version", 0, &dwType, (LPBYTE)&version, &size) == ERROR_SUCCESS) {
-           if (checkversion (version))
-               RegSetValueEx (hWinUAEKey, "Version", 0, REG_SZ, (CONST BYTE *)VersionStr, strlen (VersionStr) + 1);
-       } else {
-           RegSetValueEx (hWinUAEKey, "Version", 0, REG_SZ, (CONST BYTE *)VersionStr, strlen (VersionStr) + 1);
-       }
-       size = sizeof (version);
-       dwType = REG_SZ;
-       if (RegQueryValueEx (hWinUAEKey, "ROMCheckVersion", 0, &dwType, (LPBYTE)&version, &size) == ERROR_SUCCESS) {
-           if (checkversion (version)) {
-               if (RegSetValueEx (hWinUAEKey, "ROMCheckVersion", 0, REG_SZ, (CONST BYTE *)VersionStr, strlen (VersionStr) + 1) == ERROR_SUCCESS)
-                   forceroms = 1;
-           }
-       } else {
-           if (RegSetValueEx (hWinUAEKey, "ROMCheckVersion", 0, REG_SZ, (CONST BYTE *)VersionStr, strlen (VersionStr) + 1) == ERROR_SUCCESS)
-               forceroms = 1;
-       }
-
-       size = sizeof (quickstart);
-       dwType = REG_DWORD;
-       RegQueryValueEx(hWinUAEKey, "QuickStartMode", 0, &dwType, (LPBYTE)&quickstart, &size);
+    RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Arabuusimiehet\\WinUAE", 0, "", REG_OPTION_NON_VOLATILE,
+         KEY_WRITE | KEY_READ, NULL, &hWinUAEKey, &disposition);
+    initpath ("FloppyPath", start_path_data);
+    initpath ("KickstartPath", start_path_data);
+    initpath ("hdfPath", start_path_data);
+    initpath ("ConfigurationPath", start_path_data);
+    initpath ("ScreenshotPath", start_path_data);
+    initpath ("StatefilePath", start_path_data);
+    initpath ("SaveimagePath", start_path_data);
+    initpath ("VideoPath", start_path_data);
+    initpath ("InputPath", start_path_data);
+    if (!regexists (NULL, "MainPosX") || !regexists (NULL, "GUIPosX")) {
+       int x = GetSystemMetrics (SM_CXSCREEN);
+       int y = GetSystemMetrics (SM_CYSCREEN);
+       x = (x - 800) / 2;
+       y = (y - 600) / 2;
+       if (x < 10)
+           x = 10;
+       if (y < 10)
+           y = 10;
+        /* Create and initialize all our sub-keys to the default values */
+        regsetint(NULL, "MainPosX", x);
+        regsetint(NULL, "MainPosY", y);
+        regsetint(NULL, "GUIPosX", x);
+        regsetint(NULL, "GUIPosY", y);
+    }
+    size = sizeof (version);
+    if (regquerystr (NULL, "Version", version, &size)) {
+        if (checkversion (version))
+       regsetstr(NULL, "Version", VersionStr);
+    } else {
+        regsetstr (NULL, "Version", VersionStr);
+    }
+    size = sizeof (version);
+    if (regquerystr (NULL, "ROMCheckVersion", version, &size)) {
+        if (checkversion (version)) {
+       if (regsetstr (NULL, "ROMCheckVersion", VersionStr))
+           forceroms = 1;
+        }
+    } else {
+        if (regsetstr (NULL, "ROMCheckVersion", VersionStr))
+       forceroms = 1;
     }
+    regsetint (NULL, "QuickStartMode", quickstart);
     reopen_console();
     fetch_path ("ConfigurationPath", path, sizeof (path));
     path[strlen (path) - 1] = 0;
@@ -2453,9 +2446,7 @@ static void WIN32_HandleRegistryStuff(void)
     strcpy (savestate_fname, path);
     fetch_path ("InputPath", path, sizeof (path));
     CreateDirectory (path, NULL);
-    fkey = read_disk_history ();
-    if (fkey)
-       RegCloseKey (fkey);
+    regclosetree (read_disk_history ());
     read_rom_list ();
     load_keyring(NULL, NULL);
 }
@@ -2723,21 +2714,18 @@ static void getstartpaths(void)
     char *posn, *p;
     char tmp[MAX_DPATH], tmp2[MAX_DPATH], prevpath[MAX_DPATH];
     DWORD v;
-    HKEY key;
-    DWORD dispo;
+    UAEREG *key;
     char xstart_path_uae[MAX_DPATH], xstart_path_old[MAX_DPATH];
     char xstart_path_new1[MAX_DPATH], xstart_path_new2[MAX_DPATH];
 
     path_type = -1;
     xstart_path_uae[0] = xstart_path_old[0] = xstart_path_new1[0] = xstart_path_new2[0] = 0;
-    if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Arabuusimiehet\\WinUAE", 0, "", REG_OPTION_NON_VOLATILE,
-                         KEY_WRITE | KEY_READ, NULL, &key, &dispo) == ERROR_SUCCESS)
-    {
+    key = regcreatetree (NULL, NULL);
+    if (key)  {
        DWORD size = sizeof (prevpath);
-       DWORD dwType = REG_SZ;
-       if (RegQueryValueEx (key, "PathMode", 0, &dwType, (LPBYTE)&prevpath, &size) != ERROR_SUCCESS)
+       if (!regquerystr (NULL, "PathMode", prevpath, &size))
            prevpath[0] = 0;
-       RegCloseKey(key);
+       regclosetree (key);
     }
     if (!strcmp(prevpath, "WinUAE"))
        path_type = PATH_TYPE_WINUAE;
@@ -2754,7 +2742,7 @@ static void getstartpaths(void)
        GetModuleHandle("shell32.dll"), "SHGetFolderPathA");
     pSHGetSpecialFolderPath = (SHGETSPECIALFOLDERPATH)GetProcAddress(
        GetModuleHandle("shell32.dll"), "SHGetSpecialFolderPathA");
-    strcpy (start_path_exe, _pgmptr );
+    strcpy (start_path_exe, _pgmptr);
     if((posn = strrchr (start_path_exe, '\\')))
        posn[1] = 0;
 
@@ -2902,6 +2890,7 @@ static void makeverstr(char *s)
 }
 
 static int multi_display = 1;
+static char *inipath = NULL;
 
 static int process_arg(char **xargv)
 {
@@ -3028,6 +3017,11 @@ static int process_arg(char **xargv)
                sound_mode_skip = getval (np);
                continue;
            }
+           if  (!strcmp (arg, "-ini")) {
+               i++;
+               inipath = my_strdup (np);
+               continue;
+           }
        }
        xargv[xargc++] = my_strdup(arg);
     }
@@ -3074,6 +3068,7 @@ static int PASCAL WinMain2 (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
     argv = xcalloc (sizeof (char*),  __argc);
     argc = process_arg(argv);
 
+    reginitializeinit (inipath);
     getstartpaths();
     makeverstr(VersionStr);
     SetCurrentDirectory (start_path_data);
index bcf21193c6d5844c3bacf9782c0ecd3bb29c647d..7ae5151e78f6f378b53c498e0f8a0d500008f626 100644 (file)
@@ -15,9 +15,9 @@
 #define GETBDM(x) (((x) - ((x / 10000) * 10000)) / 100)
 #define GETBDD(x) ((x) % 100)
 
-#define WINUAEBETA 8
+#define WINUAEBETA 9
 #define WINUAEPUBLICBETA 1
-#define WINUAEDATE MAKEBD(2007, 11, 8)
+#define WINUAEDATE MAKEBD(2007, 11, 10)
 #define WINUAEEXTRA ""
 #define WINUAEREV ""
 
index 41c84ca57e6cf500308d01aeb997e71e81c86155..292e51f455fc4a5709c87adef01b85113eb1e776 100644 (file)
@@ -31,6 +31,7 @@
 #include "drawing.h"
 #include "dxwrap.h"
 #include "picasso96_win.h"
+#include "registry.h"
 #include "win32.h"
 #include "win32gfx.h"
 #include "win32gui.h"
@@ -1992,13 +1993,11 @@ static int create_windows (void)
     if (!dxfs)  {
        RECT rc;
        LONG stored_x = 1, stored_y = cymenu + cyborder;
-       DWORD regkeytype;
-       DWORD regkeysize = sizeof (LONG);
        int oldx, oldy;
        int first = 2;
 
-       RegQueryValueEx(hWinUAEKey, "MainPosX", 0, &regkeytype, (LPBYTE)&stored_x, &regkeysize);
-       RegQueryValueEx(hWinUAEKey, "MainPosY", 0, &regkeytype, (LPBYTE)&stored_y, &regkeysize);
+       regqueryint (NULL, "MainPosX", &stored_x);
+       regqueryint (NULL, "MainPosY", &stored_y);
 
        while (first) {
            first--;
index 15cb6356738974e848b66c6f0838aeaf9b39ec15..f99d210190a1a272bd8d430bd9ab51e9027d482b 100644 (file)
@@ -55,6 +55,7 @@
 
 #include "dxwrap.h"
 #include "win32.h"
+#include "registry.h"
 #include "picasso96_win.h"
 #include "win32gui.h"
 #include "win32gfx.h"
@@ -157,12 +158,9 @@ void write_disk_history (void)
 {
     int i, j;
     char tmp[16];
-    HKEY fkey;
+    UAEREG *fkey;
 
-    if (!hWinUAEKey)
-       return;
-    RegCreateKeyEx(hWinUAEKey , "DiskImageMRUList", 0, NULL, REG_OPTION_NON_VOLATILE,
-       KEY_READ | KEY_WRITE, NULL, &fkey, NULL);
+    fkey = regcreatetree (NULL, "DiskImageMRUList");
     if (fkey == NULL)
        return;
     j = 1;
@@ -171,16 +169,16 @@ void write_disk_history (void)
        if (s == 0 || strlen(s) == 0)
            continue;
        sprintf (tmp, "Image%02d", j);
-       RegSetValueEx (fkey, tmp, 0, REG_SZ, (CONST BYTE *)s, strlen(s) + 1);
+       regsetstr (fkey, tmp, s);
        j++;
    }
     while (j <= MAX_PREVIOUS_FLOPPIES) {
        char *s = "";
        sprintf (tmp, "Image%02d", j);
-       RegSetValueEx (fkey, tmp, 0, REG_SZ, (CONST BYTE *)s, strlen(s) + 1);
+       regsetstr (fkey, tmp, s);
        j++;
     }
-    RegCloseKey(fkey);
+    regclosetree (fkey);
 }
 
 void reset_disk_history (void)
@@ -192,30 +190,25 @@ void reset_disk_history (void)
     write_disk_history();
 }
 
-HKEY read_disk_history (void)
+UAEREG *read_disk_history (void)
 {
     static int regread;
     char tmp2[1000];
     DWORD size2;
     int idx, idx2;
-    HKEY fkey;
+    UAEREG *fkey;
     char tmp[1000];
     DWORD size;
 
-    if (!hWinUAEKey)
-       return NULL;
-    RegCreateKeyEx(hWinUAEKey , "DiskImageMRUList", 0, NULL, REG_OPTION_NON_VOLATILE,
-       KEY_READ | KEY_WRITE, NULL, &fkey, NULL);
+    fkey = regcreatetree (NULL, "DiskImageMRUList");
     if (fkey == NULL || regread)
        return fkey;
 
     idx = 0;
     for (;;) {
-       int err;
        size = sizeof (tmp);
        size2 = sizeof (tmp2);
-       err = RegEnumValue (fkey, idx, tmp, &size, NULL, NULL, tmp2, &size2);
-       if (err != ERROR_SUCCESS)
+       if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2))
            break;
        if (strlen (tmp) == 7) {
            idx2 = atol (tmp + 5) - 1;
@@ -400,7 +393,7 @@ static HWND cachedlist = NULL;
 #define MAX_SOUND_MEM 6
 
 struct romscandata {
-    HKEY fkey;
+    UAEREG *fkey;
     int got;
 };
 
@@ -466,7 +459,7 @@ static struct romdata *scan_single_rom (char *path)
     return scan_single_rom_2 (z);
 }
 
-static int addrom (HKEY fkey, struct romdata *rd, char *name)
+static int addrom (UAEREG *fkey, struct romdata *rd, char *name)
 {
     char tmp1[MAX_DPATH], tmp2[MAX_DPATH];
 
@@ -475,7 +468,7 @@ static int addrom (HKEY fkey, struct romdata *rd, char *name)
        char *p = tmp1 + strlen (tmp1);
        sprintf (p, "_%02d_%02d", rd->group >> 16, rd->group & 65535);
     }
-    if (RegQueryValueEx (fkey, tmp1, 0, NULL, NULL, NULL) == ERROR_SUCCESS)
+    if (regexists (fkey, tmp1))
        return 0;
     tmp2[0] = 0;
     if (name)
@@ -486,7 +479,7 @@ static int addrom (HKEY fkey, struct romdata *rd, char *name)
        else
            sprintf(tmp2, ":ROM%03d", rd->id);
     }
-    if (RegSetValueEx (fkey, tmp1, 0, REG_SZ, (CONST BYTE *)tmp2, strlen (tmp2) + 1) != ERROR_SUCCESS)
+    if (!regsetstr (fkey, tmp1, tmp2))
        return 0;
     return 1;
 }
@@ -525,7 +518,7 @@ static int scan_rom_2 (struct zfile *f, struct romscandata *rsd)
     return 0;
 }
 
-static int scan_rom (char *path, HKEY fkey)
+static int scan_rom (char *path, UAEREG *fkey)
 {
     struct romscandata rsd = { fkey, 0 };
     struct romdata *rd;
@@ -627,7 +620,7 @@ static void show_rom_list (void)
     free (p);
 }
 
-static int scan_roms_2 (HKEY fkey, char *pathp)
+static int scan_roms_2 (UAEREG *fkey, char *pathp)
 {
     char buf[MAX_DPATH], path[MAX_DPATH];
     WIN32_FIND_DATA find_data;
@@ -660,7 +653,7 @@ static int scan_roms_2 (HKEY fkey, char *pathp)
     return ret;
 }
 
-static int scan_roms_3(HKEY fkey, char **paths, int offset, char *path)
+static int scan_roms_3(void *fkey, char **paths, int offset, char *path)
 {
     int i, ret;
 
@@ -681,16 +674,15 @@ int scan_roms (int show)
     char path[MAX_DPATH];
     static int recursive;
     int id, i, ret, keys, cnt;
-    HKEY fkey = NULL;
+    UAEREG *fkey, *fkey2;
     char *paths[10];
 
     if (recursive)
        return 0;
     recursive++;
 
-    SHDeleteKey (hWinUAEKey, "DetectedROMs");
-    RegCreateKeyEx(hWinUAEKey , "DetectedROMs", 0, NULL, REG_OPTION_NON_VOLATILE,
-       KEY_READ | KEY_WRITE, NULL, &fkey, NULL);
+    regdeletetree (NULL, "DetectedROMs");
+    fkey = regcreatetree (NULL, "DetectedROMs");
     if (fkey == NULL)
        goto end;
 
@@ -719,9 +711,8 @@ int scan_roms (int show)
     for (i = 0; i < 10; i++)
        xfree(paths[i]);
 
-    RegCreateKeyEx(hWinUAEKey , "DetectedROMs", 0, NULL, REG_OPTION_NON_VOLATILE,
-       KEY_READ | KEY_WRITE, NULL, &fkey, NULL);
-    if (fkey) {
+    fkey2 = regcreatetree (NULL, "DetectedROMS");
+    if (fkey2) {
        id = 1;
        for (;;) {
            struct romdata *rd = getromdatabyid(id);
@@ -731,7 +722,7 @@ int scan_roms (int show)
                addrom(fkey, rd, NULL);
            id++;
        }
-       RegCloseKey(fkey);
+       regclosetree (fkey2);
     }
 
 end:
@@ -739,8 +730,7 @@ end:
     if (show)
        show_rom_list ();
 
-    if (fkey)
-       RegCloseKey (fkey);
+    regclosetree (fkey);
     recursive--;
     return ret;
 }
@@ -809,7 +799,7 @@ int target_cfgfile_load (struct uae_prefs *p, char *filename, int type, int isde
     type2 = type;
     if (type == 0)
        default_prefs (p, type);
-    RegQueryValueEx (hWinUAEKey, "ConfigFile_NoAuto", 0, NULL, (LPBYTE)&ct2, &size);
+    regqueryint (NULL, "ConfigFile_NoAuto", &ct2);
     v = cfgfile_load (p, fname, &type2, ct2);
     if (!v)
        return v;
@@ -819,10 +809,10 @@ int target_cfgfile_load (struct uae_prefs *p, char *filename, int type, int isde
        if (type != i) {
            size = sizeof (ct);
            ct = 0;
-           RegQueryValueEx (hWinUAEKey, configreg2[i], 0, NULL, (LPBYTE)&ct, &size);
+           regqueryint (NULL, configreg2[i], &ct);
            if (ct && ((i == 1 && p->config_hardware_path[0] == 0) || (i == 2 && p->config_host_path[0] == 0) || ct2)) {
                size = sizeof (tmp1);
-               RegQueryValueEx (hWinUAEKey, configreg[i], 0, NULL, (LPBYTE)tmp1, &size);
+               regquerystr (NULL, configreg[i], tmp1, &size);
                fetch_path ("ConfigurationPath", tmp2, sizeof (tmp2));
                strcat (tmp2, tmp1);
                v = i;
@@ -1346,15 +1336,13 @@ int DiskSelection_2 (HWND hDlg, WPARAM wParam, int flag, struct uae_prefs *prefs
            amiga_path = strstr (openFileName.lpstrFile, openFileName.lpstrFileTitle);
            if (amiga_path && amiga_path != openFileName.lpstrFile) {
                *amiga_path = 0;
-               if (hWinUAEKey)
-                   RegSetValueEx (hWinUAEKey, "FloppyPath", 0, REG_SZ, (CONST BYTE *)openFileName.lpstrFile, strlen(openFileName.lpstrFile) + 1);
+               regsetstr (NULL, "FloppyPath", openFileName.lpstrFile);
            }
        } else if (flag == 2 || flag == 3) {
            amiga_path = strstr (openFileName.lpstrFile, openFileName.lpstrFileTitle);
            if (amiga_path && amiga_path != openFileName.lpstrFile) {
                *amiga_path = 0;
-               if(hWinUAEKey)
-                   RegSetValueEx(hWinUAEKey, "hdfPath", 0, REG_SZ, (CONST BYTE *)openFileName.lpstrFile, strlen(openFileName.lpstrFile) + 1);
+               regsetstr (NULL, "hdfPath", openFileName.lpstrFile);
            }
        }
        if (!multi)
@@ -2402,38 +2390,34 @@ static HTREEITEM InitializeConfigTreeView (HWND hDlg)
 
 static void ConfigToRegistry (struct ConfigStruct *config, int type)
 {
-    if (hWinUAEKey && config) {
+    if (config) {
        char path[MAX_DPATH];
        strcpy (path, config->Path);
        strncat (path, config->Name, MAX_DPATH);
-       RegSetValueEx (hWinUAEKey, configreg[type], 0, REG_SZ, (CONST BYTE *)path, strlen(path) + 1);
+       regsetstr (NULL, configreg[type], path);
     }
 }
 static void ConfigToRegistry2 (DWORD ct, int type, DWORD noauto)
 {
-    if (!hWinUAEKey)
-       return;
     if (type > 0)
-       RegSetValueEx (hWinUAEKey, configreg2[type], 0, REG_DWORD, (CONST BYTE *)&ct, sizeof (ct));
+       regsetint (NULL, configreg2[type], ct);
     if (noauto == 0 || noauto == 1)
-       RegSetValueEx (hWinUAEKey, "ConfigFile_NoAuto", 0, REG_DWORD, (CONST BYTE *)&noauto, sizeof (noauto));
+       regsetint (NULL, "ConfigFile_NoAuto", noauto);
 }
 
 static void checkautoload (HWND        hDlg, struct ConfigStruct *config)
 {
     int ct = 0;
-    DWORD dwType = REG_DWORD;
-    DWORD dwRFPsize = sizeof (ct);
 
     if (configtypepanel > 0)
-       RegQueryValueEx (hWinUAEKey, configreg2[configtypepanel], 0, &dwType, (LPBYTE)&ct, &dwRFPsize);
+       regqueryint (NULL, configreg2[configtypepanel], &ct);
     if (!config || config->Directory) {
        ct = 0;
        ConfigToRegistry2 (ct, configtypepanel, -1);
     }
     CheckDlgButton(hDlg, IDC_CONFIGAUTO, ct ? BST_CHECKED : BST_UNCHECKED);
     ew (hDlg, IDC_CONFIGAUTO, configtypepanel > 0 && config && !config->Directory ? TRUE : FALSE);
-    RegQueryValueEx (hWinUAEKey, "ConfigFile_NoAuto", 0, &dwType, (LPBYTE)&ct, &dwRFPsize);
+    regqueryint (NULL, "ConfigFile_NoAuto", &ct);
     CheckDlgButton(hDlg, IDC_CONFIGNOLINK, ct ? BST_CHECKED : BST_UNCHECKED);
 }
 
@@ -2460,20 +2444,17 @@ static struct ConfigStruct *initloadsave (HWND hDlg, struct ConfigStruct *config
 {
     HTREEITEM root;
     char name_buf[MAX_DPATH];
+    DWORD dwRFPsize = sizeof (name_buf);
+    char path[MAX_DPATH];
 
     EnableWindow (GetDlgItem (hDlg, IDC_VIEWINFO), workprefs.info[0]);
     SetDlgItemText (hDlg, IDC_EDITPATH, "");
     SetDlgItemText (hDlg, IDC_EDITDESCRIPTION, workprefs.description);
     root = InitializeConfigTreeView (hDlg);
-    if (hWinUAEKey) {
-       DWORD dwType = REG_SZ;
-       DWORD dwRFPsize = sizeof (name_buf);
-       char path[MAX_DPATH];
-       if (RegQueryValueEx (hWinUAEKey, configreg[configtypepanel], 0, &dwType, (LPBYTE)name_buf, &dwRFPsize) == ERROR_SUCCESS) {
-           struct ConfigStruct *config2 = getconfigstorefrompath (name_buf, path, configtypepanel);
-           if (config2)
-               config = config2;
-       }
+    if (regquerystr (NULL, configreg[configtypepanel], name_buf, &dwRFPsize)) {
+        struct ConfigStruct *config2 = getconfigstorefrompath (name_buf, path, configtypepanel);
+        if (config2)
+           config = config2;
        checkautoload (hDlg, config);
     }
     config = fixloadconfig (hDlg, config);
@@ -2827,24 +2808,22 @@ static void values_to_pathsdialog (HWND hDlg)
 
 static void resetregistry (void)
 {
-    if (!hWinUAEKey)
-       return;
-    SHDeleteKey (hWinUAEKey, "DetectedROMs");
-    RegDeleteValue (hWinUAEKey, "QuickStartMode");
-    RegDeleteValue (hWinUAEKey, "ConfigFile");
-    RegDeleteValue (hWinUAEKey, "ConfigFileHardware");
-    RegDeleteValue (hWinUAEKey, "ConfigFileHost");
-    RegDeleteValue (hWinUAEKey, "ConfigFileHardware_Auto");
-    RegDeleteValue (hWinUAEKey, "ConfigFileHost_Auto");
-    RegDeleteValue (hWinUAEKey, "ConfigurationPath");
-    RegDeleteValue (hWinUAEKey, "SaveimagePath");
-    RegDeleteValue (hWinUAEKey, "ScreenshotPath");
-    RegDeleteValue (hWinUAEKey, "StatefilePath");
-    RegDeleteValue (hWinUAEKey, "VideoPath");
-    RegDeleteValue (hWinUAEKey, "QuickStartModel");
-    RegDeleteValue (hWinUAEKey, "QuickStartConfiguration");
-    RegDeleteValue (hWinUAEKey, "QuickStartCompatibility");
-    RegDeleteValue (hWinUAEKey, "QuickStartHostConfig");
+    regdeletetree (NULL, "DetectedROMs");
+    regdelete (NULL, "QuickStartMode");
+    regdelete (NULL, "ConfigFile");
+    regdelete (NULL, "ConfigFileHardware");
+    regdelete (NULL, "ConfigFileHost");
+    regdelete (NULL, "ConfigFileHardware_Auto");
+    regdelete (NULL, "ConfigFileHost_Auto");
+    regdelete (NULL, "ConfigurationPath");
+    regdelete (NULL, "SaveimagePath");
+    regdelete (NULL, "ScreenshotPath");
+    regdelete (NULL, "StatefilePath");
+    regdelete (NULL, "VideoPath");
+    regdelete (NULL, "QuickStartModel");
+    regdelete (NULL, "QuickStartConfiguration");
+    regdelete (NULL, "QuickStartCompatibility");
+    regdelete (NULL, "QuickStartHostConfig");
 }
 
 int path_type;
@@ -3008,8 +2987,7 @@ static INT_PTR CALLBACK PathsDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM
                    strcpy (start_path_data, start_path_new1);
                }
                SetCurrentDirectory (start_path_data);
-               if (hWinUAEKey)
-                   RegSetValueEx (hWinUAEKey, "PathMode", 0, REG_SZ, (CONST BYTE *)pathmode, strlen(pathmode) + 1);
+               regsetstr (NULL, "PathMode", pathmode);
                set_path ("KickstartPath", NULL);
                set_path ("ConfigurationPath", NULL);
                set_path ("ScreenshotPath", NULL);
@@ -3110,24 +3088,17 @@ static void init_quickstartdlg_tooltip (HWND hDlg, char *tt)
 static void init_quickstartdlg (HWND hDlg)
 {
     static int firsttime;
-    int i, j, idx, idx2;
-    DWORD dwType, qssize;
+    int i, j, idx, idx2, qssize;
     char tmp1[2 * MAX_DPATH], tmp2[MAX_DPATH], hostconf[MAX_DPATH];
     char *p1, *p2;
 
     qssize = sizeof (tmp1);
-    RegQueryValueEx (hWinUAEKey, "QuickStartHostConfig", 0, &dwType, (LPBYTE)hostconf, &qssize);
+    regquerystr (NULL, "QuickStartHostConfig", hostconf, &qssize);
     if (firsttime == 0) {
-       if (hWinUAEKey) {
-           qssize = sizeof (quickstart_model);
-           RegQueryValueEx (hWinUAEKey, "QuickStartModel", 0, &dwType, (LPBYTE)&quickstart_model, &qssize);
-           qssize = sizeof (quickstart_conf);
-           RegQueryValueEx (hWinUAEKey, "QuickStartConfiguration", 0, &dwType, (LPBYTE)&quickstart_conf, &qssize);
-           qssize = sizeof (quickstart_compa);
-           RegQueryValueEx (hWinUAEKey, "QuickStartCompatibility", 0, &dwType, (LPBYTE)&quickstart_compa, &qssize);
-           qssize = sizeof (quickstart_floppy);
-           RegQueryValueEx (hWinUAEKey, "QuickStartFloppies", 0, &dwType, (LPBYTE)&quickstart_floppy, &qssize);
-       }
+       regqueryint (NULL, "QuickStartModel", &quickstart_model);
+       regqueryint (NULL, "QuickStartConfiguration", &quickstart_conf);
+       regqueryint (NULL, "QuickStartCompatibility", &quickstart_compa);
+       regqueryint (NULL, "QuickStartFloppies", &quickstart_floppy);
        if (quickstart) {
            workprefs.df[0][0] = 0;
            workprefs.df[1][0] = 0;
@@ -3215,12 +3186,9 @@ static void init_quickstartdlg (HWND hDlg)
        }
     }
     SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_SETCURSEL, idx, 0);
-
-    if (hWinUAEKey) {
-       RegSetValueEx (hWinUAEKey, "QuickStartModel", 0, REG_DWORD, (CONST BYTE *)&quickstart_model, sizeof(quickstart_model));
-       RegSetValueEx (hWinUAEKey, "QuickStartConfiguration", 0, REG_DWORD, (CONST BYTE *)&quickstart_conf, sizeof(quickstart_conf));
-       RegSetValueEx (hWinUAEKey, "QuickStartCompatibility", 0, REG_DWORD, (CONST BYTE *)&quickstart_compa, sizeof(quickstart_compa));
-    }
+    regsetint (NULL, "QuickStartModel", quickstart_model);
+    regsetint (NULL, "QuickStartConfiguration", quickstart_conf);
+    regsetint (NULL, "QuickStartCompatibility", quickstart_compa);
 }
 
 static void floppytooltip (HWND hDlg, int num, uae_u32 crc32);
@@ -3369,8 +3337,7 @@ static INT_PTR CALLBACK QuickstartDlgProc (HWND hDlg, UINT msg, WPARAM wParam, L
                val = SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_GETCURSEL, 0, 0);
                if (val != CB_ERR) {
                    SendDlgItemMessage (hDlg, IDC_QUICKSTART_HOSTCONFIG, CB_GETLBTEXT, (WPARAM)val, (LPARAM)tmp);
-                   if (hWinUAEKey)
-                       RegSetValueEx (hWinUAEKey, "QuickStartHostConfig", 0, REG_SZ, (CONST BYTE *)&tmp, strlen (tmp) + 1);
+                   regsetstr (NULL, "QuickStartHostConfig", tmp);
                    quickstarthost (hDlg, tmp);
                    if (val == 0 && quickstart)
                        load_quickstart (hDlg, 0);
@@ -3382,8 +3349,7 @@ static INT_PTR CALLBACK QuickstartDlgProc (HWND hDlg, UINT msg, WPARAM wParam, L
            {
                case IDC_QUICKSTARTMODE:
                quickstart = IsDlgButtonChecked (hDlg, IDC_QUICKSTARTMODE);
-               if (hWinUAEKey)
-                   RegSetValueEx( hWinUAEKey, "QuickStartMode", 0, REG_DWORD, (CONST BYTE *)&quickstart, sizeof(quickstart));
+               regsetint (NULL, "QuickStartMode", quickstart);
                if (quickstart) {
                    init_quickstartdlg (hDlg);
                    load_quickstart (hDlg, 0);
@@ -4658,7 +4624,7 @@ static INT_PTR CALLBACK MemoryDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARA
     return FALSE;
 }
 
-static void addromfiles (HKEY fkey, HWND hDlg, DWORD d, char *path, int type)
+static void addromfiles (UAEREG *fkey, HWND hDlg, DWORD d, char *path, int type)
 {
     int idx, idx2;
     char tmp[MAX_DPATH];
@@ -4674,8 +4640,7 @@ static void addromfiles (HKEY fkey, HWND hDlg, DWORD d, char *path, int type)
     for (;fkey;) {
        DWORD size = sizeof (tmp);
        DWORD size2 = sizeof (tmp2);
-       int err = RegEnumValue(fkey, idx, tmp, &size, NULL, NULL, tmp2, &size2);
-       if (err != ERROR_SUCCESS)
+       if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2))
            break;
        if (strlen (tmp) == 6) {
            idx2 = atol (tmp + 3);
@@ -4727,21 +4692,17 @@ static void values_from_kickstartdlg (HWND hDlg)
 
 static void values_to_kickstartdlg (HWND hDlg)
 {
-    HKEY fkey;
+    UAEREG *fkey;
 
-    if (hWinUAEKey) {
-       RegCreateKeyEx(hWinUAEKey , "DetectedROMs", 0, NULL, REG_OPTION_NON_VOLATILE,
-           KEY_READ | KEY_WRITE, NULL, &fkey, NULL);
-       load_keyring(&workprefs, NULL);
-       addromfiles (fkey, hDlg, IDC_ROMFILE, workprefs.romfile,
-           ROMTYPE_KICK | ROMTYPE_KICKCD32);
-       addromfiles (fkey, hDlg, IDC_ROMFILE2, workprefs.romextfile,
-           ROMTYPE_EXTCD32 | ROMTYPE_EXTCDTV | ROMTYPE_ARCADIABIOS);
-       addromfiles (fkey, hDlg, IDC_CARTFILE, workprefs.cartfile,
-           ROMTYPE_AR | ROMTYPE_SUPERIV | ROMTYPE_NORDIC | ROMTYPE_XPOWER | ROMTYPE_ARCADIAGAME | ROMTYPE_HRTMON);
-       if (fkey)
-           RegCloseKey (fkey);
-    }
+    fkey = regcreatetree (NULL, "DetectedROMs");
+    load_keyring(&workprefs, NULL);
+    addromfiles (fkey, hDlg, IDC_ROMFILE, workprefs.romfile,
+        ROMTYPE_KICK | ROMTYPE_KICKCD32);
+    addromfiles (fkey, hDlg, IDC_ROMFILE2, workprefs.romextfile,
+        ROMTYPE_EXTCD32 | ROMTYPE_EXTCDTV | ROMTYPE_ARCADIABIOS);
+    addromfiles (fkey, hDlg, IDC_CARTFILE, workprefs.cartfile,
+        ROMTYPE_AR | ROMTYPE_SUPERIV | ROMTYPE_NORDIC | ROMTYPE_XPOWER | ROMTYPE_ARCADIAGAME | ROMTYPE_HRTMON);
+    regclosetree (fkey);
 
     SetDlgItemText(hDlg, IDC_FLASHFILE, workprefs.flashfile);
     CheckDlgButton(hDlg, IDC_KICKSHIFTER, workprefs.kickshifter);
@@ -4751,8 +4712,6 @@ static void values_to_kickstartdlg (HWND hDlg)
 
 static void init_kickstart (HWND hDlg)
 {
-    HKEY fkey;
-
 #if !defined(AUTOCONFIG)
     ew (hDlg, IDC_MAPROM), FALSE);
 #endif
@@ -4769,10 +4728,8 @@ static void init_kickstart (HWND hDlg)
     ew (hDlg, IDC_CARTCHOOSER), FALSE);
     ew (hDlg, IDC_FLASHCHOOSER), FALSE);
 #endif
-    if (RegOpenKeyEx (hWinUAEKey , "DetectedROMs", 0, KEY_READ, &fkey) != ERROR_SUCCESS)
+    if (!regexiststree (NULL , "DetectedROMs"))
        scan_roms (1);
-    if (fkey)
-       RegCloseKey (fkey);
 }
 
 static INT_PTR CALLBACK KickstartDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -4942,14 +4899,11 @@ static void misc_scsi(HWND hDlg)
 
 static void misc_lang(HWND hDlg)
 {
-    int i, idx = 0, cnt = 0;
+    int i, idx = 0, cnt = 0, lid;
     WORD langid = -1;
 
-    if (hWinUAEKey) {
-       DWORD regkeytype;
-       DWORD regkeysize = sizeof(langid);
-       RegQueryValueEx (hWinUAEKey, "Language", 0, &regkeytype, (LPBYTE)&langid, &regkeysize);
-    }
+    if (regqueryint (NULL, "Language", &lid))
+       langid = (WORD)lid;
     SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_RESETCONTENT, 0, 0);
     SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM)"Autodetect");
     SendDlgItemMessage (hDlg, IDC_LANGUAGE, CB_ADDSTRING, 0, (LPARAM)"English (built-in)");
@@ -4988,8 +4942,7 @@ static void misc_setlang(int v)
     }
     if (v == -2)
        langid = -1;
-    if (hWinUAEKey)
-       RegSetValueEx (hWinUAEKey, "Language", 0, REG_DWORD, (CONST BYTE *)&langid, sizeof(langid));
+    regsetint (NULL, "Language", langid);
     FreeLibrary(hUIDLL);
     hUIDLL = NULL;
     if (langid >= 0)
@@ -6818,7 +6771,7 @@ static void floppytooltip (HWND hDlg, int num, uae_u32 crc32)
     SendMessage (ToolTipHWND, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
 }
 
-static void addfloppyhistory_2 (HWND hDlg, HKEY fkey, int n, int f_text)
+static void addfloppyhistory_2 (HWND hDlg, UAEREG *fkey, int n, int f_text)
 {
     int i, j;
     char *s;
@@ -6868,7 +6821,7 @@ static void addfloppyhistory_2 (HWND hDlg, HKEY fkey, int n, int f_text)
 
 static void addfloppyhistory(HWND hDlg)
 {
-    HKEY fkey;
+    UAEREG *fkey;
     int f_text, max, n;
 
     if (currentpage == QUICKSTART_ID)
@@ -6889,8 +6842,7 @@ static void addfloppyhistory(HWND hDlg)
            f_text = IDC_DISKTEXT;
        addfloppyhistory_2 (hDlg, fkey, n, f_text);
     }
-    if (fkey)
-       RegCloseKey (fkey);
+    regclosetree (fkey);
 }
 
 static void addfloppytype (HWND hDlg, int n)
@@ -6973,8 +6925,7 @@ static void getfloppytypeq (HWND hDlg, int n)
            quickstart_floppy = 2;
        else
            quickstart_floppy = 1;
-       if (hWinUAEKey)
-           RegSetValueEx (hWinUAEKey, "QuickStartFloppies", 0, REG_DWORD, (CONST BYTE *)&quickstart_floppy, sizeof(quickstart_floppy));
+       regsetint (NULL, "QuickStartFloppies", quickstart_floppy);
     }
 }
 
@@ -8506,7 +8457,7 @@ static void values_to_hw3ddlg (HWND hDlg)
     char txt[100], tmp[100];
     int i, j, nofilter, fltnum, modenum;
     struct uae_filter *uf;
-    HKEY fkey;
+    UAEREG *fkey;
 
     SendDlgItemMessage(hDlg, IDC_FILTERHZ, TBM_SETRANGE, TRUE, MAKELONG (-999, +999));
     SendDlgItemMessage(hDlg, IDC_FILTERHZ, TBM_SETPAGESIZE, 0, 1);
@@ -8648,27 +8599,22 @@ static void values_to_hw3ddlg (HWND hDlg)
        sprintf(tmp, "* %s", filterpresets[i].name);
        SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_ADDSTRING, 0, (LPARAM)tmp);
     }
-    if (hWinUAEKey) {
-       RegCreateKeyEx(hWinUAEKey , "FilterPresets", 0, NULL, REG_OPTION_NON_VOLATILE,
-           KEY_READ, NULL, &fkey, NULL);
-       if (fkey) {
-           int idx = 0;
-           char tmp[MAX_DPATH], tmp2[MAX_DPATH];
-           DWORD size, size2;
-
-           for (;;) {
-               int err;
-               size = sizeof (tmp);
-               size2 = sizeof (tmp2);
-               err = RegEnumValue(fkey, idx, tmp, &size, NULL, NULL, tmp2, &size2);
-               if (err != ERROR_SUCCESS)
-                   break;
-               SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_ADDSTRING, 0, (LPARAM)tmp);
-               idx++;
-           }
-           SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_SETCURSEL, filterpreset_selected, 0);
-           RegCloseKey (fkey);
+    fkey = regcreatetree (NULL, "FilterPresets");
+    if (fkey) {
+        int idx = 0;
+        char tmp[MAX_DPATH], tmp2[MAX_DPATH];
+        DWORD size, size2;
+
+        for (;;) {
+           size = sizeof (tmp);
+           size2 = sizeof (tmp2);
+           if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2))
+               break;
+           SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_ADDSTRING, 0, (LPARAM)tmp);
+           idx++;
        }
+       SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_SETCURSEL, filterpreset_selected, 0);
+       regclosetree (fkey);
     }
 
     SendDlgItemMessage (hDlg, IDC_FILTERHZ, TBM_SETPOS, TRUE, workprefs.gfx_filter_horiz_zoom);
@@ -8687,19 +8633,16 @@ static void values_from_hw3ddlg (HWND hDlg)
 
 static void filter_preset (HWND hDlg, WPARAM wParam)
 {
-    int ok, err, load, i, builtin, userfilter;
+    int ok, load, i, builtin, userfilter;
     char tmp1[MAX_DPATH], tmp2[MAX_DPATH];
     DWORD outsize;
-    HKEY fkey = NULL;
+    UAEREG *fkey;
     LRESULT item;
 
     load = 0;
     ok = 0;
     for (builtin = 0; filterpresets[builtin].name; builtin++);
-    if (hWinUAEKey) {
-       RegCreateKeyEx(hWinUAEKey , "FilterPresets", 0, NULL, REG_OPTION_NON_VOLATILE,
-           KEY_READ | KEY_WRITE, NULL, &fkey, NULL);
-    }
+    fkey = regcreatetree (NULL, "FilterPresets");
     item = SendDlgItemMessage (hDlg, IDC_FILTERPRESETS, CB_GETCURSEL, 0, 0);
     tmp1[0] = 0;
     if (item != CB_ERR) {
@@ -8721,7 +8664,7 @@ static void filter_preset (HWND hDlg, WPARAM wParam)
 
     if (filterpreset_builtin < 0) {
        outsize = sizeof (tmp2);
-       if (tmp1[0] && fkey && RegQueryValueEx (fkey, tmp1, NULL, NULL, tmp2, &outsize) == ERROR_SUCCESS)
+       if (tmp1[0] && regquerystr (fkey, tmp1, tmp2, &outsize))
            ok = 1;
     } else {
        char *p = tmp2;
@@ -8752,13 +8695,12 @@ static void filter_preset (HWND hDlg, WPARAM wParam)
            if (tmp1[0] == 0)
                goto end;
        }
-       if (fkey)
-           RegSetValueEx (fkey, tmp1, 0, REG_SZ, (CONST BYTE *)&tmp2, strlen (tmp2) + 1);
+       regsetstr (fkey, tmp1, tmp2);
        values_to_hw3ddlg (hDlg);
     }
     if (ok) {
-       if (wParam == IDC_FILTERPRESETDELETE && userfilter && fkey) {
-           err = RegDeleteValue (fkey, tmp1);
+       if (wParam == IDC_FILTERPRESETDELETE && userfilter) {
+           regdelete (fkey, tmp1);
            values_to_hw3ddlg (hDlg);
        } else if (wParam == IDC_FILTERPRESETLOAD) {
            char *s = tmp2;
@@ -8779,8 +8721,7 @@ static void filter_preset (HWND hDlg, WPARAM wParam)
        }
     }
 end:
-    if (fkey)
-       RegCloseKey (fkey);
+    regclosetree (fkey);
     if (load) {
        values_to_hw3ddlg (hDlg);
        SendMessage (hDlg, WM_HSCROLL, 0, 0);
@@ -9477,12 +9418,12 @@ static HWND updatePanel (HWND hDlg, int id)
     if (id < 0) {
        if (isfullscreen () <= 0) {
            RECT r;
-           if (GetWindowRect (hDlg, &r) && hWinUAEKey) {
+           if (GetWindowRect (hDlg, &r)) {
                LONG left, top;
                left = r.left;
                top = r.top;
-               RegSetValueEx (hWinUAEKey, "GUIPosX", 0, REG_DWORD, (LPBYTE)&left, sizeof(LONG));
-               RegSetValueEx (hWinUAEKey, "GUIPosY", 0, REG_DWORD, (LPBYTE)&top, sizeof(LONG));
+               regsetint (NULL, "GUIPosX", left);
+               regsetint (NULL, "GUIPosY", top);
            }
        }
        ew (hDlg, IDHELP, FALSE);
@@ -9649,16 +9590,8 @@ static void centerWindow (HWND hDlg)
     if (owner == NULL)
        owner = GetDesktopWindow();
     if (isfullscreen () <= 0) {
-       DWORD regkeytype;
-       DWORD regkeysize = sizeof(LONG);
-       if (hWinUAEKey) {
-           if (RegQueryValueEx (hWinUAEKey, "GUIPosX", 0, &regkeytype, (LPBYTE)&x, &regkeysize) != ERROR_SUCCESS)
-               x = 0;
-           if (RegQueryValueEx (hWinUAEKey, "GUIPosY", 0, &regkeytype, (LPBYTE)&y, &regkeysize) != ERROR_SUCCESS)
-               y = 0;
-       } else {
-           x = y = 0;
-       }
+       regqueryint (NULL, "GUIPosX", &x);
+       regqueryint (NULL, "GUIPosY", &y);
     } else {
        GetWindowRect (owner, &rcOwner);
        GetWindowRect (hDlg, &rcDlg);
index 942aa1d3d78f21396a833466e87c5cd7916e4f10..5716ea2e6d77794ce9104eedd697680d864eca64 100644 (file)
@@ -16,7 +16,7 @@ void InitializeListView( HWND hDlg );
 extern void pre_gui_message (const char*,...);
 extern void gui_message_id (int id);
 int dragdrop (HWND hDlg, HDROP hd, struct uae_prefs *prefs, int currentpage);
-HKEY read_disk_history (void);
+UAEREG *read_disk_history (void);
 void write_disk_history (void);
 
 struct newresource
index b6aa4b5f89ff93bf1aa64e82226ba1e62b5b66fb..e549790a2961af72184ecfad0f1b3cf598247d86 100644 (file)
@@ -21,6 +21,7 @@
 #include "sysdeps.h"
 
 #include "resource.h"
+#include "registry.h"
 #include "win32.h"
 #include "win32gui.h"
 
index b9a8b5ac40ab8bb9496501d2df7a79ebfa394c70..5d95328d8f9bb231a043df56cb3934f8c0198f68 100644 (file)
                                RelativePath="..\posixemu.c"
                                >
                        </File>
+                       <File
+                               RelativePath="..\registry.c"
+                               >
+                       </File>
                        <File
                                RelativePath="..\cloanto\RetroPlatformGuestIPC.c"
                                >
index cd00373e02a415efbf7b5a1828dbf81a7f8e624b..ad24f208772a75e06b9a216e915733f20ece4142 100644 (file)
                                RelativePath="..\posixemu.c"
                                >
                        </File>
+                       <File
+                               RelativePath="..\registry.c"
+                               >
+                       </File>
                        <File
                                RelativePath="..\cloanto\RetroPlatformGuestIPC.c"
                                >
index 92315d2393a3ac38c4038483113e53253853d14a..d60bad8e8d29379a3f54eb65e5dc4fdc4d341253 100644 (file)
@@ -1,4 +1,19 @@
 
+Beta 9:
+
+- default GUI and main window position is centered, not top/left corner
+- optional ini-file registry replacement.
+  * -ini <file> in command line: use <file>
+  * winuae.ini used if it is in same directory as winuae.exe
+  * file extension must be .ini or it will be ignored
+  * file will be silently deleted and re-created if
+    - it is read-only but not delete-protected
+    - if warning messages in ini-file are modified or deleted
+    - if it is not compatible with new version
+  * message will be added to both logs if registry replacement is
+    enabled. Bug reports without also testing in non-ini mode will be
+    ignored. Pointless Windows feature "discussions" won't be allowed.
+
 Beta 8:
 
 - AGA sprite doublescan fixed (b7)
@@ -13,12 +28,13 @@ Beta 8:
 - default hardware config (used by QS) clears pc drive mount checkboxes
 - harddrive removal signal was not always send to uaehf.device if drive
   was removed with disk still in drive (for example USB ZIP drive)
-- ACTION_SET_DATE notification check crashed if file didn't exist
+- directory filesystem ACTION_SET_DATE notification check crashed if
+  file didn't exist
 - directory filesystem and hardfile slowdown fixed (b2)
 - state save crashed if directory harddrives were configured but state
   was saved before drive initialization, for example when booting
   non-dos adf
-- always have empty memory space between Z3Fast and RTG RAM
+- always include empty memory space between Z3Fast and RTG RAM
 
 Beta 7:
 
index 6792f7d3d9f1576aeb514b0de97c7ef6620e39f7..5e209dcd7120475133576c20865a8539635fc1a0 100644 (file)
@@ -9,6 +9,7 @@
 #include "debug.h"
 #include "debug_win32.h"
 #include "win32.h"
+#include "registry.h"
 
 #define SHOW_CONSOLE 0
 
@@ -55,10 +56,7 @@ static void openconsole(void)
        if (consoleopen > 0)
            return;
        if (debugger_type < 0) {
-           DWORD regkeytype;
-           DWORD regkeysize = sizeof(LONG);
-           if (hWinUAEKey)
-               RegQueryValueEx (hWinUAEKey, "DebuggerType", 0, &regkeytype, (LPBYTE)&debugger_type, &regkeysize);
+           regqueryint (NULL, "DebuggerType", &debugger_type);
            if (debugger_type <= 0)
                debugger_type = 2;
            openconsole();
@@ -86,8 +84,7 @@ void debugger_change(int mode)
        debugger_type = mode;
     if (debugger_type != 1 && debugger_type != 2)
        debugger_type = 2;
-    if (hWinUAEKey)
-       RegSetValueEx (hWinUAEKey, "DebuggerType", 0, REG_DWORD, (LPBYTE)&debugger_type, sizeof(LONG));
+    regsetint (NULL, "DebuggerType", debugger_type);
     openconsole();
 }
 
@@ -98,18 +95,16 @@ void reopen_console(void)
     if (consoleopen >= 0)
        return;
     hwnd = myGetConsoleWindow();
-    if (hwnd && hWinUAEKey) {
+    if (hwnd) {
        int newpos = 1;
        LONG x, y, w, h;
-       DWORD regkeytype;
-       DWORD regkeysize = sizeof(LONG);
-       if (RegQueryValueEx (hWinUAEKey, "LoggerPosX", 0, &regkeytype, (LPBYTE)&x, &regkeysize) != ERROR_SUCCESS)
+       if (!regqueryint (NULL, "LoggerPosX", &x))
            newpos = 0;
-       if (RegQueryValueEx (hWinUAEKey, "LoggerPosY", 0, &regkeytype, (LPBYTE)&y, &regkeysize) != ERROR_SUCCESS)
+       if (!regqueryint (NULL, "LoggerPosY", &y))
            newpos = 0;
-       if (RegQueryValueEx (hWinUAEKey, "LoggerPosW", 0, &regkeytype, (LPBYTE)&w, &regkeysize) != ERROR_SUCCESS)
+       if (!regqueryint (NULL, "LoggerPosW", &w))
            newpos = 0;
-       if (RegQueryValueEx (hWinUAEKey, "LoggerPosH", 0, &regkeytype, (LPBYTE)&h, &regkeysize) != ERROR_SUCCESS)
+       if (!regqueryint (NULL, "LoggerPosH", &h))
            newpos = 0;
        if (newpos) {
            RECT rc;
@@ -132,15 +127,15 @@ void close_console(void)
        close_debug_window();
     } else if (consoleopen < 0) {
        HWND hwnd = myGetConsoleWindow();
-       if (hwnd && hWinUAEKey) {
+       if (hwnd) {
            RECT r;
            if (GetWindowRect (hwnd, &r)) {
                r.bottom -= r.top;
                r.right -= r.left;
-               RegSetValueEx (hWinUAEKey, "LoggerPosX", 0, REG_DWORD, (LPBYTE)&r.left, sizeof(LONG));
-               RegSetValueEx (hWinUAEKey, "LoggerPosY", 0, REG_DWORD, (LPBYTE)&r.top, sizeof(LONG));
-               RegSetValueEx (hWinUAEKey, "LoggerPosW", 0, REG_DWORD, (LPBYTE)&r.right, sizeof(LONG));
-               RegSetValueEx (hWinUAEKey, "LoggerPosH", 0, REG_DWORD, (LPBYTE)&r.bottom, sizeof(LONG));
+               regsetint (NULL, "LoggerPosX", r.left);
+               regsetint (NULL, "LoggerPosY", r.top);
+               regsetint (NULL, "LoggerPosW", r.right);
+               regsetint (NULL, "LoggerPosH", r.bottom);
            }
        }
        FreeConsole();