diff options
Diffstat (limited to 'scumm')
-rw-r--r-- | scumm/dialogs.cpp | 10 | ||||
-rw-r--r-- | scumm/saveload.cpp | 52 | ||||
-rw-r--r-- | scumm/saveload.h | 30 | ||||
-rw-r--r-- | scumm/scumm.h | 21 |
4 files changed, 59 insertions, 54 deletions
diff --git a/scumm/dialogs.cpp b/scumm/dialogs.cpp index c115295ca1..e676c48775 100644 --- a/scumm/dialogs.cpp +++ b/scumm/dialogs.cpp @@ -406,12 +406,20 @@ void SaveLoadDialog::fillList() ScummVM::StringList l; char name[32]; int i = _saveMode ? 1 : 0; + bool avail_saves[81]; + SaveFileManager *mgr = _scumm->_system->get_savefile_manager(); + _scumm->listSavegames(avail_saves, 81, mgr); for (; i <= 80; i++) { // 80 - got this value from the old GUI - _scumm->getSavegameName(i, name); + if(avail_saves[i]) + _scumm->getSavegameName(i, name, mgr); + else + name[0] = 0; l.push_back(name); } + delete mgr; + _savegameList->setList(l); _savegameList->setNumberingMode(_saveMode ? kListNumberingOne : kListNumberingZero); } diff --git a/scumm/saveload.cpp b/scumm/saveload.cpp index eee440a11e..78be8b140b 100644 --- a/scumm/saveload.cpp +++ b/scumm/saveload.cpp @@ -39,15 +39,15 @@ struct SaveGameHeader { }; -bool Scumm::saveState(int slot, bool compat) +bool Scumm::saveState(int slot, bool compat, SaveFileManager *mgr) { char filename[256]; - SerializerStream out; + SaveFile *out; SaveGameHeader hdr; makeSavegameName(filename, slot, compat); - if (!out.fopen(filename, "wb")) + if (!(out = mgr->open_savefile(filename, true))) return false; memcpy(hdr.name, _saveLoadName, sizeof(hdr.name)); @@ -56,32 +56,32 @@ bool Scumm::saveState(int slot, bool compat) hdr.size = 0; hdr.ver = TO_LE_32(CURRENT_VER); - out.fwrite(&hdr, sizeof(hdr), 1); + out->fwrite(&hdr, sizeof(hdr), 1); Serializer ser(out, true, CURRENT_VER); saveOrLoad(&ser, CURRENT_VER); - out.fclose(); + delete out; debug(1, "State saved as '%s'", filename); return true; } -bool Scumm::loadState(int slot, bool compat) +bool Scumm::loadState(int slot, bool compat, SaveFileManager *mgr) { char filename[256]; - SerializerStream out; + SaveFile *out; int i, j; SaveGameHeader hdr; int sb, sh; makeSavegameName(filename, slot, compat); - if (!out.fopen(filename, "rb")) + if (!(out = mgr->open_savefile(filename, false))) return false; - out.fread(&hdr, sizeof(hdr), 1); + out->fread(&hdr, sizeof(hdr), 1); if (hdr.type != MKID('SCVM')) { warning("Invalid savegame '%s'", filename); - out.fclose(); + delete out; return false; } @@ -92,7 +92,7 @@ bool Scumm::loadState(int slot, bool compat) if (hdr.ver < VER_V7 || hdr.ver > CURRENT_VER) { warning("Invalid version of '%s'", filename); - out.fclose(); + delete out; return false; } @@ -126,7 +126,7 @@ bool Scumm::loadState(int slot, bool compat) Serializer ser(out, false, hdr.ver); saveOrLoad(&ser, hdr.ver); - out.fclose(); + delete out; sb = _screenB; sh = _screenH; @@ -174,20 +174,28 @@ void Scumm::makeSavegameName(char *out, int slot, bool compatible) sprintf(out, "%s%s.%c%.2d", dir, _game_name, compatible ? 'c' : 's', slot); } -bool Scumm::getSavegameName(int slot, char *desc) +void Scumm::listSavegames(bool *marks, int num, SaveFileManager *mgr) +{ + char prefix[256]; + makeSavegameName(prefix, 99, false); + prefix[strlen(prefix)-2] = 0; + mgr->list_savefiles(prefix, marks, num); +} + +bool Scumm::getSavegameName(int slot, char *desc, SaveFileManager *mgr) { char filename[256]; - SerializerStream out; + SaveFile *out; SaveGameHeader hdr; int len; makeSavegameName(filename, slot, false); - if (!out.fopen(filename, "rb")) { + if (!(out = mgr->open_savefile(filename, false))) { strcpy(desc, ""); return false; } - len = out.fread(&hdr, sizeof(hdr), 1); - out.fclose(); + len = out->fread(&hdr, sizeof(hdr), 1); + delete out; if (len != 1 || hdr.type != MKID('SCVM')) { strcpy(desc, "Invalid savegame"); @@ -652,12 +660,12 @@ void Scumm::saveLoadResource(Serializer *ser, int type, int idx) void Serializer::saveBytes(void *b, int len) { - _saveLoadStream.fwrite(b, 1, len); + _saveLoadStream->fwrite(b, 1, len); } void Serializer::loadBytes(void *b, int len) { - _saveLoadStream.fread(b, 1, len); + _saveLoadStream->fread(b, 1, len); } #ifdef _WIN32_WCE @@ -666,11 +674,11 @@ void Serializer::loadBytes(void *b, int len) bool Serializer::checkEOFLoadStream() { - if (!fseek(_saveLoadStream.out, 1, SEEK_CUR)) + if (!_saveLoadStream->fseek(1, SEEK_CUR)) return true; - if (feof(_saveLoadStream.out)) + if (_saveLoadStream->feof()) return true; - fseek(_saveLoadStream.out, -1, SEEK_CUR); + _saveLoadStream->fseek(-1, SEEK_CUR); return false; } diff --git a/scumm/saveload.h b/scumm/saveload.h index 1667aeb045..7be5d061a1 100644 --- a/scumm/saveload.h +++ b/scumm/saveload.h @@ -85,38 +85,12 @@ struct SaveLoadEntry { uint8 maxVersion; }; -struct SerializerStream { -#ifdef NONSTANDARD_SAVE - void *context; - - bool fopen(const char *filename, const char *mode); - void fclose(); - int fread(void *buf, int size, int cnt); - int fwrite(void *buf, int size, int cnt); -#else - FILE *out; - - FILE *fopen(const char *filename, const char *mode) { - return out = ::fopen(filename, mode); - } - void fclose() { - ::fclose(out); - } - int fread(void *buf, int size, int cnt) { - return ::fread(buf, size, cnt, out); - } - int fwrite(void *buf, int size, int cnt) { - return ::fwrite(buf, size, cnt, out); - } -#endif -}; - typedef int SerializerSaveReference(void *me, byte type, void *ref); typedef void *SerializerLoadReference(void *me, byte type, int ref); class Serializer { public: - Serializer(SerializerStream stream, bool saveOrLoad, uint32 savegameVersion) + Serializer(SaveFile *stream, bool saveOrLoad, uint32 savegameVersion) : _save_ref(0), _load_ref(0), _ref_me(0), _saveLoadStream(stream), _saveOrLoad(saveOrLoad), _savegameVersion(savegameVersion) @@ -146,7 +120,7 @@ public: void loadBytes(void *b, int len); protected: - SerializerStream _saveLoadStream; + SaveFile *_saveLoadStream; bool _saveOrLoad; uint32 _savegameVersion; diff --git a/scumm/scumm.h b/scumm/scumm.h index 5e0c54a005..ead8ef4c36 100644 --- a/scumm/scumm.h +++ b/scumm/scumm.h @@ -439,13 +439,28 @@ public: bool _saveLoadCompatible; char _saveLoadName[32]; - bool saveState(int slot, bool compat); - bool loadState(int slot, bool compat); + bool saveState(int slot, bool compat, SaveFileManager *mgr); + bool loadState(int slot, bool compat, SaveFileManager *mgr); + bool saveState(int slot, bool compat) + { + SaveFileManager *mgr = _system->get_savefile_manager(); + bool result = saveState(slot, compat, mgr); + delete mgr; + return result; + } + bool loadState(int slot, bool compat) + { + SaveFileManager *mgr = _system->get_savefile_manager(); + bool result = loadState(slot, compat, mgr); + delete mgr; + return result; + } void saveOrLoad(Serializer *s, uint32 savegameVersion); - bool getSavegameName(int slot, char *desc); + bool getSavegameName(int slot, char *desc, SaveFileManager *mgr); void makeSavegameName(char *out, int slot, bool compatible); void saveLoadResource(Serializer *ser, int type, int index); + void listSavegames(bool *marks, int num, SaveFileManager *mgr); /* Heap and memory management */ uint32 _maxHeapThreshold, _minHeapThreshold; |