aboutsummaryrefslogtreecommitdiff
path: root/engines/gob/save/saveconverter_v4.cpp
diff options
context:
space:
mode:
authorSven Hesse2009-05-31 02:15:43 +0000
committerSven Hesse2009-05-31 02:15:43 +0000
commit896df6daf337bf83f27193918eb386321c4b0166 (patch)
treec124f8f102052cdd6207e2507d097aff4bc7f44e /engines/gob/save/saveconverter_v4.cpp
parentc938667d4b60005a926007376305f3da8621f7c7 (diff)
downloadscummvm-rg350-896df6daf337bf83f27193918eb386321c4b0166.tar.gz
scummvm-rg350-896df6daf337bf83f27193918eb386321c4b0166.tar.bz2
scummvm-rg350-896df6daf337bf83f27193918eb386321c4b0166.zip
- A new save system for the GobEngine, one that is not fundamentally broken and is versioned. Unfortunately, this invalidates most save games created on big-endian machines, since endian-issues was a main problem with the old system
- Removed the now superfluous variables sizes svn-id: r41056
Diffstat (limited to 'engines/gob/save/saveconverter_v4.cpp')
-rw-r--r--engines/gob/save/saveconverter_v4.cpp147
1 files changed, 147 insertions, 0 deletions
diff --git a/engines/gob/save/saveconverter_v4.cpp b/engines/gob/save/saveconverter_v4.cpp
new file mode 100644
index 0000000000..23273446d1
--- /dev/null
+++ b/engines/gob/save/saveconverter_v4.cpp
@@ -0,0 +1,147 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/endian.h"
+#include "common/savefile.h"
+
+#include "gob/gob.h"
+#include "gob/save/saveconverter.h"
+#include "gob/save/savefile.h"
+#include "gob/save/savehandler.h"
+
+namespace Gob {
+
+SaveConverter_v4::SaveConverter_v4(GobEngine *vm, const char *fileName) :
+ SaveConverter(vm, fileName) {
+}
+
+SaveConverter_v4::~SaveConverter_v4() {
+}
+
+int SaveConverter_v4::isOldSave(Common::InSaveFile **save) const {
+ uint32 varSize = SaveHandler::getVarSize(_vm);
+ if (varSize == 0)
+ return 0;
+
+ uint32 saveSize = getActualSize(save);
+ if (saveSize == 0)
+ return 0;
+
+ // The size of the old save always follows that rule
+ if (saveSize == (varSize * 2 + kSlotNameLength + 1000 + 512000))
+ return 1;
+
+ // Not an old save, clean up
+ if (save) {
+ delete *save;
+ *save = 0;
+ }
+
+ return 0;
+}
+
+char *SaveConverter_v4::getDescription(Common::SeekableReadStream &save) const {
+ // The description starts at 1000
+ if (!save.seek(1000))
+ return 0;
+
+ char *desc = new char[kSlotNameLength];
+
+ // Read the description
+ if (save.read(desc, kSlotNameLength) != kSlotNameLength) {
+ delete desc;
+ return 0;
+ }
+
+ return desc;
+}
+
+bool SaveConverter_v4::loadFail(SavePartInfo *info, SavePartVars *vars,
+ SavePartMem *props, Common::InSaveFile *save) {
+
+ delete info;
+ delete vars;
+ delete props;
+ delete save;
+
+ clear();
+
+ return false;
+}
+
+// Loads the old save by constructing a new save containing the old save's data
+bool SaveConverter_v4::load() {
+ clear();
+
+ uint32 varSize = SaveHandler::getVarSize(_vm);
+ if (varSize == 0)
+ return false;
+
+ Common::InSaveFile *save;
+
+ // Test if it's an old savd
+ if (!isOldSave(&save) || !save)
+ return false;
+
+ displayWarning();
+
+ SaveWriter writer(3, 0);
+
+ SavePartInfo *info = readInfo(*save, kSlotNameLength, false);
+ if (!info)
+ return loadFail(0, 0, 0, save);
+
+ SavePartVars *vars = readVars(*save, varSize, true);
+ if (!vars)
+ return loadFail(info, 0, 0, save);
+
+ SavePartMem *props = readMem(*save, 256000, true);
+ if (!props)
+ return loadFail(info, vars, 0, save);
+
+ // We don't need the save anymore
+ delete save;
+
+ // Write all parts
+ if (!writer.writePart(0, info))
+ return loadFail(info, vars, props, 0);
+ if (!writer.writePart(1, vars))
+ return loadFail(info, vars, props, 0);
+ if (!writer.writePart(2, props))
+ return loadFail(info, vars, props, 0);
+
+ // We don't need those anymore
+ delete info;
+ delete vars;
+ delete props;
+
+ // Create the final read stream
+ if (!createStream(writer))
+ return loadFail(0, 0, 0, 0);
+
+ return true;
+}
+
+} // End of namespace Gob