Prevent un-prompted overwrite of files when exporting things from config (#1383).
[dcpomatic.git] / src / wx / wx_util.cc
index 91fd426247a94e40caaa82a547796864706e3c5c..db63400315e899cb1488705dffa3dda15adad12d 100644 (file)
@@ -130,7 +130,9 @@ error_dialog (wxWindow* parent, wxString m, optional<wxString> e)
 {
        wxMessageDialog* d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxOK | wxICON_ERROR);
        if (e) {
-               d->SetExtendedMessage (*e);
+               wxString em = *e;
+               em[0] = wxToupper (em[0]);
+               d->SetExtendedMessage (em);
        }
        d->ShowModal ();
        d->Destroy ();
@@ -461,10 +463,15 @@ maybe_show_splash ()
        return splash;
 }
 
-boost::filesystem::path
+optional<boost::filesystem::path>
 path_from_file_dialog (wxFileDialog* dialog, string extension)
 {
-       return boost::filesystem::path(wx_to_std(dialog->GetPath())).replace_extension(extension);
+       boost::filesystem::path p(wx_to_std(dialog->GetPath()));
+       p.replace_extension(extension);
+       if (boost::filesystem::is_regular_file(p) && !confirm_dialog(dialog, wxString::Format(_("A file named %s already exists.  Do you want to replace it?"), std_to_wx(p.filename().string())))) {
+               return optional<boost::filesystem::path>();
+       }
+       return p;
 }
 
 double