Add option to export config as a .zip (#1776).
authorCarl Hetherington <cth@carlh.net>
Sun, 23 Jan 2022 19:47:27 +0000 (20:47 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 23 Jan 2022 19:47:27 +0000 (20:47 +0100)
src/lib/config.cc
src/lib/config.h
src/tools/dcpomatic.cc

index da7082a8eed8ec1ea9ca2242b27128443d37767c..f8639692fe0b97013c4beb4c0e8b90fbf46da064 100644 (file)
@@ -34,6 +34,7 @@
 #include "ratio.h"
 #include "types.h"
 #include "util.h"
+#include "zipper.h"
 #include <dcp/certificate_chain.h>
 #include <dcp/name_format.h>
 #include <dcp/raw_convert.h>
@@ -1477,3 +1478,21 @@ Config::add_custom_language (dcp::LanguageTag tag)
        }
 }
 
+
+void
+save_all_config_as_zip (boost::filesystem::path zip_file)
+{
+       Zipper zipper (zip_file);
+
+       auto config = Config::instance();
+       zipper.add ("config.xml", dcp::file_to_string(config->config_read_file()));
+       if (boost::filesystem::exists(config->cinemas_file())) {
+               zipper.add ("cinemas.xml", dcp::file_to_string(config->cinemas_file()));
+       }
+       if (boost::filesystem::exists(config->dkdm_recipients_file())) {
+               zipper.add ("dkdm_recipients.xml", dcp::file_to_string(config->dkdm_recipients_file()));
+       }
+
+       zipper.close ();
+}
+
index bdf6c83951da3a7a3498052649e1b4ad70eaca16..956d8aa9b6bfa37d1148b3db214fdf90ed110e71 100644 (file)
@@ -44,6 +44,10 @@ class Film;
 class DKDMGroup;
 class DKDMRecipient;
 
+
+extern void save_all_config_as_zip (boost::filesystem::path zip_file);
+
+
 /** @class Config
  *  @brief A singleton class holding configuration.
  */
index 1daa75de0a839f37c7f9b1a0955ca2b7b6eaf58a..2482a9cb53cacefe2ad0aafa85d2e30f05884aa9 100644 (file)
@@ -257,6 +257,7 @@ enum {
        ID_tools_check_for_updates,
        ID_tools_send_translations,
        ID_tools_restore_default_preferences,
+       ID_tools_export_preferences,
        ID_help_report_a_problem,
        /* IDs for shortcuts (with no associated menu item) */
        ID_add_file,
@@ -339,6 +340,7 @@ public:
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_send_translations, this), ID_tools_send_translations);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_restore_default_preferences, this), ID_tools_restore_default_preferences);
+               Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_export_preferences, this), ID_tools_export_preferences);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this),              wxID_ABOUT);
                Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this),   ID_help_report_a_problem);
 
@@ -738,6 +740,21 @@ private:
                }
        }
 
+       void tools_export_preferences ()
+       {
+               auto dialog = new wxFileDialog (
+                       this, _("Specify ZIP file"), wxEmptyString, wxT("dcpomatic_config.zip"), wxT("ZIP files (*.zip)|*.zip"),
+                       wxFD_SAVE | wxFD_OVERWRITE_PROMPT
+                       );
+
+               int const r = dialog->ShowModal ();
+               dialog->Destroy ();
+
+               if (r == wxID_OK) {
+                       save_all_config_as_zip (wx_to_std(dialog->GetPath()));
+               }
+       }
+
        void jobs_make_dcp ()
        {
                double required;
@@ -1366,6 +1383,8 @@ private:
                add_item (tools, _("Send translations..."), ID_tools_send_translations, 0);
                tools->AppendSeparator ();
                add_item (tools, _("Restore default preferences"), ID_tools_restore_default_preferences, ALWAYS);
+               tools->AppendSeparator ();
+               add_item (tools, _("Export preferences..."), ID_tools_export_preferences, ALWAYS);
 
                wxMenu* help = new wxMenu;
 #ifdef __WXOSX__