diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 2a091aa40..25fd430f9 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -515,8 +515,9 @@ int Client::MakeDirectory(const char * dirName) #endif } -void Client::WriteFile(std::vector fileData, std::string filename) +bool Client::WriteFile(std::vector fileData, std::string filename) { + bool saveError = false; try { std::ofstream fileStream; @@ -526,12 +527,15 @@ void Client::WriteFile(std::vector fileData, std::string filename fileStream.write((char*)&fileData[0], fileData.size()); fileStream.close(); } + else + saveError = true; } catch (std::exception & e) { std::cerr << "WriteFile:" << e.what() << std::endl; - throw; - } + saveError = true; + } + return saveError; } bool Client::FileExists(std::string filename) @@ -554,8 +558,9 @@ bool Client::FileExists(std::string filename) return exists; } -void Client::WriteFile(std::vector fileData, std::string filename) +bool Client::WriteFile(std::vector fileData, std::string filename) { + bool saveError = false; try { std::ofstream fileStream; @@ -565,12 +570,15 @@ void Client::WriteFile(std::vector fileData, std::string filename) fileStream.write(&fileData[0], fileData.size()); fileStream.close(); } + else + saveError = true; } catch (std::exception & e) { std::cerr << "WriteFile:" << e.what() << std::endl; - throw; - } + saveError = true; + } + return saveError; } std::vector Client::ReadFile(std::string filename) diff --git a/src/client/Client.h b/src/client/Client.h index 085c60a91..6429b1850 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -111,8 +111,8 @@ public: void SetProxy(std::string proxy); int MakeDirectory(const char * dirname); - void WriteFile(std::vector fileData, std::string filename); - void WriteFile(std::vector fileData, std::string filename); + bool WriteFile(std::vector fileData, std::string filename); + bool WriteFile(std::vector fileData, std::string filename); bool FileExists(std::string filename); void AddListener(ClientListener * listener); diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 6a6702d51..241bc9e1e 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -1059,7 +1059,8 @@ void GameController::OpenLocalSaveWindow(bool asCurrent) else if (gameModel->GetSaveFile()) { Client::Ref().MakeDirectory(LOCAL_SAVE_DIR); - Client::Ref().WriteFile(gameSave->Serialise(), gameModel->GetSaveFile()->GetName()); + if (Client::Ref().WriteFile(gameSave->Serialise(), gameModel->GetSaveFile()->GetName())) + new ErrorMessage("Error", "Unable to write save file."); } } } diff --git a/src/gui/save/LocalSaveActivity.cpp b/src/gui/save/LocalSaveActivity.cpp index 084f2f2b4..05fe7dd7d 100644 --- a/src/gui/save/LocalSaveActivity.cpp +++ b/src/gui/save/LocalSaveActivity.cpp @@ -81,7 +81,6 @@ void LocalSaveActivity::Save() if (result == ConfirmPrompt::ResultOkay) { a->saveWrite(filename); - a->Exit(); } } virtual ~FileOverwriteConfirmation() { } @@ -99,7 +98,6 @@ void LocalSaveActivity::Save() else { saveWrite(finalFilename); - Exit(); } } else @@ -111,8 +109,13 @@ void LocalSaveActivity::Save() void LocalSaveActivity::saveWrite(std::string finalFilename) { Client::Ref().MakeDirectory(LOCAL_SAVE_DIR); - Client::Ref().WriteFile(save.GetGameSave()->Serialise(), finalFilename); - callback->FileSaved(&save); + if (Client::Ref().WriteFile(save.GetGameSave()->Serialise(), finalFilename)) + new ErrorMessage("Error", "Unable to write save file."); + else + { + callback->FileSaved(&save); + Exit(); + } } void LocalSaveActivity::OnDraw()