Default to filtering DKDM filenames to only see *.xml, and allow
[dcpomatic.git] / src / tools / dcpomatic_kdm.cc
index 65bb921e57ae6ec05a54371410c5b5e09ab032bc..30f2e0b827f9b3b999a5897c66b9fe76d7a2aee0 100644 (file)
 #include "lib/compose.hpp"
 #include "lib/config.h"
 #include "lib/cross.h"
+#include "lib/dcpomatic_log.h"
 #include "lib/dkdm_wrapper.h"
 #include "lib/exceptions.h"
+#include "lib/file_log.h"
 #include "lib/job_manager.h"
 #include "lib/kdm_with_metadata.h"
 #include "lib/screen.h"
 #include <dcp/encrypted_kdm.h>
 #include <dcp/decrypted_kdm.h>
 #include <dcp/exceptions.h>
-#include "lib/warnings.h"
-DCPOMATIC_DISABLE_WARNINGS
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
 #include <wx/filepicker.h>
 #include <wx/preferences.h>
 #include <wx/splash.h>
 #include <wx/treectrl.h>
 #include <wx/wx.h>
-DCPOMATIC_ENABLE_WARNINGS
+LIBDCP_ENABLE_WARNINGS
 #ifdef __WXOSX__
 #include <ApplicationServices/ApplicationServices.h>
 #endif
@@ -203,6 +205,8 @@ public:
                _export_dkdm->Bind (wxEVT_BUTTON, bind (&DOMFrame::export_dkdm_clicked, this));
 
                setup_sensitivity ();
+
+               dcpomatic_log = make_shared<FileLog>(State::write_path("kdm.log"));
        }
 
 private:
@@ -444,41 +448,53 @@ private:
 
        void add_dkdm_clicked ()
        {
-               auto d = new wxFileDialog (this, _("Select DKDM file"));
+               auto d = new wxFileDialog(
+                       this,
+                       _("Select DKDM file"),
+                       wxEmptyString,
+                       wxEmptyString,
+                       wxT("XML files|*.xml|All files|*.*"),
+                       wxFD_MULTIPLE
+                       );
+
                if (d->ShowModal() == wxID_OK) {
                        auto chain = Config::instance()->decryption_chain();
                        DCPOMATIC_ASSERT (chain->key());
 
-                       try {
-                               dcp::EncryptedKDM ekdm(dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE));
-                               /* Decrypt the DKDM to make sure that we can */
-                               dcp::DecryptedKDM dkdm(ekdm, chain->key().get());
-
-                               auto new_dkdm = make_shared<DKDM>(ekdm);
-                               auto group = dynamic_pointer_cast<DKDMGroup> (selected_dkdm());
-                               if (!group) {
-                                       group = Config::instance()->dkdms ();
+                       wxArrayString paths;
+                       d->GetPaths(paths);
+                       for (unsigned int i = 0; i < paths.GetCount(); ++i) {
+                               try {
+                                       dcp::EncryptedKDM ekdm(dcp::file_to_string(wx_to_std(paths[i]), MAX_KDM_SIZE));
+                                       /* Decrypt the DKDM to make sure that we can */
+                                       dcp::DecryptedKDM dkdm(ekdm, chain->key().get());
+
+                                       auto new_dkdm = make_shared<DKDM>(ekdm);
+                                       auto group = dynamic_pointer_cast<DKDMGroup> (selected_dkdm());
+                                       if (!group) {
+                                               group = Config::instance()->dkdms ();
+                                       }
+                                       add_dkdm_model (new_dkdm, group);
+                                       add_dkdm_view (new_dkdm);
+                               } catch (dcp::KDMFormatError& e) {
+                                       error_dialog (
+                                               this,
+                                               _("Could not read file as a KDM.  Perhaps it is badly formatted, or not a KDM at all."),
+                                               std_to_wx(e.what())
+                                               );
+                                       return;
+                               } catch (dcp::KDMDecryptionError &) {
+                                       error_dialog (
+                                               this,
+                                               _("Could not decrypt the DKDM.  Perhaps it was not created with the correct certificate.")
+                                               );
+                               } catch (dcp::MiscError& e) {
+                                       error_dialog (
+                                               this,
+                                               _("Could not read file as a KDM.  It is much too large.  Make sure you are loading a DKDM (XML) file."),
+                                               std_to_wx(e.what())
+                                               );
                                }
-                               add_dkdm_model (new_dkdm, group);
-                               add_dkdm_view (new_dkdm);
-                       } catch (dcp::KDMFormatError& e) {
-                               error_dialog (
-                                       this,
-                                       _("Could not read file as a KDM.  Perhaps it is badly formatted, or not a KDM at all."),
-                                       std_to_wx(e.what())
-                                       );
-                               return;
-                       } catch (dcp::KDMDecryptionError &) {
-                               error_dialog (
-                                       this,
-                                       _("Could not decrypt the DKDM.  Perhaps it was not created with the correct certificate.")
-                                       );
-                       } catch (dcp::MiscError& e) {
-                               error_dialog (
-                                       this,
-                                       _("Could not read file as a KDM.  It is much too large.  Make sure you are loading a DKDM (XML) file."),
-                                       std_to_wx(e.what())
-                                       );
                        }
                }
                d->Destroy ();