Exception when loading invalid save
This commit is contained in:
parent
e9770d8ee7
commit
1f388e4ca0
@ -10,6 +10,7 @@
|
||||
#include "login/LoginController.h"
|
||||
#include "interface/Point.h"
|
||||
#include "dialogues/ErrorMessage.h"
|
||||
#include "SaveLoadException.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -33,9 +34,16 @@ public:
|
||||
virtual void ControllerExit()
|
||||
{
|
||||
if(cc->search->GetLoadedSave())
|
||||
{
|
||||
try
|
||||
{
|
||||
cc->gameModel->SetSave(new Save(*(cc->search->GetLoadedSave())));
|
||||
}
|
||||
catch(SaveLoadException & ex)
|
||||
{
|
||||
new ErrorMessage("Cannot open save", ex.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -61,6 +69,7 @@ public:
|
||||
if(cc->ssave->GetSaveUploaded())
|
||||
{
|
||||
cc->gameModel->SetSave(new Save(*(cc->ssave->GetSave())));
|
||||
|
||||
}
|
||||
//cc->gameModel->SetUser(cc->loginWindow->GetUser());
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "EllipseBrush.h"
|
||||
#include "client/Client.h"
|
||||
#include "game/DecorationTool.h"
|
||||
#include "SaveLoadException.h"
|
||||
|
||||
GameModel::GameModel():
|
||||
activeTools({NULL, NULL, NULL}),
|
||||
@ -257,7 +258,12 @@ void GameModel::SetSave(Save * newSave)
|
||||
currentSave = newSave;
|
||||
if(currentSave)
|
||||
{
|
||||
sim->Load(currentSave->GetData(), currentSave->GetDataLength());
|
||||
int returnVal = sim->Load(currentSave->GetData(), currentSave->GetDataLength());
|
||||
if(returnVal){
|
||||
delete currentSave;
|
||||
currentSave = NULL;
|
||||
throw SaveLoadException(returnVal==2?"Save from newer version":"Save data corrupt");
|
||||
}
|
||||
}
|
||||
notifySaveChanged();
|
||||
notifyPausedChanged();
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "Config.h"
|
||||
#include "GameView.h"
|
||||
#include "Graphics.h"
|
||||
#include "interface/Window.h"
|
||||
#include "interface/Button.h"
|
||||
#include "interface/Colour.h"
|
||||
@ -482,7 +483,7 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
|
||||
{
|
||||
if(selectMode!=SelectNone)
|
||||
{
|
||||
if(button!=3)
|
||||
if(button==BUTTON_LEFT)
|
||||
{
|
||||
selectPoint1 = ui::Point(x, y);
|
||||
selectPoint2 = selectPoint1;
|
||||
@ -517,7 +518,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
|
||||
int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y;
|
||||
int x1 = (selectPoint2.X<selectPoint1.X)?selectPoint2.X:selectPoint1.X;
|
||||
int y1 = (selectPoint2.Y<selectPoint1.Y)?selectPoint2.Y:selectPoint1.Y;
|
||||
if(button !=3 && x2-x1>0 && y2-y1>0)
|
||||
if(button==BUTTON_LEFT && x2-x1>0 && y2-y1>0)
|
||||
{
|
||||
if(selectMode==SelectCopy)
|
||||
c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2));
|
||||
|
26
src/game/SaveLoadException.h
Normal file
26
src/game/SaveLoadException.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* SaveLoadException.h
|
||||
*
|
||||
* Created on: Mar 29, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#ifndef SAVELOADEXCEPTION_H_
|
||||
#define SAVELOADEXCEPTION_H_
|
||||
|
||||
#include <string>
|
||||
#include <exception>
|
||||
using namespace std;
|
||||
|
||||
struct SaveLoadException: public exception {
|
||||
string message;
|
||||
public:
|
||||
SaveLoadException(string message_): message(message_) {}
|
||||
const char * what() const throw()
|
||||
{
|
||||
return message.c_str();
|
||||
}
|
||||
~SaveLoadException() throw() {};
|
||||
};
|
||||
|
||||
#endif /* SAVELOADEXCEPTION_H_ */
|
Loading…
Reference in New Issue
Block a user