2 Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
35 /** @file src/asset.cc
41 #include "asset_map.h"
42 #include "compose.hpp"
43 #include "dcp_assert.h"
44 #include "exceptions.h"
46 #include "raw_convert.h"
49 LIBDCP_DISABLE_WARNINGS
50 #include <libxml++/libxml++.h>
51 LIBDCP_ENABLE_WARNINGS
52 #include <boost/algorithm/string.hpp>
56 using boost::function;
57 using std::shared_ptr;
58 using boost::optional;
59 using namespace boost::filesystem;
69 Asset::Asset (path file)
76 Asset::Asset (string id, path file)
85 Asset::add_to_pkl (shared_ptr<PKL> pkl, path root) const
89 auto path = relative_to_root (
91 canonical(_file.get())
95 /* The path of this asset is not within our DCP, so we assume it's an external
101 pkl->add_asset(_id, _id, hash(), file_size(_file.get()), pkl_type(pkl->standard()), _file->filename().string());
106 Asset::add_to_assetmap (AssetMap& asset_map, path root) const
109 add_file_to_assetmap (asset_map, root, _file.get(), _id);
114 Asset::add_file_to_assetmap (AssetMap& asset_map, path root, path file, string id)
116 auto path = relative_to_root (
122 /* The path of this asset is not within our DCP, so we assume it's an external
128 asset_map.add_asset(id, file, false);
133 Asset::hash (function<void (float)> progress) const
138 _hash = make_digest (_file.get(), progress);
146 Asset::equals (std::shared_ptr<const Asset> other, EqualityOptions, NoteHandler note) const
148 if (_hash != other->_hash) {
149 note (NoteType::ERROR, "Asset: hashes differ");
158 Asset::set_file (path file) const
160 _file = absolute (file);
161 _hash = boost::optional<string>();
166 Asset::set_hash (string hash)