From 20bf5c5ce90123c76105e4f62039a5c9899287c0 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 4 Jan 2026 21:02:23 +0100 Subject: Hacks: qube is awkward as it needs this _type The whole thing is a bit of a nightmare and there's no tests. --- src/lib/download_certificate.cc | 42 +++++++++++++++++++++++++++++++----- src/lib/download_certificate.h | 1 + src/lib/exceptions.cc | 2 +- src/wx/download_certificate_panel.cc | 25 --------------------- src/wx/download_certificate_panel.h | 2 -- src/wx/qube_certificate_panel.cc | 28 ++---------------------- 6 files changed, 41 insertions(+), 59 deletions(-) diff --git a/src/lib/download_certificate.cc b/src/lib/download_certificate.cc index c72f83476..19a5675cd 100644 --- a/src/lib/download_certificate.cc +++ b/src/lib/download_certificate.cc @@ -52,7 +52,7 @@ download_gdc_certificate(string const& serial) try { return { dcp::Certificate(get_from_url(url, true, false).as_string()), url }; } catch (dcp::MiscError& e) { - throw CertificateDownloadError(fmt::format(_("Could not read certificate file ({})"), e.what())); + throw CertificateReadError(e.what()); } } @@ -73,7 +73,7 @@ download_barco_certificate(string const& serial) try { return { dcp::Certificate(get_from_url(url, true, false).as_string()), url }; } catch (dcp::MiscError& e) { - throw CertificateDownloadError(fmt::format(_("Could not read certificate file ({})"), e.what())); + throw CertificateReadError(e.what()); } } @@ -238,8 +238,8 @@ download_dolby_certificate(string const& serial, std::function yield) try { auto data = get_from_zip_url(location.url, location.file, true, true); return { dcp::Certificate(get_from_zip_url(location.url, location.file, true, true).as_string()), location.url }; - } catch (dcp:MiscError& e) { - throw CertificateDownloadError(fmt::format(_("Could not read certificate file ({})"), e.what())); + } catch (dcp::MiscError& e) { + throw CertificateReadError(e.what()); } } @@ -247,7 +247,7 @@ download_dolby_certificate(string const& serial, std::function yield) for (auto e: errors) { s += e + "\n"; } - throw CertificateDownloadError(s); + throw CertificateReadError(s); } @@ -284,6 +284,36 @@ download_christie_certificate(string serial) } +pair +download_qube_certificate(Manufacturer manufacturer, string const& serial) +{ + static string const base = "ftp://certificates.qubecinema.com/"; + auto files = ls_url(fmt::format("{}SMPTE-{}/", base, _type)); + if (files.empty()) { + throw DownloadError(_("Could not read certificates from Qube server.")); + } + + optional name; + for (auto i: files) { + if (boost::algorithm::starts_with(i, fmt::format("{}-{}-", _type, serial))) { + name = i; + break; + } + } + + if (!name) { + throw DownloadError(fmt::format(_("Could not find serial number {}"), serial)); + } + + try { + auto const url = fmt::format("{}SMPTE-{}/{}", base, _type, *name); + return { dcp::Certificate(get_from_url(url, true, false).as_string()), url }; + } catch (dcp::MiscError& e) { + throw CertificateReadError(e.what()); + } +} + + pair download_certificate(Manufacturer manufacturer, string const& serial, std::function yield) { @@ -296,6 +326,8 @@ download_certificate(Manufacturer manufacturer, string const& serial, std::funct return download_dolby_certificate(serial, yield); case Manufacturer::CHRISTIE: return download_christie_certificate(serial); + case Manufacturer::QUBE: + return download_qube_certificate(serial); } return {}; diff --git a/src/lib/download_certificate.h b/src/lib/download_certificate.h index 60ee4f69f..81902ea87 100644 --- a/src/lib/download_certificate.h +++ b/src/lib/download_certificate.h @@ -28,6 +28,7 @@ enum class Manufacturer BARCO, DOLBY, CHRISTIE, + QUBE, }; diff --git a/src/lib/exceptions.cc b/src/lib/exceptions.cc index dbeae409f..a34d8f90b 100644 --- a/src/lib/exceptions.cc +++ b/src/lib/exceptions.cc @@ -193,7 +193,7 @@ SQLError::get_filename(SQLiteDatabase& db) CertificateReadError::CertificateReadError(string const& detail) - : std::runtime_error(fmt::format(_("Could not read certificate file ({})", detail))) + : std::runtime_error(fmt::format(_("Could not read certificate file ({})"), detail)) { } diff --git a/src/wx/download_certificate_panel.cc b/src/wx/download_certificate_panel.cc index 656e998a2..0f3378559 100644 --- a/src/wx/download_certificate_panel.cc +++ b/src/wx/download_certificate_panel.cc @@ -56,35 +56,10 @@ DownloadCertificatePanel::DownloadCertificatePanel (DownloadCertificateDialog* d } -void -DownloadCertificatePanel::load_certificate(dcp::Data const& data, string url) -{ - try { - _certificate = dcp::Certificate(data.as_string()); - _url = url; - } catch (dcp::MiscError& e) { - throw CertificateDownloadError(fmt::format(wx_to_std(_("Could not read certificate file ({})")), e.what())); - } -} - - -void -DownloadCertificatePanel::load_certificate_from_chain(dcp::Data const& data, string url) -{ - try { - _certificate = dcp::CertificateChain(data.as_string()).leaf(); - _url = url; - } catch (dcp::MiscError& e) { - throw CertificateDownloadError(fmt::format(wx_to_std(_("Could not read certificate file ({})")), e.what())); - } -} - - optional DownloadCertificatePanel::certificate () const { return _certificate; - } diff --git a/src/wx/download_certificate_panel.h b/src/wx/download_certificate_panel.h index c53b30009..05f4e289c 100644 --- a/src/wx/download_certificate_panel.h +++ b/src/wx/download_certificate_panel.h @@ -48,8 +48,6 @@ public: virtual bool ready_to_download () const; void download (); - void load_certificate(dcp::Data const& data, std::string url); - void load_certificate_from_chain(dcp::Data const& data, std::string url); boost::optional certificate () const; boost::optional url () const; diff --git a/src/wx/qube_certificate_panel.cc b/src/wx/qube_certificate_panel.cc index b2603d1b8..0b1b65bde 100644 --- a/src/wx/qube_certificate_panel.cc +++ b/src/wx/qube_certificate_panel.cc @@ -23,6 +23,7 @@ #include "qube_certificate_panel.h" #include "wx_util.h" #include "lib/config.h" +#include "lib/download_certificate.h" #include "lib/internet.h" #include @@ -36,9 +37,6 @@ using namespace boost::placeholders; #endif -static string const base = "ftp://certificates.qubecinema.com/"; - - QubeCertificatePanel::QubeCertificatePanel (DownloadCertificateDialog* dialog, string type) : DownloadCertificatePanel (dialog) , _type (type) @@ -50,33 +48,11 @@ QubeCertificatePanel::QubeCertificatePanel (DownloadCertificateDialog* dialog, s void QubeCertificatePanel::do_download () { - auto files = ls_url(fmt::format("{}SMPTE-{}/", base, _type)); - if (files.empty()) { - error_dialog (this, _("Could not read certificates from Qube server.")); - return; - } - auto serial = wx_to_std(_serial->GetValue()); trim(serial); - optional name; - for (auto i: files) { - if (boost::algorithm::starts_with(i, fmt::format("{}-{}-", _type, serial))) { - name = i; - break; - } - } - - if (!name) { - _dialog->message()->SetLabel({}); - error_dialog (this, wxString::Format(_("Could not find serial number %s"), std_to_wx(serial).data())); - return; - } - try { - auto const url = fmt::format("{}SMPTE-{}/{}", base, _type, *name); - auto const data = get_from_url(url, true, false); - load_certificate(data, url); + std::tie(_certificate, _url) = download_certificate(Manufacturer::GDC, serial, []() { wxYield(); }); _dialog->message()->SetLabel(_("Certificate downloaded")); _dialog->setup_sensitivity (); } catch (std::exception& e) { -- cgit v1.2.3