MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / CheckVersion

Function CheckVersion

pcsx2/SaveState.cpp:1084–1121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1082}
1083
1084static bool CheckVersion(const std::string& filename, zip_t* zf, Error* error)
1085{
1086 u32 savever;
1087
1088 auto zff = zip_fopen_managed(zf, EntryFilename_StateVersion, 0);
1089 if (!zff || zip_fread(zff.get(), &savever, sizeof(savever)) != sizeof(savever))
1090 {
1091 Error::SetString(error, "Savestate file does not contain version indicator.");
1092 return false;
1093 }
1094
1095 char version_string[STATE_PCSX2_VERSION_SIZE];
1096 if (zip_fread(zff.get(), version_string, STATE_PCSX2_VERSION_SIZE) == STATE_PCSX2_VERSION_SIZE)
1097 version_string[STATE_PCSX2_VERSION_SIZE - 1] = 0;
1098 else
1099 StringUtil::Strlcpy(version_string, "Unknown", std::size(version_string));
1100
1101 // Major version mismatch. Means we can't load this savestate at all. Support for it
1102 // was removed entirely.
1103 // check for a "minor" version incompatibility; which happens if the savestate being loaded is a newer version
1104 // than the emulator recognizes. 99% chance that trying to load it will just corrupt emulation or crash.
1105 if (savever > g_SaveVersion || (savever >> 16) != (g_SaveVersion >> 16))
1106 {
1107 std::string current_emulator_version = BuildVersion::GitTag;
1108 if (current_emulator_version.empty())
1109 {
1110 current_emulator_version = "Unknown";
1111 }
1112 Error::SetString(error, fmt::format(TRANSLATE_FS("SaveState","This save state was created with PCSX2 version {0}. It is no longer compatible "
1113 "with your current PCSX2 version {1}.\n\n"
1114 "If you have any unsaved progress on this save state, you can download the compatible PCSX2 version {0} "
1115 "from pcsx2.net, load the save state, and save your progress to the memory card."),
1116 version_string, current_emulator_version));
1117 return false;
1118 }
1119
1120 return true;
1121}
1122
1123static zip_int64_t CheckFileExistsInState(zip_t* zf, const char* name, bool required)
1124{

Callers 1

SaveState_UnzipFromDiskFunction · 0.85

Calls 7

zip_fopen_managedFunction · 0.85
zip_freadFunction · 0.85
StrlcpyFunction · 0.85
sizeFunction · 0.50
formatFunction · 0.50
getMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected