Prevent un-prompted overwrite of files when exporting things from config (#1383).
[dcpomatic.git] / src / wx / config_dialog.cc
index 4b8e44f92309342aacbd4a5d23839ed31eed43d8..e55de008fb91b86ad2cf4742590a3a63820787ff 100644 (file)
@@ -113,7 +113,7 @@ void
 GeneralPage::add_language_controls (wxGridBagSizer* table, int& r)
 {
        _set_language = new wxCheckBox (_panel, wxID_ANY, _("Set language"));
-       table->Add (_set_language, wxGBPosition (r, 0));
+       table->Add (_set_language, wxGBPosition (r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
        _language = new wxChoice (_panel, wxID_ANY);
        vector<pair<string, string> > languages;
        languages.push_back (make_pair ("Čeština", "cs_CZ"));
@@ -153,7 +153,7 @@ void
 GeneralPage::add_play_sound_controls (wxGridBagSizer* table, int& r)
 {
        _sound = new wxCheckBox (_panel, wxID_ANY, _("Play sound via"));
-       table->Add (_sound, wxGBPosition (r, 0));
+       table->Add (_sound, wxGBPosition (r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
        _sound_output = new wxChoice (_panel, wxID_ANY);
        table->Add (_sound_output, wxGBPosition (r, 1));
        ++r;
@@ -526,14 +526,17 @@ CertificateChainEditor::export_certificate ()
        }
 
        if (d->ShowModal () == wxID_OK) {
-               FILE* f = fopen_boost (path_from_file_dialog (d, "pem"), "w");
-               if (!f) {
-                       throw OpenFileError (wx_to_std (d->GetPath ()), errno, false);
-               }
+               optional<boost::filesystem::path> path = path_from_file_dialog (d, "pem");
+               if (path) {
+                       FILE* f = fopen_boost (*path, "w");
+                       if (!f) {
+                               throw OpenFileError (*path, errno, false);
+                       }
 
-               string const s = j->certificate (true);
-               fwrite (s.c_str(), 1, s.length(), f);
-               fclose (f);
+                       string const s = j->certificate (true);
+                       fwrite (s.c_str(), 1, s.length(), f);
+                       fclose (f);
+               }
        }
        d->Destroy ();
 }
@@ -698,14 +701,17 @@ CertificateChainEditor::export_private_key ()
                );
 
        if (d->ShowModal () == wxID_OK) {
-               FILE* f = fopen_boost (path_from_file_dialog (d, "pem"), "w");
-               if (!f) {
-                       throw OpenFileError (wx_to_std (d->GetPath ()), errno, false);
-               }
+               optional<boost::filesystem::path> path = path_from_file_dialog (d, "pem");
+               if (path) {
+                       FILE* f = fopen_boost (*path, "w");
+                       if (!f) {
+                               throw OpenFileError (*path, errno, false);
+                       }
 
-               string const s = _get()->key().get ();
-               fwrite (s.c_str(), 1, s.length(), f);
-               fclose (f);
+                       string const s = _get()->key().get ();
+                       fwrite (s.c_str(), 1, s.length(), f);
+                       fclose (f);
+               }
        }
        d->Destroy ();
 }
@@ -793,17 +799,20 @@ KeysPage::export_decryption_chain_and_key ()
                );
 
        if (d->ShowModal () == wxID_OK) {
-               FILE* f = fopen_boost (path_from_file_dialog (d, "dom"), "w");
-               if (!f) {
-                       throw OpenFileError (wx_to_std (d->GetPath ()), errno, false);
-               }
+               optional<boost::filesystem::path> path = path_from_file_dialog (d, "dom");
+               if (path) {
+                       FILE* f = fopen_boost (*path, "w");
+                       if (!f) {
+                               throw OpenFileError (wx_to_std (d->GetPath ()), errno, false);
+                       }
 
-               string const chain = Config::instance()->decryption_chain()->chain();
-               fwrite (chain.c_str(), 1, chain.length(), f);
-               optional<string> const key = Config::instance()->decryption_chain()->key();
-               DCPOMATIC_ASSERT (key);
-               fwrite (key->c_str(), 1, key->length(), f);
-               fclose (f);
+                       string const chain = Config::instance()->decryption_chain()->chain();
+                       fwrite (chain.c_str(), 1, chain.length(), f);
+                       optional<string> const key = Config::instance()->decryption_chain()->key();
+                       DCPOMATIC_ASSERT (key);
+                       fwrite (key->c_str(), 1, key->length(), f);
+                       fclose (f);
+               }
        }
        d->Destroy ();
 
@@ -865,19 +874,22 @@ void
 KeysPage::export_decryption_chain ()
 {
        wxFileDialog* d = new wxFileDialog (
-               _panel, _("Select Chain File"), wxEmptyString, wxEmptyString, wxT ("PEM files (*.pem)|*.pem"),
+               _panel, _("Select Chain File"), wxEmptyString, _("dcpomatic_kdm_decryption_chain.pem"), wxT ("PEM files (*.pem)|*.pem"),
                wxFD_SAVE | wxFD_OVERWRITE_PROMPT
                );
 
        if (d->ShowModal () == wxID_OK) {
-               FILE* f = fopen_boost (path_from_file_dialog (d, "pem"), "w");
-               if (!f) {
-                       throw OpenFileError (wx_to_std (d->GetPath ()), errno, false);
-               }
+               optional<boost::filesystem::path> path = path_from_file_dialog (d, "pem");
+               if (path) {
+                       FILE* f = fopen_boost (*path, "w");
+                       if (!f) {
+                               throw OpenFileError (*path, errno, false);
+                       }
 
-               string const s = Config::instance()->decryption_chain()->chain();
-               fwrite (s.c_str(), 1, s.length(), f);
-               fclose (f);
+                       string const s = Config::instance()->decryption_chain()->chain();
+                       fwrite (s.c_str(), 1, s.length(), f);
+                       fclose (f);
+               }
        }
        d->Destroy ();
 }
@@ -886,19 +898,23 @@ void
 KeysPage::export_decryption_certificate ()
 {
        wxFileDialog* d = new wxFileDialog (
-               _panel, _("Select Certificate File"), wxEmptyString, wxEmptyString, wxT ("PEM files (*.pem)|*.pem"),
+               _panel, _("Select Certificate File"), wxEmptyString, _("dcpomatic_kdm_decryption_cert.pem"), wxT ("PEM files (*.pem)|*.pem"),
                wxFD_SAVE | wxFD_OVERWRITE_PROMPT
                );
 
        if (d->ShowModal () == wxID_OK) {
-               FILE* f = fopen_boost (path_from_file_dialog (d, "pem"), "w");
-               if (!f) {
-                       throw OpenFileError (wx_to_std (d->GetPath ()), errno, false);
-               }
+               optional<boost::filesystem::path> path = path_from_file_dialog (d, "pem");
+               if (path) {
+                       FILE* f = fopen_boost (*path, "w");
+                       if (!f) {
+                               throw OpenFileError (*path, errno, false);
+                       }
 
-               string const s = Config::instance()->decryption_chain()->leaf().certificate (true);
-               fwrite (s.c_str(), 1, s.length(), f);
-               fclose (f);
+                       string const s = Config::instance()->decryption_chain()->leaf().certificate (true);
+                       fwrite (s.c_str(), 1, s.length(), f);
+                       fclose (f);
+               }
        }
+
        d->Destroy ();
 }