s/use_template/take_settings_from/g
[dcpomatic.git] / src / lib / cross.cc
index 3c0103b1445a98ef0bd090a571a0a047dad705b4..7c05ba2226182f39f9ec85d697899fe349cfbb44 100644 (file)
@@ -21,6 +21,7 @@
 #include "cross.h"
 #include "compose.hpp"
 #include "log.h"
+#include "config.h"
 #include "exceptions.h"
 extern "C" {
 #include <libavformat/avio.h>
@@ -34,6 +35,8 @@ extern "C" {
 #include <windows.h>
 #undef DATADIR
 #include <shlwapi.h>
+#include <shellapi.h>
+#include <fcntl.h>
 #endif
 #ifdef DCPOMATIC_OSX
 #include <sys/sysctl.h>
@@ -380,7 +383,6 @@ start_batch_converter (boost::filesystem::path dcpomatic)
 #if defined(DCPOMATIC_LINUX) || defined(DCPOMATIC_OSX)
        pid_t pid = fork ();
        if (pid == 0) {
-               std::cout << "start " << batch << " from " << dcpomatic << "\n";
                int const r = system (batch.string().c_str());
                exit (WEXITSTATUS (r));
        }
@@ -416,11 +418,33 @@ avio_open_boost (AVIOContext** s, boost::filesystem::path file, int flags)
 #ifdef DCPOMATIC_WINDOWS
        int const length = (file.string().length() + 1) * 2;
        char* utf8 = new char[length];
-       WideCharToMultibyte (CP_UTF8, 0, file.c_str(), -1, utf8, length, 0, 0);
-       int const r = avio_open_boost (s, file.c_str(), flags);
+       WideCharToMultiByte (CP_UTF8, 0, file.c_str(), -1, utf8, length, 0, 0);
+       int const r = avio_open (s, utf8, flags);
        delete[] utf8;
        return r;
 #else
-       return avio_open_boost (s, file.c_str(), flags);
+       return avio_open (s, file.c_str(), flags);
 #endif
 }
+
+#ifdef DCPOMATIC_WINDOWS
+void
+maybe_open_console ()
+{
+       if (Config::instance()->win32_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