Go back to 10-year certificate validity periods (#2174).
[dcpomatic.git] / src / lib / config.cc
index bfde74a75678e063de6fc90ef136083b5d35850a..abf0eb42bcf6a19d3d2ab4088c618f65c2f9cfc6 100644 (file)
@@ -125,6 +125,9 @@ Config::set_defaults ()
 #ifdef DCPOMATIC_WINDOWS
        _win32_console = false;
 #endif
+       /* At the moment we don't write these files anywhere new after a version change, so they will be read from
+        * ~/.config/dcpomatic2 (or equivalent) and written back there.
+        */
        _cinemas_file = read_path ("cinemas.xml");
        _dkdm_recipients_file = read_path ("dkdm_recipients.xml");
        _show_hints_before_make_dcp = true;
@@ -168,7 +171,6 @@ Config::set_defaults ()
        _image_display = 0;
        _video_view_type = VIDEO_VIEW_SIMPLE;
        _respect_kdm_validity_periods = true;
-       _player_activity_log_file = boost::none;
        _player_debug_log_file = boost::none;
        _player_content_directory = boost::none;
        _player_playlist_directory = boost::none;
@@ -202,6 +204,7 @@ Config::create_certificate_chain ()
 {
        return make_shared<dcp::CertificateChain> (
                openssl_path(),
+               CERTIFICATE_VALIDITY_PERIOD,
                "dcpomatic.com",
                "dcpomatic.com",
                ".dcpomatic.smpte-430-2.ROOT",
@@ -213,17 +216,38 @@ Config::create_certificate_chain ()
 void
 Config::backup ()
 {
-       /* Make a copy of the configuration */
-       try {
+       using namespace boost::filesystem;
+
+       auto copy_adding_number = [](path const& path_to_copy) {
+
+               auto add_number = [](path const& path, int number) {
+                       return String::compose("%1.%2", path, number);
+               };
+
                int n = 1;
-               while (n < 100 && boost::filesystem::exists(write_path(String::compose("config.xml.%1", n)))) {
+               while (n < 100 && exists(add_number(path_to_copy, n))) {
                        ++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
+        * to write over.  This is more intended for the situation where we have a corrupted config.xml,
+        * 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.
+        */
 
-               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 (...) {}
+       /* 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
@@ -535,11 +559,6 @@ try
                _video_view_type = VIDEO_VIEW_SIMPLE;
        }
        _respect_kdm_validity_periods = f.optional_bool_child("RespectKDMValidityPeriods").get_value_or(true);
-       /* PlayerLogFile is old name */
-       _player_activity_log_file = f.optional_string_child("PlayerLogFile");
-       if (!_player_activity_log_file) {
-               _player_activity_log_file = f.optional_string_child("PlayerActivityLogFile");
-       }
        _player_debug_log_file = f.optional_string_child("PlayerDebugLogFile");
        _player_content_directory = f.optional_string_child("PlayerContentDirectory");
        _player_playlist_directory = f.optional_string_child("PlayerPlaylistDirectory");
@@ -573,7 +592,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 ();
@@ -962,10 +981,6 @@ Config::write_config () const
        }
        /* [XML] RespectKDMValidityPeriods 1 to refuse to use KDMs that are out of date, 0 to ignore KDM dates. */
        root->add_child("RespectKDMValidityPeriods")->add_child_text(_respect_kdm_validity_periods ? "1" : "0");
-       if (_player_activity_log_file) {
-               /* [XML] PlayerLogFile Filename to use for player activity logs (e.g starting, stopping, playlist loads) */
-               root->add_child("PlayerActivityLogFile")->add_child_text(_player_activity_log_file->string());
-       }
        if (_player_debug_log_file) {
                /* [XML] PlayerLogFile Filename to use for player debug logs. */
                root->add_child("PlayerDebugLogFile")->add_child_text(_player_debug_log_file->string());