X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fasset.cc;h=49ec72519108a4546f557821efa156506c8d956a;hb=247629f8e6f3e05c125cfa6b369eb6b9f0594982;hp=32f4e07974c2f194bd441b1db9e1f2bf1a1967c5;hpb=d927e9b913606f4fc982885c7582ecaf0e3c5a1a;p=libdcp.git diff --git a/src/asset.cc b/src/asset.cc index 32f4e079..49ec7251 100644 --- a/src/asset.cc +++ b/src/asset.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2015 Carl Hetherington + Copyright (C) 2014-2018 Carl Hetherington This file is part of libdcp. @@ -41,11 +41,13 @@ #include "exceptions.h" #include "dcp_assert.h" #include "compose.hpp" +#include "pkl.h" #include #include using std::string; using boost::function; +using std::shared_ptr; using boost::optional; using namespace dcp; @@ -64,6 +66,10 @@ Asset::Asset (boost::filesystem::path file) } +/** Create an Asset from a given file with a known ID. + * @param file File name. + * @param id ID. + */ Asset::Asset (string id, boost::filesystem::path file) : Object (id) , _file (file) @@ -72,13 +78,13 @@ Asset::Asset (string id, boost::filesystem::path file) } void -Asset::write_to_pkl (xmlpp::Node* node, boost::filesystem::path root, Standard standard) const +Asset::add_to_pkl (shared_ptr pkl, boost::filesystem::path root) const { - DCP_ASSERT (!_file.empty ()); + DCP_ASSERT (_file); optional path = relative_to_root ( boost::filesystem::canonical (root), - boost::filesystem::canonical (_file) + boost::filesystem::canonical (_file.get()) ); if (!path) { @@ -88,22 +94,22 @@ Asset::write_to_pkl (xmlpp::Node* node, boost::filesystem::path root, Standard s return; } - xmlpp::Node* asset = node->add_child ("Asset"); - asset->add_child("Id")->add_child_text ("urn:uuid:" + _id); - asset->add_child("AnnotationText")->add_child_text (_id); - asset->add_child("Hash")->add_child_text (hash ()); - asset->add_child("Size")->add_child_text (raw_convert (boost::filesystem::file_size (_file))); - asset->add_child("Type")->add_child_text (pkl_type (standard)); + pkl->add_asset (_id, _id, hash(), boost::filesystem::file_size (_file.get()), pkl_type (pkl->standard())); } void Asset::write_to_assetmap (xmlpp::Node* node, boost::filesystem::path root) const { - DCP_ASSERT (!_file.empty ()); + DCP_ASSERT (_file); + write_file_to_assetmap (node, root, _file.get(), _id); +} +void +Asset::write_file_to_assetmap (xmlpp::Node* node, boost::filesystem::path root, boost::filesystem::path file, string id) +{ optional path = relative_to_root ( boost::filesystem::canonical (root), - boost::filesystem::canonical (_file) + boost::filesystem::canonical (file) ); if (!path) { @@ -114,30 +120,30 @@ Asset::write_to_assetmap (xmlpp::Node* node, boost::filesystem::path root) const } xmlpp::Node* asset = node->add_child ("Asset"); - asset->add_child("Id")->add_child_text ("urn:uuid:" + _id); + asset->add_child("Id")->add_child_text ("urn:uuid:" + id); xmlpp::Node* chunk_list = asset->add_child ("ChunkList"); xmlpp::Node* chunk = chunk_list->add_child ("Chunk"); chunk->add_child("Path")->add_child_text (path.get().generic_string()); chunk->add_child("VolumeIndex")->add_child_text ("1"); chunk->add_child("Offset")->add_child_text ("0"); - chunk->add_child("Length")->add_child_text (raw_convert (boost::filesystem::file_size (_file))); + chunk->add_child("Length")->add_child_text (raw_convert (boost::filesystem::file_size (file))); } string Asset::hash (function progress) const { - DCP_ASSERT (!_file.empty ()); + DCP_ASSERT (_file); if (!_hash) { - _hash = make_digest (_file, progress); + _hash = make_digest (_file.get(), progress); } return _hash.get(); } bool -Asset::equals (boost::shared_ptr other, EqualityOptions, NoteHandler note) const +Asset::equals (std::shared_ptr other, EqualityOptions, NoteHandler note) const { if (_hash != other->_hash) { note (DCP_ERROR, "Asset: hashes differ");