}
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++ = '\"';
#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;
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*);
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;
}
inputdevice_init ();
- changed_prefs = currprefs;
+ copy_prefs(&currprefs, &changed_prefs);
+
no_gui = ! currprefs.start_gui;
if (restart_program == 2)
no_gui = 1;
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"));
#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;
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;
{
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));
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));