Support TGA file directories and improve progress reporting when hashing directories...
authorCarl Hetherington <cth@carlh.net>
Tue, 20 Aug 2013 22:48:51 +0000 (23:48 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 20 Aug 2013 22:48:51 +0000 (23:48 +0100)
src/lib/content.cc
src/lib/film.h
src/lib/moving_image_content.cc
src/lib/util.cc
src/lib/util.h

index 44b52a4715597a68025a9052f939756573d2f5ba..d2a07f79523f0e052b649a0d64425af9941b62d7 100644 (file)
@@ -80,7 +80,7 @@ Content::as_xml (xmlpp::Node* node) const
 }
 
 void
-Content::examine (shared_ptr<Job>)
+Content::examine (shared_ptr<Job> job)
 {
        boost::mutex::scoped_lock lm (_mutex);
        boost::filesystem::path p = _path;
@@ -90,7 +90,7 @@ Content::examine (shared_ptr<Job>)
        if (boost::filesystem::is_regular_file (p)) {
                d = md5_digest (p);
        } else {
-               d = md5_digest_directory (p);
+               d = md5_digest_directory (p, job);
        }
 
        lm.lock ();
index e7f017b0278b2623178cef5e034280adb37698e6..df26a3ae54fbd0d9f370041e2f70aa0ad1b58d3e 100644 (file)
@@ -41,6 +41,7 @@ class Content;
 class Player;
 class Playlist;
 class AudioContent;
+class Scaler;
 
 /** @class Film
  *
index 63b4b9f249d5f794f1400df3695641d63c29f68c..a72ad6e8e3d33858409be576e4116e3be4a53892 100644 (file)
@@ -23,6 +23,7 @@
 #include "config.h"
 #include "compose.hpp"
 #include "film.h"
+#include "job.h"
 
 #include "i18n.h"
 
@@ -80,12 +81,16 @@ MovingImageContent::as_xml (xmlpp::Node* node) const
 void
 MovingImageContent::examine (shared_ptr<Job> job)
 {
+       job->descend (0.5);
        Content::examine (job);
+       job->ascend ();
 
        shared_ptr<const Film> film = _film.lock ();
        assert (film);
        
+       job->descend (0.5);
        shared_ptr<MovingImageExaminer> examiner (new MovingImageExaminer (film, shared_from_this(), job));
+       job->ascend ();
 
        take_from_video_examiner (examiner);
 
index 26dfa8bf7912561a74812c17d1ca0d0e6e8609c4..4180bbfd7e5dc50dd22a4d986e8fe9c0e92b37ac 100644 (file)
@@ -61,6 +61,7 @@ extern "C" {
 #include "sound_processor.h"
 #include "config.h"
 #include "ratio.h"
+#include "job.h"
 #ifdef DCPOMATIC_WINDOWS
 #include "stack.hpp"
 #endif
@@ -407,15 +408,24 @@ md5_digest (boost::filesystem::path file)
        return s.str ();
 }
 
+/** @param job Optional job for which to report progress */
 string
-md5_digest_directory (boost::filesystem::path directory)
+md5_digest_directory (boost::filesystem::path directory, shared_ptr<Job> job)
 {
        int const buffer_size = 64 * 1024;
        char buffer[buffer_size];
 
        MD5_CTX md5_context;
        MD5_Init (&md5_context);
-       
+
+       int files = 0;
+       if (job) {
+               for (boost::filesystem::directory_iterator i(directory); i != boost::filesystem::directory_iterator(); ++i) {
+                       ++files;
+               }
+       }
+
+       int j = 0;
        for (boost::filesystem::directory_iterator i(directory); i != boost::filesystem::directory_iterator(); ++i) {
                ifstream f (i->path().string().c_str(), std::ios::binary);
                if (!f.good ()) {
@@ -432,6 +442,11 @@ md5_digest_directory (boost::filesystem::path directory)
                        MD5_Update (&md5_context, buffer, t);
                        bytes -= t;
                }
+
+               if (job) {
+                       job->set_progress (float (j) / files);
+                       ++j;
+               }
        }
 
        unsigned char digest[MD5_DIGEST_LENGTH];
@@ -781,6 +796,6 @@ valid_image_file (boost::filesystem::path f)
 {
        string ext = f.extension().string();
        transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
-       return (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp");
+       return (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp" || ext == ".tga");
 }
 
index 121deb532eb62cae1ab1e7f5e40eddc3fa2da10c..a83426206f88e7398423a152b408573cb31066cb 100644 (file)
@@ -51,8 +51,7 @@ extern "C" {
 /** The maximum number of audio channels that we can cope with */
 #define MAX_AUDIO_CHANNELS 6
 
-class Scaler;
-class Film;
+class Job;
 
 extern std::string seconds_to_hms (int);
 extern std::string seconds_to_approximate_hms (int);
@@ -63,7 +62,7 @@ extern void dcpomatic_setup ();
 extern void dcpomatic_setup_gettext_i18n (std::string);
 extern std::vector<std::string> split_at_spaces_considering_quotes (std::string);
 extern std::string md5_digest (boost::filesystem::path);
-extern std::string md5_digest_directory (boost::filesystem::path);
+extern std::string md5_digest_directory (boost::filesystem::path, boost::shared_ptr<Job>);
 extern std::string md5_digest (void const *, int);
 extern void ensure_ui_thread ();
 extern std::string audio_channel_name (int);