From 04ee130b6afe7b1a9afdd65d554cfb44791e6232 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Tue, 19 Mar 2024 18:59:02 +0200 Subject: [PATCH] Get default statefile name from config file path --- od-win32/win32.cpp | 18 +++++++++++++++--- od-win32/win32gui.cpp | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index d20c4fe8..d77ef794 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -6007,10 +6007,22 @@ void target_setdefaultstatefilename(const TCHAR *name) if (!name || !name[0]) { _tcscat(path, _T("default.uss")); } else { - _tcscat(path, name); - const TCHAR *p = _tcsrchr(name, '.'); + const TCHAR *p2 = _tcsrchr(name, '\\'); + const TCHAR *p3 = _tcsrchr(name, '/'); + const TCHAR *p1 = NULL; + if (p2 >= p3) { + p1 = p2; + } else if (p3 >= p2) { + p1 = p3; + } + if (p1) { + _tcscat(path, p1 + 1); + } else { + _tcscat(path, name); + } + const TCHAR *p = _tcsrchr(path, '.'); if (p) { - path[_tcslen(path) - ((name + _tcslen(name)) - p)] = 0; + path[_tcslen(path) - ((path + _tcslen(path)) - p)] = 0; _tcscat(path, _T(".uss")); } } diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index d6d45a43..a310b61c 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -2304,6 +2304,7 @@ int target_cfgfile_load (struct uae_prefs *p, const TCHAR *filename, int type, i else _tcscpy (fname, filename); } + target_setdefaultstatefilename(filename); if (!isdefault) qs_override = 1; @@ -4247,7 +4248,6 @@ static TCHAR *HandleConfiguration (HWND hDlg, int flag, struct ConfigStruct *con WIN32GUI_LoadUIString (IDS_MUSTSELECTCONFIG, szMessage, MAX_DPATH); pre_gui_message (szMessage); } else { - target_setdefaultstatefilename(config_filename); if (target_cfgfile_load (&workprefs, path, configtypepanel, 0) == 0) { TCHAR szMessage[MAX_DPATH]; WIN32GUI_LoadUIString (IDS_COULDNOTLOADCONFIG, szMessage, MAX_DPATH); -- 2.47.3