summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-06-09 22:38:58 +0200
committerCarl Hetherington <cth@carlh.net>2022-06-10 23:12:13 +0200
commite68386830c8812f80cb4b3af9871170226b916b4 (patch)
tree4cfae4bb14134d6b58e0dbc4492b6abd6991d51b
parent3d9c0674236a425f0be5e9caff5e23f59e7c037a (diff)
Add Film::last_written_by_earlier_than()
-rw-r--r--src/lib/film.cc40
-rw-r--r--src/lib/film.h4
2 files changed, 44 insertions, 0 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc
index 1aba68eeb..4084ca59c 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -534,6 +534,8 @@ Film::read_metadata (optional<boost::filesystem::path> path)
}
}
+ _last_written_by = f.optional_string_child("LastWrittenBy");
+
_name = f.string_child ("Name");
if (_state_version >= 9) {
_use_isdcf_name = f.bool_child ("UseISDCFName");
@@ -2167,3 +2169,41 @@ Film::set_dirty (bool dirty)
}
}
+
+/** @return true if the metadata was (probably) last written by a version earlier
+ * than the given one; false if it definitely was not.
+ */
+bool
+Film::last_written_by_earlier_than(int major, int minor, int micro) const
+{
+ if (!_last_written_by) {
+ return true;
+ }
+
+ vector<string> parts;
+ boost::split(parts, *_last_written_by, boost::is_any_of("."));
+
+ if (parts.size() != 3) {
+ /* Not sure what's going on, so let's say it was written by an old version */
+ return true;
+ }
+
+ if (boost::ends_with(parts[2], "pre")) {
+ parts[2] = parts[2].substr(0, parts[2].length() - 3);
+ }
+
+ int our_major = dcp::raw_convert<int>(parts[0]);
+ int our_minor = dcp::raw_convert<int>(parts[1]);
+ int our_micro = dcp::raw_convert<int>(parts[2]);
+
+ if (our_major != major) {
+ return our_major < major;
+ }
+
+ if (our_minor != minor) {
+ return our_minor < minor;
+ }
+
+ return our_micro < micro;
+}
+
diff --git a/src/lib/film.h b/src/lib/film.h
index 5318d6a12..72d6d5e8d 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -210,6 +210,8 @@ public:
return _tolerant;
}
+ bool last_written_by_earlier_than(int major, int minor, int micro) const;
+
/** Identifiers for the parts of our state;
used for signalling changes.
*/
@@ -516,6 +518,8 @@ private:
*/
boost::optional<boost::filesystem::path> _directory;
+ boost::optional<std::string> _last_written_by;
+
/** Name for DCP-o-matic */
std::string _name;
/** True if a auto-generated ISDCF-compliant name should be used for our DCP */