Better behaviour if config fails to load.
authorCarl Hetherington <cth@carlh.net>
Thu, 14 Jul 2016 20:20:50 +0000 (21:20 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 14 Jul 2016 20:20:50 +0000 (21:20 +0100)
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.

ChangeLog
src/lib/config.cc
src/lib/config.h
src/tools/dcpomatic.cc

index efe48eca295b16de18fb413adf685165e21c13ff..2e05ac7f05319b99326bbab1fe6edd11debc07ff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-07-14  Carl Hetherington  <cth@carlh.net>
+
+       * Use default configuration if the config.xml failed to load;
+       may help with #917.
+
 2016-07-12  Carl Hetherington  <cth@carlh.net>
 
        * Version 2.9.2 released.
index c483734f85f5f40a71220d01a6c90606b36cd2d5..c6c6cac8b3d38be39e650d13f2ebb9a17aa1177e 100644 (file)
@@ -59,6 +59,7 @@ using boost::optional;
 using boost::algorithm::trim;
 
 Config* Config::_instance = 0;
+boost::signals2::signal<void ()> 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<string> 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
index feaac8390842b902559ea3d90e86f7e0156f7d5e..61c6bfa69f8fa1eb3d980244d8c63cdab25c3c56 100644 (file)
@@ -483,6 +483,10 @@ public:
 
        void changed (Property p = OTHER);
        boost::signals2::signal<void (Property)> 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<void ()> FailedToLoad;
 
        void write () const;
 
index f3146428216ce3d90e2a88076dc282f689768224..88310ad3ef42dc9d6f7dee1c3498b5f56fe8d59a 100644 (file)
@@ -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<wxTimer> _timer;
        string _film_to_load;