[Add] Possibility to delete save games.
This commit is contained in:
parent
2120f5da90
commit
5800461f1d
31
src/save.c
31
src/save.c
@ -1,3 +1,7 @@
|
||||
#ifdef _POSIX_SOURCE
|
||||
#include <unistd.h> // Unlink.
|
||||
#endif
|
||||
|
||||
#include "lephisto.h"
|
||||
#include "log.h"
|
||||
#include "xml.h"
|
||||
@ -29,6 +33,7 @@ extern void menu_main_close(void);
|
||||
static int save_data(xmlTextWriterPtr writer);
|
||||
static void load_menu_close(char* str);
|
||||
static void load_menu_load(char* str);
|
||||
static void load_menu_delete(char* str);
|
||||
static int load_game(char* file);
|
||||
|
||||
// Save all the game data.
|
||||
@ -131,6 +136,9 @@ void load_game_menu(void) {
|
||||
window_addButton(wid, -20, 30 + BUTTON_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||
"btnLoad", "Load", load_menu_load);
|
||||
|
||||
window_addButton(wid, -20, 20+2*(10+BUTTON_HEIGHT), BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||
"btnDelete", "Del", load_menu_delete);
|
||||
|
||||
// Default action.
|
||||
window_setFptr(wid, load_menu_load);
|
||||
}
|
||||
@ -159,6 +167,29 @@ static void load_menu_load(char* str) {
|
||||
menu_main_close();
|
||||
}
|
||||
|
||||
static void load_menu_delete(char* str) {
|
||||
(void)str;
|
||||
char* save, path[PATH_MAX];
|
||||
int wid;
|
||||
|
||||
wid = window_get("Load Game");
|
||||
save = toolkit_getList(wid, "lstSaves");
|
||||
|
||||
if(strcmp(save, "None") == 0)
|
||||
return;
|
||||
|
||||
if(dialogue_YesNo("Permanently Delete?",
|
||||
"Are you sure you want to permanently delete '%s'?", save) == 0)
|
||||
return;
|
||||
|
||||
snprintf(path, PATH_MAX, "%ssaves/%s.ls", lfile_basePath(), save);
|
||||
unlink(path);
|
||||
|
||||
// Need to reload the menu.
|
||||
load_menu_close(NULL);
|
||||
load_game_menu();
|
||||
}
|
||||
|
||||
// Load a new game.
|
||||
static int load_game(char* file) {
|
||||
xmlNodePtr node;
|
||||
|
Loading…
Reference in New Issue
Block a user