mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-22 18:59:04 +02:00
Code cleanup for save state notification, add metadata field
This commit is contained in:
1 parent
87a74546bc
commit
231aefe476
9 files changed
+44
-48
No files matched your search
+14
-13
@@ -414,7 +414,7 @@ int g_screenshotFailures;
|
||||
Path backup = GetSysDirectory(DIRECTORY_SAVESTATE) / LOAD_UNDO_NAME;
|
||||
|
||||
std::string prefix(gamePrefix);
|
||||
auto saveCallback = [prefix, fn, backup, slot, callback](Status status, std::string_view message) {
|
||||
auto saveCallback = [prefix, fn, backup, slot, callback](Status status, std::string_view message, std::string_view metadata) {
|
||||
if (status != Status::FAILURE) {
|
||||
DeleteIfExists(backup);
|
||||
File::Rename(backup.WithExtraExtension(".tmp"), backup);
|
||||
@@ -438,7 +438,7 @@ int g_screenshotFailures;
|
||||
} else {
|
||||
if (callback) {
|
||||
auto sy = GetI18NCategory(I18NCat::SYSTEM);
|
||||
callback(Status::FAILURE, sy->T("Failed to load state. Error in the file system."));
|
||||
callback(Status::FAILURE, sy->T("Failed to load state. Error in the file system."), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -451,7 +451,7 @@ int g_screenshotFailures;
|
||||
if (g_Config.sStateLoadUndoGame != gamePrefix) {
|
||||
if (callback) {
|
||||
auto sy = GetI18NCategory(I18NCat::SYSTEM);
|
||||
callback(Status::FAILURE, sy->T("Error: load undo state is from a different game"));
|
||||
callback(Status::FAILURE, sy->T("Error: load undo state is from a different game"), "");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -463,7 +463,7 @@ int g_screenshotFailures;
|
||||
} else {
|
||||
if (callback) {
|
||||
auto sy = GetI18NCategory(I18NCat::SYSTEM);
|
||||
callback(Status::FAILURE, sy->T("Failed to load state for load undo. Error in the file system."));
|
||||
callback(Status::FAILURE, sy->T("Failed to load state for load undo. Error in the file system."), "");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -480,7 +480,7 @@ int g_screenshotFailures;
|
||||
Path shot = GenerateSaveSlotPath(gamePrefix, slot, SCREENSHOT_EXTENSION);
|
||||
|
||||
std::string prefix(gamePrefix);
|
||||
auto renameCallback = [fn, fnUndo, prefix, slot, callback](Status status, std::string_view message) {
|
||||
auto renameCallback = [fn, fnUndo, prefix, slot, callback](Status status, std::string_view message, std::string_view metadata) {
|
||||
if (status != Status::FAILURE) {
|
||||
if (g_Config.bEnableStateUndo) {
|
||||
DeleteIfExists(fnUndo);
|
||||
@@ -494,7 +494,7 @@ int g_screenshotFailures;
|
||||
File::Rename(fn.WithExtraExtension(".tmp"), fn);
|
||||
}
|
||||
if (callback) {
|
||||
callback(status, message);
|
||||
callback(status, message, "");
|
||||
}
|
||||
};
|
||||
// Let's also create a screenshot.
|
||||
@@ -508,7 +508,7 @@ int g_screenshotFailures;
|
||||
} else {
|
||||
if (callback) {
|
||||
auto sy = GetI18NCategory(I18NCat::SYSTEM);
|
||||
callback(Status::FAILURE, sy->T("Failed to save state. Error in the file system."));
|
||||
callback(Status::FAILURE, sy->T("Failed to save state. Error in the file system."), "");
|
||||
}
|
||||
}
|
||||
Rescan(gamePrefix);
|
||||
@@ -714,7 +714,7 @@ int g_screenshotFailures;
|
||||
return copy;
|
||||
}
|
||||
|
||||
bool HandleLoadFailure(bool wasRewinding) {
|
||||
static bool HandleLoadFailure(bool wasRewinding, std::string *metadata) {
|
||||
if (wasRewinding) {
|
||||
WARN_LOG(Log::SaveState, "HandleLoadFailure - trying a rewind state.");
|
||||
// Okay, first, let's give the next rewind state a shot - maybe we can at least not reset entirely.
|
||||
@@ -722,7 +722,7 @@ int g_screenshotFailures;
|
||||
CChunkFileReader::Error result;
|
||||
do {
|
||||
std::string errorString;
|
||||
result = rewindStates.Restore(&errorString);
|
||||
result = rewindStates.Restore(&errorString, metadata);
|
||||
} while (result == CChunkFileReader::ERROR_BROKEN_STATE);
|
||||
|
||||
if (result == CChunkFileReader::ERROR_NONE) {
|
||||
@@ -813,6 +813,7 @@ int g_screenshotFailures;
|
||||
CChunkFileReader::Error result;
|
||||
Status callbackResult;
|
||||
std::string callbackMessage;
|
||||
std::string callbackMetadata;
|
||||
std::string title;
|
||||
|
||||
auto sc = GetI18NCategory(I18NCat::SCREEN);
|
||||
@@ -849,7 +850,7 @@ int g_screenshotFailures;
|
||||
#endif
|
||||
g_lastSaveTime = time_now_d();
|
||||
} else if (result == CChunkFileReader::ERROR_BROKEN_STATE) {
|
||||
HandleLoadFailure(false);
|
||||
HandleLoadFailure(false, &callbackMetadata);
|
||||
callbackMessage = std::string(i18nLoadFailure) + ": " + errorString;
|
||||
ERROR_LOG(Log::SaveState, "Load state failure: %s", errorString.c_str());
|
||||
callbackResult = Status::FAILURE;
|
||||
@@ -909,7 +910,7 @@ int g_screenshotFailures;
|
||||
|
||||
case OperationType::Rewind:
|
||||
INFO_LOG(Log::SaveState, "Rewinding to recent savestate snapshot");
|
||||
result = rewindStates.Restore(&errorString);
|
||||
result = rewindStates.Restore(&errorString, &callbackMetadata);
|
||||
if (result == CChunkFileReader::ERROR_NONE) {
|
||||
callbackMessage = sc->T("Loaded State");
|
||||
callbackResult = Status::SUCCESS;
|
||||
@@ -917,7 +918,7 @@ int g_screenshotFailures;
|
||||
Core_ResetException();
|
||||
} else if (result == CChunkFileReader::ERROR_BROKEN_STATE) {
|
||||
// Cripes. Good news is, we might have more. Let's try those too, better than a reset.
|
||||
if (HandleLoadFailure(true)) {
|
||||
if (HandleLoadFailure(true, &callbackMetadata)) {
|
||||
// Well, we did rewind, even if too much...
|
||||
callbackMessage = sc->T("Loaded State");
|
||||
callbackResult = Status::SUCCESS;
|
||||
@@ -940,7 +941,7 @@ int g_screenshotFailures;
|
||||
}
|
||||
|
||||
if (op.callback) {
|
||||
op.callback(callbackResult, callbackMessage);
|
||||
op.callback(callbackResult, callbackMessage, callbackMetadata);
|
||||
}
|
||||
}
|
||||
if (operations.size()) {
|
||||
|
||||
Reference in new issue
Block a user