From e10e412bba99090b67a99cd7fddd5405172452f1 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 21 May 2012 21:21:48 +0300 Subject: COMMON: Allow the savefile manager to create uncompressed saves These are useful in cases where the files can be used in the original interpreters (such as the exported characters from QFG), in order to avoid confusion in cases where the users are unaware that these saves are compressed and are trying to load them in the original interpreters. --- backends/platform/ds/arm9/source/gbampsave.cpp | 2 +- backends/platform/ds/arm9/source/gbampsave.h | 2 +- backends/platform/ps2/savefilemgr.cpp | 4 ++-- backends/platform/ps2/savefilemgr.h | 2 +- backends/saves/default/default-saves.cpp | 4 ++-- backends/saves/default/default-saves.h | 2 +- common/savefile.h | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/backends/platform/ds/arm9/source/gbampsave.cpp b/backends/platform/ds/arm9/source/gbampsave.cpp index 03729c5e6e..3192e2d277 100644 --- a/backends/platform/ds/arm9/source/gbampsave.cpp +++ b/backends/platform/ds/arm9/source/gbampsave.cpp @@ -45,7 +45,7 @@ static Common::String getSavePath() { // GBAMP Save File Manager ////////////////////////// -Common::OutSaveFile *GBAMPSaveFileManager::openForSaving(const Common::String &filename) { +Common::OutSaveFile *GBAMPSaveFileManager::openForSaving(const Common::String &filename, bool compress) { Common::String fileSpec = getSavePath(); if (fileSpec.lastChar() != '/') fileSpec += '/'; diff --git a/backends/platform/ds/arm9/source/gbampsave.h b/backends/platform/ds/arm9/source/gbampsave.h index 492054dc52..0d9d9aca8c 100644 --- a/backends/platform/ds/arm9/source/gbampsave.h +++ b/backends/platform/ds/arm9/source/gbampsave.h @@ -27,7 +27,7 @@ class GBAMPSaveFileManager : public Common::SaveFileManager { public: - virtual Common::OutSaveFile *openForSaving(const Common::String &filename); + virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true); virtual Common::InSaveFile *openForLoading(const Common::String &filename); virtual bool removeSavefile(const Common::String &filename); diff --git a/backends/platform/ps2/savefilemgr.cpp b/backends/platform/ps2/savefilemgr.cpp index 421edc3e2e..46af42e193 100644 --- a/backends/platform/ps2/savefilemgr.cpp +++ b/backends/platform/ps2/savefilemgr.cpp @@ -145,7 +145,7 @@ Common::InSaveFile *Ps2SaveFileManager::openForLoading(const Common::String &fil return Common::wrapCompressedReadStream(sf); } -Common::OutSaveFile *Ps2SaveFileManager::openForSaving(const Common::String &filename) { +Common::OutSaveFile *Ps2SaveFileManager::openForSaving(const Common::String &filename, bool compress) { Common::FSNode savePath(ConfMan.get("savepath")); // TODO: is this fast? Common::WriteStream *sf; @@ -193,7 +193,7 @@ Common::OutSaveFile *Ps2SaveFileManager::openForSaving(const Common::String &fil } _screen->wantAnim(false); - return Common::wrapCompressedWriteStream(sf); + return compress ? Common::wrapCompressedWriteStream(sf) : sf; } bool Ps2SaveFileManager::removeSavefile(const Common::String &filename) { diff --git a/backends/platform/ps2/savefilemgr.h b/backends/platform/ps2/savefilemgr.h index a25fb063ae..163706eace 100644 --- a/backends/platform/ps2/savefilemgr.h +++ b/backends/platform/ps2/savefilemgr.h @@ -35,7 +35,7 @@ public: virtual ~Ps2SaveFileManager(); virtual Common::InSaveFile *openForLoading(const Common::String &filename); - virtual Common::OutSaveFile *openForSaving(const Common::String &filename); + virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true); virtual Common::StringArray listSavefiles(const Common::String &pattern); virtual bool removeSavefile(const Common::String &filename); diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp index 237c50a1ba..64e7e778b6 100644 --- a/backends/saves/default/default-saves.cpp +++ b/backends/saves/default/default-saves.cpp @@ -97,7 +97,7 @@ Common::InSaveFile *DefaultSaveFileManager::openForLoading(const Common::String return Common::wrapCompressedReadStream(sf); } -Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const Common::String &filename) { +Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const Common::String &filename, bool compress) { // Ensure that the savepath is valid. If not, generate an appropriate error. Common::String savePathName = getSavePath(); checkPath(Common::FSNode(savePathName)); @@ -112,7 +112,7 @@ Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const Common::String // Open the file for saving Common::WriteStream *sf = file.createWriteStream(); - return Common::wrapCompressedWriteStream(sf); + return compress ? Common::wrapCompressedWriteStream(sf) : sf; } bool DefaultSaveFileManager::removeSavefile(const Common::String &filename) { diff --git a/backends/saves/default/default-saves.h b/backends/saves/default/default-saves.h index 1ea87efc67..c7fca279bc 100644 --- a/backends/saves/default/default-saves.h +++ b/backends/saves/default/default-saves.h @@ -38,7 +38,7 @@ public: virtual Common::StringArray listSavefiles(const Common::String &pattern); virtual Common::InSaveFile *openForLoading(const Common::String &filename); - virtual Common::OutSaveFile *openForSaving(const Common::String &filename); + virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true); virtual bool removeSavefile(const Common::String &filename); protected: diff --git a/common/savefile.h b/common/savefile.h index 03a7b52add..3aa0f423e3 100644 --- a/common/savefile.h +++ b/common/savefile.h @@ -108,7 +108,7 @@ public: * @param name the name of the savefile * @return pointer to an OutSaveFile, or NULL if an error occurred. */ - virtual OutSaveFile *openForSaving(const String &name) = 0; + virtual OutSaveFile *openForSaving(const String &name, bool compress = true) = 0; /** * Open the file with the specified name in the given directory for loading. -- cgit v1.2.3 From 4c4a127ca23ca55ec4f3348b40553ac5f72a3892 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 21 May 2012 23:17:28 +0300 Subject: COMMON: Add documentation regarding the new parameter in openForSaving() --- common/savefile.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/savefile.h b/common/savefile.h index 3aa0f423e3..2f4b8a2d5b 100644 --- a/common/savefile.h +++ b/common/savefile.h @@ -105,7 +105,8 @@ public: /** * Open the savefile with the specified name in the given directory for saving. - * @param name the name of the savefile + * @param name the name of the savefile + * @param compress toggles whether to compress the resulting save file (default) or not. * @return pointer to an OutSaveFile, or NULL if an error occurred. */ virtual OutSaveFile *openForSaving(const String &name, bool compress = true) = 0; -- cgit v1.2.3 From c9ace6426ebd4cac2777f199848dcfa5770b65ca Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 21 Jun 2012 10:35:27 +0300 Subject: COMMON: Add a detailed explanation on when to create uncompressed saves --- common/savefile.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/common/savefile.h b/common/savefile.h index 2f4b8a2d5b..abe0df2758 100644 --- a/common/savefile.h +++ b/common/savefile.h @@ -104,9 +104,32 @@ public: virtual String popErrorDesc(); /** - * Open the savefile with the specified name in the given directory for saving. + * Open the savefile with the specified name in the given directory for + * saving. + * + * Saved games are always compressed using ZIP compression on platforms + * where the zlib library is included (i.e. almost all platforms except the + * NDS). Engines are expected to always create compressed saved games. + * A notable exception is when the created saved games are compatible with + * the ones that the original interpreters create, and they are then used + * with later game versions in a game series which are not supported by + * ScummVM. An example is the characters exported in the Quest for Glory + * games: these saved states actually contain simple text strings with + * character attributes, which can then be used with later games in the + * Quest for Glory Series. Currently, ScummVM supports Quest for Glory + * 1, 2 and 3. These exported heroes can also be read by the AGS VGA fan + * made version of Quest for Glory 2 and the SCI32 game Quest for Glory IV, + * none of which is supported by ScummVM yet. Moreover, these heroes can + * also be imported into Quest for Glory V, which is a 3D game and thus + * outside of ScummVM's scope. For these reasons, in such cases engines can + * create uncompressed saved games to help users import them in other games + * not supported by ScummVM. Users only need to know that such saved games + * exported by ScummVM are compatible with later unsupported games, without + * needing to explain how to uncompress them. + * * @param name the name of the savefile - * @param compress toggles whether to compress the resulting save file (default) or not. + * @param compress toggles whether to compress the resulting save file + * (default) or not. * @return pointer to an OutSaveFile, or NULL if an error occurred. */ virtual OutSaveFile *openForSaving(const String &name, bool compress = true) = 0; -- cgit v1.2.3 From eb8230988a413ffff3458f0cfade5a94c95940b1 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 21 Jun 2012 12:15:25 +0300 Subject: SCI: Don't compress exported heroes in the Quest for Glory games This allows them to be used by other games in the series not supported by ScummVM (i.e. QFG4, QFG5 and the fanmade AGS version of QFG2) --- engines/sci/engine/file.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/engines/sci/engine/file.cpp b/engines/sci/engine/file.cpp index 0d575f97dd..a0f7ebf4a2 100644 --- a/engines/sci/engine/file.cpp +++ b/engines/sci/engine/file.cpp @@ -57,11 +57,24 @@ namespace Sci { reg_t file_open(EngineState *s, const Common::String &filename, int mode, bool unwrapFilename) { Common::String englishName = g_sci->getSciLanguageString(filename, K_LANG_ENGLISH); + englishName.toLowercase(); + Common::String wrappedName = unwrapFilename ? g_sci->wrapFilename(englishName) : englishName; Common::SeekableReadStream *inFile = 0; Common::WriteStream *outFile = 0; Common::SaveFileManager *saveFileMan = g_sci->getSaveFileManager(); + bool isCompressed = true; + const SciGameId gameId = g_sci->getGameId(); + if ((gameId == GID_QFG1 || gameId == GID_QFG1VGA || gameId == GID_QFG2 || gameId == GID_QFG3) + && englishName.hasSuffix(".sav")) { + // QFG Characters are saved via the CharSave object. + // We leave them uncompressed so that they can be imported in later QFG + // games. + // Rooms/Scripts: QFG1: 601, QFG2: 840, QFG3/4: 52 + isCompressed = false; + } + if (mode == _K_FILE_MODE_OPEN_OR_FAIL) { // Try to open file, abort if not possible inFile = saveFileMan->openForLoading(wrappedName); @@ -74,12 +87,12 @@ reg_t file_open(EngineState *s, const Common::String &filename, int mode, bool u debugC(kDebugLevelFile, " -> file_open(_K_FILE_MODE_OPEN_OR_FAIL): failed to open file '%s'", englishName.c_str()); } else if (mode == _K_FILE_MODE_CREATE) { // Create the file, destroying any content it might have had - outFile = saveFileMan->openForSaving(wrappedName); + outFile = saveFileMan->openForSaving(wrappedName, isCompressed); if (!outFile) debugC(kDebugLevelFile, " -> file_open(_K_FILE_MODE_CREATE): failed to create file '%s'", englishName.c_str()); } else if (mode == _K_FILE_MODE_OPEN_OR_CREATE) { // Try to open file, create it if it doesn't exist - outFile = saveFileMan->openForSaving(wrappedName); + outFile = saveFileMan->openForSaving(wrappedName, isCompressed); if (!outFile) debugC(kDebugLevelFile, " -> file_open(_K_FILE_MODE_CREATE): failed to create file '%s'", englishName.c_str()); -- cgit v1.2.3 From 16adcb5145ce293af120b7cc828a08166da310e2 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 25 Jun 2012 22:32:00 +0300 Subject: COMMON: Simplify the documentation in openForSaving() The new more concise description is courtesy of wjp. --- common/savefile.h | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/common/savefile.h b/common/savefile.h index abe0df2758..da787289ee 100644 --- a/common/savefile.h +++ b/common/savefile.h @@ -107,25 +107,13 @@ public: * Open the savefile with the specified name in the given directory for * saving. * - * Saved games are always compressed using ZIP compression on platforms - * where the zlib library is included (i.e. almost all platforms except the - * NDS). Engines are expected to always create compressed saved games. - * A notable exception is when the created saved games are compatible with - * the ones that the original interpreters create, and they are then used - * with later game versions in a game series which are not supported by - * ScummVM. An example is the characters exported in the Quest for Glory - * games: these saved states actually contain simple text strings with - * character attributes, which can then be used with later games in the - * Quest for Glory Series. Currently, ScummVM supports Quest for Glory - * 1, 2 and 3. These exported heroes can also be read by the AGS VGA fan - * made version of Quest for Glory 2 and the SCI32 game Quest for Glory IV, - * none of which is supported by ScummVM yet. Moreover, these heroes can - * also be imported into Quest for Glory V, which is a 3D game and thus - * outside of ScummVM's scope. For these reasons, in such cases engines can - * create uncompressed saved games to help users import them in other games - * not supported by ScummVM. Users only need to know that such saved games - * exported by ScummVM are compatible with later unsupported games, without - * needing to explain how to uncompress them. + * Saved games are compressed by default, and engines are expected to + * always write compressed saves. + * + * A notable exception is if uncompressed files are needed for + * compatibility with games not supported by ScummVM, such as character + * exports from the Quest for Glory series. QfG5 is a 3D game and won't be + * supported by ScummVM. * * @param name the name of the savefile * @param compress toggles whether to compress the resulting save file -- cgit v1.2.3 From 659d0cfcc39721001f607e4ca51b8eb477708404 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 25 Jun 2012 22:39:28 +0300 Subject: COMMON: Also adapt openForSaving() in the DC and N64 backends --- backends/platform/dc/vmsave.cpp | 5 +++-- backends/platform/n64/framfs_save_manager.h | 4 ++-- backends/platform/n64/pakfs_save_manager.h | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/backends/platform/dc/vmsave.cpp b/backends/platform/dc/vmsave.cpp index e06dd7fa43..ba3b787942 100644 --- a/backends/platform/dc/vmsave.cpp +++ b/backends/platform/dc/vmsave.cpp @@ -316,8 +316,9 @@ public: class VMSaveManager : public Common::SaveFileManager { public: - virtual Common::OutSaveFile *openForSaving(const Common::String &filename) { - return Common::wrapCompressedWriteStream(new OutVMSave(filename.c_str())); + virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true) { + OutVMSave *s = new OutVMSave(filename.c_str()); + return compress ? Common::wrapCompressedWriteStream(s) : s; } virtual Common::InSaveFile *openForLoading(const Common::String &filename) { diff --git a/backends/platform/n64/framfs_save_manager.h b/backends/platform/n64/framfs_save_manager.h index da553e423a..0a88c8666b 100644 --- a/backends/platform/n64/framfs_save_manager.h +++ b/backends/platform/n64/framfs_save_manager.h @@ -100,10 +100,10 @@ public: class FRAMSaveManager : public Common::SaveFileManager { public: - virtual Common::OutSaveFile *openForSaving(const Common::String &filename) { + virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true) { OutFRAMSave *s = new OutFRAMSave(filename.c_str()); if (!s->err()) { - return Common::wrapCompressedWriteStream(s); + return compress ? Common::wrapCompressedWriteStream(s) : s; } else { delete s; return 0; diff --git a/backends/platform/n64/pakfs_save_manager.h b/backends/platform/n64/pakfs_save_manager.h index e0fcbc1e2d..6e67fb0f5f 100644 --- a/backends/platform/n64/pakfs_save_manager.h +++ b/backends/platform/n64/pakfs_save_manager.h @@ -101,10 +101,10 @@ public: class PAKSaveManager : public Common::SaveFileManager { public: - virtual Common::OutSaveFile *openForSaving(const Common::String &filename) { + virtual Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true) { OutPAKSave *s = new OutPAKSave(filename.c_str()); if (!s->err()) { - return Common::wrapCompressedWriteStream(s); + return compress ? Common::wrapCompressedWriteStream(s) : s; } else { delete s; return NULL; -- cgit v1.2.3