X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fcross_osx.cc;h=d0cb9f216980846307f70c84745e98a38f5a18be;hb=a5f481aae19a6ef5b0cad48edaea5b58fc00ee05;hp=fc8ccd4a872dbe2566324d877d053e5beaa80637;hpb=8aa97c043d73e0c6c8bc484a307b944702c7d3dd;p=dcpomatic.git diff --git a/src/lib/cross_osx.cc b/src/lib/cross_osx.cc index fc8ccd4a8..d0cb9f216 100644 --- a/src/lib/cross_osx.cc +++ b/src/lib/cross_osx.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "cross.h" #include "compose.hpp" #include "log.h" @@ -52,6 +53,7 @@ extern "C" { #include "i18n.h" + using std::pair; using std::list; using std::ifstream; @@ -65,7 +67,8 @@ using std::runtime_error; using std::map; using std::shared_ptr; using boost::optional; -using boost::function; +using std::function; + /** @param s Number of seconds to sleep for */ void @@ -74,12 +77,14 @@ dcpomatic_sleep_seconds (int s) sleep (s); } + void dcpomatic_sleep_milliseconds (int ms) { usleep (ms * 1000); } + /** @return A string of CPU information (model name etc.) */ string cpu_info () @@ -88,7 +93,7 @@ cpu_info () char buffer[64]; size_t N = sizeof (buffer); - if (sysctlbyname ("machdep.cpu.brand_string", buffer, &N, 0, 0) == 0) { + if (sysctlbyname("machdep.cpu.brand_string", buffer, &N, 0, 0) == 0) { info = buffer; } @@ -127,7 +132,7 @@ tags_path () void run_ffprobe (boost::filesystem::path content, boost::filesystem::path out) { - boost::filesystem::path path = directory_containing_executable () / "ffprobe"; + auto path = directory_containing_executable () / "ffprobe"; string ffprobe = "\"" + path.string() + "\" \"" + content.string() + "\" 2> \"" + out.string() + "\""; LOG_GENERAL (N_("Probing with %1"), ffprobe); @@ -135,13 +140,14 @@ run_ffprobe (boost::filesystem::path content, boost::filesystem::path out) } -list > + +list> mount_info () { - list > m; - return m; + return {}; } + boost::filesystem::path openssl_path () { @@ -158,6 +164,7 @@ disk_writer_path () } #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. @@ -165,40 +172,45 @@ disk_writer_path () FILE * fopen_boost (boost::filesystem::path p, string t) { - return fopen (p.c_str(), t.c_str ()); + return fopen (p.c_str(), t.c_str()); } + int dcpomatic_fseek (FILE* stream, int64_t offset, int whence) { return fseek (stream, offset, whence); } + void Waker::nudge () { } + Waker::Waker () { boost::mutex::scoped_lock lm (_mutex); IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR ("Encoding DCP"), &_assertion_id); } + Waker::~Waker () { boost::mutex::scoped_lock lm (_mutex); IOPMAssertionRelease (_assertion_id); } + void 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 + auto 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"; @@ -235,18 +247,21 @@ thread_id () return (uint64_t) pthread_self (); } + int avio_open_boost (AVIOContext** s, boost::filesystem::path file, int flags) { return avio_open (s, file.c_str(), flags); } + boost::filesystem::path home_directory () { - return getenv("HOME"); + return getenv("HOME"); } + /** @return true if this process is a 32-bit one running on a 64-bit-capable OS */ bool running_32_on_64 () @@ -255,6 +270,7 @@ running_32_on_64 () return false; } + static optional get_vendor (CFDictionaryRef& description) { @@ -273,6 +289,7 @@ get_vendor (CFDictionaryRef& description) return s; } + static optional get_model (CFDictionaryRef& description) { @@ -291,12 +308,14 @@ get_model (CFDictionaryRef& description) return s; } + struct MediaPath { bool real; ///< true for a "real" disk, false for a synthesized APFS one std::string prt; ///< "PRT" entry from the media path }; + static optional analyse_media_path (CFDictionaryRef& description) { @@ -343,6 +362,7 @@ analyse_media_path (CFDictionaryRef& description) return mp; } + static bool is_whole_drive (DADiskRef& disk) { @@ -357,6 +377,7 @@ is_whole_drive (DADiskRef& disk) return whole_media; } + static optional mount_point (CFDictionaryRef& description) { @@ -372,6 +393,7 @@ mount_point (CFDictionaryRef& description) return boost::filesystem::path(mount_path_buffer); } + /* Here follows some rather intricate and (probably) fragile code to find the list of available * "real" drives on macOS that we might want to write a DCP to. * @@ -408,6 +430,7 @@ struct Disk unsigned long size; }; + static void disk_appeared (DADiskRef disk, void* context) { @@ -463,19 +486,20 @@ disk_appeared (DADiskRef disk, void* context) reinterpret_cast*>(context)->push_back(this_disk); } + vector Drive::get () { using namespace boost::algorithm; vector disks; - DASessionRef session = DASessionCreate(kCFAllocatorDefault); + auto session = DASessionCreate(kCFAllocatorDefault); if (!session) { return {}; } DARegisterDiskAppearedCallback (session, NULL, disk_appeared, &disks); - CFRunLoopRef run_loop = CFRunLoopGetCurrent (); + auto run_loop = CFRunLoopGetCurrent (); DASessionScheduleWithRunLoop (session, run_loop, kCFRunLoopDefaultMode); CFRunLoopStop (run_loop); CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.05, 0); @@ -496,7 +520,7 @@ Drive::get () } /* Make a map of the PRT codes and mount points of mounted, synthesized disks */ - map > mounted_synths; + map> mounted_synths; for (auto& i: disks) { if (!i.real && !i.mount_points.empty()) { LOG_DISK("Found a mounted synth %1 with %2", i.mount_point, i.prt); @@ -559,12 +583,12 @@ Drive::unmount () { LOG_DISK_NC("Unmount operation started"); - DASessionRef session = DASessionCreate(kCFAllocatorDefault); + auto session = DASessionCreate(kCFAllocatorDefault); if (!session) { return false; } - DADiskRef disk = DADiskCreateFromBSDName(kCFAllocatorDefault, session, _device.c_str()); + auto disk = DADiskCreateFromBSDName(kCFAllocatorDefault, session, _device.c_str()); if (!disk) { return false; } @@ -607,3 +631,19 @@ dcpomatic::get_process_id () { return dcp::raw_convert(getpid()); } + + +boost::filesystem::path +fix_long_path (boost::filesystem::path path) +{ + return path; +} + + +bool +show_in_file_manager (boost::filesystem::path, boost::filesystem::path select) +{ + int r = system (String::compose("open -R \"%1\"", select.string()).c_str()); + return static_cast(WEXITSTATUS(r)); +} +