From cd1768a140d074463cc1fb763260ff56671f7358 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sat, 23 Jan 2010 14:47:01 +0000 Subject: [PATCH] Add code to save the current game info (not tested) --- disc_menu.cpp | 10 ++++++++-- gui.cpp | 28 ++++++++++++++++++++++++++++ gui.hh | 3 +++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/disc_menu.cpp b/disc_menu.cpp index 6d374ed..d611094 100644 --- a/disc_menu.cpp +++ b/disc_menu.cpp @@ -26,7 +26,6 @@ public: void draw(SDL_Surface *where); -protected: DiscMenu *menu; GameInfoBox *gameInfo; }; @@ -48,8 +47,15 @@ public: virtual void selectCallback(int which) { - printf("entry %d selected: %s\n", which, this->pp_msgs[which]); + const char *fileName = this->pp_msgs[this->cur_sel]; + Gui::gui->timerController->disarm(this); + Gui::gui->dv->loadGameInfo(fileName); + + if (Gui::gui->dv->gameInfo->gi) + Gui::gui->updateGameInfo(Gui::gui->dv->gameInfo->gi); + else + Gui::gui->updateGameInfo(new GameInfo(fileName)); } virtual void hoverCallback(int which) diff --git a/gui.cpp b/gui.cpp index 66a895e..8474be8 100644 --- a/gui.cpp +++ b/gui.cpp @@ -85,6 +85,7 @@ Gui::Gui() this->game_base_path = GAME_ROOT_PATH; this->cur_gameInfo = new GameInfo(); + this->gameInfoChanged = false; this->dlg = NULL; this->kbd = NULL; @@ -318,6 +319,33 @@ void Gui::updateGameInfo(GameInfo *gi) panic_if(!gi, "gi must be set\n"); delete this->cur_gameInfo; this->cur_gameInfo = gi; + this->gameInfoChanged = true; +} + +void Gui::saveGameInfo() +{ + struct game_info *p = this->cur_gameInfo->dump(); + + if (p) + { + char buf[255]; + FILE *fp; + + snprintf(buf, sizeof(buf), "%s/%s", + METADATA_ROOT_PATH, this->cur_gameInfo->filename); + fp = fopen(buf, "w"); + if (!fp) + { + warning("Could not open %s for writing\n", buf); + return; + } + int n = fwrite((const void*)p, 1, p->sz, fp); + if (n != p->sz) + warning("Could only write %d bytes of %s\n", n, buf); + fclose(fp); + } + + this->gameInfoChanged = false; } diff --git a/gui.hh b/gui.hh index c76ca9f..9cab008 100644 --- a/gui.hh +++ b/gui.hh @@ -63,6 +63,8 @@ public: void updateGameInfo(GameInfo *gi); + void saveGameInfo(); + void exitMenu(); /* These are private, keep off! */ @@ -113,6 +115,7 @@ public: const char *game_base_path; GameInfo *cur_gameInfo; + bool gameInfoChanged; /* New preferences */ Prefs *np;