From cb10e7c6bda34ed02982970a8752c33670efa210 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sun, 25 Mar 2018 13:08:24 +0300 Subject: [PATCH] cfgfile_searchconfig: start scan from the beginning fully if configstore was created between searches. Do not set config as changed unless it really did change. --- cfgfile.cpp | 45 ++++++++++++++++++++++++++++----------------- inputdevice.cpp | 6 +++++- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/cfgfile.cpp b/cfgfile.cpp index cecd6082..47fbb232 100644 --- a/cfgfile.cpp +++ b/cfgfile.cpp @@ -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"); diff --git a/inputdevice.cpp b/inputdevice.cpp index 0b13f134..f018669f 100644 --- a/inputdevice.cpp +++ b/inputdevice.cpp @@ -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; } -- 2.47.3