Fix crashes when using templates in some cases (#2491).
[dcpomatic.git] / src / lib / types.cc
1 /*
2     Copyright (C) 2013-2019 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic 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.
10
11     DCP-o-matic 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.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "types.h"
22 #include "compose.hpp"
23 #include "dcpomatic_assert.h"
24 #include <dcp/cpl.h>
25 #include <dcp/dcp.h>
26 #include <dcp/raw_convert.h>
27 #include <dcp/reel_asset.h>
28 #include <dcp/reel_file_asset.h>
29 #include <dcp/warnings.h>
30 LIBDCP_DISABLE_WARNINGS
31 #include <libxml++/libxml++.h>
32 LIBDCP_ENABLE_WARNINGS
33 #include <libcxml/cxml.h>
34
35 #include "i18n.h"
36
37 using std::max;
38 using std::min;
39 using std::string;
40 using std::list;
41 using std::shared_ptr;
42 using std::vector;
43 using dcp::raw_convert;
44
45
46 CPLSummary::CPLSummary (boost::filesystem::path p)
47         : dcp_directory (p.leaf().string())
48 {
49         dcp::DCP dcp (p);
50
51         vector<dcp::VerificationNote> notes;
52         dcp.read (&notes);
53         for (auto i: notes) {
54                 if (i.code() != dcp::VerificationNote::Code::EXTERNAL_ASSET) {
55                         /* It's not just a warning about this DCP being a VF */
56                         throw dcp::ReadError(dcp::note_to_string(i));
57                 }
58         }
59
60         cpl_id = dcp.cpls().front()->id();
61         cpl_annotation_text = dcp.cpls().front()->annotation_text();
62         cpl_file = dcp.cpls().front()->file().get();
63
64         encrypted = false;
65         for (auto j: dcp.cpls()) {
66                 for (auto k: j->reel_file_assets()) {
67                         if (k->encrypted()) {
68                                 encrypted = true;
69                         }
70                 }
71         }
72
73         boost::system::error_code ec;
74         auto last_write = boost::filesystem::last_write_time (p, ec);
75         last_write_time = ec ? 0 : last_write;
76 }
77
78