diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-04-03 02:27:03 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-04-03 20:35:44 +0200 |
| commit | 1f24df1a4265040443109a982acb88de5849ccb8 (patch) | |
| tree | 207a1ec3f4193629a58c675d53a9d78bdd5a7289 | |
| parent | 79d401cc04ed5a69be991bb242ff503c97a0b0f4 (diff) | |
Fixes to macOS drive finding.
| -rw-r--r-- | src/lib/cross_osx.cc | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/src/lib/cross_osx.cc b/src/lib/cross_osx.cc index 7197eef79..f26127e7a 100644 --- a/src/lib/cross_osx.cc +++ b/src/lib/cross_osx.cc @@ -32,6 +32,7 @@ extern "C" { #include <boost/algorithm/string.hpp> #include <boost/foreach.hpp> #include <boost/dll/runtime_symbol_info.hpp> +#include <boost/regex.hpp> #include <sys/sysctl.h> #include <mach-o/dyld.h> #include <IOKit/pwr_mgt/IOPMLib.h> @@ -131,6 +132,7 @@ openssl_path () boost::filesystem::path disk_writer_path () { + return "/Users/carl/dcpomatic/src/dcpomatic/build/src/tools/dcpomatic2_disk_writer"; boost::filesystem::path path = app_contents(); path /= "MacOS"; path /= "dcpomatic2_disk_writer"; @@ -239,18 +241,60 @@ running_32_on_64 () } static void -disk_appeared(DADiskRef disk, void* context) +disk_appeared (DADiskRef disk, void* context) { const char* name = DADiskGetBSDName (disk); - if (name) { - vector<Drive>* drives = reinterpret_cast<vector<Drive>*> (context); - drives->push_back (Drive(name, 0, false, optional<string>(), optional<string>())); + if (!name) { + return; } + + vector<Drive>* drives = reinterpret_cast<vector<Drive>*> (context); + + CFDictionaryRef description = DADiskCopyDescription (disk); + + optional<string> vendor; + void const* str = CFDictionaryGetValue (description, kDADiskDescriptionDeviceVendorKey); + if (str) { + vendor = CFStringGetCStringPtr ((CFStringRef) str, kCFStringEncodingUTF8); + } + + optional<string> model; + str = CFDictionaryGetValue (description, kDADiskDescriptionDeviceModelKey); + if (str) { + model = CFStringGetCStringPtr ((CFStringRef) str, kCFStringEncodingUTF8); + } + + str = CFDictionaryGetValue (description, kDADiskDescriptionMediaPathKey); + if (str) { + if (strncmp(str, "IoDeviceTree:", 13) != 0) { + return; + } + } + + io_service_t service = DADiskCopyIOMedia (disk); + CFTypeRef whole_media_ref = IORegistryEntryCreateCFProperty (service, CFSTR(kIOMediaWholeKey), kCFAllocatorDefault, 0); + bool whole_media = false; + if (whole_media_ref) { + whole_media = CFBooleanGetValue((CFBooleanRef) whole_media); + CFRelease (whole_media_ref); + } + IOObjectRelease (service); + if (!whole_media) { + return; + } + + unsigned long size; + CFNumberGetValue ((CFNumberRef) CFDictionaryGetValue (description, kDADiskDescriptionMediaSizeKey), kCFNumberLongType, &size); + + CFRelease (description); + + drives->push_back (Drive(name, size, false, vendor, model)); } vector<Drive> get_drives () { +std::cout << "get_drives!\n"; vector<Drive> drives; DASessionRef session = DASessionCreate(kCFAllocatorDefault); |
