- 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
This commit is contained in:
alexey.lysiuk 2020-02-05 13:56:54 +02:00 committed by Christoph Oelckers
parent 67a2952ead
commit 787211c9dc
3 changed files with 34 additions and 30 deletions

View file

@ -47,13 +47,15 @@
#include "quotemgr.h" #include "quotemgr.h"
#include "mapinfo.h" #include "mapinfo.h"
#include "v_video.h" #include "v_video.h"
#include "gamecontrol.h"
#include "m_argv.h"
static CompositeSavegameWriter savewriter; static CompositeSavegameWriter savewriter;
static FResourceFile *savereader; static FResourceFile *savereader;
void LoadEngineState(); void LoadEngineState();
void SaveEngineState(); 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 G_BuildSaveName (const char *prefix)
{ {
FString name = *save_dir; FString name;
if (name.IsEmpty()) bool usefilter;
name = M_GetSavegamesPath();
size_t len = name.Len(); if (const char *const dir = Args->CheckValue("-savedir"))
if (name[0] != '\0' && name[len-1] != '\\' && name[len-1] != '/')
{ {
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; name << prefix;
if (!strchr(prefix, '.')) name << SAVEGAME_EXT; // only add an extension if the prefix doesn't have one already. if (!strchr(prefix, '.')) name << SAVEGAME_EXT; // only add an extension if the prefix doesn't have one already.
name = NicePath(name); name = NicePath(name);

View file

@ -199,7 +199,6 @@ FString M_GetSavegamesPath()
path += "/" GAME_DIR "/Savegames/"; path += "/" GAME_DIR "/Savegames/";
} }
CreatePath(path);
return path; return path;
} }

View file

@ -43,7 +43,6 @@
#include "cmdlib.h" #include "cmdlib.h"
#include "i_findfile.h" #include "i_findfile.h"
#include "gamecontrol.h" #include "gamecontrol.h"
#include "m_argv.h"
#include "version.h" // for GAMENAME #include "version.h" // for GAMENAME
// Stuff that needs to be set up later. // Stuff that needs to be set up later.
@ -267,47 +266,32 @@ FString M_GetScreenshotsPath()
// Returns the path to the default save games directory. // Returns the path to the default save games directory.
// //
//=========================================================================== //===========================================================================
CVAR(String, cl_savedir, "", CVAR_ARCHIVE)
FString M_GetSavegamesPath() FString M_GetSavegamesPath()
{ {
FString path; FString path;
auto dir = Args->CheckValue("-savedir"); if (!UseKnownFolders())
if (dir)
{ {
path = dir; path << progdir << "Save/";
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 << "/";
} }
// Try standard Saved Games folder // Try standard Saved Games folder
else if (GetKnownFolder(-1, FOLDERID_SavedGames, true, path)) else if (GetKnownFolder(-1, FOLDERID_SavedGames, true, path))
{ {
path << "/" GAMENAME "/" << LumpFilter << "/"; path << "/" GAMENAME "/";
} }
// Try defacto My Documents/My Games folder // Try defacto My Documents/My Games folder
else if (GetKnownFolder(CSIDL_PERSONAL, FOLDERID_Documents, true, path)) else if (GetKnownFolder(CSIDL_PERSONAL, FOLDERID_Documents, true, path))
{ {
// I assume since this isn't a standard folder, it doesn't have // I assume since this isn't a standard folder, it doesn't have
// a localized name either. // a localized name either.
path << "/My Games/" GAMENAME "/" << LumpFilter << "/"; path << "/My Games/" GAMENAME "/";
} }
else else
{ {
path << progdir << "Save/" << LumpFilter << "/"; path << progdir << "Save/";
} }
CreatePath(path);
return path; return path;
} }