- unified demo path handling for all platforms

The current game subdirectory is now created on all platforms
This commit is contained in:
alexey.lysiuk 2020-02-05 13:57:17 +02:00 committed by Christoph Oelckers
parent 787211c9dc
commit 1479e1feae
7 changed files with 22 additions and 14 deletions

View file

@ -42,7 +42,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "network.h" #include "network.h"
#include "player.h" #include "player.h"
#include "screen.h" #include "screen.h"
#include "i_specialpaths.h"
#include "view.h" #include "view.h"
#include "gamecontrol.h" #include "gamecontrol.h"
#include "menu/menu.h" #include "menu/menu.h"
@ -127,7 +126,7 @@ bool CDemo::Create(const char *pzFile)
{ {
for (int i = 0; i < 8 && !vc; i++) for (int i = 0; i < 8 && !vc; i++)
{ {
snprintf(buffer, BMAX_PATH, "%s%s0%02d.dem", M_GetDemoPath().GetChars(), BloodIniPre, i); snprintf(buffer, BMAX_PATH, "%s%s0%02d.dem", G_GetDemoPath().GetChars(), BloodIniPre, i);
if (access(buffer, 0) != -1) if (access(buffer, 0) != -1)
vc = 1; vc = 1;
} }
@ -140,7 +139,7 @@ bool CDemo::Create(const char *pzFile)
} }
else else
{ {
snprintf(buffer, BMAX_PATH, "%s%s", M_GetDemoPath().GetChars(), pzFile); snprintf(buffer, BMAX_PATH, "%s%s", G_GetDemoPath().GetChars(), pzFile);
hRFile = fopen(buffer, "wb"); hRFile = fopen(buffer, "wb");
if (hRFile == NULL) if (hRFile == NULL)
return false; return false;
@ -401,7 +400,7 @@ void CDemo::LoadDemoInfo(void)
auto pDemo = &pFirstDemo; auto pDemo = &pFirstDemo;
at59ef = 0; at59ef = 0;
char zFN[BMAX_PATH]; char zFN[BMAX_PATH];
snprintf(zFN, BMAX_PATH, "%s%s*.dem", M_GetDemoPath().GetChars(), BloodIniPre); snprintf(zFN, BMAX_PATH, "%s%s*.dem", G_GetDemoPath().GetChars(), BloodIniPre);
TArray<FString> demos; TArray<FString> demos;
D_AddWildFile(demos, zFN); D_AddWildFile(demos, zFN);

View file

@ -878,3 +878,13 @@ int CalcSmoothRatio(const ClockTicks &totalclk, const ClockTicks &ototalclk, int
return clamp(xs_RoundToInt(ratio * 65536), 0, 65536); return clamp(xs_RoundToInt(ratio * 65536), 0, 65536);
} }
FString G_GetDemoPath()
{
FString path = M_GetDemoPath();
path << LumpFilter << '/';
CreatePath(path);
return path;
}

View file

@ -160,6 +160,8 @@ void G_HandleMemErr(int32_t lineNum, const char* fileName, const char* funcName)
void G_FatalEngineError(void); void G_FatalEngineError(void);
int CalcSmoothRatio(const ClockTicks& totalclk, const ClockTicks& ototalclk, int realgameticspersec); int CalcSmoothRatio(const ClockTicks& totalclk, const ClockTicks& ototalclk, int realgameticspersec);
FString G_GetDemoPath();
struct FStartupInfo struct FStartupInfo
{ {

View file

@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "menus.h" #include "menus.h"
#include "savegame.h" #include "savegame.h"
#include "screens.h" #include "screens.h"
#include "i_specialpaths.h"
#include "printf.h" #include "printf.h"
#include "menu/menu.h" #include "menu/menu.h"
@ -152,7 +151,7 @@ void G_OpenDemoWrite(void)
if (demonum == MAXDEMOS) if (demonum == MAXDEMOS)
return; return;
if (snprintf(demofn, sizeof(demofn), "%s" DEMOFN_FMT, M_GetDemoPath().GetChars(), demonum)) if (snprintf(demofn, sizeof(demofn), "%s" DEMOFN_FMT, G_GetDemoPath().GetChars(), demonum))
{ {
initprintf("Couldn't start demo writing: INTERNAL ERROR: file name too long\n"); initprintf("Couldn't start demo writing: INTERNAL ERROR: file name too long\n");
goto error_wopen_demo; goto error_wopen_demo;

View file

@ -239,7 +239,7 @@ FString M_GetDemoPath()
{ {
path += "/" GAME_DIR "/Demos/"; path += "/" GAME_DIR "/Demos/";
} }
CreatePath(path);
return path; return path;
} }

View file

@ -42,7 +42,6 @@
#include "printf.h" #include "printf.h"
#include "cmdlib.h" #include "cmdlib.h"
#include "i_findfile.h" #include "i_findfile.h"
#include "gamecontrol.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.
@ -349,7 +348,7 @@ FString M_GetDemoPath()
FStringf inipath("%s" GAMENAME "_portable.ini", progdir.GetChars()); FStringf inipath("%s" GAMENAME "_portable.ini", progdir.GetChars());
if (FileExists(inipath) || !UseKnownFolders()) if (FileExists(inipath) || !UseKnownFolders())
{ {
path << progdir << "Demos/" << LumpFilter << '/'; path << progdir << "Demos/";
} }
else else
// Try defacto My Documents/My Games folder // Try defacto My Documents/My Games folder
@ -357,13 +356,13 @@ FString M_GetDemoPath()
{ {
// 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 << "Demos/" << LumpFilter << '/'; path << progdir << "Demos/";
} }
CreatePath(path);
return path; return path;
} }

View file

@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "menus.h" #include "menus.h"
#include "savegame.h" #include "savegame.h"
#include "screens.h" #include "screens.h"
#include "i_specialpaths.h"
BEGIN_RR_NS BEGIN_RR_NS
@ -151,7 +150,7 @@ void G_OpenDemoWrite(void)
if (demonum == MAXDEMOS) if (demonum == MAXDEMOS)
return; return;
if (snprintf(demofn, sizeof(demofn), "%s" DEMOFN_FMT, M_GetDemoPath().GetChars(), demonum)) if (snprintf(demofn, sizeof(demofn), "%s" DEMOFN_FMT, G_GetDemoPath().GetChars(), demonum))
{ {
initprintf("Couldn't start demo writing: INTERNAL ERROR: file name too long\n"); initprintf("Couldn't start demo writing: INTERNAL ERROR: file name too long\n");
goto error_wopen_demo; goto error_wopen_demo;