From e94f84e40b2ac959bedb4b76dd3eeff2e2e0f0d3 Mon Sep 17 00:00:00 2001 From: Ioan Chera Date: Mon, 6 Nov 2023 08:05:57 +0200 Subject: [PATCH] Now CMD_NewProject is safe over Project_ApplyChanges failing --- src/m_loadsave.cc | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/m_loadsave.cc b/src/m_loadsave.cc index 5bad4151..5ac920d5 100644 --- a/src/m_loadsave.cc +++ b/src/m_loadsave.cc @@ -203,6 +203,7 @@ void Instance::CMD_ManageProject() void Instance::CMD_NewProject() { + std::shared_ptr initialEditWad = wad.master.editWad(); try { if (!Main_ConfirmQuit("create a new project")) @@ -227,27 +228,6 @@ void Instance::CMD_NewProject() return; } - - /* third, delete file if it already exists - [ the file chooser should have asked for confirmation ] - */ - - if (FileExists(*filename)) - { - // TODO?? M_BackupWad(wad); - - if (!FileDelete(*filename)) - { - DLG_Notify("Unable to delete the existing file."); - - return; - } - - Fl::wait(0.1); - Fl::wait(0.1); - } - - wad.master.RemoveEditWad(); // this calls Main_LoadResources which resets the master directory @@ -285,6 +265,8 @@ void Instance::CMD_NewProject() } catch (const std::runtime_error& e) { + // Restore state before command + wad.master.ReplaceEditWad(initialEditWad); DLG_ShowError(false, "Could not start new project: %s", e.what()); }