summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-02-19 23:22:31 +0100
committerCarl Hetherington <cth@carlh.net>2024-02-19 23:22:31 +0100
commit51dda295b5bd63e6635ae17786e4657c41a3678a (patch)
tree77e57cb29e188d3b66f9d60c11b5ed6176ad4c93 /src/lib
parent8af709285d056476933dbfaf63c9b2121fbd4ce8 (diff)
parentf23b9491dcd25d02f7966f39dfdbb0ad998aa5ad (diff)
Merge tag 'v2.16.77' into v2.17.x
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/config.cc40
-rw-r--r--src/lib/config.h2
-rw-r--r--src/lib/unzipper.cc89
-rw-r--r--src/lib/unzipper.h43
-rw-r--r--src/lib/wscript1
-rw-r--r--src/lib/zipper.h2
6 files changed, 174 insertions, 3 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc
index 530834bc7..8dce6237a 100644
--- a/src/lib/config.cc
+++ b/src/lib/config.cc
@@ -32,6 +32,7 @@
#include "filter.h"
#include "log.h"
#include "ratio.h"
+#include "unzipper.h"
#include "zipper.h"
#include <dcp/certificate_chain.h>
#include <dcp/name_format.h>
@@ -196,6 +197,7 @@ Config::set_defaults ()
_initial_paths["DebugLogPath"] = boost::none;
_initial_paths["CinemaDatabasePath"] = boost::none;
_initial_paths["ConfigFilePath"] = boost::none;
+ _initial_paths["Preferences"] = boost::none;
_use_isdcf_name_by_default = true;
_write_kdms_to_disk = true;
_email_kdms = false;
@@ -1235,7 +1237,7 @@ void
Config::drop ()
{
delete _instance;
- _instance = 0;
+ _instance = nullptr;
}
void
@@ -1648,6 +1650,38 @@ save_all_config_as_zip (boost::filesystem::path zip_file)
void
+Config::load_from_zip(boost::filesystem::path zip_file)
+{
+ Unzipper unzipper(zip_file);
+ dcp::write_string_to_file(unzipper.get("config.xml"), config_write_file());
+
+ try {
+ dcp::write_string_to_file(unzipper.get("cinemas.xml"), cinemas_file());
+ dcp::write_string_to_file(unzipper.get("dkdm_recipient.xml"), dkdm_recipients_file());
+ } catch (std::runtime_error&) {}
+
+ read();
+
+ changed(Property::USE_ANY_SERVERS);
+ changed(Property::SERVERS);
+ changed(Property::CINEMAS);
+ changed(Property::DKDM_RECIPIENTS);
+ changed(Property::SOUND);
+ changed(Property::SOUND_OUTPUT);
+ changed(Property::PLAYER_CONTENT_DIRECTORY);
+ changed(Property::PLAYER_PLAYLIST_DIRECTORY);
+ changed(Property::PLAYER_DEBUG_LOG);
+ changed(Property::HISTORY);
+ changed(Property::SHOW_EXPERIMENTAL_AUDIO_PROCESSORS);
+ changed(Property::AUDIO_MAPPING);
+ changed(Property::AUTO_CROP_THRESHOLD);
+ changed(Property::ALLOW_SMPTE_BV20);
+ changed(Property::ISDCF_NAME_PART_LENGTH);
+ changed(Property::OTHER);
+}
+
+
+void
Config::set_initial_path(string id, boost::filesystem::path path)
{
auto iter = _initial_paths.find(id);
@@ -1661,7 +1695,9 @@ optional<boost::filesystem::path>
Config::initial_path(string id) const
{
auto iter = _initial_paths.find(id);
- DCPOMATIC_ASSERT(iter != _initial_paths.end());
+ if (iter == _initial_paths.end()) {
+ return {};
+ }
return iter->second;
}
diff --git a/src/lib/config.h b/src/lib/config.h
index d990068ad..74b4316d2 100644
--- a/src/lib/config.h
+++ b/src/lib/config.h
@@ -79,6 +79,8 @@ public:
boost::filesystem::path default_directory_or (boost::filesystem::path a) const;
boost::filesystem::path default_kdm_directory_or (boost::filesystem::path a) const;
+ void load_from_zip(boost::filesystem::path zip_file);
+
enum Property {
USE_ANY_SERVERS,
SERVERS,
diff --git a/src/lib/unzipper.cc b/src/lib/unzipper.cc
new file mode 100644
index 000000000..2add8f2a9
--- /dev/null
+++ b/src/lib/unzipper.cc
@@ -0,0 +1,89 @@
+/*
+ Copyright (C) 2024 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "dcpomatic_assert.h"
+#include "exceptions.h"
+#include "unzipper.h"
+#include <dcp/filesystem.h>
+#include <dcp/scope_guard.h>
+#include <zip.h>
+#include <boost/filesystem.hpp>
+#include <stdexcept>
+
+#include "i18n.h"
+
+
+using std::runtime_error;
+using std::shared_ptr;
+using std::string;
+
+
+Unzipper::Unzipper(boost::filesystem::path file)
+{
+ int error;
+ _zip = zip_open(dcp::filesystem::fix_long_path(file).string().c_str(), ZIP_RDONLY, &error);
+ if (!_zip) {
+ throw FileError("could not open ZIP file", file);
+ }
+}
+
+
+Unzipper::~Unzipper()
+{
+ zip_close(_zip);
+}
+
+
+string
+Unzipper::get(string const& filename)
+{
+ auto file = zip_fopen(_zip, filename.c_str(), 0);
+ if (!file) {
+ throw runtime_error(String::compose(_("Could not find file %1 in ZIP file"), filename));
+ }
+
+ dcp::ScopeGuard sg = [file]() { zip_fclose(file); };
+
+ int constexpr maximum = 65536;
+
+ dcp::ArrayData data(maximum);
+ int remaining = maximum;
+ uint8_t* next = data.data();
+
+ while (remaining > 0) {
+ auto read = zip_fread(file, next, remaining);
+ if (read == 0) {
+ break;
+ } else if (read == -1) {
+ throw runtime_error("Could not read from ZIP file");
+ }
+
+ next += read;
+ remaining -= read;
+ }
+
+ if (remaining == 0) {
+ throw runtime_error("File from ZIP is too big");
+ }
+
+ return string(reinterpret_cast<char*>(data.data()), maximum - remaining);
+}
+
diff --git a/src/lib/unzipper.h b/src/lib/unzipper.h
new file mode 100644
index 000000000..7cab6e5f4
--- /dev/null
+++ b/src/lib/unzipper.h
@@ -0,0 +1,43 @@
+/*
+ Copyright (C) 2024 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include <boost/filesystem.hpp>
+#include <memory>
+#include <vector>
+
+
+class Unzipper
+{
+public:
+ explicit Unzipper(boost::filesystem::path file);
+ ~Unzipper();
+
+ Unzipper(Unzipper const&) = delete;
+ Unzipper& operator=(Unzipper const&) = delete;
+
+ std::string get(std::string const& filename);
+
+private:
+ struct zip* _zip;
+ std::vector<std::shared_ptr<std::string>> _store;
+};
+
+
diff --git a/src/lib/wscript b/src/lib/wscript
index 296a77805..5bae3e0d1 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -198,6 +198,7 @@ sources = """
rough_duration.cc
signal_manager.cc
stdout_log.cc
+ unzipper.cc
update_checker.cc
upload_job.cc
uploader.cc
diff --git a/src/lib/zipper.h b/src/lib/zipper.h
index f554e2e8f..8b634423d 100644
--- a/src/lib/zipper.h
+++ b/src/lib/zipper.h
@@ -27,7 +27,7 @@
class Zipper
{
public:
- Zipper (boost::filesystem::path file);
+ explicit Zipper(boost::filesystem::path file);
~Zipper ();
Zipper (Zipper const&) = delete;