SWORD25: Added description field to savegames

This stores the date and time of when the game was saved, since ScummVM doesn't support getting a file's age like the original engine did.

svn-id: r53638
This commit is contained in:
Paul Gilbert 2010-10-20 11:11:09 +00:00
parent 66ecd08868
commit 14e82dbe7f
4 changed files with 19 additions and 26 deletions

View File

@ -45,7 +45,7 @@ static Common::String loadString(Common::ReadStream &in, uint maxSize = 999) {
while (!in.eos() && (result.size() < maxSize)) {
char ch = (char)in.readByte();
if ((ch == '\0') || (ch == ' '))
if (ch == '\0')
break;
result += ch;
@ -65,8 +65,9 @@ uint findEmbeddedPNG(const byte *fileDataPtr, uint fileSize) {
// Headerinformationen der Spielstandes einlesen.
uint compressedGamedataSize;
loadString(stream);
loadString(stream);
loadString(stream); // Marker
loadString(stream); // Version
loadString(stream); // Description
Common::String gameSize = loadString(stream);
compressedGamedataSize = atoi(gameSize.c_str());
loadString(stream);

View File

@ -91,15 +91,6 @@ public:
return size;
}
virtual TimeDate getFileTime(const Common::String &filename) {
// TODO: There isn't any way in ScummVM to get a file's modified date/time. We will need to check
// what code makes use of it. If it's only the save game code, for example, we may be able to
// encode the date/time inside the savegame files themselves.
TimeDate result;
g_system->getTimeAndDate(result);
return result;
}
virtual bool fileExists(const Common::String &filename) {
Common::File f;
if (f.exists(filename))

View File

@ -81,11 +81,6 @@ public:
* determined, or the file does not exist, returns -1
*/
virtual int32 getFileSize(const Common::String &filename) = 0;
/**
* @param Filename The path to a file.
* @return Returns the timestamp of the specified file.
*/
virtual TimeDate getFileTime(const Common::String &filename) = 0;
/**
* @param Filename The path to a file.
* @return Returns true if the file exists.

View File

@ -87,7 +87,7 @@ Common::String loadString(Common::InSaveFile *in, uint maxSize = 999) {
Common::String result;
char ch = (char)in->readByte();
while ((ch != '\0') && (ch != ' ')) {
while (ch != '\0') {
result += ch;
if (result.size() >= maxSize)
break;
@ -155,6 +155,7 @@ struct PersistenceService::Impl {
// Read in the header
Common::String storedMarker = loadString(file);
Common::String storedVersionID = loadString(file);
Common::String gameDescription = loadString(file);
Common::String gameDataLength = loadString(file);
curSavegameInfo.gamedataLength = atoi(gameDataLength.c_str());
Common::String gamedataUncompressedLength = loadString(file);
@ -169,7 +170,7 @@ struct PersistenceService::Impl {
// Dateinamen des Spielstandes speichern.
curSavegameInfo.filename = generateSavegameFilename(slotID);
// Die Beschreibung des Spielstandes besteht aus einer textuellen Darstellung des Änderungsdatums der Spielstanddatei.
curSavegameInfo.description = formatTimestamp(FileSystemUtil::getInstance().getFileTime(filename));
curSavegameInfo.description = gameDescription;
// Den Offset zu den gespeicherten Spieldaten innerhalb der Datei speichern.
// Dieses entspricht der aktuellen Position, da nach der letzten Headerinformation noch ein Leerzeichen als trenner folgt.
curSavegameInfo.gamedataOffset = static_cast<uint>(file->pos());
@ -267,9 +268,14 @@ bool PersistenceService::saveGame(uint slotID, const Common::String &screenshotF
Common::OutSaveFile *file = sfm->openForSaving(filename);
file->writeString(FILE_MARKER);
file->writeByte(' ');
file->writeByte(0);
file->writeString(VERSIONID);
file->writeByte(' ');
file->writeByte(0);
TimeDate dt;
g_system->getTimeAndDate(dt);
file->writeString(formatTimestamp(dt));
file->writeByte(0);
if (file->err()) {
error("Unable to write header data to savegame file \"%s\".", filename.c_str());
@ -299,10 +305,10 @@ bool PersistenceService::saveGame(uint slotID, const Common::String &screenshotF
char sBuffer[10];
snprintf(sBuffer, 10, "%ld", compressedLength);
file->writeString(sBuffer);
file->writeByte(' ');
file->writeByte(0);
snprintf(sBuffer, 10, "%u", writer.getDataSize());
file->writeString(sBuffer);
file->writeByte(' ');
file->writeByte(0);
// Komprimierte Daten in die Datei schreiben.
file->write(reinterpret_cast<char *>(&compressionBuffer[0]), compressedLength);
@ -325,13 +331,13 @@ bool PersistenceService::saveGame(uint slotID, const Common::String &screenshotF
BS_LOG_WARNINGLN("The screenshot file \"%s\" does not exist. Savegame is written without a screenshot.", filename.c_str());
}
// Savegameinformationen für diesen Slot aktualisieren.
_impl->readSlotSavegameInformation(slotID);
file->finalize();
delete file;
delete[] compressionBuffer;
// Savegameinformationen für diesen Slot aktualisieren.
_impl->readSlotSavegameInformation(slotID);
// Erfolg signalisieren.
return true;
}