diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-03-17 11:53:28 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-03-18 23:30:48 +0100 |
| commit | cf4e4272f72346c39964b128f78b2297f04dba55 (patch) | |
| tree | 380d760483d5bf2cec0e33db42e82207b387ecb4 /src | |
| parent | b0b3c6f0cdc034ef515f72d72fd72fbb71d1ca63 (diff) | |
Tidy how we're finding the tags and xsd directories.
Diffstat (limited to 'src')
| -rw-r--r-- | src/util.cc | 42 | ||||
| -rw-r--r-- | src/util.h | 7 | ||||
| -rw-r--r-- | src/verify.cc | 19 | ||||
| -rw-r--r-- | src/verify.h | 2 |
4 files changed, 52 insertions, 18 deletions
diff --git a/src/util.cc b/src/util.cc index 7c21c889..0b011bf9 100644 --- a/src/util.cc +++ b/src/util.cc @@ -56,8 +56,11 @@ #include <libxml++/nodes/element.h> #include <libxml++/document.h> #include <openssl/sha.h> -#include <boost/filesystem.hpp> #include <boost/algorithm/string.hpp> +#if BOOST_VERSION >= 106100 +#include <boost/dll/runtime_symbol_info.hpp> +#endif +#include <boost/filesystem.hpp> #include <stdexcept> #include <iostream> #include <iomanip> @@ -192,12 +195,7 @@ dcp::init (optional<boost::filesystem::path> tags_directory) asdcp_smpte_dict = &ASDCP::DefaultSMPTEDict(); if (!tags_directory) { - char* prefix = getenv("LIBDCP_SHARE_PREFIX"); - if (prefix) { - tags_directory = boost::filesystem::path(prefix) / "tags"; - } else { - tags_directory = LIBDCP_SHARE_PREFIX "/tags"; - } + tags_directory = resources_directory() / "tags"; } load_language_tag_lists (*tags_directory); @@ -440,3 +438,33 @@ ASDCPErrorSuspender::~ASDCPErrorSuspender () delete _sink; } + +boost::filesystem::path dcp::directory_containing_executable () +{ +#if BOOST_VERSION >= 106100 + return boost::filesystem::canonical(boost::dll::program_location().parent_path()); +#else + char buffer[PATH_MAX]; + ssize_t N = readlink ("/proc/self/exe", buffer, PATH_MAX); + return boost::filesystem::path(string(buffer, N)).parent_path(); +#endif +} + + +boost::filesystem::path dcp::resources_directory () +{ +#if defined(LIBDCP_OSX) + return directory_containing_executable().parent_path() / "Resources"; +#elif defined(LIBDCP_WINDOWS) + return directory_containing_executable().parent_path(); +#else + /* We need a way to specify the tags directory for running un-installed binaries */ + char* prefix = getenv("LIBDCP_RESOURCES"); + if (prefix) { + return prefix; + } + return directory_containing_executable().parent_path() / "share" / "libdcp"; +#endif +} + + @@ -94,8 +94,8 @@ extern std::string remove_urn_uuid (std::string raw); * by client applications. * * @param tags_directory Path to a copy of the tags directory from the source code; - * if none is specified libdcp will look for a tags directory inside the environment - * variable LIBDCP_SHARE_PREFIX or the LIBDCP_SHARE_PREFIX #defined during the build. + * if none is specified libdcp will look for a tags directory in the environment + * variable LIBDCP_RESOURCES or based on where the current executable is. */ extern void init (boost::optional<boost::filesystem::path> tags_directory = boost::optional<boost::filesystem::path>()); @@ -150,6 +150,9 @@ extern std::string unique_string (std::vector<std::string> existing, std::string extern ASDCP::Dictionary const* asdcp_smpte_dict; +extern boost::filesystem::path directory_containing_executable (); +extern boost::filesystem::path resources_directory (); + class ASDCPErrorSuspender { diff --git a/src/verify.cc b/src/verify.cc index 97758e61..8c367563 100644 --- a/src/verify.cc +++ b/src/verify.cc @@ -1104,17 +1104,20 @@ dcp::verify ( vector<boost::filesystem::path> directories, function<void (string, optional<boost::filesystem::path>)> stage, function<void (float)> progress, - boost::filesystem::path xsd_dtd_directory + optional<boost::filesystem::path> xsd_dtd_directory ) { - xsd_dtd_directory = boost::filesystem::canonical (xsd_dtd_directory); + if (!xsd_dtd_directory) { + xsd_dtd_directory = resources_directory() / "xsd"; + } + *xsd_dtd_directory = boost::filesystem::canonical (*xsd_dtd_directory); vector<VerificationNote> notes; State state{}; vector<shared_ptr<DCP>> dcps; for (auto i: directories) { - dcps.push_back (shared_ptr<DCP> (new DCP (i))); + dcps.push_back (make_shared<DCP>(i)); } for (auto dcp: dcps) { @@ -1137,7 +1140,7 @@ dcp::verify ( for (auto cpl: dcp->cpls()) { stage ("Checking CPL", cpl->file()); - validate_xml (cpl->file().get(), xsd_dtd_directory, notes); + validate_xml (cpl->file().get(), *xsd_dtd_directory, notes); if (cpl->any_encrypted() && !cpl->all_encrypted()) { notes.push_back ({VerificationNote::Type::BV21_ERROR, VerificationNote::Code::PARTIALLY_ENCRYPTED}); @@ -1266,7 +1269,7 @@ dcp::verify ( if (reel->main_subtitle()) { verify_main_subtitle_reel (reel->main_subtitle(), notes); if (reel->main_subtitle()->asset_ref().resolved()) { - verify_subtitle_asset (reel->main_subtitle()->asset(), stage, xsd_dtd_directory, notes, state); + verify_subtitle_asset (reel->main_subtitle()->asset(), stage, *xsd_dtd_directory, notes, state); } have_main_subtitle = true; } else { @@ -1276,7 +1279,7 @@ dcp::verify ( for (auto i: reel->closed_captions()) { verify_closed_caption_reel (i, notes); if (i->asset_ref().resolved()) { - verify_closed_caption_asset (i->asset(), stage, xsd_dtd_directory, notes); + verify_closed_caption_asset (i->asset(), stage, *xsd_dtd_directory, notes); } } @@ -1384,7 +1387,7 @@ dcp::verify ( for (auto pkl: dcp->pkls()) { stage ("Checking PKL", pkl->file()); - validate_xml (pkl->file().get(), xsd_dtd_directory, notes); + validate_xml (pkl->file().get(), *xsd_dtd_directory, notes); if (pkl_has_encrypted_assets(dcp, pkl)) { cxml::Document doc ("PackingList"); doc.read_file (pkl->file().get()); @@ -1396,7 +1399,7 @@ dcp::verify ( if (dcp->asset_map_path()) { stage ("Checking ASSETMAP", dcp->asset_map_path().get()); - validate_xml (dcp->asset_map_path().get(), xsd_dtd_directory, notes); + validate_xml (dcp->asset_map_path().get(), *xsd_dtd_directory, notes); } else { notes.push_back ({VerificationNote::Type::ERROR, VerificationNote::Code::MISSING_ASSETMAP}); } diff --git a/src/verify.h b/src/verify.h index 16700127..f14382c5 100644 --- a/src/verify.h +++ b/src/verify.h @@ -436,7 +436,7 @@ std::vector<VerificationNote> verify ( std::vector<boost::filesystem::path> directories, boost::function<void (std::string, boost::optional<boost::filesystem::path>)> stage, boost::function<void (float)> progress, - boost::filesystem::path xsd_dtd_directory + boost::optional<boost::filesystem::path> xsd_dtd_directory = boost::optional<boost::filesystem::path>() ); std::string note_to_string (dcp::VerificationNote note); |
