"Save from a newer version" is now just a warning (OPS format never changes)

Also, actual save errors now prevent you from clicking "Open" (which allowed you to vote and do other stuff even though the save was never loaded)
This commit is contained in:
jacob1 2015-10-01 21:35:40 -04:00
parent 9c44fc641c
commit b184c78cff
5 changed files with 33 additions and 8 deletions

View File

@ -51,6 +51,7 @@ originalData(save.originalData)
blockHeight = save.blockHeight;
}
particlesCount = save.particlesCount;
fromNewerVersion = false;
}
GameSave::GameSave(int width, int height)
@ -63,6 +64,7 @@ GameSave::GameSave(int width, int height)
fanVelYPtr = NULL;
particles = NULL;
fromNewerVersion = false;
hasOriginalData = false;
expanded = true;
setSize(width, height);
@ -81,6 +83,7 @@ GameSave::GameSave(std::vector<char> data)
fanVelYPtr = NULL;
particles = NULL;
fromNewerVersion = false;
expanded = false;
hasOriginalData = true;
originalData = data;
@ -113,6 +116,7 @@ GameSave::GameSave(std::vector<unsigned char> data)
fanVelYPtr = NULL;
particles = NULL;
fromNewerVersion = false;
expanded = false;
hasOriginalData = true;
originalData = std::vector<char>(data.begin(), data.end());
@ -145,6 +149,7 @@ GameSave::GameSave(char * data, int dataSize)
fanVelYPtr = NULL;
particles = NULL;
fromNewerVersion = false;
expanded = false;
hasOriginalData = true;
originalData = std::vector<char>(data, data+dataSize);
@ -246,6 +251,8 @@ void GameSave::read(char * data, int dataSize)
#ifdef DEBUG
std::cout << "Reading OPS..." << std::endl;
#endif
if (data[3] != '1')
throw ParseException(ParseException::WrongVersion, "Save format from newer version");
readOPS(data, dataSize);
}
else
@ -456,15 +463,16 @@ void GameSave::readOPS(char * data, int dataLength)
fullH = blockH*CELL;
//From newer version
if(savedVersion > SAVE_VERSION)
throw ParseException(ParseException::WrongVersion, "Save from newer version");
if (savedVersion > SAVE_VERSION)
fromNewerVersion = true;
//throw ParseException(ParseException::WrongVersion, "Save from newer version");
//Incompatible cell size
if(inputData[5] > CELL)
if (inputData[5] > CELL)
throw ParseException(ParseException::InvalidDimensions, "Incorrect CELL size");
//Too large/off screen
if(blockX+blockW > XRES/CELL || blockY+blockH > YRES/CELL)
if (blockX+blockW > XRES/CELL || blockY+blockH > YRES/CELL)
throw ParseException(ParseException::InvalidDimensions, "Save too large");
setSize(blockW, blockH);
@ -476,11 +484,11 @@ void GameSave::readOPS(char * data, int dataLength)
//Check for overflows, don't load saves larger than 200MB
unsigned int toAlloc = bsonDataLen+1;
if(toAlloc > 209715200 || !toAlloc)
if (toAlloc > 209715200 || !toAlloc)
throw ParseException(ParseException::InvalidDimensions, "Save data too large, refusing");
bsonData = (unsigned char*)malloc(toAlloc);
if(!bsonData)
if (!bsonData)
throw ParseException(ParseException::InternalError, "Unable to allocate memory");
//Make sure bsonData is null terminated, since all string functions need null terminated strings

View File

@ -21,7 +21,7 @@ public:
{
return message.c_str();
}
~ParseException() throw() {};
~ParseException() throw() {}
};
class GameSave
@ -29,6 +29,7 @@ class GameSave
public:
int blockWidth, blockHeight;
bool fromNewerVersion;
//Simulation data
//int ** particleMap;

View File

@ -7,6 +7,7 @@
PreviewModel::PreviewModel():
doOpen(false),
canOpen(true),
save(NULL),
saveData(NULL),
saveComments(NULL),
@ -92,6 +93,11 @@ bool PreviewModel::GetDoOpen()
return doOpen;
}
bool PreviewModel::GetCanOpen()
{
return canOpen;
}
SaveInfo * PreviewModel::GetSave()
{
return save;
@ -169,11 +175,15 @@ void PreviewModel::OnResponseReady(void * object, int identifier)
commentsTotal = save->Comments;
try
{
save->SetGameSave(new GameSave(*saveData));
GameSave *gameSave = new GameSave(*saveData);
if (gameSave->fromNewerVersion)
new ErrorMessage("This save is from a newer version", "Please update TPT in game or at http://powdertoy.co.uk");
save->SetGameSave(gameSave);
}
catch(ParseException &e)
{
new ErrorMessage("Error", e.what());
canOpen = false;
}
notifySaveChanged();
notifyCommentsPageChanged();

View File

@ -16,6 +16,7 @@ using namespace std;
class PreviewView;
class PreviewModel: RequestListener {
bool doOpen;
bool canOpen;
vector<PreviewView*> observers;
SaveInfo * save;
std::vector<unsigned char> * saveData;
@ -52,6 +53,7 @@ public:
void UpdateSave(int saveID, int saveDate);
void SetFavourite(bool favourite);
bool GetDoOpen();
bool GetCanOpen();
void SetDoOpen(bool doOpen);
void Update();
virtual void OnResponseReady(void * object, int identifier);

View File

@ -465,6 +465,8 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
savePreview->Height *= scaleFactor;
}
}
else if (!sender->GetCanOpen())
openButton->Enabled = false;
}
else
{
@ -474,6 +476,8 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
authorDateLabel->SetText("");
saveDescriptionLabel->SetText("");
favButton->Enabled = false;
if (!sender->GetCanOpen())
openButton->Enabled = false;
}
}