]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
cfgfile_searchconfig: start scan from the beginning fully if configstore was created...
authorToni Wilen <twilen@winuae.net>
Sun, 25 Mar 2018 10:08:24 +0000 (13:08 +0300)
committerToni Wilen <twilen@winuae.net>
Sun, 25 Mar 2018 10:08:24 +0000 (13:08 +0300)
cfgfile.cpp
inputdevice.cpp

index cecd6082b5da5438d034d6762981740f578aa892..47fbb2329240eda396c1058ad46e961c0604ee16 100644 (file)
@@ -6020,6 +6020,7 @@ static bool createconfigstore (struct uae_prefs *p)
        cfgfile_save_options (configstore, p, 0);
        uaeconfig--;
        zfile_fwrite (zeros, 1, sizeof zeros, configstore);
+       zfile_truncate(configstore, zfile_ftell(configstore));
        zfile_fseek (configstore, 0, SEEK_SET);
        return true;
 }
@@ -6876,8 +6877,14 @@ int cfgfile_searchconfig(const TCHAR *in, int index, TCHAR *out, int outsize)
        if (!configstore)
                return 20;
 
-       if (index < 0)
+       if (index < 0) {
+               index = 0;
                zfile_fseek(configstore, 0, SEEK_SET);
+       } else {
+               // if seek position==0: configstore was reset, always start from the beginning.
+               if (zfile_ftell(configstore) > 0)
+                       index = 0;
+       }
 
        tmp[0] = 0;
        for (;;) {
@@ -6899,23 +6906,27 @@ int cfgfile_searchconfig(const TCHAR *in, int index, TCHAR *out, int outsize)
                }
                if (b == '\n') {
                        if (!_tcsncmp (tmp, in, inlen) && ((inlen > 0 && _tcslen (tmp) > inlen && tmp[inlen] == '=') || (joker))) {
-                               TCHAR *p;
-                               if (joker)
-                                       p = tmp - 1;
-                               else
-                                       p = _tcschr (tmp, '=');
-                               if (p) {
-                                       for (int i = 0; out && i < outsize - 1; i++) {
-                                               TCHAR b = *++p;
-                                               out[i] = b;
-                                               out[i + 1] = 0;
-                                               if (!b)
-                                                       break;
+                               if (index <= 0) {
+                                       TCHAR *p;
+                                       if (joker)
+                                               p = tmp - 1;
+                                       else
+                                               p = _tcschr(tmp, '=');
+                                       if (p) {
+                                               for (int i = 0; out && i < outsize - 1; i++) {
+                                                       TCHAR b = *++p;
+                                                       out[i] = b;
+                                                       out[i + 1] = 0;
+                                                       if (!b)
+                                                               break;
+                                               }
                                        }
+                                       err = 0xffffffff;
+                                       configsearchfound = true;
+                                       goto end;
+                               } else {
+                                       index--;
                                }
-                               err = 0xffffffff;
-                               configsearchfound = true;
-                               goto end;
                        }
                        j = 0;
                } else {
@@ -8559,7 +8570,7 @@ void set_config_changed (void)
 void config_check_vsync (void)
 {
        if (config_changed) {
-#ifdef WITH_LUA
+#if 0
                if (config_changed == 1) {
                        createconfigstore (&currprefs);
                        uae_lua_run_handler ("on_uae_config_changed");
index 0b13f13473fea0227e1051fdd3cbd386087999e3..f018669fc57b656cae7d087e1aed854cb5b2ff74 100644 (file)
@@ -3676,6 +3676,7 @@ int handle_custom_event (const TCHAR *custom, int append)
        bool noquot = false;
        bool first = true;
        int adddelay = 0;
+       bool maybe_config_changed = false;
 
        if (custom == NULL) {
                return 0;
@@ -3766,10 +3767,11 @@ int handle_custom_event (const TCHAR *custom, int append)
                if (first) {
                        first = false;
                        if (!append)
-                               set_config_changed ();
+                               maybe_config_changed = true;
                }
                if (!_tcsicmp (p, _T("no_config_check"))) {
                        config_changed = 0;
+                       maybe_config_changed = false;
                } else if (!_tcsicmp (p, _T("do_config_check"))) {
                        set_config_changed ();
                } else if (!_tcsnicmp(p, _T("shellexec "), 10)) {
@@ -3803,6 +3805,8 @@ int handle_custom_event (const TCHAR *custom, int append)
                        break;
                p = nextp;
        }
+       if (maybe_config_changed)
+               set_config_changed();
        xfree (buf);
        return 0;
 }