From 2f7498214baa790efc0259c2821368b2262716f6 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Tue, 26 May 2009 01:05:01 +0000 Subject: [PATCH] - Specifying non-existent directories with -savedir or the save_dir cvar now attempts to create them. SVN r1607 (trunk) --- docs/rh-log.txt | 2 ++ src/cmdlib.cpp | 15 +++++++++------ src/g_game.cpp | 21 ++++++++++++--------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 55efbe3a2..2b0c2a7de 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,6 @@ May 25, 2009 +- Specifiying non-existant directories with -savedir or the save_dir cvar now + attempts to create them. - I_CheckNativeMouse() now checks the foreground window to determine if the mouse should be grabbed. This fixes the case where you start the game in the background and it grabs the mouse anyway. diff --git a/src/cmdlib.cpp b/src/cmdlib.cpp index e9924785d..5403141ee 100644 --- a/src/cmdlib.cpp +++ b/src/cmdlib.cpp @@ -352,7 +352,7 @@ const char *myasctime () /* */ /************************************************************************/ #ifdef _WIN32 -void DoCreatePath(const char * fn) +void DoCreatePath(const char *fn) { char drive[_MAX_DRIVE]; char path[PATH_MAX]; @@ -367,17 +367,20 @@ void DoCreatePath(const char * fn) _mkdir(p); } -void CreatePath(const char * fn) +void CreatePath(const char *fn) { - char name[PATH_MAX]; char c = fn[strlen(fn)-1]; - if (c!='\\' && c!='/') + if (c != '\\' && c != '/') { - mysnprintf(name, countof(name), "%s/", fn); + FString name(fn); + name += '/'; DoCreatePath(name); } - else DoCreatePath(fn); + else + { + DoCreatePath(fn); + } } #else void CreatePath(const char *fn) diff --git a/src/g_game.cpp b/src/g_game.cpp index 2f37e292b..b139fa1f8 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -1777,24 +1777,27 @@ FString G_BuildSaveName (const char *prefix, int slot) { leader = save_dir; } +#ifdef unix + if (leader.IsEmpty()) + { + leader = "~" GAME_DIR; + } +#endif } size_t len = leader.Len(); if (leader[0] != '\0' && leader[len-1] != '\\' && leader[len-1] != '/') { slash = "/"; } - name.Format("%s%s%s", leader.GetChars(), slash, prefix); + name << leader << slash; + name = NicePath(name); + CreatePath(name); + name << prefix; if (slot >= 0) { name.AppendFormat("%d.zds", slot); } -#ifdef unix - if (leader[0] == 0) - { - return GetUserFile (name); - } -#endif - return NicePath(name); + return name; } CVAR (Int, autosavenum, 0, CVAR_NOSET|CVAR_ARCHIVE|CVAR_GLOBALCONFIG) @@ -1911,7 +1914,7 @@ void G_DoSaveGame (bool okForQuicksave, FString filename, const char *descriptio insave = true; G_SnapshotLevel (); - FILE *stdfile = fopen (filename.GetChars(), "wb"); + FILE *stdfile = fopen (filename, "wb"); if (stdfile == NULL) {