[Scummvm-git-logs] scummvm master -> dceb68bc7af54ef277570f0bdec729124650642f
elasota
noreply at scummvm.org
Sun Jun 11 21:56:23 UTC 2023
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
dceb68bc7a VCRUISE: Fix most recent save detection when autosaves are disabled.
Commit: dceb68bc7af54ef277570f0bdec729124650642f
https://github.com/scummvm/scummvm/commit/dceb68bc7af54ef277570f0bdec729124650642f
Author: elasota (ejlasota at gmail.com)
Date: 2023-06-11T17:54:53-04:00
Commit Message:
VCRUISE: Fix most recent save detection when autosaves are disabled.
Changed paths:
engines/vcruise/menu.cpp
engines/vcruise/vcruise.cpp
engines/vcruise/vcruise.h
diff --git a/engines/vcruise/menu.cpp b/engines/vcruise/menu.cpp
index 6bc647821a3..892ee2e7670 100644
--- a/engines/vcruise/menu.cpp
+++ b/engines/vcruise/menu.cpp
@@ -28,6 +28,7 @@
#include "vcruise/menu.h"
#include "vcruise/runtime.h"
+#include "vcruise/vcruise.h"
namespace VCruise {
@@ -1109,7 +1110,7 @@ void ReahSchizmMainMenuPage::start() {
void ReahSchizmMainMenuPage::onButtonClicked(uint button, bool &outChangedState) {
switch (button) {
case kButtonContinue: {
- Common::Error loadError = g_engine->loadGameState(g_engine->getAutosaveSlot());
+ Common::Error loadError = static_cast<VCruise::VCruiseEngine *>(g_engine)->loadMostRecentSave();
outChangedState = (loadError.getCode() == Common::kNoError);
} break;
diff --git a/engines/vcruise/vcruise.cpp b/engines/vcruise/vcruise.cpp
index 9c2a4e412ea..7124479e6c9 100644
--- a/engines/vcruise/vcruise.cpp
+++ b/engines/vcruise/vcruise.cpp
@@ -374,14 +374,75 @@ void VCruiseEngine::initializePath(const Common::FSNode &gamePath) {
}
bool VCruiseEngine::hasDefaultSave() {
- const Common::String &autoSaveName = getSaveStateName(getMetaEngine()->getAutosaveSlot());
- bool autoSaveExists = getSaveFileManager()->exists(autoSaveName);
-
- return autoSaveExists;
+ return hasAnySave();
}
bool VCruiseEngine::hasAnySave() {
- return hasDefaultSave(); // Maybe could do this better, but with how ScummVM works, if there are any saves at all, then the autosave should exist.
+ Common::StringArray saveFiles = getSaveFileManager()->listSavefiles(_targetName + ".*");
+ return saveFiles.size() > 0;
+}
+
+Common::Error VCruiseEngine::loadMostRecentSave() {
+ Common::SaveFileManager *sfm = getSaveFileManager();
+
+ Common::StringArray saveFiles = sfm->listSavefiles(_targetName + ".*");
+
+ uint64 highestDateTime = 0;
+ uint32 highestPlayTime = 0;
+ Common::String highestSaveFileName;
+
+ for (const Common::String &saveFileName : saveFiles) {
+ Common::InSaveFile *saveFile = sfm->openForLoading(saveFileName);
+
+ if (!saveFile) {
+ warning("Couldn't load save file '%s' to determine recency", saveFileName.c_str());
+ continue;
+ }
+
+ ExtendedSavegameHeader header;
+ bool loadedHeader = getMetaEngine()->readSavegameHeader(saveFile, &header, true);
+ if (!loadedHeader) {
+ warning("Couldn't parse header from '%s'", saveFileName.c_str());
+ continue;
+ }
+
+ // FIXME: Leaky abstraction, date doesn't increase in a way that later dates are always higher numbered so we must do this
+ uint day = (header.date >> 24) & 0xff;
+ uint month = (header.date >> 16) & 0xff;
+ uint year = (header.date & 0xffff);
+
+ uint hour = ((header.time >> 8) & 0xff);
+ uint minute = (header.time & 0xff);
+
+ uint64 dateTime = static_cast<uint64>(year) << 32;
+ dateTime |= month << 24;
+ dateTime |= day << 16;
+ dateTime |= hour << 8;
+ dateTime |= minute;
+
+ uint32 playTime = header.playtime;
+
+ if (dateTime > highestDateTime || (dateTime == highestDateTime && playTime > highestPlayTime)) {
+ highestSaveFileName = saveFileName;
+ highestDateTime = dateTime;
+ highestPlayTime = playTime;
+ }
+ }
+
+ if (highestSaveFileName.empty()) {
+ warning("Couldn't find any valid saves to load");
+ return Common::Error(Common::kReadingFailed);
+ }
+
+ Common::String slotStr = highestSaveFileName.substr(_targetName.size() + 1);
+
+ int slot = 0;
+ if (sscanf(slotStr.c_str(), "%i", &slot) != 1) {
+ warning("Couldn't parse save slot ID from %s", highestSaveFileName.c_str());
+ return Common::Error(Common::kReadingFailed);
+ }
+
+ return loadGameState(slot);
}
diff --git a/engines/vcruise/vcruise.h b/engines/vcruise/vcruise.h
index a99cee86fbb..0be86ef5c29 100644
--- a/engines/vcruise/vcruise.h
+++ b/engines/vcruise/vcruise.h
@@ -65,6 +65,8 @@ public:
bool hasDefaultSave();
bool hasAnySave();
+ Common::Error loadMostRecentSave();
+
protected:
void pauseEngineIntern(bool pause) override;
More information about the Scummvm-git-logs
mailing list