C++11 cleanup.
[dcpomatic.git] / src / lib / config.cc
index f8639692fe0b97013c4beb4c0e8b90fbf46da064..463778887af03b05280177ff3e819c5c56f13bf4 100644 (file)
@@ -185,6 +185,7 @@ Config::set_defaults ()
        _custom_languages.clear ();
        _add_files_path = boost::none;
        _auto_crop_threshold = 0.1;
+       _use_isdcf_name_by_default = true;
 
        _allowed_dcp_frame_rates.clear ();
        _allowed_dcp_frame_rates.push_back (24);
@@ -234,7 +235,8 @@ Config::backup ()
                while (n < 100 && exists(add_number(path_to_copy, n))) {
                        ++n;
                }
-               copy_file(path_to_copy, add_number(path_to_copy, n));
+               boost::system::error_code ec;
+               copy_file(path_to_copy, add_number(path_to_copy, n), ec);
        };
 
        /* Make a backup copy of any config.xml, cinemas.xml, dkdm_recipients.xml that we might be about
@@ -242,18 +244,17 @@ Config::backup ()
         * and decide to overwrite it with a new one (possibly losing important details in the corrupted
         * file).  But we might as well back up the other files while we're about it.
         */
-       try {
-               /* This uses the State::write_path stuff so, e.g. for a current version 2.16 we might copy
-                * ~/.config/dcpomatic2/2.16/config.xml to ~/.config/dcpomatic2/2.16/config.xml.1
-                */
-               copy_adding_number (config_write_file());
 
-               /* These do not use State::write_path, so whatever path is in the Config we will copy
-                * adding a number.
-                */
-               copy_adding_number (_cinemas_file);
-               copy_adding_number (_dkdm_recipients_file);
-       } catch (...) {}
+       /* This uses the State::write_path stuff so, e.g. for a current version 2.16 we might copy
+        * ~/.config/dcpomatic2/2.16/config.xml to ~/.config/dcpomatic2/2.16/config.xml.1
+        */
+       copy_adding_number (config_write_file());
+
+       /* These do not use State::write_path, so whatever path is in the Config we will copy
+        * adding a number.
+        */
+       copy_adding_number (_cinemas_file);
+       copy_adding_number (_dkdm_recipients_file);
 }
 
 void
@@ -586,6 +587,7 @@ try
 
        _add_files_path = f.optional_string_child("AddFilesPath");
        _auto_crop_threshold = f.optional_number_child<double>("AutoCropThreshold").get_value_or(0.1);
+       _use_isdcf_name_by_default = f.optional_bool_child("UseISDCFNameByDefault").get_value_or(true);
 
        if (boost::filesystem::exists (_cinemas_file)) {
                cxml::Document f ("Cinemas");
@@ -600,7 +602,7 @@ try
        }
 }
 catch (...) {
-       if (have_existing ("config.xml")) {
+       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 ();
@@ -617,7 +619,7 @@ catch (...) {
 Config *
 Config::instance ()
 {
-       if (_instance == 0) {
+       if (_instance == nullptr) {
                _instance = new Config;
                _instance->read ();
        }
@@ -1018,6 +1020,7 @@ Config::write_config () const
                root->add_child("AddFilesPath")->add_child_text(_add_files_path->string());
        }
        root->add_child("AutoCropThreshold")->add_child_text(raw_convert<string>(_auto_crop_threshold));
+       root->add_child("UseISDCFNameByDefault")->add_child_text(_use_isdcf_name_by_default ? "1" : "0");
 
        auto target = config_write_file();