"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:
parent
9c44fc641c
commit
b184c78cff
@ -51,6 +51,7 @@ originalData(save.originalData)
|
|||||||
blockHeight = save.blockHeight;
|
blockHeight = save.blockHeight;
|
||||||
}
|
}
|
||||||
particlesCount = save.particlesCount;
|
particlesCount = save.particlesCount;
|
||||||
|
fromNewerVersion = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameSave::GameSave(int width, int height)
|
GameSave::GameSave(int width, int height)
|
||||||
@ -63,6 +64,7 @@ GameSave::GameSave(int width, int height)
|
|||||||
fanVelYPtr = NULL;
|
fanVelYPtr = NULL;
|
||||||
particles = NULL;
|
particles = NULL;
|
||||||
|
|
||||||
|
fromNewerVersion = false;
|
||||||
hasOriginalData = false;
|
hasOriginalData = false;
|
||||||
expanded = true;
|
expanded = true;
|
||||||
setSize(width, height);
|
setSize(width, height);
|
||||||
@ -81,6 +83,7 @@ GameSave::GameSave(std::vector<char> data)
|
|||||||
fanVelYPtr = NULL;
|
fanVelYPtr = NULL;
|
||||||
particles = NULL;
|
particles = NULL;
|
||||||
|
|
||||||
|
fromNewerVersion = false;
|
||||||
expanded = false;
|
expanded = false;
|
||||||
hasOriginalData = true;
|
hasOriginalData = true;
|
||||||
originalData = data;
|
originalData = data;
|
||||||
@ -113,6 +116,7 @@ GameSave::GameSave(std::vector<unsigned char> data)
|
|||||||
fanVelYPtr = NULL;
|
fanVelYPtr = NULL;
|
||||||
particles = NULL;
|
particles = NULL;
|
||||||
|
|
||||||
|
fromNewerVersion = false;
|
||||||
expanded = false;
|
expanded = false;
|
||||||
hasOriginalData = true;
|
hasOriginalData = true;
|
||||||
originalData = std::vector<char>(data.begin(), data.end());
|
originalData = std::vector<char>(data.begin(), data.end());
|
||||||
@ -145,6 +149,7 @@ GameSave::GameSave(char * data, int dataSize)
|
|||||||
fanVelYPtr = NULL;
|
fanVelYPtr = NULL;
|
||||||
particles = NULL;
|
particles = NULL;
|
||||||
|
|
||||||
|
fromNewerVersion = false;
|
||||||
expanded = false;
|
expanded = false;
|
||||||
hasOriginalData = true;
|
hasOriginalData = true;
|
||||||
originalData = std::vector<char>(data, data+dataSize);
|
originalData = std::vector<char>(data, data+dataSize);
|
||||||
@ -246,6 +251,8 @@ void GameSave::read(char * data, int dataSize)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::cout << "Reading OPS..." << std::endl;
|
std::cout << "Reading OPS..." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
if (data[3] != '1')
|
||||||
|
throw ParseException(ParseException::WrongVersion, "Save format from newer version");
|
||||||
readOPS(data, dataSize);
|
readOPS(data, dataSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -456,15 +463,16 @@ void GameSave::readOPS(char * data, int dataLength)
|
|||||||
fullH = blockH*CELL;
|
fullH = blockH*CELL;
|
||||||
|
|
||||||
//From newer version
|
//From newer version
|
||||||
if(savedVersion > SAVE_VERSION)
|
if (savedVersion > SAVE_VERSION)
|
||||||
throw ParseException(ParseException::WrongVersion, "Save from newer version");
|
fromNewerVersion = true;
|
||||||
|
//throw ParseException(ParseException::WrongVersion, "Save from newer version");
|
||||||
|
|
||||||
//Incompatible cell size
|
//Incompatible cell size
|
||||||
if(inputData[5] > CELL)
|
if (inputData[5] > CELL)
|
||||||
throw ParseException(ParseException::InvalidDimensions, "Incorrect CELL size");
|
throw ParseException(ParseException::InvalidDimensions, "Incorrect CELL size");
|
||||||
|
|
||||||
//Too large/off screen
|
//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");
|
throw ParseException(ParseException::InvalidDimensions, "Save too large");
|
||||||
|
|
||||||
setSize(blockW, blockH);
|
setSize(blockW, blockH);
|
||||||
@ -476,11 +484,11 @@ void GameSave::readOPS(char * data, int dataLength)
|
|||||||
|
|
||||||
//Check for overflows, don't load saves larger than 200MB
|
//Check for overflows, don't load saves larger than 200MB
|
||||||
unsigned int toAlloc = bsonDataLen+1;
|
unsigned int toAlloc = bsonDataLen+1;
|
||||||
if(toAlloc > 209715200 || !toAlloc)
|
if (toAlloc > 209715200 || !toAlloc)
|
||||||
throw ParseException(ParseException::InvalidDimensions, "Save data too large, refusing");
|
throw ParseException(ParseException::InvalidDimensions, "Save data too large, refusing");
|
||||||
|
|
||||||
bsonData = (unsigned char*)malloc(toAlloc);
|
bsonData = (unsigned char*)malloc(toAlloc);
|
||||||
if(!bsonData)
|
if (!bsonData)
|
||||||
throw ParseException(ParseException::InternalError, "Unable to allocate memory");
|
throw ParseException(ParseException::InternalError, "Unable to allocate memory");
|
||||||
|
|
||||||
//Make sure bsonData is null terminated, since all string functions need null terminated strings
|
//Make sure bsonData is null terminated, since all string functions need null terminated strings
|
||||||
|
@ -21,7 +21,7 @@ public:
|
|||||||
{
|
{
|
||||||
return message.c_str();
|
return message.c_str();
|
||||||
}
|
}
|
||||||
~ParseException() throw() {};
|
~ParseException() throw() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class GameSave
|
class GameSave
|
||||||
@ -29,6 +29,7 @@ class GameSave
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
int blockWidth, blockHeight;
|
int blockWidth, blockHeight;
|
||||||
|
bool fromNewerVersion;
|
||||||
|
|
||||||
//Simulation data
|
//Simulation data
|
||||||
//int ** particleMap;
|
//int ** particleMap;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
PreviewModel::PreviewModel():
|
PreviewModel::PreviewModel():
|
||||||
doOpen(false),
|
doOpen(false),
|
||||||
|
canOpen(true),
|
||||||
save(NULL),
|
save(NULL),
|
||||||
saveData(NULL),
|
saveData(NULL),
|
||||||
saveComments(NULL),
|
saveComments(NULL),
|
||||||
@ -92,6 +93,11 @@ bool PreviewModel::GetDoOpen()
|
|||||||
return doOpen;
|
return doOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PreviewModel::GetCanOpen()
|
||||||
|
{
|
||||||
|
return canOpen;
|
||||||
|
}
|
||||||
|
|
||||||
SaveInfo * PreviewModel::GetSave()
|
SaveInfo * PreviewModel::GetSave()
|
||||||
{
|
{
|
||||||
return save;
|
return save;
|
||||||
@ -169,11 +175,15 @@ void PreviewModel::OnResponseReady(void * object, int identifier)
|
|||||||
commentsTotal = save->Comments;
|
commentsTotal = save->Comments;
|
||||||
try
|
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)
|
catch(ParseException &e)
|
||||||
{
|
{
|
||||||
new ErrorMessage("Error", e.what());
|
new ErrorMessage("Error", e.what());
|
||||||
|
canOpen = false;
|
||||||
}
|
}
|
||||||
notifySaveChanged();
|
notifySaveChanged();
|
||||||
notifyCommentsPageChanged();
|
notifyCommentsPageChanged();
|
||||||
|
@ -16,6 +16,7 @@ using namespace std;
|
|||||||
class PreviewView;
|
class PreviewView;
|
||||||
class PreviewModel: RequestListener {
|
class PreviewModel: RequestListener {
|
||||||
bool doOpen;
|
bool doOpen;
|
||||||
|
bool canOpen;
|
||||||
vector<PreviewView*> observers;
|
vector<PreviewView*> observers;
|
||||||
SaveInfo * save;
|
SaveInfo * save;
|
||||||
std::vector<unsigned char> * saveData;
|
std::vector<unsigned char> * saveData;
|
||||||
@ -52,6 +53,7 @@ public:
|
|||||||
void UpdateSave(int saveID, int saveDate);
|
void UpdateSave(int saveID, int saveDate);
|
||||||
void SetFavourite(bool favourite);
|
void SetFavourite(bool favourite);
|
||||||
bool GetDoOpen();
|
bool GetDoOpen();
|
||||||
|
bool GetCanOpen();
|
||||||
void SetDoOpen(bool doOpen);
|
void SetDoOpen(bool doOpen);
|
||||||
void Update();
|
void Update();
|
||||||
virtual void OnResponseReady(void * object, int identifier);
|
virtual void OnResponseReady(void * object, int identifier);
|
||||||
|
@ -465,6 +465,8 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
|||||||
savePreview->Height *= scaleFactor;
|
savePreview->Height *= scaleFactor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!sender->GetCanOpen())
|
||||||
|
openButton->Enabled = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -474,6 +476,8 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
|||||||
authorDateLabel->SetText("");
|
authorDateLabel->SetText("");
|
||||||
saveDescriptionLabel->SetText("");
|
saveDescriptionLabel->SetText("");
|
||||||
favButton->Enabled = false;
|
favButton->Enabled = false;
|
||||||
|
if (!sender->GetCanOpen())
|
||||||
|
openButton->Enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user