From e68386830c8812f80cb4b3af9871170226b916b4 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 9 Jun 2022 22:38:58 +0200 Subject: [PATCH] Add Film::last_written_by_earlier_than() --- src/lib/film.cc | 40 ++++++++++++++++++++++++++++++++++++++++ src/lib/film.h | 4 ++++ 2 files changed, 44 insertions(+) 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 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 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(parts[0]); + int our_minor = dcp::raw_convert(parts[1]); + int our_micro = dcp::raw_convert(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 _directory; + boost::optional _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 */ -- 2.30.2