diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-09-27 11:55:27 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-09-27 11:55:27 +0200 |
| commit | 6e3e984162ca7a181bc7c98d90c295e88e4e7f6c (patch) | |
| tree | f514e6618e9012c307188a11a9d2a2ade2e04d19 /src | |
| parent | a3d4dfb4357a265d4c3a4bfafe7d17a8ecc72f66 (diff) | |
| parent | 0771af91ad52ed2e25ab89410eb6e783b50f7329 (diff) | |
Merge branch 'own-config' into v2.15.x
This makes 2.15.x copy the 2.14.x configuration so you can run 2.14.x
again afterwards without recreating everything.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/analytics.cc | 6 | ||||
| -rw-r--r-- | src/lib/config.cc | 105 | ||||
| -rw-r--r-- | src/lib/config.h | 8 | ||||
| -rw-r--r-- | src/lib/cross.h | 2 | ||||
| -rw-r--r-- | src/lib/cross_linux.cc | 8 | ||||
| -rw-r--r-- | src/lib/cross_osx.cc | 5 | ||||
| -rw-r--r-- | src/lib/cross_windows.cc | 5 | ||||
| -rw-r--r-- | src/lib/film.cc | 2 | ||||
| -rw-r--r-- | src/lib/state.cc | 59 | ||||
| -rw-r--r-- | src/lib/state.h | 3 | ||||
| -rw-r--r-- | src/tools/dcpomatic.cc | 2 | ||||
| -rw-r--r-- | src/tools/dcpomatic_disk.cc | 2 | ||||
| -rw-r--r-- | src/tools/dcpomatic_disk_writer.cc | 4 | ||||
| -rw-r--r-- | src/wx/full_config_dialog.cc | 6 |
14 files changed, 135 insertions, 82 deletions
diff --git a/src/lib/analytics.cc b/src/lib/analytics.cc index ac0abc222..7483166ba 100644 --- a/src/lib/analytics.cc +++ b/src/lib/analytics.cc @@ -96,11 +96,11 @@ Analytics::write () const root->add_child("SuccessfulDCPEncodes")->add_child_text(raw_convert<string>(_successful_dcp_encodes)); try { - doc.write_to_file_formatted(path("analytics.xml").string()); + doc.write_to_file_formatted(write_path("analytics.xml").string()); } catch (xmlpp::exception& e) { string s = e.what (); trim (s); - throw FileError (s, path("analytics.xml")); + throw FileError (s, write_path("analytics.xml")); } } @@ -110,7 +110,7 @@ Analytics::read () try { cxml::Document f ("Analytics"); - f.read_file (path("analytics.xml")); + f.read_file (read_path("analytics.xml")); _successful_dcp_encodes = f.number_child<int>("SuccessfulDCPEncodes"); } catch (...) { /* Never mind */ diff --git a/src/lib/config.cc b/src/lib/config.cc index ed00d274b..4924d13ba 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -56,8 +56,6 @@ using std::list; using std::min; using std::max; using std::remove; -using std::exception; -using std::cerr; using std::shared_ptr; using std::make_shared; using boost::optional; @@ -127,8 +125,8 @@ Config::set_defaults () #ifdef DCPOMATIC_WINDOWS _win32_console = false; #endif - _cinemas_file = path ("cinemas.xml"); - _dkdm_recipients_file = path ("dkdm_recipients.xml"); + _cinemas_file = read_path ("cinemas.xml"); + _dkdm_recipients_file = read_path ("dkdm_recipients.xml"); _show_hints_before_make_dcp = true; _confirm_kdm_email = true; _kdm_container_name_format = dcp::NameFormat ("KDM %f %c"); @@ -218,13 +216,13 @@ 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)))) { + while (n < 100 && boost::filesystem::exists(write_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)); - boost::filesystem::copy_file(path("dkdm_recipients.xml", false), path(String::compose("dkdm_recipients.xml.%1", n), false)); + boost::filesystem::copy_file(read_path("config.xml"), write_path(String::compose("config.xml.%1", n))); + boost::filesystem::copy_file(read_path("cinemas.xml"), write_path(String::compose("cinemas.xml.%1", n))); + boost::filesystem::copy_file(read_path("dkdm_recipients.xml"), write_path(String::compose("dkdm_recipients.xml.%1", n))); } catch (...) {} } @@ -233,7 +231,7 @@ Config::read () try { cxml::Document f ("Config"); - f.read_file (config_file ()); + f.read_file (config_read_file()); auto version = f.optional_number_child<int> ("Version"); if (version && *version < _current_version) { @@ -469,8 +467,8 @@ try _dkdms->add (DKDMBase::read (i)); } } - _cinemas_file = f.optional_string_child("CinemasFile").get_value_or (path ("cinemas.xml").string ()); - _dkdm_recipients_file = f.optional_string_child("DKDMRecipientsFile").get_value_or (path("dkdm_recipients.xml").string()); + _cinemas_file = f.optional_string_child("CinemasFile").get_value_or(read_path("cinemas.xml").string()); + _dkdm_recipients_file = f.optional_string_child("DKDMRecipientsFile").get_value_or(read_path("dkdm_recipients.xml").string()); _show_hints_before_make_dcp = f.optional_bool_child("ShowHintsBeforeMakeDCP").get_value_or (true); _confirm_kdm_email = f.optional_bool_child("ConfirmKDMEmail").get_value_or (true); _kdm_container_name_format = dcp::NameFormat (f.optional_string_child("KDMContainerNameFormat").get_value_or ("KDM %f %c")); @@ -995,21 +993,23 @@ Config::write_config () const root->add_child("AddFilesPath")->add_child_text(_add_files_path->string()); } + auto target = config_write_file(); + try { auto const s = doc.write_to_string_formatted (); - boost::filesystem::path tmp (string(config_file().string()).append(".tmp")); + boost::filesystem::path tmp (string(target.string()).append(".tmp")); auto f = fopen_boost (tmp, "w"); if (!f) { throw FileError (_("Could not open file for writing"), tmp); } checked_fwrite (s.c_str(), s.bytes(), f, tmp); fclose (f); - boost::filesystem::remove (config_file()); - boost::filesystem::rename (tmp, config_file()); + boost::filesystem::remove (target); + boost::filesystem::rename (tmp, target); } catch (xmlpp::exception& e) { string s = e.what (); trim (s); - throw FileError (s, config_file()); + throw FileError (s, target); } } @@ -1203,12 +1203,14 @@ Config::clean_history_internal (vector<boost::filesystem::path>& h) } } + bool Config::have_existing (string file) { - return boost::filesystem::exists (path (file, false)); + return boost::filesystem::exists (read_path(file)); } + void Config::read_cinemas (cxml::Document const & f) { @@ -1252,41 +1254,23 @@ Config::read_dkdm_recipients (cxml::Document const & f) } } -void -Config::set_dkdm_recipients_file (boost::filesystem::path file) -{ - if (file == _dkdm_recipients_file) { - return; - } - - _dkdm_recipients_file = file; - - if (boost::filesystem::exists (_dkdm_recipients_file)) { - /* Existing file; read it in */ - cxml::Document f ("DKDMRecipients"); - f.read_file (_dkdm_recipients_file); - read_dkdm_recipients (f); - } - - changed (OTHER); -} - void Config::save_template (shared_ptr<const Film> film, string name) const { - film->write_template (template_path (name)); + film->write_template (template_write_path(name)); } + list<string> Config::templates () const { - if (!boost::filesystem::exists (path ("templates"))) { + if (!boost::filesystem::exists(read_path("templates"))) { return {}; } list<string> n; - for (auto const& i: boost::filesystem::directory_iterator(path("templates"))) { + for (auto const& i: boost::filesystem::directory_iterator(read_path("templates"))) { n.push_back (i.path().filename().string()); } return n; @@ -1295,33 +1279,41 @@ Config::templates () const bool Config::existing_template (string name) const { - return boost::filesystem::exists (template_path (name)); + return boost::filesystem::exists (template_read_path(name)); +} + + +boost::filesystem::path +Config::template_read_path (string name) const +{ + return read_path("templates") / tidy_for_filename (name); } + boost::filesystem::path -Config::template_path (string name) const +Config::template_write_path (string name) const { - return path("templates") / tidy_for_filename (name); + return write_path("templates") / tidy_for_filename (name); } + void Config::rename_template (string old_name, string new_name) const { - boost::filesystem::rename (template_path (old_name), template_path (new_name)); + boost::filesystem::rename (template_read_path(old_name), template_write_path(new_name)); } void Config::delete_template (string name) const { - boost::filesystem::remove (template_path (name)); + boost::filesystem::remove (template_write_path(name)); } /** @return Path to the config.xml containing the actual settings, following a link if required */ boost::filesystem::path -Config::config_file () +config_file (boost::filesystem::path main) { cxml::Document f ("Config"); - auto main = path("config.xml", false); if (!boost::filesystem::exists (main)) { /* It doesn't exist, so there can't be any links; just return it */ return main; @@ -1343,6 +1335,21 @@ Config::config_file () return main; } + +boost::filesystem::path +Config::config_read_file () +{ + return config_file (read_path("config.xml")); +} + + +boost::filesystem::path +Config::config_write_file () +{ + return config_file (write_path("config.xml")); +} + + void Config::reset_cover_sheet () { @@ -1356,11 +1363,11 @@ Config::link (boost::filesystem::path new_file) const xmlpp::Document doc; doc.create_root_node("Config")->add_child("Link")->add_child_text(new_file.string()); try { - doc.write_to_file_formatted(path("config.xml", true).string()); + doc.write_to_file_formatted(write_path("config.xml").string()); } catch (xmlpp::exception& e) { string s = e.what (); trim (s); - throw FileError (s, path("config.xml")); + throw FileError (s, write_path("config.xml")); } } @@ -1368,14 +1375,14 @@ void Config::copy_and_link (boost::filesystem::path new_file) const { write (); - boost::filesystem::copy_file (config_file(), new_file, boost::filesystem::copy_option::overwrite_if_exists); + boost::filesystem::copy_file (config_read_file(), new_file, boost::filesystem::copy_option::overwrite_if_exists); link (new_file); } bool Config::have_write_permission () const { - auto f = fopen_boost (config_file(), "r+"); + auto f = fopen_boost (config_write_file(), "r+"); if (!f) { return false; } diff --git a/src/lib/config.h b/src/lib/config.h index 46bd390cc..c9206b139 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -827,8 +827,6 @@ public: void set_cinemas_file (boost::filesystem::path file); - void set_dkdm_recipients_file (boost::filesystem::path file); - void set_show_hints_before_make_dcp (bool s) { maybe_set (_show_hints_before_make_dcp, s); } @@ -1095,7 +1093,8 @@ public: void save_template (std::shared_ptr<const Film> film, std::string name) const; bool existing_template (std::string name) const; std::list<std::string> templates () const; - boost::filesystem::path template_path (std::string name) const; + boost::filesystem::path template_read_path (std::string name) const; + boost::filesystem::path template_write_path (std::string name) const; void rename_template (std::string old_name, std::string new_name) const; void delete_template (std::string name) const; @@ -1103,7 +1102,8 @@ public: static void drop (); static void restore_defaults (); static bool have_existing (std::string); - static boost::filesystem::path config_file (); + static boost::filesystem::path config_read_file (); + static boost::filesystem::path config_write_file (); private: Config (); diff --git a/src/lib/cross.h b/src/lib/cross.h index 919113305..ed1d0c8e7 100644 --- a/src/lib/cross.h +++ b/src/lib/cross.h @@ -64,7 +64,7 @@ extern int avio_open_boost (AVIOContext** s, boost::filesystem::path file, int f extern boost::filesystem::path home_directory (); extern bool running_32_on_64 (); extern void unprivileged (); -extern boost::filesystem::path config_path (); +extern boost::filesystem::path config_path (boost::optional<std::string> version); extern boost::filesystem::path directory_containing_executable (); extern boost::filesystem::path fix_long_path (boost::filesystem::path path); extern bool show_in_file_manager (boost::filesystem::path dir, boost::filesystem::path select); diff --git a/src/lib/cross_linux.cc b/src/lib/cross_linux.cc index d142c416f..ee49d50bc 100644 --- a/src/lib/cross_linux.cc +++ b/src/lib/cross_linux.cc @@ -52,13 +52,10 @@ DCPOMATIC_ENABLE_WARNINGS using std::cerr; using std::cout; -using std::function; using std::ifstream; using std::list; using std::make_pair; using std::pair; -using std::runtime_error; -using std::shared_ptr; using std::string; using std::vector; using std::wstring; @@ -382,11 +379,14 @@ Drive::unmount () boost::filesystem::path -config_path () +config_path (optional<string> version) { boost::filesystem::path p; p /= g_get_user_config_dir (); p /= "dcpomatic2"; + if (version) { + p /= *version; + } return p; } diff --git a/src/lib/cross_osx.cc b/src/lib/cross_osx.cc index d0cb9f216..ff40ffb70 100644 --- a/src/lib/cross_osx.cc +++ b/src/lib/cross_osx.cc @@ -552,7 +552,7 @@ Drive::get () boost::filesystem::path -config_path () +config_path (optional<string> version) { boost::filesystem::path p; p /= g_get_home_dir (); @@ -560,6 +560,9 @@ config_path () p /= "Preferences"; p /= "com.dcpomatic"; p /= "2"; + if (version) { + p /= *version; + } return p; } diff --git a/src/lib/cross_windows.cc b/src/lib/cross_windows.cc index 723828d7e..b3d9a1558 100644 --- a/src/lib/cross_windows.cc +++ b/src/lib/cross_windows.cc @@ -672,11 +672,14 @@ Drive::unmount () boost::filesystem::path -config_path () +config_path (optional<string> version) { boost::filesystem::path p; p /= g_get_user_config_dir (); p /= "dcpomatic2"; + if (version) { + p /= *version; + } return p; } diff --git a/src/lib/film.cc b/src/lib/film.cc index 3e6430ee3..0d277b82a 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1921,7 +1921,7 @@ void Film::use_template (string name) { _template_film.reset (new Film (optional<boost::filesystem::path>())); - _template_film->read_metadata (Config::instance()->template_path (name)); + _template_film->read_metadata (Config::instance()->template_read_path(name)); _use_isdcf_name = _template_film->_use_isdcf_name; _dcp_content_type = _template_film->_dcp_content_type; _container = _template_film->_container; diff --git a/src/lib/state.cc b/src/lib/state.cc index 5f7e9a701..e22f9e0b9 100644 --- a/src/lib/state.cc +++ b/src/lib/state.cc @@ -19,33 +19,70 @@ */ -#include "state.h" #include "cross.h" +#include "state.h" +#include "util.h" #include <glib.h> using std::string; +using boost::optional; boost::optional<boost::filesystem::path> State::override_path; +/* List of config versions to look for in descending order of preference; + * i.e. look at the first one, and if that doesn't exist, try the second, etc. + */ +static std::vector<std::string> config_versions = { "2.16" }; + + +static +boost::filesystem::path +config_path_or_override (optional<string> version) +{ + if (State::override_path) { + auto p = *State::override_path; + if (version) { + p /= *version; + } + return p; + } + + return config_path (version); +} + + /** @param file State filename - * @return Full path to write @file to. + * @return Full path to read @file from. */ boost::filesystem::path -State::path (string file, bool create_directories) +State::read_path (string file) { - boost::filesystem::path p; - if (override_path) { - p = *override_path; - } else { - p = config_path (); + using namespace boost::filesystem; + + for (auto i: config_versions) { + auto full = config_path_or_override(i) / file; + if (exists(full)) { + return full; + } } + + return config_path_or_override({}) / file; +} + + +/** @param file State filename + * @return Full path to write @file to. + */ +boost::filesystem::path +State::write_path (string file) +{ + boost::filesystem::path p = config_path_or_override(config_versions.front()); boost::system::error_code ec; - if (create_directories) { - boost::filesystem::create_directories (p, ec); - } + boost::filesystem::create_directories (p, ec); p /= file; return p; } + diff --git a/src/lib/state.h b/src/lib/state.h index f1ed775a2..9338aae0c 100644 --- a/src/lib/state.h +++ b/src/lib/state.h @@ -40,7 +40,8 @@ public: /** If set, this overrides the standard path (in home, Library, AppData or wherever) for config.xml, cinemas.xml etc. */ static boost::optional<boost::filesystem::path> override_path; - static boost::filesystem::path path (std::string file, bool create_directories = true); + static boost::filesystem::path read_path (std::string file); + static boost::filesystem::path write_path (std::string file); }; diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index ca45963f4..0b7f632e1 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -933,7 +933,7 @@ private: _("You are making a DKDM which is encrypted by a private key held in" "\n\n<tt>%s</tt>\n\nIt is <span weight=\"bold\" size=\"larger\">VITALLY IMPORTANT</span> " "that you <span weight=\"bold\" size=\"larger\">BACK UP THIS FILE</span> since if it is lost " - "your DKDMs (and the DCPs they protect) will become useless."), std_to_wx(Config::config_file().string()).data() + "your DKDMs (and the DCPs they protect) will become useless."), std_to_wx(Config::config_read_file().string()).data() ) ); diff --git a/src/tools/dcpomatic_disk.cc b/src/tools/dcpomatic_disk.cc index 7e43c0684..ec5d8e782 100644 --- a/src/tools/dcpomatic_disk.cc +++ b/src/tools/dcpomatic_disk.cc @@ -139,7 +139,7 @@ public: /* XXX: this is a hack, but I expect we'll need logs and I'm not sure if there's * a better place to put them. */ - dcpomatic_log.reset(new FileLog(config_path() / "disk.log")); + dcpomatic_log = make_shared<FileLog>(State::write_path("disk.log")); dcpomatic_log->set_types (dcpomatic_log->types() | LogEntry::TYPE_DISK); LOG_DISK("dcpomatic_disk %1 started", dcpomatic_git_commit); diff --git a/src/tools/dcpomatic_disk_writer.cc b/src/tools/dcpomatic_disk_writer.cc index c638b72eb..ef384bbba 100644 --- a/src/tools/dcpomatic_disk_writer.cc +++ b/src/tools/dcpomatic_disk_writer.cc @@ -27,7 +27,9 @@ #include "lib/exceptions.h" #include "lib/ext.h" #include "lib/file_log.h" +#include "lib/state.h" #include "lib/nanomsg.h" +#include "lib/util.h" #include "lib/version.h" #include "lib/warnings.h" @@ -288,7 +290,7 @@ main () /* XXX: this is a hack, but I expect we'll need logs and I'm not sure if there's * a better place to put them. */ - dcpomatic_log.reset(new FileLog(config_path() / "disk_writer.log", LogEntry::TYPE_DISK)); + dcpomatic_log.reset(new FileLog(State::write_path("disk_writer.log"), LogEntry::TYPE_DISK)); LOG_DISK_NC("dcpomatic_disk_writer started"); #endif diff --git a/src/wx/full_config_dialog.cc b/src/wx/full_config_dialog.cc index 1d0c1e01a..dcfcf394b 100644 --- a/src/wx/full_config_dialog.cc +++ b/src/wx/full_config_dialog.cc @@ -153,7 +153,7 @@ private: checked_set (_analyse_ebur128, config->analyse_ebur128 ()); #endif checked_set (_automatic_audio_analysis, config->automatic_audio_analysis ()); - checked_set (_config_file, config->config_file()); + checked_set (_config_file, config->config_read_file()); checked_set (_cinemas_file, config->cinemas_file()); GeneralPage::config_changed (); @@ -198,7 +198,7 @@ private: { auto config = Config::instance(); boost::filesystem::path new_file = wx_to_std(_config_file->GetPath()); - if (new_file == config->config_file()) { + if (new_file == config->config_read_file()) { return; } bool copy_and_link = true; @@ -212,7 +212,7 @@ private: if (copy_and_link) { config->write (); - if (new_file != config->config_file()) { + if (new_file != config->config_read_file()) { config->copy_and_link (new_file); } } else { |
