Untested basics of macOS drive finding.
authorCarl Hetherington <cth@carlh.net>
Mon, 20 Jan 2020 21:59:39 +0000 (22:59 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 28 Mar 2020 18:47:28 +0000 (19:47 +0100)
src/lib/cross.cc

index 25647bf3e65a466e85724d9aaaa80fe598cb1c0a..72ac11caec5f477492f7f485ee6ff50b7551cdd4 100644 (file)
@@ -544,10 +544,39 @@ running_32_on_64 ()
        return false;
 }
 
+#ifdef DCPOMATIC_OSX
+static void
+disk_appeared(DADiskRef disk, void* context)
+{
+       const char* name = DADiskGetBSDName (disk);
+       if (name) {
+               list<Drive>* drives = reinterpret_cast<list<Drive>*> (context);
+               drives->push_back (name, 0, false, optional<string>(), optional<string>());
+       }
+}
+#endif
+
 vector<Drive>
 get_drives ()
 {
        vector<Drive> drives;
+
+#ifdef DCPOMATIC_OSX
+       DASessionRef session = DASessionCreate(kCFAllocatorDefault);
+       if (!session) {
+               return drives;
+       }
+
+       DARegisterDiskAppearedCallback (session, NULL, disk_appeared, &drives);
+       CFRunLoopRef run_loop = CFRunLoopGetCurrent ();
+       DASessionScheduleWithRunLoop (session, run_loop, kCFRunLoopDefaultMode);
+       CFRunLoopStop (run_loop);
+       CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.05, 0);
+       DAUnregisterCallback(session, (void *) disk_appeared, &drives);
+       CFRelease(session);
+}
+#endif
+
 #ifdef DCPOMATIC_LINUX
 
        using namespace boost::filesystem;