Remove LocaleGuard and lexical_cast<> in favour of libdcp::raw_convert,
[dcpomatic.git] / src / tools / dcpomatic_batch.cc
index 23d5a4819685ae41c088647bd88b719a790ff934..58fbaec985a4c369c9de547d869fd87cd9082f9e 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <wx/aboutdlg.h>
 #include <wx/stdpaths.h>
+#include <wx/cmdline.h>
 #include <wx/wx.h>
 #include "lib/version.h"
 #include "lib/compose.hpp"
 #include "wx/wx_ui_signaller.h"
 #include "wx/job_manager_view.h"
 
+using std::exception;
 using boost::shared_ptr;
 
+static std::string film_to_load;
+
 enum {
        ID_file_add_film = 1,
        ID_file_quit,
@@ -164,6 +168,10 @@ private:
        void add_film ()
        {
                wxDirDialog* c = new wxDirDialog (this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
+               if (_last_parent) {
+                       c->SetPath (std_to_wx (_last_parent.get().string ()));
+               }
+               
                int r;
                while (1) {
                        r = c->ShowModal ();
@@ -186,8 +194,17 @@ private:
                        }
                }
 
+               _last_parent = boost::filesystem::path (wx_to_std (c->GetPath ())).parent_path ();
+
                c->Destroy ();
        }
+
+       boost::optional<boost::filesystem::path> _last_parent;
+};
+
+static const wxCmdLineEntryDesc command_line_description[] = {
+       { wxCMD_LINE_PARAM, 0, 0, "film to load", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL },
+       { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
 };
 
 class App : public wxApp
@@ -228,6 +245,17 @@ class App : public wxApp
                ui_signaller = new wxUISignaller (this);
                this->Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
 
+               shared_ptr<Film> film;
+               if (!film_to_load.empty() && boost::filesystem::is_directory (film_to_load)) {
+                       try {
+                               film.reset (new Film (film_to_load));
+                               film->read_metadata ();
+                               film->make_dcp ();
+                       } catch (exception& e) {
+                               error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load film %1 (%2)")), film_to_load, e.what())));
+                       }
+               }
+
                return true;
        }
 
@@ -235,6 +263,21 @@ class App : public wxApp
        {
                ui_signaller->ui_idle ();
        }
+
+       void OnInitCmdLine (wxCmdLineParser& parser)
+       {
+               parser.SetDesc (command_line_description);
+               parser.SetSwitchChars (wxT ("-"));
+       }
+
+       bool OnCmdLineParsed (wxCmdLineParser& parser)
+       {
+               if (parser.GetParamCount() > 0) {
+                       film_to_load = wx_to_std (parser.GetParam(0));
+               }
+
+               return true;
+       }
 };
 
 IMPLEMENT_APP (App)