Skip to content

Commit

Permalink
allow to toggle "Organize save files" at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiangreffrath committed Dec 7, 2024
1 parent 458c61a commit 9a959c7
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 97 deletions.
197 changes: 101 additions & 96 deletions src/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,57 +889,6 @@ void IdentifyVersion(void)

basedefault = M_StringJoin(D_DoomPrefDir(), DIR_SEPARATOR_S,
D_DoomExeName(), ".cfg");
// set save path to -save parm or current dir

screenshotdir = M_StringDuplicate("."); // [FG] default to current dir

basesavegame = M_StringDuplicate(
D_DoomPrefDir()); // jff 3/27/98 default to current dir

//!
// @arg <directory>
//
// Specify a path from which to load and save games. If the directory
// does not exist then it will automatically be created.
//

int p = M_CheckParmWithArgs("-save", 1);
if (p > 0)
{
if (basesavegame)
{
free(basesavegame);
}
basesavegame = M_StringDuplicate(myargv[p + 1]);

M_MakeDirectory(basesavegame);

// [FG] fall back to -save parm
if (screenshotdir)
{
free(screenshotdir);
}
screenshotdir = M_StringDuplicate(basesavegame);
}

//!
// @arg <directory>
//
// Specify a path to save screenshots. If the directory does not
// exist then it will automatically be created.
//

p = M_CheckParmWithArgs("-shotdir", 1);
if (p > 0)
{
if (screenshotdir)
{
free(screenshotdir);
}
screenshotdir = M_StringDuplicate(myargv[p + 1]);

M_MakeDirectory(screenshotdir);
}

// locate the IWAD and determine game mode from it

Expand Down Expand Up @@ -1759,14 +1708,113 @@ static boolean CheckHaveSSG (void)
return true;
}

static int mainwadfile;

void D_SetSavegameDirectory(void)
{
// set save path to -save parm or current dir

screenshotdir = M_StringDuplicate("."); // [FG] default to current dir

basesavegame = M_StringDuplicate(
D_DoomPrefDir()); // jff 3/27/98 default to current dir

//!
// @arg <directory>
//
// Specify a path from which to load and save games. If the directory
// does not exist then it will automatically be created.
//

int p = M_CheckParmWithArgs("-save", 1);
if (p > 0)
{
if (basesavegame)
{
free(basesavegame);
}
basesavegame = M_StringDuplicate(myargv[p + 1]);

M_MakeDirectory(basesavegame);

// [FG] fall back to -save parm
if (screenshotdir)
{
free(screenshotdir);
}
screenshotdir = M_StringDuplicate(basesavegame);
}
else
{
if (organize_savefiles == -1)
{
// [FG] check for at least one savegame in the old location
glob_t *glob = I_StartMultiGlob(
basesavegame, GLOB_FLAG_NOCASE | GLOB_FLAG_SORTED, "*.dsg");

organize_savefiles = (I_NextGlob(glob) == NULL);

I_EndGlob(glob);
}

if (organize_savefiles)
{
const char *wadname = wadfiles[0];
char *oldsavegame = basesavegame;

for (int i = mainwadfile; i < array_size(wadfiles); i++)
{
if (FileContainsMaps(wadfiles[i]))
{
wadname = wadfiles[i];
break;
}
}

basesavegame =
M_StringJoin(oldsavegame, DIR_SEPARATOR_S, "savegames");
free(oldsavegame);

M_MakeDirectory(basesavegame);

oldsavegame = basesavegame;
basesavegame = M_StringJoin(oldsavegame, DIR_SEPARATOR_S,
M_BaseName(wadname));
free(oldsavegame);

M_MakeDirectory(basesavegame);
}
}

//!
// @arg <directory>
//
// Specify a path to save screenshots. If the directory does not
// exist then it will automatically be created.
//

p = M_CheckParmWithArgs("-shotdir", 1);
if (p > 0)
{
if (screenshotdir)
{
free(screenshotdir);
}
screenshotdir = M_StringDuplicate(myargv[p + 1]);

M_MakeDirectory(screenshotdir);
}

I_Printf(VB_INFO, "Savegame directory: %s", basesavegame);
}

//
// D_DoomMain
//

void D_DoomMain(void)
{
int p;
int mainwadfile = 0;

setbuf(stdout,NULL);

Expand Down Expand Up @@ -2323,50 +2371,7 @@ void D_DoomMain(void)

G_ParseCompDatabase();

if (!M_CheckParm("-save"))
{
if (organize_savefiles == -1)
{
// [FG] check for at least one savegame in the old location
glob_t *glob = I_StartMultiGlob(
basesavegame, GLOB_FLAG_NOCASE | GLOB_FLAG_SORTED, "*.dsg");

organize_savefiles = (I_NextGlob(glob) == NULL);

I_EndGlob(glob);
}

if (organize_savefiles)
{
int i;
const char *wadname = wadfiles[0];
char *oldsavegame = basesavegame;

for (i = mainwadfile; i < array_size(wadfiles); i++)
{
if (FileContainsMaps(wadfiles[i]))
{
wadname = wadfiles[i];
break;
}
}

basesavegame =
M_StringJoin(oldsavegame, DIR_SEPARATOR_S, "savegames");
free(oldsavegame);

M_MakeDirectory(basesavegame);

oldsavegame = basesavegame;
basesavegame = M_StringJoin(oldsavegame, DIR_SEPARATOR_S,
M_BaseName(wadname));
free(oldsavegame);

M_MakeDirectory(basesavegame);
}
}

I_Printf(VB_INFO, "Savegame directory: %s", basesavegame);
D_SetSavegameDirectory();

V_InitColorTranslation(); //jff 4/24/98 load color translation lumps

Expand Down
1 change: 1 addition & 0 deletions src/d_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ char *D_DoomExeName(void); // killough 10/98: executable's name
extern char *basesavegame; // killough 2/16/98: savegame path
extern char *screenshotdir; // [FG] screenshot path
char *D_DoomPrefDir(void); // [FG] default configuration dir
void D_SetSavegameDirectory(void);

extern const char *gamedescription;

Expand Down
3 changes: 2 additions & 1 deletion src/mn_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -3305,7 +3305,7 @@ static setup_menu_t gen_settings6[] = {
.action = M_ResetAutoSave},

{"Organize save files", S_ONOFF | S_PRGWARN, OFF_CNTR_X, M_SPC,
{"organize_savefiles"}},
{"organize_savefiles"}, .action = D_SetSavegameDirectory},

MI_GAP,

Expand Down Expand Up @@ -4858,6 +4858,7 @@ void MN_SetupResetMenu(void)
DisableItem(!brightmaps_found || force_brightmaps, gen_settings5,
"brightmaps");
DisableItem(!trakinfo_found, gen_settings2, "extra_music");
DisableItem(M_ParmExists("-save"), gen_settings6, "organize_savefiles");
UpdateInterceptsEmuItem();
UpdateStatsFormatItem();
UpdateCrosshairItems();
Expand Down

0 comments on commit 9a959c7

Please sign in to comment.