aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlolbot-iichan2019-05-20 23:53:16 +0300
committerFilippos Karapetis2020-01-11 18:05:39 +0200
commit4bd18fd25e0dffe40bb9e2aa9e59d3b41ac17529 (patch)
treeae15e9bad289973551416ef804201bed800431b4
parente3595393c85cbffa4fd604527e747bc701a2d5f4 (diff)
downloadscummvm-rg350-4bd18fd25e0dffe40bb9e2aa9e59d3b41ac17529.tar.gz
scummvm-rg350-4bd18fd25e0dffe40bb9e2aa9e59d3b41ac17529.tar.bz2
scummvm-rg350-4bd18fd25e0dffe40bb9e2aa9e59d3b41ac17529.zip
WINTERMUTE: GetSaveSlotDescription refactoring
-rw-r--r--engines/wintermute/base/base_game.cpp6
-rw-r--r--engines/wintermute/base/saveload.cpp28
-rw-r--r--engines/wintermute/base/saveload.h2
3 files changed, 15 insertions, 21 deletions
diff --git a/engines/wintermute/base/base_game.cpp b/engines/wintermute/base/base_game.cpp
index 16ad1f51a2..e389b6795a 100644
--- a/engines/wintermute/base/base_game.cpp
+++ b/engines/wintermute/base/base_game.cpp
@@ -1363,10 +1363,8 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
else if (strcmp(name, "GetSaveSlotDescription") == 0) {
stack->correctParams(1);
int slot = stack->pop()->getInt();
- char desc[512];
- desc[0] = '\0';
- SaveLoad::getSaveSlotDescription(slot, desc);
- stack->pushString(desc);
+ Common::String desc = SaveLoad::getSaveSlotDescription(slot);
+ stack->pushString(desc.c_str());
return STATUS_OK;
}
diff --git a/engines/wintermute/base/saveload.cpp b/engines/wintermute/base/saveload.cpp
index 6299cf6e01..e0f97f0d88 100644
--- a/engines/wintermute/base/saveload.cpp
+++ b/engines/wintermute/base/saveload.cpp
@@ -159,31 +159,27 @@ void SaveLoad::afterLoadScript(void *script, void *data) {
}
Common::String SaveLoad::getSaveSlotFilename(int slot) {
+ Common::String filename;
BasePersistenceManager *pm = new BasePersistenceManager();
- Common::String filename = pm->getFilenameForSlot(slot);
- delete pm;
+ if (pm) {
+ filename = pm->getFilenameForSlot(slot);
+ delete pm;
+ }
debugC(kWintermuteDebugSaveGame, "getSaveSlotFileName(%d) = %s", slot, filename.c_str());
return filename;
}
-bool SaveLoad::getSaveSlotDescription(int slot, char *buffer) {
- buffer[0] = '\0';
-
+Common::String SaveLoad::getSaveSlotDescription(int slot) {
+ Common::String description;
Common::String filename = getSaveSlotFilename(slot);
BasePersistenceManager *pm = new BasePersistenceManager();
- if (!pm) {
- return false;
- }
-
- if (!(pm->initLoad(filename))) {
+ if (pm) {
+ if ((pm->initLoad(filename))) {
+ description = pm->_savedDescription;
+ }
delete pm;
- return false;
}
-
- strcpy(buffer, pm->_savedDescription);
- delete pm;
-
- return true;
+ return description;
}
bool SaveLoad::isSaveSlotUsed(int slot) {
diff --git a/engines/wintermute/base/saveload.h b/engines/wintermute/base/saveload.h
index 31f5841f41..e98c7b2f73 100644
--- a/engines/wintermute/base/saveload.h
+++ b/engines/wintermute/base/saveload.h
@@ -37,7 +37,7 @@ class SaveLoad {
public:
static bool emptySaveSlot(int slot);
static bool isSaveSlotUsed(int slot);
- static bool getSaveSlotDescription(int slot, char *buffer);
+ static Common::String getSaveSlotDescription(int slot);
static Common::String getSaveSlotFilename(int slot);
static bool loadGame(const Common::String &filename, BaseGame *gameRef);