--- /dev/null
+/*
+ Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "check_content_change_job.h"
+#include "job_manager.h"
+#include "examine_content_job.h"
+#include "content.h"
+#include "film.h"
+#include <boost/foreach.hpp>
+#include <iostream>
+
+#include "i18n.h"
+
+using std::string;
+using std::list;
+using std::cout;
+using boost::shared_ptr;
+
+CheckContentChangeJob::CheckContentChangeJob (shared_ptr<const Film> film)
+ : Job (film)
+{
+
+}
+
+string
+CheckContentChangeJob::name () const
+{
+ return _("Check content for changes");
+}
+
+string
+CheckContentChangeJob::json_name () const
+{
+ return N_("check_content_change");
+}
+
+void
+CheckContentChangeJob::run ()
+{
+ set_progress_unknown ();
+
+ list<shared_ptr<Content> > changed;
+
+ BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
+ bool ic = false;
+ for (size_t j = 0; j < i->number_of_paths(); ++j) {
+ cout << boost::filesystem::last_write_time(i->path(j)) << " " << i->last_write_time(j) << "\n";
+ if (boost::filesystem::last_write_time(i->path(j)) != i->last_write_time(j)) {
+ cout << "last write differs.\n";
+ ic = true;
+ break;
+ }
+ }
+ if (!ic && i->calculate_digest() != i->digest()) {
+ cout << "digest differs.\n";
+ ic = true;
+ }
+ if (ic) {
+ cout << i->path(0) << " changed.\n";
+ changed.push_back (i);
+ }
+ }
+
+ BOOST_FOREACH (shared_ptr<Content> i, changed) {
+ JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob(_film, i)));
+ }
+
+ set_progress (1);
+ set_state (FINISHED_OK);
+}
--- /dev/null
+/*
+ Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "job.h"
+
+/** @class CheckContentChangeJob
+ * @brief A job to check whether content has changed since it was added to the film.
+ */
+
+class CheckContentChangeJob : public Job
+{
+public:
+ CheckContentChangeJob (boost::shared_ptr<const Film>);
+
+ std::string name () const;
+ std::string json_name () const;
+ void run ();
+};
list<cxml::NodePtr> path_children = node->node_children ("Path");
BOOST_FOREACH (cxml::NodePtr i, path_children) {
_paths.push_back (i->content());
- optional<time_t> const mod = i->optional_number_child<time_t>("mtime");
+ optional<time_t> const mod = i->optional_number_attribute<time_t>("mtime");
if (mod) {
_last_write_times.push_back (*mod);
} else if (boost::filesystem::exists(i->content())) {
}
}
-void
-Content::examine (shared_ptr<Job> job)
+string
+Content::calculate_digest () const
{
- if (job) {
- job->sub (_("Computing digest"));
- }
-
boost::mutex::scoped_lock lm (_mutex);
vector<boost::filesystem::path> p = _paths;
lm.unlock ();
digest here: a digest of the first and last 1e6 bytes with the
size of the first file tacked on the end as a string.
*/
- string const d = digest_head_tail (p, 1000000) + raw_convert<string> (boost::filesystem::file_size (p.front ()));
+ return digest_head_tail(p, 1000000) + raw_convert<string>(boost::filesystem::file_size(p.front()));
+}
- lm.lock ();
+void
+Content::examine (shared_ptr<Job> job)
+{
+ if (job) {
+ job->sub (_("Computing digest"));
+ }
+
+ string const d = calculate_digest ();
+
+ boost::mutex::scoped_lock lm (_mutex);
_digest = d;
}
return _paths[i];
}
+ std::time_t last_write_time (size_t i) const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _last_write_times[i];
+ }
+
bool paths_valid () const;
/** @return Digest of the content's file(s). Note: this is
std::list<UserProperty> user_properties () const;
+ std::string calculate_digest () const;
+
/* CHANGE_PENDING and CHANGE_CANCELLED may be emitted from any thread; CHANGE_DONE always from GUI thread */
boost::signals2::signal<void (ChangeType, boost::weak_ptr<Content>, int, bool)> Change;
text_content.cc
text_decoder.cc
case_insensitive_sorter.cc
+ check_content_change_job.cc
cinema.cc
cinema_kdms.cc
cinema_sound_processor.cc
#include "lib/transcode_job.h"
#include "lib/dkdm_wrapper.h"
#include "lib/audio_content.h"
+#include "lib/check_content_change_job.h"
#include "lib/text_content.h"
#include <dcp/exceptions.h>
#include <dcp/raw_convert.h>
}
set_film (film);
+
+ JobManager::instance()->add(shared_ptr<Job>(new CheckContentChangeJob(film)));
}
catch (std::exception& e) {
wxString p = std_to_wx (file.string ());