mirror of
https://github.com/fabiangreffrath/woof.git
synced 2025-09-23 03:52:12 -04:00
allow to toggle "Organize save files" at runtime (#2082)
* allow to toggle "Organize save files" at runtime * create savegame directory only when saving the game * put free/reassign into a macro
This commit is contained in:
parent
84a56a26f0
commit
913c0688b3
191
src/d_main.c
191
src/d_main.c
@ -889,57 +889,6 @@ void IdentifyVersion(void)
|
|||||||
|
|
||||||
basedefault = M_StringJoin(D_DoomPrefDir(), DIR_SEPARATOR_S,
|
basedefault = M_StringJoin(D_DoomPrefDir(), DIR_SEPARATOR_S,
|
||||||
D_DoomExeName(), ".cfg");
|
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
|
// locate the IWAD and determine game mode from it
|
||||||
|
|
||||||
@ -1759,6 +1708,100 @@ static boolean CheckHaveSSG (void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int mainwadfile;
|
||||||
|
|
||||||
|
#define SET_DIR(a, b) \
|
||||||
|
if ((a)) \
|
||||||
|
{ \
|
||||||
|
free((a)); \
|
||||||
|
} \
|
||||||
|
(a) = (b);
|
||||||
|
|
||||||
|
void D_SetSavegameDirectory(void)
|
||||||
|
{
|
||||||
|
// set save path to -save parm or current dir
|
||||||
|
|
||||||
|
SET_DIR(screenshotdir, M_StringDuplicate("."));
|
||||||
|
|
||||||
|
SET_DIR(basesavegame, M_StringDuplicate(D_DoomPrefDir()));
|
||||||
|
|
||||||
|
//!
|
||||||
|
// @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)
|
||||||
|
{
|
||||||
|
SET_DIR(basesavegame, M_StringDuplicate(myargv[p + 1]));
|
||||||
|
|
||||||
|
M_MakeDirectory(basesavegame);
|
||||||
|
|
||||||
|
// [FG] fall back to -save parm
|
||||||
|
SET_DIR(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];
|
||||||
|
|
||||||
|
for (int i = mainwadfile; i < array_size(wadfiles); i++)
|
||||||
|
{
|
||||||
|
if (FileContainsMaps(wadfiles[i]))
|
||||||
|
{
|
||||||
|
wadname = wadfiles[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *oldsavegame = basesavegame;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//!
|
||||||
|
// @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)
|
||||||
|
{
|
||||||
|
SET_DIR(screenshotdir, M_StringDuplicate(myargv[p + 1]));
|
||||||
|
|
||||||
|
M_MakeDirectory(screenshotdir);
|
||||||
|
}
|
||||||
|
|
||||||
|
I_Printf(VB_INFO, "Savegame directory: %s", basesavegame);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef SET_DIR
|
||||||
|
|
||||||
//
|
//
|
||||||
// D_DoomMain
|
// D_DoomMain
|
||||||
//
|
//
|
||||||
@ -1766,7 +1809,6 @@ static boolean CheckHaveSSG (void)
|
|||||||
void D_DoomMain(void)
|
void D_DoomMain(void)
|
||||||
{
|
{
|
||||||
int p;
|
int p;
|
||||||
int mainwadfile = 0;
|
|
||||||
|
|
||||||
setbuf(stdout,NULL);
|
setbuf(stdout,NULL);
|
||||||
|
|
||||||
@ -2323,50 +2365,7 @@ void D_DoomMain(void)
|
|||||||
|
|
||||||
G_ParseCompDatabase();
|
G_ParseCompDatabase();
|
||||||
|
|
||||||
if (!M_CheckParm("-save"))
|
D_SetSavegameDirectory();
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
V_InitColorTranslation(); //jff 4/24/98 load color translation lumps
|
V_InitColorTranslation(); //jff 4/24/98 load color translation lumps
|
||||||
|
|
||||||
|
@ -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 *basesavegame; // killough 2/16/98: savegame path
|
||||||
extern char *screenshotdir; // [FG] screenshot path
|
extern char *screenshotdir; // [FG] screenshot path
|
||||||
char *D_DoomPrefDir(void); // [FG] default configuration dir
|
char *D_DoomPrefDir(void); // [FG] default configuration dir
|
||||||
|
void D_SetSavegameDirectory(void);
|
||||||
|
|
||||||
extern const char *gamedescription;
|
extern const char *gamedescription;
|
||||||
|
|
||||||
|
@ -2465,6 +2465,8 @@ static void DoSaveGame(char *name)
|
|||||||
|
|
||||||
length = save_p - savebuffer;
|
length = save_p - savebuffer;
|
||||||
|
|
||||||
|
M_MakeDirectory(basesavegame);
|
||||||
|
|
||||||
if (!M_WriteFile(name, savebuffer, length))
|
if (!M_WriteFile(name, savebuffer, length))
|
||||||
displaymsg("%s", errno ? strerror(errno) : "Could not save game: Error unknown");
|
displaymsg("%s", errno ? strerror(errno) : "Could not save game: Error unknown");
|
||||||
else
|
else
|
||||||
|
@ -3313,7 +3313,7 @@ static setup_menu_t gen_settings6[] = {
|
|||||||
.action = M_ResetAutoSave},
|
.action = M_ResetAutoSave},
|
||||||
|
|
||||||
{"Organize save files", S_ONOFF | S_PRGWARN, OFF_CNTR_X, M_SPC,
|
{"Organize save files", S_ONOFF | S_PRGWARN, OFF_CNTR_X, M_SPC,
|
||||||
{"organize_savefiles"}},
|
{"organize_savefiles"}, .action = D_SetSavegameDirectory},
|
||||||
|
|
||||||
MI_GAP,
|
MI_GAP,
|
||||||
|
|
||||||
@ -4867,6 +4867,7 @@ void MN_SetupResetMenu(void)
|
|||||||
DisableItem(!brightmaps_found || force_brightmaps, gen_settings5,
|
DisableItem(!brightmaps_found || force_brightmaps, gen_settings5,
|
||||||
"brightmaps");
|
"brightmaps");
|
||||||
DisableItem(!trakinfo_found, gen_settings2, "extra_music");
|
DisableItem(!trakinfo_found, gen_settings2, "extra_music");
|
||||||
|
DisableItem(M_ParmExists("-save"), gen_settings6, "organize_savefiles");
|
||||||
UpdateInterceptsEmuItem();
|
UpdateInterceptsEmuItem();
|
||||||
UpdateStatsFormatItem();
|
UpdateStatsFormatItem();
|
||||||
UpdateCrosshairItems();
|
UpdateCrosshairItems();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user