BOOST_FOREACH.
[dcpomatic.git] / src / lib / cross_windows.cc
index 96c69d78086a029e3b848394b8e7e21b0dd6cc1b..0ab56bb6b24f9e4ca24a069402d9d06b475bb943 100644 (file)
@@ -31,7 +31,6 @@ extern "C" {
 #include <libavformat/avio.h>
 }
 #include <boost/algorithm/string.hpp>
-#include <boost/foreach.hpp>
 #include <boost/dll/runtime_symbol_info.hpp>
 #include <windows.h>
 #include <winternl.h>
@@ -59,7 +58,7 @@ using std::cerr;
 using std::cout;
 using std::runtime_error;
 using std::map;
-using boost::shared_ptr;
+using std::shared_ptr;
 using boost::optional;
 
 static std::vector<pair<HANDLE, string> > locked_volumes;
@@ -127,9 +126,7 @@ run_ffprobe (boost::filesystem::path content, boost::filesystem::path out)
        }
 
        wchar_t dir[512];
-       GetModuleFileName (GetModuleHandle (0), dir, sizeof (dir));
-       PathRemoveFileSpec (dir);
-       SetCurrentDirectory (dir);
+       MultiByteToWideChar (CP_UTF8, 0, directory_containing_executable().string().c_str(), -1, dir, sizeof(dir));
 
        STARTUPINFO startup_info;
        ZeroMemory (&startup_info, sizeof (startup_info));
@@ -148,7 +145,7 @@ run_ffprobe (boost::filesystem::path content, boost::filesystem::path out)
 
        PROCESS_INFORMATION process_info;
        ZeroMemory (&process_info, sizeof (process_info));
-       if (!CreateProcess (0, command, 0, 0, TRUE, CREATE_NO_WINDOW, 0, 0, &startup_info, &process_info)) {
+       if (!CreateProcess (0, command, 0, 0, TRUE, CREATE_NO_WINDOW, 0, dir, &startup_info, &process_info)) {
                LOG_ERROR_NC (N_("ffprobe call failed (could not CreateProcess)"));
                return;
        }
@@ -185,32 +182,51 @@ mount_info ()
        return m;
 }
 
-static boost::filesystem::path
-executable_path ()
+
+boost::filesystem::path
+directory_containing_executable ()
 {
        return boost::dll::program_location().parent_path();
 }
 
+
 boost::filesystem::path
-shared_path ()
+resources_path ()
 {
-       return executable_path().parent_path();
+       return directory_containing_executable().parent_path();
 }
 
+
+boost::filesystem::path
+xsd_path ()
+{
+       return directory_containing_executable().parent_path() / "xsd";
+}
+
+
+boost::filesystem::path
+tags_path ()
+{
+       return directory_containing_executable().parent_path() / "tags";
+}
+
+
 boost::filesystem::path
 openssl_path ()
 {
-       return executable_path() / "openssl.exe";
+       return directory_containing_executable() / "openssl.exe";
 }
 
+
 #ifdef DCPOMATIC_DISK
 boost::filesystem::path
 disk_writer_path ()
 {
-       return executable_path() / "dcpomatic2_disk_writer.exe";
+       return directory_containing_executable() / "dcpomatic2_disk_writer.exe";
 }
 #endif
 
+
 /* Apparently there is no way to create an ofstream using a UTF-8
    filename under Windows.  We are hence reduced to using fopen
    with this wrapper.
@@ -246,10 +262,11 @@ Waker::~Waker ()
 
 }
 
+
 void
-start_tool (boost::filesystem::path dcpomatic, string executable, string)
+start_tool (string executable)
 {
-       boost::filesystem::path batch = dcpomatic.parent_path() / executable;
+       boost::filesystem::path batch = directory_containing_executable() / executable;
 
        STARTUPINFO startup_info;
        ZeroMemory (&startup_info, sizeof (startup_info));
@@ -263,18 +280,21 @@ start_tool (boost::filesystem::path dcpomatic, string executable, string)
        CreateProcess (0, cmd, 0, 0, FALSE, 0, 0, 0, &startup_info, &process_info);
 }
 
+
 void
-start_batch_converter (boost::filesystem::path dcpomatic)
+start_batch_converter ()
 {
-       start_tool (dcpomatic, "dcpomatic2_batch", "DCP-o-matic\\ 2\\ Batch\\ Converter.app");
+       start_tool ("dcpomatic2_batch");
 }
 
+
 void
-start_player (boost::filesystem::path dcpomatic)
+start_player ()
 {
-       start_tool (dcpomatic, "dcpomatic2_player", "DCP-o-matic\\ 2\\ Player.app");
+       start_tool ("dcpomatic2_player");
 }
 
+
 uint64_t
 thread_id ()
 {
@@ -324,12 +344,6 @@ home_directory ()
        return boost::filesystem::path(getenv("HOMEDRIVE")) / boost::filesystem::path(getenv("HOMEPATH"));
 }
 
-string
-command_and_read (string)
-{
-       return "";
-}
-
 /** @return true if this process is a 32-bit one running on a 64-bit-capable OS */
 bool
 running_32_on_64 ()
@@ -546,7 +560,7 @@ Drive::get ()
                                &geom, sizeof(geom), &returned, 0
                                );
 
-               LOG_DISK("Having a looky through %1 locked volumes", locked_volumes.size());
+               LOG_DISK("Having a look through %1 locked volumes", locked_volumes.size());
                bool locked = false;
                for (vector<pair<HANDLE, string> >::const_iterator i = locked_volumes.begin(); i != locked_volumes.end(); ++i) {
                        if (i->second == physical_drive) {
@@ -570,7 +584,7 @@ Drive::get ()
 bool
 Drive::unmount ()
 {
-       LOG_DISK("Unmounting %1 with %2 mount points XXX! MMMYEAH!", _device, _mount_points.size());
+       LOG_DISK("Unmounting %1 with %2 mount points", _device, _mount_points.size());
        DCPOMATIC_ASSERT (_mount_points.size() == 1);
        string const device_name = String::compose ("\\\\.\\%1", _mount_points.front());
        string const truncated = device_name.substr (0, device_name.length() - 1);
@@ -596,13 +610,6 @@ Drive::unmount ()
 }
 
 
-string
-Drive::device_for_write () const
-{
-       return device ();
-}
-
-
 boost::filesystem::path
 config_path ()
 {
@@ -621,3 +628,9 @@ disk_write_finished ()
 }
 
 
+string
+dcpomatic::get_process_id ()
+{
+       return dcp::raw_convert<string>(GetCurrentProcessId());
+}
+