From: Carl Hetherington Date: Tue, 3 Jan 2023 16:28:53 +0000 (+0100) Subject: Cleanup: use ScopeGuard. X-Git-Tag: v2.16.39~8 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=b40f6bc1a3ab39b1bc0fa8fda1f97cb6a01bc85c;hp=0689506c22e91bc2d25e00f566a7005352e89f80 Cleanup: use ScopeGuard. --- diff --git a/src/tools/dcpomatic_kdm.cc b/src/tools/dcpomatic_kdm.cc index 5a7b4e6de..0d6ecbab0 100644 --- a/src/tools/dcpomatic_kdm.cc +++ b/src/tools/dcpomatic_kdm.cc @@ -46,6 +46,7 @@ #include "lib/file_log.h" #include "lib/job_manager.h" #include "lib/kdm_with_metadata.h" +#include "lib/scope_guard.h" #include "lib/screen.h" #include "lib/send_kdm_email_job.h" #include @@ -497,47 +498,50 @@ private: wxFD_MULTIPLE ); - if (d->ShowModal() == wxID_OK) { - auto chain = Config::instance()->decryption_chain(); - DCPOMATIC_ASSERT (chain->key()); - - 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(ekdm); - auto group = dynamic_pointer_cast (selected_dkdm()); - if (!group) { - group = Config::instance()->dkdms (); - } - add_dkdm(new_dkdm, group); - } 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()) - ); + ScopeGuard sg = [d]() { d->Destroy(); }; + + if (d->ShowModal() != wxID_OK) { + return; + } + + auto chain = Config::instance()->decryption_chain(); + DCPOMATIC_ASSERT (chain->key()); + + 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(ekdm); + auto group = dynamic_pointer_cast (selected_dkdm()); + if (!group) { + group = Config::instance()->dkdms (); } + add_dkdm(new_dkdm, group); + } 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()) + ); } - update_dkdm_view(); } - d->Destroy (); + update_dkdm_view(); } void add_dkdm_folder_clicked ()