From 787211c9dcda13cdbb10cc94df355c739900cc8c Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 5 Feb 2020 13:56:54 +0200 Subject: [PATCH] - unified saved games path handling for all platforms The current game subdirectory is now created on all platforms Added support for -savedir command line switch for all platforms Removed save_dir CVAR in favor of cl_savedir which was available on Windows only Made cl_savedir CVAR global instead of different value per each game --- source/common/savegamehelp.cpp | 35 ++++++++++++++++----- source/platform/posix/osx/i_specialpaths.mm | 1 - source/platform/win32/i_specialpaths.cpp | 28 ++++------------- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/source/common/savegamehelp.cpp b/source/common/savegamehelp.cpp index f680738ad..e789d95b7 100644 --- a/source/common/savegamehelp.cpp +++ b/source/common/savegamehelp.cpp @@ -47,13 +47,15 @@ #include "quotemgr.h" #include "mapinfo.h" #include "v_video.h" +#include "gamecontrol.h" +#include "m_argv.h" static CompositeSavegameWriter savewriter; static FResourceFile *savereader; void LoadEngineState(); void SaveEngineState(); -CVAR(String, save_dir, "", CVAR_ARCHIVE|CVAR_GLOBALCONFIG); +CVAR(String, cl_savedir, "", CVAR_ARCHIVE|CVAR_GLOBALCONFIG) //============================================================================= // @@ -344,14 +346,33 @@ int G_ValidateSavegame(FileReader &fr, FString *savetitle, bool formenu) FString G_BuildSaveName (const char *prefix) { - FString name = *save_dir; - if (name.IsEmpty()) - name = M_GetSavegamesPath(); - size_t len = name.Len(); - if (name[0] != '\0' && name[len-1] != '\\' && name[len-1] != '/') + FString name; + bool usefilter; + + if (const char *const dir = Args->CheckValue("-savedir")) { - name << "/"; + name = dir; + usefilter = false; } + else + { + name = **cl_savedir ? cl_savedir : M_GetSavegamesPath(); + usefilter = true; + } + + const size_t len = name.Len(); + if (len > 0) + { + name.Substitute("\\", "/"); + if (name[len - 1] != '/') + name << '/'; + } + + if (usefilter) + name << LumpFilter << '/'; + + CreatePath(name); + name << prefix; if (!strchr(prefix, '.')) name << SAVEGAME_EXT; // only add an extension if the prefix doesn't have one already. name = NicePath(name); diff --git a/source/platform/posix/osx/i_specialpaths.mm b/source/platform/posix/osx/i_specialpaths.mm index 60f26bf15..9ea2c4719 100644 --- a/source/platform/posix/osx/i_specialpaths.mm +++ b/source/platform/posix/osx/i_specialpaths.mm @@ -199,7 +199,6 @@ FString M_GetSavegamesPath() path += "/" GAME_DIR "/Savegames/"; } - CreatePath(path); return path; } diff --git a/source/platform/win32/i_specialpaths.cpp b/source/platform/win32/i_specialpaths.cpp index 3141b096b..213d425a7 100644 --- a/source/platform/win32/i_specialpaths.cpp +++ b/source/platform/win32/i_specialpaths.cpp @@ -43,7 +43,6 @@ #include "cmdlib.h" #include "i_findfile.h" #include "gamecontrol.h" -#include "m_argv.h" #include "version.h" // for GAMENAME // Stuff that needs to be set up later. @@ -267,47 +266,32 @@ FString M_GetScreenshotsPath() // Returns the path to the default save games directory. // //=========================================================================== -CVAR(String, cl_savedir, "", CVAR_ARCHIVE) FString M_GetSavegamesPath() { FString path; - auto dir = Args->CheckValue("-savedir"); - if (dir) + if (!UseKnownFolders()) { - path = dir; - path.Substitute("\\", "/"); - if (path[path.Len() - 1] != '/') path << '/'; - } - else if (**cl_savedir) - { - path = cl_savedir; - path.Substitute("\\", "/"); - if (path[path.Len() - 1] != '/') path << '/'; - path << LumpFilter << '/'; - } - else if (!UseKnownFolders()) - { - path << progdir << "Save/" << LumpFilter << "/"; + path << progdir << "Save/"; } // Try standard Saved Games folder else if (GetKnownFolder(-1, FOLDERID_SavedGames, true, path)) { - path << "/" GAMENAME "/" << LumpFilter << "/"; + path << "/" GAMENAME "/"; } // Try defacto My Documents/My Games folder else if (GetKnownFolder(CSIDL_PERSONAL, FOLDERID_Documents, true, path)) { // I assume since this isn't a standard folder, it doesn't have // a localized name either. - path << "/My Games/" GAMENAME "/" << LumpFilter << "/"; + path << "/My Games/" GAMENAME "/"; } else { - path << progdir << "Save/" << LumpFilter << "/"; + path << progdir << "Save/"; } - CreatePath(path); + return path; }