From ebfcea35ec5167b1ac1d2cd92c1901aca2004f18 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 29 Oct 2009 18:07:39 +0000 Subject: - Implemented savegame deletion for SQ4 floppy - Added a more proper way to disable the "Change Directory" button, by checking its name, rather than the string it contains svn-id: r45504 --- engines/sci/engine/kfile.cpp | 26 ++++++++++++++++++++++--- engines/sci/engine/kgraphics.cpp | 42 ++++++---------------------------------- 2 files changed, 29 insertions(+), 39 deletions(-) diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp index 5d325b1076..d922374a6b 100644 --- a/engines/sci/engine/kfile.cpp +++ b/engines/sci/engine/kfile.cpp @@ -800,11 +800,31 @@ reg_t kFileIO(EngineState *s, int argc, reg_t *argv) { } case K_FILEIO_UNLINK : { Common::String name = s->_segMan->getString(argv[1]); + Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); + // SQ4 floppy prepends /\ to the filenames + if (name.hasPrefix("/\\")) { + name.deleteChar(0); + name.deleteChar(0); + } + + // Special case for SQ4 floppy: This game has hardcoded names for all of its + // savegames, and they are all named "sq4sg.xxx", where xxx is the slot. We just + // take the slot number here, and delete the appropriate save game + if (name.hasPrefix("sq4sg.")) { + // Special handling for SQ4... get the slot number and construct the save game name + int slotNum = atoi(name.c_str() + name.size() - 3); + Common::Array saves; + listSavegames(saves); + int savedir_nr = saves[slotNum].id; + name = ((Sci::SciEngine*)g_engine)->getSavegameName(savedir_nr); + saveFileMan->removeSavefile(name); + } else { + const Common::String wrappedName = ((Sci::SciEngine*)g_engine)->wrapFilename(name); + saveFileMan->removeSavefile(wrappedName); + } + debug(3, "K_FILEIO_UNLINK(%s)", name.c_str()); - Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); - const Common::String wrappedName = ((Sci::SciEngine*)g_engine)->wrapFilename(name); - saveFileMan->removeSavefile(wrappedName); // TODO/FIXME: Should we return something (like, a bool indicating // whether deleting the save succeeded or failed)? break; diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index 94164cae7b..35d8642791 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -621,44 +621,14 @@ reg_t kAssertPalette(EngineState *s, int argc, reg_t *argv) { return s->r_acc; } -static void disableCertainButtons(EngineState *s, Common::String gameName, reg_t obj) { - reg_t text_pos = GET_SEL32(s->_segMan, obj, text); - Common::String text; - if (!text_pos.isNull()) - text = s->_segMan->getString(text_pos); - Common::String englishText = s->getLanguageString(text.c_str(), K_LANG_ENGLISH); - englishText.trim(); - int type = GET_SEL32V(s->_segMan, obj, type); - int state = GET_SEL32V(s->_segMan, obj, state); - - /* - * WORKAROUND: The function is a "prevent the user from doing something - * nasty" type of thing, and goes back to the ugly way in which savegame - * deletion is implemented in SCI (and even worse in SQ4/Floppy, for - * which the workaround is intended). The result is basically that you - * can't implement savegame deletion for SQ4/Floppy unless you duplicate - * the exact naming scheme of savefiles (i.e. savefiles must be named - * SQ4SG.) and the exact file format of the savegame index - * (SQ4SG.DIR). From the earlier discussions on file I/O handling - - * before as well as after the merge - I gather that this is not an - * option. - * - * SQ4/Floppy is special, being the first game to implement savegame - * deletion at all. For later games, we manage to implement deletion by - * using gross hacks in kDeviceInfo() (essentially repurposing a few - * subfunctions). I decided at the time that SQ4/Floppy was not worth the - * effort (see above), and to simply disable the delete functionality for - * that game - bringing the save/load dialog on a par with SCI0. - */ - if (type == SCI_CONTROLS_TYPE_BUTTON && (gameName == "sq4") && - getSciVersion() < SCI_VERSION_1_1 && englishText == "Delete") { - PUT_SEL32V(s->_segMan, obj, state, (state | kControlStateDisabled) & ~kControlStateEnabled); - } +static void disableCertainButtons(SegManager *segMan, reg_t obj) { + Common::String objName = segMan->getObjectName(obj); // Disable the "Change Directory" button, as we don't allow the game engine to // change the directory where saved games are placed - if (type == SCI_CONTROLS_TYPE_BUTTON && englishText == "Change\r\nDirectory") { - PUT_SEL32V(s->_segMan, obj, state, (state | kControlStateDisabled) & ~kControlStateEnabled); + if (objName == "changeDirI") { + int state = GET_SEL32V(segMan, obj, state); + PUT_SEL32V(segMan, obj, state, (state | kControlStateDisabled) & ~kControlStateEnabled); } } @@ -783,7 +753,7 @@ void _k_GenericDrawControl(EngineState *s, reg_t controlObject, bool hilite) { reg_t kDrawControl(EngineState *s, int argc, reg_t *argv) { reg_t controlObject = argv[0]; - disableCertainButtons(s, s->_gameName, controlObject); + disableCertainButtons(s->_segMan, controlObject); _k_GenericDrawControl(s, controlObject, false); return NULL_REG; } -- cgit v1.2.3