]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Per-config statefile path
authorToni Wilen <twilen@winuae.net>
Sat, 4 Jan 2025 11:13:28 +0000 (13:13 +0200)
committerToni Wilen <twilen@winuae.net>
Sat, 4 Jan 2025 11:13:28 +0000 (13:13 +0200)
cfgfile.cpp
include/savestate.h
od-win32/win32.cpp
od-win32/win32gui.cpp
savestate.cpp

index 8016288bbe60a52d4aae94bbed3892915c010a87..ae4af973d4f9440e8e3f7f354ee0a7b789e37832 100644 (file)
@@ -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);
index 7bcb68c0b4879a677eac51acf466cd15a256ba8f..86da1149febc4f13f2503bee2fcfd2bd0088a490 100644 (file)
@@ -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)
index 74ac7629b19ae02923c0a3090e0b3073940ad80d..c40fba209f4505cf1fbc59024ce738deb08612b6 100644 (file)
@@ -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 {
index 179777ca16777a7053b488fb4754928acbbb49b3..aa50718db59f15ab7a86fa4ddda45c1207d5af4e 100644 (file)
@@ -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;
index 7ad304e880a567267cc0626b4e2297debb08544e..f0f6574d039bf2ee3ae580dedd8d68efdeb74125 100644 (file)
@@ -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);
        }
 }