diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-03-28 23:59:10 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-03-28 23:59:10 (GMT) |
| commit | 1f388e4ca02f0a84e4b9d9b19e6308224389818d (patch) | |
| tree | 3cb5d7caf052d57e6873a291bbe451a4119bdcef /src | |
| parent | e9770d8ee7a44d5680c23749c786a03c0d5b41ff (diff) | |
| download | powder-1f388e4ca02f0a84e4b9d9b19e6308224389818d.zip powder-1f388e4ca02f0a84e4b9d9b19e6308224389818d.tar.gz | |
Exception when loading invalid save
Diffstat (limited to 'src')
| -rw-r--r-- | src/game/GameController.cpp | 11 | ||||
| -rw-r--r-- | src/game/GameModel.cpp | 8 | ||||
| -rw-r--r-- | src/game/GameView.cpp | 5 | ||||
| -rw-r--r-- | src/game/SaveLoadException.h | 26 |
4 files changed, 46 insertions, 4 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index a4a99c2..e5c3013 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 85f4249..a1d6b8b 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 16f7551..7faeaf1 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.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)); diff --git a/src/game/SaveLoadException.h b/src/game/SaveLoadException.h new file mode 100644 index 0000000..fea2ad5 --- /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 <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_ */ |
