summaryrefslogtreecommitdiff
path: root/src/lib/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-08-20 23:48:51 +0100
committerCarl Hetherington <cth@carlh.net>2013-08-20 23:48:51 +0100
commitbed373d380d35294b03d228a2ef41cfa8fceb4b0 (patch)
tree0814e6039bb4d9e4aa4d12da989d005da5305b6e /src/lib/util.cc
parent2b1f823c64e400de11799849c4788d4ee774b286 (diff)
Support TGA file directories and improve progress reporting when hashing directories of image files.
Diffstat (limited to 'src/lib/util.cc')
-rw-r--r--src/lib/util.cc21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 26dfa8bf7..4180bbfd7 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -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");
}