summaryrefslogtreecommitdiff
path: root/src/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-07-17 20:30:30 +0100
committerCarl Hetherington <cth@carlh.net>2012-07-17 20:30:30 +0100
commit4709b2fe88040f3678560997726f3a209eacc660 (patch)
treedb4c7f923de4bd4e09de6c5237288424f0622a24 /src/util.cc
parent43cc9d6e1b1e1957288c545cc55f5a0df8492b55 (diff)
Fix up progress reporting, some better exceptions.
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/util.cc b/src/util.cc
index c9f50289..0af9c871 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -21,6 +21,7 @@
#include <sstream>
#include <iostream>
#include <iomanip>
+#include <boost/filesystem.hpp>
#include <openssl/sha.h>
#include "KM_util.h"
#include "KM_fileio.h"
@@ -28,6 +29,7 @@
#include "util.h"
using namespace std;
+using namespace boost;
/** Create a UUID.
* @return UUID.
@@ -47,8 +49,10 @@ libdcp::make_uuid ()
* @return Digest.
*/
string
-libdcp::make_digest (string filename)
+libdcp::make_digest (string filename, sigc::signal1<void, float>* progress)
{
+ int const file_size = filesystem::file_size (filename);
+
Kumu::FileReader reader;
if (ASDCP_FAILURE (reader.OpenRead (filename.c_str ()))) {
throw runtime_error ("could not open file to compute digest");
@@ -58,6 +62,7 @@ libdcp::make_digest (string filename)
SHA1_Init (&sha);
Kumu::ByteString read_buffer (65536);
+ int done = 0;
while (1) {
ui32_t read = 0;
Kumu::Result_t r = reader.Read (read_buffer.Data(), read_buffer.Capacity(), &read);
@@ -69,6 +74,11 @@ libdcp::make_digest (string filename)
}
SHA1_Update (&sha, read_buffer.Data(), read);
+ done += read;
+
+ if (progress) {
+ (*progress) (0.5 + (0.5 * done / file_size));
+ }
}
byte_t byte_buffer[20];