Add a description of which part of the config failed to load.
[dcpomatic.git] / src / lib / config.cc
index c9b42857149a665da7fdc901c8fdfeb41751bf21..94595f9f8ac88a78d7a9df26035dac5539799b7e 100644 (file)
@@ -69,7 +69,7 @@ using dcp::raw_convert;
 
 Config* Config::_instance = 0;
 int const Config::_current_version = 3;
-boost::signals2::signal<void ()> Config::FailedToLoad;
+boost::signals2::signal<void (Config::LoadFailure)> Config::FailedToLoad;
 boost::signals2::signal<void (string)> Config::Warning;
 boost::signals2::signal<bool (Config::BadReason)> Config::Bad;
 
@@ -270,6 +270,15 @@ Config::backup ()
 
 void
 Config::read ()
+{
+       read_config();
+       read_cinemas();
+       read_dkdm_recipients();
+}
+
+
+void
+Config::read_config()
 try
 {
        cxml::Document f ("Config");
@@ -597,24 +606,12 @@ try
        _last_release_notes_version = f.optional_string_child("LastReleaseNotesVersion");
 
        _export.read(f.optional_node_child("Export"));
-
-       if (boost::filesystem::exists (_cinemas_file)) {
-               cxml::Document f ("Cinemas");
-               f.read_file (_cinemas_file);
-               read_cinemas (f);
-       }
-
-       if (boost::filesystem::exists (_dkdm_recipients_file)) {
-               cxml::Document f ("DKDMRecipients");
-               f.read_file (_dkdm_recipients_file);
-               read_dkdm_recipients (f);
-       }
 }
 catch (...) {
        if (have_existing("config.xml") || have_existing("cinemas.xml") || have_existing("dkdm_recipients.xml")) {
                backup ();
                /* We have a config file but it didn't load */
-               FailedToLoad ();
+               FailedToLoad(LoadFailure::CONFIG);
        }
        set_defaults ();
        /* Make a new set of signing certificates and key */
@@ -624,6 +621,29 @@ catch (...) {
        write ();
 }
 
+
+void
+Config::read_cinemas()
+{
+       if (boost::filesystem::exists (_cinemas_file)) {
+               cxml::Document f ("Cinemas");
+               f.read_file (_cinemas_file);
+               read_cinemas (f);
+       }
+}
+
+
+void
+Config::read_dkdm_recipients()
+{
+       if (boost::filesystem::exists (_dkdm_recipients_file)) {
+               cxml::Document f ("DKDMRecipients");
+               f.read_file (_dkdm_recipients_file);
+               read_dkdm_recipients (f);
+       }
+}
+
+
 /** @return Singleton instance */
 Config *
 Config::instance ()