46 #include "filesystem.h"
50 #include <boost/filesystem.hpp>
56 using std::dynamic_pointer_cast;
59 using std::shared_ptr;
62 using boost::optional;
65 boost::filesystem::path
66 make_unique (boost::filesystem::path path)
68 if (!dcp::filesystem::exists(path)) {
72 for (
int i = 0; i < 10000; ++i) {
73 boost::filesystem::path p = path.parent_path() / (path.stem().string() + dcp::raw_convert<string>(i) + path.extension().string());
74 if (!dcp::filesystem::exists(p)) {
86 create_hard_link_or_copy (boost::filesystem::path from, boost::filesystem::path to)
89 dcp::filesystem::create_hard_link(from, to);
90 }
catch (boost::filesystem::filesystem_error& e) {
91 if (e.code() == boost::system::errc::cross_device_link) {
92 dcp::filesystem::copy_file(from, to);
102 vector<boost::filesystem::path> inputs,
103 boost::filesystem::path output,
107 string annotation_text,
108 shared_ptr<const CertificateChain> signer
111 DCP_ASSERT (!inputs.empty());
113 DCP output_dcp (output);
114 optional<dcp::Standard> standard;
116 for (
auto i: inputs) {
120 standard = *
dcp.standard();
121 }
else if (standard !=
dcp.standard()) {
122 throw CombineError (
"Cannot combine Interop and SMPTE DCPs.");
126 vector<boost::filesystem::path> paths;
127 vector<shared_ptr<dcp::Asset>> assets;
129 for (
auto i: inputs) {
133 for (
auto j:
dcp.cpls()) {
137 for (
auto j:
dcp.assets(
true)) {
138 if (dynamic_pointer_cast<dcp::CPL>(j)) {
142 auto sub = dynamic_pointer_cast<dcp::InteropTextAsset>(j);
149 auto fonts = sub->font_filenames ();
150 for (
auto const& k: fonts) {
151 sub->set_font_file (k.first, make_unique(output / k.second.filename()));
153 auto file = sub->file();
155 auto new_path = make_unique(output / file->filename());
156 sub->write (new_path);
157 add_to_container(assets, sub->font_assets());
160 assets.push_back (j);
164 output_dcp.resolve_refs (assets);
166 for (
auto i: output_dcp.assets()) {
167 if (!dynamic_pointer_cast<dcp::FontAsset>(i) && !dynamic_pointer_cast<dcp::CPL>(i)) {
168 auto file = i->file();
170 auto new_path = make_unique(output / file->filename());
171 create_hard_link_or_copy (*file, new_path);
172 i->set_file (new_path);
176 output_dcp.set_issuer(issuer);
177 output_dcp.set_creator(creator);
178 output_dcp.set_issue_date(issue_date);
179 output_dcp.set_annotation_text(annotation_text);
181 output_dcp.write_xml(signer);
Exceptions thrown by libdcp.
Namespace for everything in libdcp.
Methods for conversion to/from string.