]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Config file copy helper routines.
authorToni Wilen <twilen@winuae.net>
Sun, 4 Feb 2018 13:51:57 +0000 (15:51 +0200)
committerToni Wilen <twilen@winuae.net>
Sun, 4 Feb 2018 13:51:57 +0000 (15:51 +0200)
cfgfile.cpp
include/options.h
main.cpp
od-win32/win32gui.cpp

index ab45a000115c09837ea4b6f6037f1e8dc9e9d2af..c4c5c8b2654579b9e984a15f15a0726a2a281cf8 100644 (file)
@@ -505,7 +505,7 @@ static TCHAR *cfgfile_escape (const TCHAR *s, const TCHAR *escstr, bool quote)
        }
        if (escstr == NULL && quote)
                doquote = true;
-       TCHAR *s2 = xmalloc (TCHAR, _tcslen (s) + cnt * 4 + 1);
+       TCHAR *s2 = xmalloc (TCHAR, _tcslen (s) + cnt * 4 + 2 + 1);
        TCHAR *p = s2;
        if (doquote)
                *p++ = '\"';
@@ -7145,6 +7145,57 @@ static void default_prefs_mini (struct uae_prefs *p, int type)
 
 #include "sounddep/sound.h"
 
+static void copy_inputdevice_settings(struct uae_input_device *src, struct uae_input_device *dst)
+{
+       for (int l = 0; l < MAX_INPUT_DEVICE_EVENTS; l++) {
+               for (int i = 0; i < MAX_INPUT_SUB_EVENT_ALL; i++) {
+                       if (src->custom[l][i]) {
+                               dst->custom[l][i] = my_strdup(src->custom[l][i]);
+                       } else {
+                               dst->custom[l][i] = NULL;
+                       }
+               }
+       }
+}
+
+static void copy_inputdevice_settings_free(struct uae_input_device *src, struct uae_input_device *dst)
+{
+       for (int l = 0; l < MAX_INPUT_DEVICE_EVENTS; l++) {
+               for (int i = 0; i < MAX_INPUT_SUB_EVENT_ALL; i++) {
+                       if (dst->custom[l][i] == NULL && src->custom[l][i] == NULL)
+                               continue;
+                       // same string in both src and dest: separate them (fixme: this shouldn't happen!)
+                       if (dst->custom[l][i] == src->custom[l][i]) {
+                               dst->custom[l][i] = NULL;
+                       } else {
+                               if (dst->custom[l][i]) {
+                                       xfree(dst->custom[l][i]);
+                                       dst->custom[l][i] = NULL;
+                               }
+                       }
+               }
+       }
+}
+
+void copy_prefs(struct uae_prefs *src, struct uae_prefs *dst)
+{
+       for (int slot = 0; slot < MAX_INPUT_SETTINGS; slot++) {
+               for (int m = 0; m < MAX_INPUT_DEVICES; m++) {
+                       copy_inputdevice_settings_free(&src->joystick_settings[slot][m], &dst->joystick_settings[slot][m]);
+                       copy_inputdevice_settings_free(&src->mouse_settings[slot][m], &dst->mouse_settings[slot][m]);
+                       copy_inputdevice_settings_free(&src->keyboard_settings[slot][m], &dst->keyboard_settings[slot][m]);
+               }
+       }
+       memcpy(dst, src, sizeof(struct uae_prefs));
+       for (int slot = 0; slot < MAX_INPUT_SETTINGS; slot++) {
+               for (int m = 0; m < MAX_INPUT_DEVICES; m++) {
+                       copy_inputdevice_settings(&src->joystick_settings[slot][m], &dst->joystick_settings[slot][m]);
+                       copy_inputdevice_settings(&src->mouse_settings[slot][m], &dst->mouse_settings[slot][m]);
+                       copy_inputdevice_settings(&src->keyboard_settings[slot][m], &dst->keyboard_settings[slot][m]);
+               }
+       }
+}
+
 void default_prefs (struct uae_prefs *p, bool reset, int type)
 {
        int i;
index 18c60b85d2f6345a8886b872efcccc8006c1b961..f89747232b2ea5f67e139f85e98c06133267288d 100644 (file)
@@ -860,6 +860,7 @@ extern bool is_error_log (void);
 
 extern void default_prefs (struct uae_prefs *, bool, int);
 extern void discard_prefs (struct uae_prefs *, int);
+extern void copy_prefs(struct uae_prefs *src, struct uae_prefs *dst);
 
 int parse_cmdline_option (struct uae_prefs *, TCHAR, const TCHAR*);
 
index c1c20e6a6565b6e9aa8381909a2c8cd68f37dbdc..1d6e8c0e0a496385cd7fc7e10331d80eec16dd3d 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1050,7 +1050,7 @@ static int real_main2 (int argc, TCHAR **argv)
        if (restart_config[0])
                parse_cmdline_and_init_file (argc, argv);
        else
-               currprefs = changed_prefs;
+               copy_prefs(&changed_prefs, &currprefs);
 
        if (!machdep_init ()) {
                restart_program = 0;
@@ -1068,7 +1068,8 @@ static int real_main2 (int argc, TCHAR **argv)
        }
        inputdevice_init ();
 
-       changed_prefs = currprefs;
+       copy_prefs(&currprefs, &changed_prefs);
+
        no_gui = ! currprefs.start_gui;
        if (restart_program == 2)
                no_gui = 1;
@@ -1077,7 +1078,7 @@ static int real_main2 (int argc, TCHAR **argv)
        restart_program = 0;
        if (! no_gui) {
                int err = gui_init ();
-               currprefs = changed_prefs;
+               copy_prefs(&changed_prefs, &currprefs);
                set_config_changed ();
                if (err == -1) {
                        write_log (_T("Failed to initialize the GUI\n"));
@@ -1120,7 +1121,7 @@ static int real_main2 (int argc, TCHAR **argv)
 #ifdef RETROPLATFORM
        rp_fixup_options (&currprefs);
 #endif
-       changed_prefs = currprefs;
+       copy_prefs(&currprefs, &changed_prefs);
        target_run ();
        /* force sound settings change */
        currprefs.produce_sound = 0;
@@ -1174,7 +1175,7 @@ void real_main (int argc, TCHAR **argv)
 
        while (restart_program) {
                int ret;
-               changed_prefs = currprefs;
+               copy_prefs(&currprefs, &changed_prefs);
                ret = real_main2 (argc, argv);
                if (ret == 0 && quit_to_gui)
                        restart_program = 1;
index f4a649fcdbf9ce4670be446a9cb43e45bcb70766..80f68e653ecc253f62b2d6745adaf975d66df8f5 100644 (file)
@@ -2292,7 +2292,7 @@ static void prefs_to_gui (struct uae_prefs *p)
 {
        int st = savestate_state;
        default_prefs(&workprefs, false, 0);
-       workprefs = *p;
+       copy_prefs(p, &workprefs);
        /* filesys hack */
        workprefs.mountitems = currprefs.mountitems;
        memcpy (&workprefs.mountconfig, &currprefs.mountconfig, MOUNT_CONFIG_SIZE * sizeof (struct uaedev_config_info));
@@ -2304,7 +2304,7 @@ static void prefs_to_gui (struct uae_prefs *p)
 static void gui_to_prefs (void)
 {
        /* Always copy our prefs to changed_prefs, ... */
-       changed_prefs = workprefs;
+       copy_prefs(&workprefs, &changed_prefs);
        /* filesys hack */
        currprefs.mountitems = changed_prefs.mountitems;
        memcpy (&currprefs.mountconfig, &changed_prefs.mountconfig, MOUNT_CONFIG_SIZE * sizeof (struct uaedev_config_info));