2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <boost/lexical_cast.hpp>
22 #include <boost/filesystem.hpp>
23 #include "check_hashes_job.h"
24 #include "film_state.h"
27 #include "job_manager.h"
28 #include "ab_transcode_job.h"
29 #include "transcode_job.h"
32 using namespace boost;
34 CheckHashesJob::CheckHashesJob (shared_ptr<const FilmState> s, shared_ptr<const Options> o, Log* l, shared_ptr<Job> req)
42 CheckHashesJob::name () const
44 return String::compose ("Check hashes of %1", _fs->name);
48 CheckHashesJob::run ()
52 int const N = _fs->dcp_length ();
54 for (int i = 0; i < N; ++i) {
55 string const j2k_file = _opt->frame_out_path (i, false);
56 string const hash_file = j2k_file + ".md5";
58 ifstream ref (hash_file.c_str ());
62 if (hash != md5_digest (j2k_file)) {
63 _log->log ("Frame " + lexical_cast<string> (i) + " has wrong hash; deleting.");
64 filesystem::remove (j2k_file);
65 filesystem::remove (hash_file);
69 set_progress (float (i) / _fs->length);
76 tc.reset (new ABTranscodeJob (_fs, _opt, _log, shared_from_this()));
78 tc.reset (new TranscodeJob (_fs, _opt, _log, shared_from_this()));
81 JobManager::instance()->add_after (shared_from_this(), tc);
82 JobManager::instance()->add_after (tc, shared_ptr<Job> (new CheckHashesJob (_fs, _opt, _log, tc)));
86 set_state (FINISHED_OK);
90 CheckHashesJob::status () const
94 if (overall_progress() > 0) {
96 s << "; no bad frames found";
97 } else if (_bad == 1) {
98 s << "; 1 bad frame found";
100 s << "; " << _bad << " bad frames found";