From e9e5017252a7972704e5e30da8aacda698bf994d Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 4 Jan 2025 13:13:28 +0200 Subject: [PATCH] Per-config statefile path --- cfgfile.cpp | 8 +++++++ include/savestate.h | 1 + od-win32/win32.cpp | 6 ++++- od-win32/win32gui.cpp | 3 +++ savestate.cpp | 56 +++++++++++++++++++++++++++---------------- 5 files changed, 53 insertions(+), 21 deletions(-) diff --git a/cfgfile.cpp b/cfgfile.cpp index 8016288b..ae4af973 100644 --- a/cfgfile.cpp +++ b/cfgfile.cpp @@ -2166,6 +2166,8 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type) cfgfile_write_path2(f, _T("statefile"), p->statefile, PATH_NONE); if (p->quitstatefile[0]) cfgfile_write_path2(f, _T("statefile_quit"), p->quitstatefile, PATH_NONE); + if (p->statefile_path[0]) + cfgfile_dwrite_path2(f, _T("statefile_path"), p->statefile_path, PATH_NONE); cfgfile_write (f, _T("nr_floppies"), _T("%d"), p->nr_floppies); cfgfile_dwrite_bool (f, _T("floppy_write_protect"), p->floppy_read_only); @@ -4354,6 +4356,12 @@ static int cfgfile_parse_host (struct uae_prefs *p, TCHAR *option, TCHAR *value) if (cfgfile_path(option, value, _T("statefile_quit"), p->quitstatefile, sizeof p->quitstatefile / sizeof (TCHAR))) return 1; + if (cfgfile_path(option, value, _T("statefile_path"), p->statefile_path, sizeof p->statefile_path / sizeof(TCHAR))) { + _tcscpy(path_statefile, p->statefile_path); + target_setdefaultstatefilename(path_statefile); + return 1; + } + if (cfgfile_string (option, value, _T("statefile_name"), tmpbuf, sizeof tmpbuf / sizeof (TCHAR))) { fetch_statefilepath (savestate_fname, sizeof savestate_fname / sizeof (TCHAR)); _tcscat (savestate_fname, tmpbuf); diff --git a/include/savestate.h b/include/savestate.h index 7bcb68c0..86da1149 100644 --- a/include/savestate.h +++ b/include/savestate.h @@ -274,6 +274,7 @@ extern bool savestate_check(void); extern int savestate_state; extern TCHAR savestate_fname[MAX_DPATH]; +extern TCHAR path_statefile[MAX_DPATH]; extern struct zfile *savestate_file; STATIC_INLINE bool isrestore(void) diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index 74ac7629..c40fba20 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -5106,6 +5106,10 @@ void fetch_ripperpath(TCHAR *out, int size) } void fetch_statefilepath(TCHAR *out, int size) { + if (path_statefile[0]) { + _tcsncpy(out, path_statefile, size); + return; + } fetch_path(_T("StatefilePath"), out, size); } void fetch_inputfilepath(TCHAR *out, int size) @@ -6007,7 +6011,7 @@ static void WIN32_HandleRegistryStuff (void) void target_setdefaultstatefilename(const TCHAR *name) { TCHAR path[MAX_DPATH]; - fetch_path(_T("StatefilePath"), path, sizeof(path) / sizeof(TCHAR)); + fetch_statefilepath(path, sizeof(path) / sizeof(TCHAR)); if (!name || !name[0]) { _tcscat(path, _T("default.uss")); } else { diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index 179777ca..aa50718d 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -2294,6 +2294,9 @@ int target_cfgfile_load (struct uae_prefs *p, const TCHAR *filename, int type, i TCHAR tmp1[MAX_DPATH], tmp2[MAX_DPATH]; TCHAR fname[MAX_DPATH], cname[MAX_DPATH]; + if (isdefault) { + path_statefile[0] = 0; + } error_log(NULL); _tcscpy (fname, filename); cname[0] = 0; diff --git a/savestate.cpp b/savestate.cpp index 7ad304e8..f0f6574d 100644 --- a/savestate.cpp +++ b/savestate.cpp @@ -77,9 +77,17 @@ static bool new_blitter = false; static int replaycounter; struct zfile *savestate_file; -static int savestate_docompress, savestate_specialdump, savestate_nodialogs; + +#define SAVESTATE_DOCOMPRESS 1 +#define SAVESTATE_NODIALOGS 2 +#define SAVESTATE_SPECIALDUMP1 4 +#define SAVESTATE_SPECIALDUMP2 8 +#define SAVESTATE_ALWAYSUSEPATH 16 +#define SAVESTATE_SPECIALDUMP (SAVESTATE_SPECIALDUMP1 | SAVESTATE_SPECIALDUMP2) +static int savestate_flags; TCHAR savestate_fname[MAX_DPATH]; +TCHAR path_statefile[MAX_DPATH]; #define STATEFILE_ALLOC_SIZE 600000 static int statefile_alloc; @@ -899,17 +907,15 @@ bool savestate_restore_finish(void) /* 1=compressed,2=not compressed,3=ram dump,4=audio dump */ void savestate_initsave (const TCHAR *filename, int mode, int nodialogs, bool save) { + savestate_flags = 0; if (filename == NULL) { savestate_fname[0] = 0; - savestate_docompress = 0; - savestate_specialdump = 0; - savestate_nodialogs = 0; return; } _tcscpy (savestate_fname, filename); - savestate_docompress = (mode == 1) ? 1 : 0; - savestate_specialdump = (mode == 3) ? 1 : (mode == 4) ? 2 : 0; - savestate_nodialogs = nodialogs; + savestate_flags |= (mode == 1) ? SAVESTATE_DOCOMPRESS : 0; + savestate_flags |= (mode == 3) ? SAVESTATE_SPECIALDUMP1 : (mode == 4) ? SAVESTATE_SPECIALDUMP2 : 0; + savestate_flags |= nodialogs ? SAVESTATE_NODIALOGS : 0; new_blitter = false; if (save) { savestate_free (); @@ -1254,9 +1260,9 @@ static int save_state_internal (struct zfile *f, const TCHAR *description, int c int save_state (const TCHAR *filename, const TCHAR *description) { struct zfile *f; - int comp = savestate_docompress; + int comp = (savestate_flags & SAVESTATE_DOCOMPRESS) != 0; - if (!savestate_specialdump && !savestate_nodialogs) { + if (!(savestate_flags & SAVESTATE_SPECIALDUMP) && !(savestate_flags & SAVESTATE_NODIALOGS)) { if (is_savestate_incompatible()) { static int warned; if (!warned) { @@ -1270,18 +1276,19 @@ int save_state (const TCHAR *filename, const TCHAR *description) } } new_blitter = false; - savestate_nodialogs = 0; - custom_prepare_savestate (); + savestate_flags &= ~SAVESTATE_NODIALOGS; + custom_prepare_savestate(); f = zfile_fopen (filename, _T("w+b"), 0); if (!f) return 0; - if (savestate_specialdump) { + if (savestate_flags & SAVESTATE_SPECIALDUMP) { size_t pos; - if (savestate_specialdump == 2) + if (savestate_flags & SAVESTATE_SPECIALDUMP2) { write_wavheader (f, 0, 22050); + } pos = zfile_ftell32(f); save_rams (f, -1); - if (savestate_specialdump == 2) { + if (savestate_flags & SAVESTATE_SPECIALDUMP2) { size_t len, len2, i; uae_u8 *tmp; len = zfile_ftell32(f) - pos; @@ -1306,28 +1313,36 @@ int save_state (const TCHAR *filename, const TCHAR *description) return v; } -void savestate_quick (int slot, int save) +void savestate_quick(int slot, int save) { + if (path_statefile[0]) { + _tcscpy(savestate_fname, path_statefile); + } int i, len = uaetcslen(savestate_fname); i = len - 1; - while (i >= 0 && savestate_fname[i] != '_') + while (i >= 0 && savestate_fname[i] != '_') { i--; + } if (i < len - 6 || i <= 0) { /* "_?.uss" */ i = len - 1; - while (i >= 0 && savestate_fname[i] != '.') + while (i >= 0 && savestate_fname[i] != '.') { i--; + } if (i <= 0) { write_log (_T("savestate name skipped '%s'\n"), savestate_fname); return; } } _tcscpy (savestate_fname + i, _T(".uss")); - if (slot > 0) + if (slot > 0) { _stprintf (savestate_fname + i, _T("_%d.uss"), slot); + } + savestate_flags = 0; if (save) { write_log (_T("saving '%s'\n"), savestate_fname); - savestate_docompress = 1; - savestate_nodialogs = 1; + savestate_flags |= SAVESTATE_DOCOMPRESS; + savestate_flags |= SAVESTATE_NODIALOGS; + savestate_flags |= SAVESTATE_ALWAYSUSEPATH; save_state (savestate_fname, _T("")); } else { if (!zfile_exists (savestate_fname)) { @@ -1335,6 +1350,7 @@ void savestate_quick (int slot, int save) return; } savestate_state = STATE_DORESTORE; + savestate_flags |= SAVESTATE_ALWAYSUSEPATH; write_log (_T("staterestore starting '%s'\n"), savestate_fname); } } -- 2.47.3