#include <boost/lexical_cast.hpp>
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
+ #ifdef DCPOMATIC_WINDOWS
+ #include <boost/locale.hpp>
+ #endif
#include <glib.h>
#include <openjpeg.h>
#include <openssl/md5.h>
using std::vector;
using std::hex;
using std::setw;
- using std::ifstream;
using std::ios;
using std::min;
using std::max;
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;
LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *)
{
dbg::stack s;
- ofstream f (backtrace_file.string().c_str());
- std::copy(s.begin(), s.end(), std::ostream_iterator<dbg::stack_frame>(f, "\n"));
+ FILE* f = fopen_boost (backtrace_file, "w");
+ for (dbg::stack::const_iterator i = s.begin(); i != s.end(); ++i) {
+ fprintf (f, "%p %s %d %s", i->instruction, i->function.c_str(), i->line, i->module.c_str());
+ }
+ fclose (f);
return EXCEPTION_CONTINUE_SEARCH;
}
#endif
backtrace_file /= g_get_user_config_dir ();
backtrace_file /= "backtrace.txt";
SetUnhandledExceptionFilter(exception_handler);
+
+ /* Dark voodoo which, I think, gets boost::filesystem::path to
+ correctly convert UTF-8 strings to paths, and also paths
+ back to UTF-8 strings (on path::string()).
+
+ After this, constructing boost::filesystem::paths from strings
+ converts from UTF-8 to UTF-16 inside the path. Then
+ path::string().c_str() gives UTF-8 and
+ path::c_str() gives UTF-16.
+
+ This is all Windows-only. AFAICT Linux/OS X use UTF-8 everywhere,
+ so things are much simpler.
+ */
+ std::locale::global (boost::locale::generator().generate (""));
+ boost::filesystem::path::imbue (std::locale ());
#endif
avfilter_register_all ();
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];
using std::make_pair;
using std::list;
using std::exception;
- using std::ofstream;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
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);
std_to_wx (
String::compose (wx_to_std (_("The directory %1 already exists and is not empty. "
"Are you sure you want to use it?")),
- d->get_path().c_str())
+ d->get_path().string().c_str())
)
)) {
return;
#include "lib/filter.h"
#include "lib/ratio.h"
#include "lib/config.h"
-#include "lib/still_image_content.h"
-#include "lib/moving_image_content.h"
+#include "lib/image_content.h"
#include "lib/ffmpeg_content.h"
#include "lib/sndfile_content.h"
#include "lib/dcp_content_type.h"
}
++r;
- _encrypted = new wxCheckBox (_dcp_panel, wxID_ANY, wxT ("Encrypted"));
+ _encrypted = new wxCheckBox (_dcp_panel, wxID_ANY, _("Encrypted"));
grid->Add (_encrypted, wxGBPosition (r, 0), wxGBSpan (1, 2));
++r;
void
FilmEditor::content_add_file_clicked ()
{
- wxFileDialog* d = new wxFileDialog (this, _("Choose a file or files"), wxT (""), wxT (""), wxT ("*.*"), wxFD_MULTIPLE);
+ /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using
+ non-Latin filenames or paths.
+ */
+ wxFileDialog* d = new wxFileDialog (this, _("Choose a file or files"), wxT (""), wxT (""), wxT ("*.*"), wxFD_MULTIPLE | wxFD_CHANGE_DIR);
int const r = d->ShowModal ();
- d->Destroy ();
if (r != wxID_OK) {
+ d->Destroy ();
return;
}
/* XXX: check for lots of files here and do something */
for (unsigned int i = 0; i < paths.GetCount(); ++i) {
- _film->examine_and_add_content (content_factory (_film, wx_to_std (paths[i])));
+ _film->examine_and_add_content (content_factory (_film, wx_to_std (d->GetPath ())));
}
+
+ d->Destroy ();
}
void
}
_film->examine_and_add_content (
- shared_ptr<MovingImageContent> (
- new MovingImageContent (_film, boost::filesystem::path (wx_to_std (d->GetPath ())))
+ shared_ptr<ImageContent> (
+ new ImageContent (_film, boost::filesystem::path (wx_to_std (d->GetPath ())))
)
);
}
break;
}
- sel.push_back (_film->content()[s]);
+ if (s < int (_film->content().size ())) {
+ sel.push_back (_film->content()[s]);
+ }
}
return sel;