diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-05-24 10:50:21 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-05-24 12:23:59 +0100 |
| commit | aaf1d809a0ebbc2eb7dcd9ea7146cfe7bb4702f1 (patch) | |
| tree | 266111b8fac68f13081ab9f2bb526cd59befafd2 /src | |
| parent | bfb8c684886592f325f85c490d9f0aafd7056734 (diff) | |
Don't crash when failing to parse a KDM.
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/dcpomatic_kdm.cc | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/tools/dcpomatic_kdm.cc b/src/tools/dcpomatic_kdm.cc index 75149a718..072cc2b0e 100644 --- a/src/tools/dcpomatic_kdm.cc +++ b/src/tools/dcpomatic_kdm.cc @@ -158,7 +158,6 @@ public: dkdm_sizer->Add (dkdm_buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP); right->Add (dkdm_sizer, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP); - _dkdm_id[_dkdm->AddRoot("root")] = Config::instance()->dkdms(); add_dkdm_view (Config::instance()->dkdms(), shared_ptr<DKDMGroup> ()); h = new wxStaticText (overall_panel, wxID_ANY, _("Output")); @@ -372,7 +371,22 @@ private: { wxFileDialog* d = new wxFileDialog (this, _("Select DKDM file")); if (d->ShowModal() == wxID_OK) { - shared_ptr<DKDMBase> new_dkdm (new DKDM (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)))); + shared_ptr<DKDMBase> new_dkdm; + try { + new_dkdm.reset ( + new DKDM (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE))) + ); + } catch (dcp::KDMFormatError& e) { + error_dialog ( + this, + wxString::Format ( + _("Could not read file as a KDM. Perhaps it is badly formatted, or not a KDM at all.\n\n%s"), + std_to_wx(e.what()).data() + ) + ); + return; + } + shared_ptr<DKDMGroup> group = dynamic_pointer_cast<DKDMGroup> (selected_dkdm ()); if (!group) { group = Config::instance()->dkdms (); |
