X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fcross_osx.cc;h=76c451a6f3df2078b77d3ed951421318592f0f18;hp=3b08c96849edc328b3808b361885d9ef035eb3f8;hb=dd9be86db6cde0afa5da0d1d1ac43b42e05dca26;hpb=56caa542a558a3e261a3da4773c9ed3e66e262ab diff --git a/src/lib/cross_osx.cc b/src/lib/cross_osx.cc index 3b08c9684..76c451a6f 100644 --- a/src/lib/cross_osx.cc +++ b/src/lib/cross_osx.cc @@ -24,6 +24,7 @@ #include "dcpomatic_log.h" #include "config.h" #include "exceptions.h" +#include "warnings.h" #include #include extern "C" { @@ -32,6 +33,10 @@ extern "C" { #include #include #include +#if BOOST_VERSION >= 106100 +#include +#endif +#include #include #include #include @@ -59,7 +64,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; using boost::function; @@ -91,14 +96,13 @@ cpu_info () return info; } -/** @return Path of the Contents directory in the .app */ + boost::filesystem::path -app_contents () +directory_containing_executable () { - /* Could use boost::dll::program_location().parent_path().parent_path() but that - * boost library isn't in the 10.6 environment we're currently using and I don't - * really want to change it right now. - */ +#if BOOST_VERSION >= 106100 + return boost::dll::program_location().parent_path(); +#else uint32_t size = 1024; char buffer[size]; if (_NSGetExecutablePath (buffer, &size)) { @@ -107,29 +111,43 @@ app_contents () boost::filesystem::path path (buffer); path = boost::filesystem::canonical (path); - path = path.parent_path (); - path = path.parent_path (); - return path; + return path.parent_path (); +#endif +} + + +boost::filesystem::path +resources_path () +{ + return directory_containing_executable().parent_path() / "Resources"; } + boost::filesystem::path -shared_path () +xsd_path () { - return app_contents() / "Resources"; + return resources_path() / "xsd"; } + +boost::filesystem::path +tags_path () +{ + return resources_path() / "tags"; +} + + void run_ffprobe (boost::filesystem::path content, boost::filesystem::path out) { - boost::filesystem::path path = app_contents(); - path /= "MacOS"; - path /= "ffprobe"; + boost::filesystem::path path = directory_containing_executable () / "ffprobe"; string ffprobe = "\"" + path.string() + "\" \"" + content.string() + "\" 2> \"" + out.string() + "\""; LOG_GENERAL (N_("Probing with %1"), ffprobe); system (ffprobe.c_str ()); } + list > mount_info () { @@ -140,21 +158,16 @@ mount_info () boost::filesystem::path openssl_path () { - boost::filesystem::path path = app_contents(); - path /= "MacOS"; - path /= "openssl"; - return path; + return directory_containing_executable() / "openssl"; } + #ifdef DCPOMATIC_DISK /* Note: this isn't actually used at the moment as the disk writer is started as a service */ boost::filesystem::path disk_writer_path () { - boost::filesystem::path path = app_contents(); - path /= "MacOS"; - path /= "dcpomatic2_disk_writer"; - return path; + return directory_containing_executable() / "dcpomatic2_disk_writer"; } #endif @@ -183,10 +196,7 @@ Waker::nudge () Waker::Waker () { boost::mutex::scoped_lock lm (_mutex); - /* We should use this */ - // IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR ("Encoding DCP"), &_assertion_id); - /* but it's not available on 10.5, so we use this */ - IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &_assertion_id); + IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR ("Encoding DCP"), &_assertion_id); } Waker::~Waker () @@ -196,37 +206,42 @@ Waker::~Waker () } void -start_tool (boost::filesystem::path dcpomatic, string executable, string app) -{ - boost::filesystem::path batch = dcpomatic.parent_path (); - batch = batch.parent_path (); // MacOS - batch = batch.parent_path (); // Contents - batch = batch.parent_path (); // DCP-o-matic.app - batch = batch.parent_path (); // Applications - batch /= app; - batch /= "Contents"; - batch /= "MacOS"; - batch /= executable; +start_tool (string executable, string app) +{ + boost::filesystem::path exe_path = directory_containing_executable(); + exe_path = exe_path.parent_path (); // Contents + exe_path = exe_path.parent_path (); // DCP-o-matic 2.app + exe_path = exe_path.parent_path (); // Applications + exe_path /= app; + exe_path /= "Contents"; + exe_path /= "MacOS"; + exe_path /= executable; pid_t pid = fork (); if (pid == 0) { - int const r = system (batch.string().c_str()); + LOG_GENERAL ("start_tool %1 %2 with path %3", executable, app, exe_path.string()); + int const r = system (exe_path.string().c_str()); exit (WEXITSTATUS (r)); + } else if (pid == -1) { + LOG_ERROR_NC("Fork failed in start_tool"); } } + 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", "DCP-o-matic\\ 2\\ Batch\\ Converter.app"); } + void -start_player (boost::filesystem::path dcpomatic) +start_player () { - start_tool (dcpomatic, "dcpomatic2_player", "DCP-o-matic\\ 2\\ Player.app"); + start_tool ("dcpomatic2_player", "DCP-o-matic\\ 2\\ Player.app"); } + uint64_t thread_id () { @@ -245,12 +260,6 @@ home_directory () return getenv("HOME"); } -string -command_and_read (string cmd) -{ - return ""; -} - /** @return true if this process is a 32-bit one running on a 64-bit-capable OS */ bool running_32_on_64 () @@ -298,10 +307,19 @@ analyse_media_path (CFDictionaryRef& description) void const* str = CFDictionaryGetValue (description, kDADiskDescriptionMediaPathKey); if (!str) { + LOG_DISK_NC("There is no MediaPathKey"); return optional(); } string path(CFStringGetCStringPtr((CFStringRef) str, kCFStringEncodingUTF8)); + LOG_DISK("MediaPathKey is %1", path); + + if (path.find("/IOHDIXController") != string::npos) { + /* This is a disk image, so we completely ignore it */ + LOG_DISK_NC("Ignoring this as it seems to be a disk image"); + return optional(); + } + MediaPath mp; if (starts_with(path, "IODeviceTree:")) { mp.real = true; @@ -507,7 +525,7 @@ config_path () } -void done_callback(DADiskRef disk, DADissenterRef dissenter, void* context) +void done_callback(DADiskRef, DADissenterRef dissenter, void* context) { LOG_DISK_NC("Unmount finished"); bool* success = reinterpret_cast (context); @@ -557,3 +575,20 @@ disk_write_finished () } + +void +make_foreground_application () +{ + ProcessSerialNumber serial; +DCPOMATIC_DISABLE_WARNINGS + GetCurrentProcess (&serial); +DCPOMATIC_ENABLE_WARNINGS + TransformProcessType (&serial, kProcessTransformToForegroundApplication); +} + + +string +dcpomatic::get_process_id () +{ + return dcp::raw_convert(getpid()); +}