A whole load of UTF-8/-16 confusion fixes for Windows.
[dcpomatic.git] / src / tools / dcpomatic.cc
index af620c5a2e93c487a10c1d5c3a6b922526abfe3c..2a0cb9cd36935a1ae53d67fafd60e8d92578b7c6 100644 (file)
@@ -41,6 +41,7 @@
 #include "wx/about_dialog.h"
 #include "wx/kdm_dialog.h"
 #include "wx/servers_list_dialog.h"
+#include "wx/hints_dialog.h"
 #include "lib/film.h"
 #include "lib/config.h"
 #include "lib/util.h"
@@ -61,7 +62,6 @@ using std::map;
 using std::make_pair;
 using std::list;
 using std::exception;
-using std::ofstream;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 
@@ -181,6 +181,7 @@ enum {
        ID_jobs_make_kdms,
        ID_jobs_send_dcp_to_tms,
        ID_jobs_show_dcp,
+       ID_tools_hints,
        ID_tools_encoding_servers,
 };
 
@@ -219,6 +220,7 @@ setup_menu (wxMenuBar* m)
        add_item (jobs_menu, _("S&how DCP"), ID_jobs_show_dcp, NEEDS_FILM | NOT_DURING_DCP_CREATION | NEEDS_DCP);
 
        wxMenu* tools = new wxMenu;
+       add_item (tools, _("Hints..."), ID_tools_hints, 0);
        add_item (tools, _("Encoding Servers..."), ID_tools_encoding_servers, 0);
 
        wxMenu* help = new wxMenu;
@@ -244,6 +246,22 @@ public:
                : wxFrame (NULL, -1, title)
                , _servers_list_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);
@@ -258,6 +276,7 @@ public:
                Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_make_kdms, this),         ID_jobs_make_kdms);
                Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_send_dcp_to_tms, this),   ID_jobs_send_dcp_to_tms);
                Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::jobs_show_dcp, this),          ID_jobs_show_dcp);
+               Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::tools_hints, this),            ID_tools_hints);
                Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::tools_encoding_servers, this), ID_tools_encoding_servers);
                Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&Frame::help_about, this),             wxID_ABOUT);
 
@@ -328,7 +347,7 @@ private:
                                            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;
@@ -354,7 +373,13 @@ private:
 
        void file_open ()
        {
-               wxDirDialog* c = new wxDirDialog (this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
+               wxDirDialog* c = new wxDirDialog (
+                       this,
+                       _("Select film to open"),
+                       std_to_wx (Config::instance()->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())).string ()),
+                       wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
+                       );
+               
                int r;
                while (1) {
                        r = c->ShowModal ();
@@ -473,6 +498,15 @@ private:
 #endif         
        }
 
+       void tools_hints ()
+       {
+               if (!_hints_dialog) {
+                       _hints_dialog = new HintsDialog (this, film);
+               }
+
+               _hints_dialog->Show ();
+       }
+
        void tools_encoding_servers ()
        {
                if (!_servers_list_dialog) {
@@ -517,6 +551,7 @@ private:
                ev.Skip ();
        }
 
+       HintsDialog* _hints_dialog;
        ServersListDialog* _servers_list_dialog;
 };