aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/kernel
diff options
context:
space:
mode:
authorPaul Gilbert2010-09-19 05:00:45 +0000
committerEugene Sandulenko2010-10-12 23:59:23 +0000
commit80521ed5dd279316d0534fc3cc4b61c27d19ef4e (patch)
treed941a865c999150be0a2028fc5f1b73c4c21395b /engines/sword25/kernel
parent1e07d9561fc43e1b1c0763d54c3eea4154fff070 (diff)
downloadscummvm-rg350-80521ed5dd279316d0534fc3cc4b61c27d19ef4e.tar.gz
scummvm-rg350-80521ed5dd279316d0534fc3cc4b61c27d19ef4e.tar.bz2
scummvm-rg350-80521ed5dd279316d0534fc3cc4b61c27d19ef4e.zip
SWORD25: Further savegame work, including savegame screenshots
This handles saving (but not yet re-loaded display) of screenshots into savegame files. It also changes the original engine behaviour of temporarily saving the screenshots in a file 'tmp.png' to keeping the raw PNG file data in a memory block. svn-id: r53373
Diffstat (limited to 'engines/sword25/kernel')
-rw-r--r--engines/sword25/kernel/filesystemutil.cpp19
-rw-r--r--engines/sword25/kernel/filesystemutil.h6
-rw-r--r--engines/sword25/kernel/persistenceservice.cpp23
3 files changed, 36 insertions, 12 deletions
diff --git a/engines/sword25/kernel/filesystemutil.cpp b/engines/sword25/kernel/filesystemutil.cpp
index 71b3dc9aa8..b6fcce5467 100644
--- a/engines/sword25/kernel/filesystemutil.cpp
+++ b/engines/sword25/kernel/filesystemutil.cpp
@@ -41,6 +41,7 @@
#include "common/savefile.h"
#include "common/system.h"
#include "sword25/kernel/filesystemutil.h"
+#include "sword25/kernel/persistenceservice.h"
namespace Sword25 {
@@ -113,7 +114,13 @@ public:
virtual bool FileExists(const Common::String &Filename) {
Common::File f;
- return f.exists(Filename);
+ if (f.exists(Filename))
+ return true;
+
+ // Check if the file exists in the save folder
+ Common::FSNode folder(PersistenceService::GetSavegameDirectory());
+ Common::FSNode fileNode = folder.getChild(FileSystemUtil::GetInstance().GetPathFilename(Filename));
+ return fileNode.exists();
}
virtual bool CreateDirectory(const Common::String &DirectoryName) {
@@ -128,6 +135,16 @@ public:
sort(filenames.begin(), filenames.end());
return filenames;
}
+
+ virtual Common::String GetPathFilename(const Common::String &Path) {
+ for (int i = Path.size() - 1; i >= 0; --i) {
+ if ((Path[i] == '/') || (Path[i] == '\\')) {
+ return Common::String(&Path.c_str()[i + 1]);
+ }
+ }
+
+ return Path;
+ }
};
// -----------------------------------------------------------------------------
diff --git a/engines/sword25/kernel/filesystemutil.h b/engines/sword25/kernel/filesystemutil.h
index 469c0b509a..3ff18e166d 100644
--- a/engines/sword25/kernel/filesystemutil.h
+++ b/engines/sword25/kernel/filesystemutil.h
@@ -107,6 +107,12 @@ public:
* @return Returns a vector containing all of the found filenames
*/
virtual Common::StringArray GetFilesInDirectory(const Common::String &Path) = 0;
+ /**
+ * Gets the filename from a path and filename
+ * @param Filename The full path and filename
+ * @return Returns just the filename
+ */
+ virtual Common::String GetPathFilename(const Common::String &Path) = 0;
};
} // End of namespace Sword25
diff --git a/engines/sword25/kernel/persistenceservice.cpp b/engines/sword25/kernel/persistenceservice.cpp
index de077bd8ae..3620e8c4a4 100644
--- a/engines/sword25/kernel/persistenceservice.cpp
+++ b/engines/sword25/kernel/persistenceservice.cpp
@@ -62,7 +62,7 @@ const char *SAVEGAME_DIRECTORY = "saves";
const char *FILE_MARKER = "BS25SAVEGAME";
const uint SLOT_COUNT = 18;
const uint FILE_COPY_BUFFER_SIZE = 1024 * 10;
-const char *VERSIONID = "5";
+const char *VERSIONID = "SCUMMVM1";
// -------------------------------------------------------------------------
@@ -194,8 +194,8 @@ struct PersistenceService::Impl {
// Die Beschreibung des Spielstandes besteht aus einer textuellen Darstellung des Änderungsdatums der Spielstanddatei.
CurSavegameInfo.Description = FormatTimestamp(FileSystemUtil::GetInstance().GetFileTime(Filename));
// Den Offset zu den gespeicherten Spieldaten innerhalb der Datei speichern.
- // Dieses entspricht der aktuellen Position + 1, da nach der letzten Headerinformation noch ein Leerzeichen als trenner folgt.
- CurSavegameInfo.GamedataOffset = static_cast<uint>(File->pos()) + 1;
+ // Dieses entspricht der aktuellen Position, da nach der letzten Headerinformation noch ein Leerzeichen als trenner folgt.
+ CurSavegameInfo.GamedataOffset = static_cast<uint>(File->pos());
}
delete File;
@@ -357,17 +357,18 @@ bool PersistenceService::SaveGame(uint SlotID, const Common::String &ScreenshotF
error("Unable to write game data to savegame file \"%s\".", Filename.c_str());
}
- // Screenshotdatei an die Datei anfügen.
- if (FileSystemUtil::GetInstance().FileExists(ScreenshotFilename)) {
- Common::File ScreenshotFile;
- if (!ScreenshotFile.open(ScreenshotFilename.c_str()))
- error("Unable to load screenshot file");
+ // Get the screenshot
+ Common::MemoryReadStream *thumbnail = (static_cast<GraphicEngine *>(
+ Kernel::GetInstance()->GetService("gfx")))->getThumbnail();
+ if (thumbnail) {
byte *Buffer = new Byte[FILE_COPY_BUFFER_SIZE];
- while (!ScreenshotFile.eos()) {
- int bytesRead = ScreenshotFile.read(&Buffer[0], FILE_COPY_BUFFER_SIZE);
+ while (!thumbnail->eos()) {
+ int bytesRead = thumbnail->read(&Buffer[0], FILE_COPY_BUFFER_SIZE);
File->write(&Buffer[0], bytesRead);
}
+
+ delete[] Buffer;
} else {
BS_LOG_WARNINGLN("The screenshot file \"%s\" does not exist. Savegame is written without a screenshot.", Filename.c_str());
}
@@ -416,7 +417,7 @@ bool PersistenceService::LoadGame(uint SlotID) {
byte *CompressedDataBuffer = new byte[CurSavegameInfo.GamedataLength];
byte *UncompressedDataBuffer = new Bytef[CurSavegameInfo.GamedataUncompressedLength];
- File = sfm->openForLoading(GenerateSavegamePath(SlotID));
+ File = sfm->openForLoading(GenerateSavegameFilename(SlotID));
File->seek(CurSavegameInfo.GamedataOffset);
File->read(reinterpret_cast<char *>(&CompressedDataBuffer[0]), CurSavegameInfo.GamedataLength);