Add Film::last_written_by_earlier_than()
[dcpomatic.git] / src / lib / film.cc
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;
+}
+