Skip to content

Commit

Permalink
Now CMD_NewProject is safe over Project_ApplyChanges failing
Browse files Browse the repository at this point in the history
  • Loading branch information
ioan-chera committed Nov 6, 2023
1 parent 869f244 commit e94f84e
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions src/m_loadsave.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ void Instance::CMD_ManageProject()

void Instance::CMD_NewProject()
{
std::shared_ptr<Wad_file> initialEditWad = wad.master.editWad();
try
{
if (!Main_ConfirmQuit("create a new project"))
Expand All @@ -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
Expand Down Expand Up @@ -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());
}

Expand Down

0 comments on commit e94f84e

Please sign in to comment.