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;
);
}
+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
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();
}
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 ();
}
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. */
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) {
int _frames_in_memory_multiplier;
boost::optional<int> _decode_reduction;
+ static int const _current_version;
+
/** Singleton instance, or 0 */
static Config* _instance;
};