diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index a4a99c2b9..e5c301336 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -10,6 +10,7 @@ #include "login/LoginController.h" #include "interface/Point.h" #include "dialogues/ErrorMessage.h" +#include "SaveLoadException.h" using namespace std; @@ -34,7 +35,14 @@ public: { if(cc->search->GetLoadedSave()) { - cc->gameModel->SetSave(new Save(*(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()); } diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 85f4249c4..a1d6b8bd2 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -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(); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 16f755107..7faeaf164 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -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.X0 && 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)); diff --git a/src/game/SaveLoadException.h b/src/game/SaveLoadException.h new file mode 100644 index 000000000..fea2ad55d --- /dev/null +++ b/src/game/SaveLoadException.h @@ -0,0 +1,26 @@ +/* + * SaveLoadException.h + * + * Created on: Mar 29, 2012 + * Author: Simon + */ + +#ifndef SAVELOADEXCEPTION_H_ +#define SAVELOADEXCEPTION_H_ + +#include +#include +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_ */