X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fasset.cc;h=213d4878410e2553f7b48963da1ea185432d9f06;hb=ac5445d9ee7dbb6fd7dda08f965c661b01e26c90;hp=b911c70b958435c754d2e153c58edc811789e18e;hpb=e1e7de8d73bedd0c741e7df0390068c67867e09f;p=libdcp.git diff --git a/src/asset.cc b/src/asset.cc index b911c70b..213d4878 100644 --- a/src/asset.cc +++ b/src/asset.cc @@ -37,14 +37,19 @@ */ -#include "raw_convert.h" #include "asset.h" -#include "util.h" -#include "exceptions.h" -#include "dcp_assert.h" +#include "asset_map.h" #include "compose.hpp" +#include "dcp_assert.h" +#include "equality_options.h" +#include "exceptions.h" #include "pkl.h" +#include "raw_convert.h" +#include "util.h" +#include "warnings.h" +LIBDCP_DISABLE_WARNINGS #include +LIBDCP_ENABLE_WARNINGS #include @@ -94,20 +99,20 @@ Asset::add_to_pkl (shared_ptr pkl, path root) const return; } - pkl->add_asset (_id, _id, hash(), file_size(_file.get()), pkl_type(pkl->standard())); + pkl->add_asset(_id, _id, hash(), file_size(_file.get()), pkl_type(pkl->standard()), _file->filename().string()); } void -Asset::write_to_assetmap (xmlpp::Node* node, path root) const +Asset::add_to_assetmap (AssetMap& asset_map, path root) const { DCP_ASSERT (_file); - write_file_to_assetmap (node, root, _file.get(), _id); + add_file_to_assetmap (asset_map, root, _file.get(), _id); } void -Asset::write_file_to_assetmap (xmlpp::Node* node, path root, path file, string id) +Asset::add_file_to_assetmap (AssetMap& asset_map, path root, path file, string id) { auto path = relative_to_root ( canonical(root), @@ -121,15 +126,7 @@ Asset::write_file_to_assetmap (xmlpp::Node* node, path root, path file, string i return; } - auto asset = node->add_child ("Asset"); - asset->add_child("Id")->add_child_text("urn:uuid:" + id); - auto chunk_list = asset->add_child ("ChunkList"); - auto 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(file_size(file))); + asset_map.add_asset(id, file, false); } @@ -147,11 +144,15 @@ Asset::hash (function progress) const bool -Asset::equals (std::shared_ptr other, EqualityOptions, NoteHandler note) const +Asset::equals(std::shared_ptr other, EqualityOptions const& opt, NoteHandler note) const { if (_hash != other->_hash) { - note (NoteType::ERROR, "Asset: hashes differ"); - return false; + if (!opt.asset_hashes_can_differ) { + note(NoteType::ERROR, "Asset: hashes differ"); + return false; + } else { + note(NoteType::NOTE, "Asset: hashes differ"); + } } return true; @@ -162,7 +163,21 @@ void Asset::set_file (path file) const { _file = absolute (file); - _hash = {}; + _hash = optional(); +} + + +void +Asset::set_file_preserving_hash(path file) const +{ + _file = absolute(file); +} + + +void +Asset::rename_file(path file) +{ + _file = absolute(file); } @@ -171,3 +186,11 @@ Asset::set_hash (string hash) { _hash = hash; } + + +void +Asset::unset_hash() +{ + _hash = optional(); +} +