Skip to content

Commit

Permalink
Improve previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JNechaevsky committed Apr 22, 2024
1 parent 27d96ee commit e692367
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
38 changes: 1 addition & 37 deletions src/doom/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ int mouseSensitivity = 5;
// Still used for config file compatibility.
static int screenblocks = 10;

// [JN] "savegames_path" config file variable.
static char *SavePathConfig;


//
// D_ProcessEvents
Expand Down Expand Up @@ -513,39 +510,6 @@ void D_BindVariables(void)
CRL_BindVariables();
}

// -----------------------------------------------------------------------------
// D_SetDefaultSavePath
// [JN] Set the default directory where savegames are saved.
// -----------------------------------------------------------------------------

static void D_SetDefaultSavePath (void)
{
// Gather default "savegames" folder location.
savegamedir = M_GetSaveGameDir(D_SaveGameIWADName(gamemission, gamevariant));

if (!strcmp(savegamedir, ""))
{
if (SavePathConfig == NULL || !strcmp(SavePathConfig, ""))
{
// Config file variable not existing or emptry,
// so use generated path from above.
savegamedir = M_StringDuplicate("");
}
else
{
// Variable existing, use it's path.
savegamedir = M_StringDuplicate(SavePathConfig);
}
}

// Overwrite config file variable only if following command line
// parameters are not present:
if (!M_ParmExists("-savedir") && !M_ParmExists("-cdrom"))
{
SavePathConfig = savegamedir;
}
}

//
// D_GrabMouseCallback
//
Expand Down Expand Up @@ -1924,7 +1888,7 @@ void D_DoomMain (void)
D_SetGameDescription();

// [JN] Set the default directory where savegames are saved.
D_SetDefaultSavePath();
savegamedir = M_GetSaveGameDir(D_SaveGameIWADName(gamemission, gamevariant));

// [JN] Set the default directory where screenshots are saved.
M_SetScreenshotDir();
Expand Down
55 changes: 45 additions & 10 deletions src/m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ static char *autoload_path = "";

static const char *default_main_config;

// [JN] "savegames_path" config file variable.

char *SavePathConfig;

// [JN] Location where screenshots are saved.

char *screenshotdir;
Expand Down Expand Up @@ -1093,13 +1097,13 @@ char *M_GetSaveGameDir(const char *iwadname)

if (existing_path != NULL && strlen(existing_path) > 0)
{
// It exist, use it's provided path.
savegamedir = M_StringDuplicate("");
// Variable existing, use it's path.
savegamedir = M_StringDuplicate(SavePathConfig);
}
else
{
// Otherwise, create and use "savegames" folder in program folder.
savegamedir = M_StringJoin(M_StringDuplicate(exedir), "savegames", DIR_SEPARATOR_S, NULL);
// Config file variable not existing or emptry, generate a path.
savegamedir = M_StringJoin(M_StringDuplicate(exedir), "savegames", NULL);
}
M_MakeDirectory(savegamedir);
#else
Expand All @@ -1123,6 +1127,15 @@ char *M_GetSaveGameDir(const char *iwadname)
free(topdir);
}

// Overwrite config file variable only if following command line
// parameters are not present:
if (!M_ParmExists("-savedir") && !M_ParmExists("-cdrom"))
{
SavePathConfig = savegamedir;
// add separator at end just in case
savegamedir = M_StringJoin(savegamedir, DIR_SEPARATOR_S, NULL);
}

return savegamedir;
}

Expand Down Expand Up @@ -1188,16 +1201,38 @@ void M_SetScreenshotDir (void)

printf("Screenshot directory changed to %s\n", screenshotdir);
}
#ifdef _WIN32
// In -cdrom mode, we write screenshots to a specific directory
// in addition to configs.

else if (M_ParmExists("-cdrom"))
{
screenshotdir = M_StringDuplicate(configdir);
}
#endif
else
{
// [JN] Check if "screenshots_path" variable is existing in config file.
const char *existing_path = M_GetStringVariable("screenshots_path");

if (existing_path != NULL && strlen(existing_path) > 0)
{
// Variable existing, use it's path.
screenshotdir = M_StringDuplicate(ShotPathConfig);
}
else
{
#ifdef _WIN32
// [JN] Always use "screenshots" folder in program folder.
screenshotdir = M_StringJoin(exedir, "screenshots", DIR_SEPARATOR_S, NULL);
// [JN] Always use "screenshots" folder in program folder.
screenshotdir = M_StringJoin(exedir, "screenshots", NULL);
#else
// ~/.local/share/crl/screenshots
screenshotdir = M_StringJoin(configdir, "screenshots", DIR_SEPARATOR_S, NULL);
// ~/.local/share/inter-doom/screenshots
screenshotdir = M_StringJoin(configdir, "screenshots", NULL);
#endif
M_MakeDirectory(screenshotdir);
ShotPathConfig = screenshotdir;
}
M_MakeDirectory(screenshotdir);
ShotPathConfig = screenshotdir;
// add separator at end just in case
screenshotdir = M_StringJoin(screenshotdir, DIR_SEPARATOR_S, NULL);
}
}
1 change: 1 addition & 0 deletions src/m_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ char *M_GetAutoloadDir(const char *iwadname);
void M_SetScreenshotDir (void);

extern const char *configdir;
extern char *SavePathConfig;
extern char *screenshotdir;
extern char *ShotPathConfig;

Expand Down

0 comments on commit e692367

Please sign in to comment.