X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fpkl.cc;h=463d046acaac5d54968a4cbde6b2974b88235049;hb=a8d2013b99626ed08e7c80e6e58cf234b53b0c4d;hp=9cec68be13539d8288fb0d156ee094544de45cb8;hpb=ceaf7bc52712cb60708ed5eb5c62c5e463dd8e89;p=libdcp.git diff --git a/src/pkl.cc b/src/pkl.cc index 9cec68be..463d046a 100644 --- a/src/pkl.cc +++ b/src/pkl.cc @@ -37,12 +37,16 @@ */ -#include "pkl.h" +#include "dcp_assert.h" #include "exceptions.h" -#include "util.h" +#include "filesystem.h" +#include "pkl.h" #include "raw_convert.h" -#include "dcp_assert.h" +#include "util.h" +#include "warnings.h" +LIBDCP_DISABLE_WARNINGS #include +LIBDCP_ENABLE_WARNINGS #include @@ -61,14 +65,14 @@ PKL::PKL (boost::filesystem::path file) : _file (file) { cxml::Document pkl ("PackingList"); - pkl.read_file (file); + pkl.read_file(dcp::filesystem::fix_long_path(file)); if (pkl.namespace_uri() == pkl_interop_ns) { _standard = Standard::INTEROP; } else if (pkl.namespace_uri() == pkl_smpte_ns) { _standard = Standard::SMPTE; } else { - boost::throw_exception (XMLError ("Unrecognised packing list namesapce " + pkl.namespace_uri())); + boost::throw_exception(XMLError("Unrecognised packing list namespace " + pkl.namespace_uri())); } _id = remove_urn_uuid (pkl.string_child ("Id")); @@ -78,20 +82,20 @@ PKL::PKL (boost::filesystem::path file) _creator = pkl.string_child ("Creator"); for (auto i: pkl.node_child("AssetList")->node_children("Asset")) { - _asset_list.push_back (make_shared(i)); + _assets.push_back(make_shared(i)); } } void -PKL::add_asset (std::string id, boost::optional annotation_text, std::string hash, int64_t size, std::string type) +PKL::add_asset(std::string id, boost::optional annotation_text, std::string hash, int64_t size, std::string type, std::string original_filename) { - _asset_list.push_back (make_shared(id, annotation_text, hash, size, type)); + _assets.push_back(make_shared(id, annotation_text, hash, size, type, original_filename)); } void -PKL::write (boost::filesystem::path file, shared_ptr signer) const +PKL::write_xml (boost::filesystem::path file, shared_ptr signer) const { xmlpp::Document doc; xmlpp::Element* pkl; @@ -101,24 +105,27 @@ PKL::write (boost::filesystem::path file, shared_ptr sig pkl = doc.create_root_node("PackingList", pkl_smpte_ns); } - pkl->add_child("Id")->add_child_text ("urn:uuid:" + _id); + cxml::add_text_child(pkl, "Id", "urn:uuid:" + _id); if (_annotation_text) { - pkl->add_child("AnnotationText")->add_child_text (*_annotation_text); + cxml::add_text_child(pkl, "AnnotationText", *_annotation_text); } - pkl->add_child("IssueDate")->add_child_text (_issue_date); - pkl->add_child("Issuer")->add_child_text (_issuer); - pkl->add_child("Creator")->add_child_text (_creator); - - auto asset_list = pkl->add_child("AssetList"); - for (auto i: _asset_list) { - auto asset = asset_list->add_child("Asset"); - asset->add_child("Id")->add_child_text ("urn:uuid:" + i->id()); + cxml::add_text_child(pkl, "IssueDate", _issue_date); + cxml::add_text_child(pkl, "Issuer", _issuer); + cxml::add_text_child(pkl, "Creator", _creator); + + auto asset_list = cxml::add_child(pkl, "AssetList"); + for (auto i: _assets) { + auto asset = cxml::add_child(asset_list, "Asset"); + cxml::add_text_child(asset, "Id", "urn:uuid:" + i->id()); if (i->annotation_text()) { - asset->add_child("AnnotationText")->add_child_text (*i->annotation_text()); + cxml::add_text_child(asset, "AnnotationText", *i->annotation_text()); + } + cxml::add_text_child(asset, "Hash", i->hash()); + cxml::add_text_child(asset, "Size", raw_convert(i->size())); + cxml::add_text_child(asset, "Type", i->type()); + if (auto filename = i->original_filename()) { + cxml::add_text_child(asset, "OriginalFileName", *filename); } - asset->add_child("Hash")->add_child_text (i->hash()); - asset->add_child("Size")->add_child_text (raw_convert(i->size())); - asset->add_child("Type")->add_child_text (i->type()); } indent (pkl, 0); @@ -127,7 +134,7 @@ PKL::write (boost::filesystem::path file, shared_ptr sig signer->sign (pkl, _standard); } - doc.write_to_file_formatted (file.string(), "UTF-8"); + doc.write_to_file_formatted(dcp::filesystem::fix_long_path(file).string(), "UTF-8"); _file = file; } @@ -135,7 +142,7 @@ PKL::write (boost::filesystem::path file, shared_ptr sig optional PKL::hash (string id) const { - for (auto i: _asset_list) { + for (auto i: _assets) { if (i->id() == id) { return i->hash(); } @@ -148,7 +155,7 @@ PKL::hash (string id) const optional PKL::type (string id) const { - for (auto i: _asset_list) { + for (auto i: _assets) { if (i->id() == id) { return i->type(); } @@ -156,3 +163,10 @@ PKL::type (string id) const return {}; } + + +void +PKL::clear_assets() +{ + _assets.clear(); +}