diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-02-26 13:14:31 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-02-26 13:14:57 +0000 |
| commit | 65a510d3fce55aa4f3aa96cd06f8ab380eb73ed4 (patch) | |
| tree | 8d9c7fb3bb854fd544d185cab65754c747ed27a8 | |
| parent | a5c7ea460adbde2cb87e8d2af0666e4c9c7df0d0 (diff) | |
Make a backup of configuration when we load in a Version 2 file, and bump our config file version to 3.
| -rw-r--r-- | src/lib/config.cc | 37 | ||||
| -rw-r--r-- | src/lib/config.h | 3 |
2 files changed, 26 insertions, 14 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index 503ca9c5f..ec5b05afa 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -64,6 +64,7 @@ using boost::algorithm::trim; using dcp::raw_convert; Config* Config::_instance = 0; +int const Config::_current_version = 3; boost::signals2::signal<void ()> Config::FailedToLoad; boost::signals2::signal<void (string)> Config::Warning; boost::optional<boost::filesystem::path> Config::test_path; @@ -181,6 +182,21 @@ Config::create_certificate_chain () } void +Config::backup () +{ + /* Make a copy of the configuration */ + try { + int n = 1; + while (n < 100 && boost::filesystem::exists(path(String::compose("config.xml.%1", n)))) { + ++n; + } + + boost::filesystem::copy_file(path("config.xml", false), path(String::compose("config.xml.%1", n), false)); + boost::filesystem::copy_file(path("cinemas.xml", false), path(String::compose("cinemas.xml.%1", n), false)); + } catch (...) {} +} + +void Config::read () try { @@ -188,6 +204,10 @@ try f.read_file (config_file ()); optional<int> version = f.optional_number_child<int> ("Version"); + if (version && *version < _current_version) { + /* Back up the old config before we re-write it in a back-incompatible way */ + backup (); + } if (f.optional_number_child<int>("NumLocalEncodingThreads")) { _master_encoding_threads = _server_encoding_threads = f.optional_number_child<int>("NumLocalEncodingThreads").get(); @@ -400,18 +420,7 @@ try } catch (...) { if (have_existing ("config.xml")) { - - /* Make a copy of the configuration */ - try { - int n = 1; - while (n < 100 && boost::filesystem::exists(path(String::compose("config.xml.%1", n)))) { - ++n; - } - - boost::filesystem::copy_file(path("config.xml", false), path(String::compose("config.xml.%1", n), false)); - boost::filesystem::copy_file(path("cinemas.xml", false), path(String::compose("cinemas.xml.%1", n), false)); - } catch (...) {} - + backup (); /* We have a config file but it didn't load */ FailedToLoad (); } @@ -476,8 +485,8 @@ Config::write_config () const xmlpp::Document doc; xmlpp::Element* root = doc.create_root_node ("Config"); - /* [XML] Version The version number of the configuration file format; currently 2. */ - root->add_child("Version")->add_child_text ("2"); + /* [XML] Version The version number of the configuration file format */ + root->add_child("Version")->add_child_text (String::compose ("%1", _current_version)); /* [XML] MasterEncodingThreads Number of encoding threads to use when running as master. */ root->add_child("MasterEncodingThreads")->add_child_text (raw_convert<string> (_master_encoding_threads)); /* [XML] ServerEncodingThreads Number of encoding threads to use when running as server. */ diff --git a/src/lib/config.h b/src/lib/config.h index d50e585e3..90ebb0b33 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -729,6 +729,7 @@ private: boost::shared_ptr<dcp::CertificateChain> create_certificate_chain (); boost::filesystem::path directory_or (boost::optional<boost::filesystem::path> dir, boost::filesystem::path a) const; void add_to_history_internal (std::vector<boost::filesystem::path>& h, boost::filesystem::path p); + void backup (); template <class T> void maybe_set (T& member, T new_value, Property prop = OTHER) { @@ -844,6 +845,8 @@ private: int _frames_in_memory_multiplier; boost::optional<int> _decode_reduction; + static int const _current_version; + /** Singleton instance, or 0 */ static Config* _instance; }; |
