Add Film::last_written_by_earlier_than()
authorCarl Hetherington <cth@carlh.net>
Thu, 9 Jun 2022 20:38:58 +0000 (22:38 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 10 Jun 2022 21:12:13 +0000 (23:12 +0200)
src/lib/film.cc
src/lib/film.h

index 1aba68eeb653f8342e158bcc598f74ec751d2d52..4084ca59c1700ec2d5ecae874b8eb5b0732b62b5 100644 (file)
@@ -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;
+}
+
index 5318d6a12aa837229d4e4ea6ff94ffe1a958fdb8..72d6d5e8d409bce8b2751e565c6fce1de789e751 100644 (file)
@@ -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 */