Rename shared_path -> resources_path.
[dcpomatic.git] / src / lib / cross_osx.cc
index a15ad032257be78bc907b2d107e6d54190186900..ef193b640aa202a0288c7e5ea800934bf50228c1 100644 (file)
@@ -24,6 +24,7 @@
 #include "dcpomatic_log.h"
 #include "config.h"
 #include "exceptions.h"
+#include "warnings.h"
 #include <dcp/raw_convert.h>
 #include <glib.h>
 extern "C" {
@@ -32,6 +33,10 @@ extern "C" {
 #include <boost/algorithm/string.hpp>
 #include <boost/foreach.hpp>
 #include <boost/regex.hpp>
+#if BOOST_VERSION >= 106100
+#include <boost/dll/runtime_symbol_info.hpp>
+#endif
+#include <ApplicationServices/ApplicationServices.h>
 #include <sys/sysctl.h>
 #include <mach-o/dyld.h>
 #include <IOKit/pwr_mgt/IOPMLib.h>
@@ -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,36 @@ 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";
 }
 
+
 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<pair<string, string> >
 mount_info ()
 {
@@ -140,21 +151,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 +189,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,9 +199,9 @@ Waker::~Waker ()
 }
 
 void
-start_tool (boost::filesystem::path dcpomatic, string executable, string app)
+start_tool (string executable, string app)
 {
-       boost::filesystem::path batch = dcpomatic.parent_path ();
+       boost::filesystem::path batch = directory_containing_executable();
        batch = batch.parent_path (); // MacOS
        batch = batch.parent_path (); // Contents
        batch = batch.parent_path (); // DCP-o-matic.app
@@ -215,18 +218,21 @@ start_tool (boost::filesystem::path dcpomatic, string executable, string app)
        }
 }
 
+
 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 ()
 {
@@ -246,7 +252,7 @@ home_directory ()
 }
 
 string
-command_and_read (string cmd)
+command_and_read (string)
 {
        return "";
 }
@@ -516,7 +522,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<bool*> (context);
@@ -566,3 +572,14 @@ disk_write_finished ()
 
 }
 
+
+void
+make_foreground_application ()
+{
+       ProcessSerialNumber serial;
+DCPOMATIC_DISABLE_WARNINGS
+       GetCurrentProcess (&serial);
+DCPOMATIC_ENABLE_WARNINGS
+       TransformProcessType (&serial, kProcessTransformToForegroundApplication);
+}
+