From ae0b6e87be61e81f0d66cd8df7e4ef1ba051ae18 Mon Sep 17 00:00:00 2001 From: terminx Date: Thu, 8 Mar 2018 05:15:11 +0000 Subject: [PATCH] Display number of savegames to be deleted before removing, automatically remove old savegames from the install dir in EDUKE32_STANDALONE builds. DONT_BUILD. git-svn-id: https://svn.eduke32.com/eduke32@6754 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/game.cpp | 4 ++++ source/duke3d/src/menus.cpp | 25 +++++++++++++++++++------ source/duke3d/src/savegame.cpp | 15 +++++++++++++++ source/duke3d/src/savegame.h | 1 + 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index d32335f35..a41199f28 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -6195,6 +6195,10 @@ int app_main(int argc, char const * const * argv) #endif #endif +#ifdef EDUKE32_STANDALONE + G_DeleteOldSaves(); +#endif + G_ExtPreInit(argc, argv); #ifdef __APPLE__ diff --git a/source/duke3d/src/menus.cpp b/source/duke3d/src/menus.cpp index 4cd400bd8..c39ae58b2 100644 --- a/source/duke3d/src/menus.cpp +++ b/source/duke3d/src/menus.cpp @@ -175,7 +175,7 @@ static void Menu_DrawCursorText(int32_t x, int32_t y, int32_t h, int32_t ydim_up } extern int32_t g_quitDeadline; - +static size_t g_oldSaveCnt; @@ -335,7 +335,11 @@ static MenuLink_t MEO_MAIN_NEWGAME_NETWORK = { MENU_NETWORK, MA_Advance, }; MAKE_MENU_TOP_ENTRYLINK( s_SaveGame, MEF_MainMenu, MAIN_SAVEGAME, MENU_SAVE ); MAKE_MENU_TOP_ENTRYLINK( s_LoadGame, MEF_MainMenu, MAIN_LOADGAME, MENU_LOAD ); MAKE_MENU_TOP_ENTRYLINK( s_Options, MEF_MainMenu, MAIN_OPTIONS, MENU_OPTIONS ); -MAKE_MENU_TOP_ENTRYLINK( "Help", MEF_MainMenu, MAIN_HELP, MENU_STORY ); +#ifdef EDUKE32_STANDALONE +MAKE_MENU_TOP_ENTRYLINK( "Read me!", MEF_MainMenu, MAIN_HELP, MENU_STORY ); +#else +MAKE_MENU_TOP_ENTRYLINK("Help", MEF_MainMenu, MAIN_HELP, MENU_STORY); +#endif #ifndef EDUKE32_SIMPLE_MENU MAKE_MENU_TOP_ENTRYLINK( s_Credits, MEF_MainMenu, MAIN_CREDITS, MENU_CREDITS ); #endif @@ -2357,11 +2361,19 @@ static void Menu_PreDraw(MenuID_t cm, MenuEntry_t *entry, const vec2_t origin) case MENU_SAVECLEANVERIFY: fade_screen_black(1); - mgametextcenter(origin.x, origin.y + (90<<16), "Delete obsolete saves?" + + if (g_oldSaveCnt) + { + Bsprintf(tempbuf, "Delete %zu obsolete saves?\nThis action cannot be undone." #ifndef EDUKE32_ANDROID_MENU - "\n(Y/N)" + "\n(Y/N)" #endif - ); + , g_oldSaveCnt); + } + else + Bsprintf(tempbuf, "No obsolete saves found!"); + + mgametextcenter(origin.x, origin.y + (90<<16), tempbuf); break; case MENU_LOADVERIFY: @@ -2403,7 +2415,7 @@ static void Menu_PreDraw(MenuID_t cm, MenuEntry_t *entry, const vec2_t origin) { fade_screen_black(1); menusave_t & msv = cm == MENU_LOADDELVERIFY ? g_menusaves[M_LOAD.currentEntry] : g_menusaves[M_SAVE.currentEntry-1]; - Bsprintf(tempbuf, "Delete saved game:\n\"%s\"" + Bsprintf(tempbuf, "Delete saved game:\n\"%s\"?" #ifndef EDUKE32_ANDROID_MENU "\n(Y/N)" #endif @@ -3057,6 +3069,7 @@ static void Menu_EntryLinkActivate(MenuEntry_t *entry) } else if (entry == &ME_SAVESETUP_CLEANUP) { + g_oldSaveCnt = G_CountOldSaves(); Menu_Change(MENU_SAVECLEANVERIFY); } else if (entry == &ME_COLCORR_RESET) diff --git a/source/duke3d/src/savegame.cpp b/source/duke3d/src/savegame.cpp index ab6666804..7c22dd7c2 100644 --- a/source/duke3d/src/savegame.cpp +++ b/source/duke3d/src/savegame.cpp @@ -506,6 +506,21 @@ void G_DeleteOldSaves(void) } } +size_t G_CountOldSaves(void) +{ + ReadSaveGameHeaders(); + + size_t bad = 0; + for (size_t x = 0; x < g_numinternalsaves; ++x) + { + menusave_t const & msv = g_internalsaves[x]; + if (msv.isOldVer || msv.isUnreadable) + ++bad; + } + + return bad; +} + int32_t G_SavePlayer(savebrief_t & sv, bool isAutoSave) { #ifdef __ANDROID__ diff --git a/source/duke3d/src/savegame.h b/source/duke3d/src/savegame.h index 6da69eb3e..2583c816d 100644 --- a/source/duke3d/src/savegame.h +++ b/source/duke3d/src/savegame.h @@ -117,6 +117,7 @@ int32_t sv_saveandmakesnapshot(FILE *fil, char const *name, int8_t spot, int8_t void sv_freemem(); void G_DeleteSave(savebrief_t const & sv); void G_DeleteOldSaves(void); +size_t G_CountOldSaves(void); int32_t G_SavePlayer(savebrief_t & sv, bool isAutoSave); int32_t G_LoadPlayer(savebrief_t & sv); int32_t G_LoadSaveHeaderNew(char const *fn, savehead_t *saveh);