From 267e5cd9a9cd85c90fe80bdf14fead3923fd5489 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 14 Jul 2016 21:20:50 +0100 Subject: Better behaviour if config fails to load. Create a default config if any exception is thrown by ::read, and tell the UI so that it can pop up a message to say what has happened. --- src/lib/config.cc | 24 +++++++++++++++--------- src/lib/config.h | 4 ++++ src/tools/dcpomatic.cc | 7 +++++++ 3 files changed, 26 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/lib/config.cc b/src/lib/config.cc index c483734f8..c6c6cac8b 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -59,6 +59,7 @@ using boost::optional; using boost::algorithm::trim; Config* Config::_instance = 0; +boost::signals2::signal Config::FailedToLoad; /** Construct default configuration */ Config::Config () @@ -143,16 +144,8 @@ Config::create_certificate_chain () void Config::read () +try { - if (!have_existing ("config.xml")) { - /* Make a new set of signing certificates and key */ - _signer_chain = create_certificate_chain (); - /* And similar for decryption of KDMs */ - _decryption_chain = create_certificate_chain (); - write (); - return; - } - cxml::Document f ("Config"); f.read_file (path ("config.xml")); optional c; @@ -305,6 +298,19 @@ Config::read () read_cinemas (f); } } +catch (...) { + if (have_existing ("config.xml")) { + /* We have a config file but it didn't load */ + FailedToLoad (); + } + set_defaults (); + /* Make a new set of signing certificates and key */ + _signer_chain = create_certificate_chain (); + /* And similar for decryption of KDMs */ + _decryption_chain = create_certificate_chain (); + write (); +} + /** @return Filename to write configuration to */ boost::filesystem::path diff --git a/src/lib/config.h b/src/lib/config.h index feaac8390..61c6bfa69 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -483,6 +483,10 @@ public: void changed (Property p = OTHER); boost::signals2::signal Changed; + /** Emitted if ::read() failed on an existing Config file. There is nothing + a listener can do about it: this is just for information. + */ + static boost::signals2::signal FailedToLoad; void write () const; diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index f31464282..88310ad3e 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -1006,6 +1006,8 @@ private: { wxInitAllImageHandlers (); + Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this)); + wxSplashScreen* splash = 0; try { if (!Config::have_existing ("config.xml")) { @@ -1175,6 +1177,11 @@ private: } } + void config_failed_to_load () + { + message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create.")); + } + DOMFrame* _frame; shared_ptr _timer; string _film_to_load; -- cgit v1.2.3