Skip to content

Commit

Permalink
Check versions when loading
Browse files Browse the repository at this point in the history
Be more lenient if not using a release version.
  • Loading branch information
ashdnazg committed Mar 7, 2016
1 parent 6202415 commit 6818c13
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions rts/System/LoadSave/CregLoadSaveHandler.cpp
Expand Up @@ -8,6 +8,7 @@
#include "Map/ReadMap.h"
#include "Game/Game.h"
#include "Game/GameSetup.h"
#include "Game/GameVersion.h"
#include "Game/GlobalUnsynced.h"
#include "Game/WaitCommandsAI.h"
#include "Net/GameServer.h"
Expand Down Expand Up @@ -126,6 +127,7 @@ void CCregLoadSaveHandler::SaveGame(const std::string& path)
std::stringstream oss;

// write our own header. SavePackage() will add its own
WriteString(oss, SpringVersion::GetSync());
WriteString(oss, gameSetup->setupText);
WriteString(oss, modName);
WriteString(oss, mapName);
Expand Down Expand Up @@ -180,6 +182,18 @@ void CCregLoadSaveHandler::LoadGameStartInfo(const std::string& path)
while ((len = saveFile.Read(buf, sizeof(buf))) > 0)
sbuf->sputn(buf, len);

//Check for compatible save versions
std::string saveVersion;
ReadString(*iss, saveVersion);
if (saveVersion != SpringVersion::GetSync()) {
if (SpringVersion::IsRelease()) {
throw content_error("File was saved by an incompatible engine version: " + saveVersion);
} else {
LOG_L(L_WARNING, "File was saved by a different engine version: %s", saveVersion.c_str());
}
}


// in case these contained values alredy
// (this is the case when loading a game through the spring menu eg),
// we set them to empty strings, as ReadString() does append,
Expand Down

0 comments on commit 6818c13

Please sign in to comment.