using std::istream;
using std::numeric_limits;
using std::pair;
- using std::ofstream;
using std::cout;
+using std::streampos;
using boost::shared_ptr;
using boost::thread;
using boost::lexical_cast;
return s.str ();
}
-/** @param file File name.
- * @return MD5 digest of file's contents.
- */
-string
-md5_digest (boost::filesystem::path file)
-{
- FILE* f = fopen_boost (file, "rb");
- if (!f) {
- throw OpenFileError (file.string());
- }
-
- boost::uintmax_t bytes = boost::filesystem::file_size (file);
-
- boost::uintmax_t const buffer_size = 64 * 1024;
- char buffer[buffer_size];
-
- MD5_CTX md5_context;
- MD5_Init (&md5_context);
- while (bytes > 0) {
- int const t = min (bytes, buffer_size);
- fread (buffer, 1, t, f);
- MD5_Update (&md5_context, buffer, t);
- bytes -= t;
- }
-
- unsigned char digest[MD5_DIGEST_LENGTH];
- MD5_Final (digest, &md5_context);
- fclose (f);
-
- stringstream s;
- for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
- s << std::hex << std::setfill('0') << std::setw(2) << ((int) digest[i]);
- }
-
- return s.str ();
-}
-
/** @param job Optional job for which to report progress */
string
-md5_digest_directory (boost::filesystem::path directory, shared_ptr<Job> job)
+md5_digest (vector<boost::filesystem::path> files, shared_ptr<Job> job)
{
- int const buffer_size = 64 * 1024;
+ boost::uintmax_t 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;
- }
+ vector<int64_t> sizes;
+ for (size_t i = 0; i < files.size(); ++i) {
+ sizes.push_back (boost::filesystem::file_size (files[i]));
}
- int j = 0;
- for (boost::filesystem::directory_iterator i(directory); i != boost::filesystem::directory_iterator(); ++i) {
- FILE* f = fopen_boost (i->path(), "rb");
+ for (size_t i = 0; i < files.size(); ++i) {
- ifstream f (files[i].string().c_str(), std::ios::binary);
- if (!f.good ()) {
++ FILE* f = fopen_boost (files[i], "rb");
+ if (!f) {
- throw OpenFileError (i->path().string());
+ throw OpenFileError (files[i].string());
}
-
- f.seekg (0, std::ios::end);
- streampos const bytes = f.tellg ();
- f.seekg (0, std::ios::beg);
- streampos remaining = bytes;
- boost::uintmax_t bytes = boost::filesystem::file_size (i->path ());
++ boost::uintmax_t const bytes = boost::filesystem::file_size (files[i]);
++ boost::uintmax_t remaining = bytes;
+
- while (bytes > 0) {
- int const t = min (bytes, buffer_size);
+ while (remaining > 0) {
- int const t = min (remaining, streampos (buffer_size));
- f.read (buffer, t);
++ int const t = min (remaining, buffer_size);
+ fread (buffer, 1, t, f);
MD5_Update (&md5_context, buffer, t);
- bytes -= t;
- }
+ remaining -= t;
- if (job) {
- job->set_progress (float (j) / files);
- ++j;
+ if (job) {
+ job->set_progress ((float (i) + 1 - float(remaining) / bytes) / files.size ());
+ }
}
+
+ fclose (f);
}
unsigned char digest[MD5_DIGEST_LENGTH];
Frame (wxString const & title)
: wxFrame (NULL, -1, title)
, _servers_list_dialog (0)
+ , _hints_dialog (0)
{
+ #ifdef DCPOMATIC_WINDOWS_CONSOLE
+ AllocConsole();
+
+ HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
+ int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
+ FILE* hf_out = _fdopen(hCrt, "w");
+ setvbuf(hf_out, NULL, _IONBF, 1);
+ *stdout = *hf_out;
+
+ HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
+ hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
+ FILE* hf_in = _fdopen(hCrt, "r");
+ setvbuf(hf_in, NULL, _IONBF, 128);
+ *stdin = *hf_in;
+ #endif
+
wxMenuBar* bar = new wxMenuBar;
setup_menu (bar);
SetMenuBar (bar);