enumarating removable drives on mac - added Secure Digital option
hopefully a fix for issue #3793
This commit is contained in:
parent
56fa84c9d9
commit
0836df93e1
2 changed files with 29 additions and 6 deletions
|
@ -339,8 +339,10 @@ void RemovableDriveManager::eject_drive()
|
||||||
// but neither triggers "succesful safe removal messege"
|
// but neither triggers "succesful safe removal messege"
|
||||||
std::string command =
|
std::string command =
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
//this->eject_device(m_last_save_path);
|
|
||||||
"diskutil unmount ";
|
"diskutil unmount ";
|
||||||
|
//Another option how to eject at mac. Currently not working.
|
||||||
|
//used insted of system() command;
|
||||||
|
//this->eject_device(correct_path);
|
||||||
#else
|
#else
|
||||||
"umount ";
|
"umount ";
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,10 +4,22 @@
|
||||||
#import <AppKit/AppKit.h>
|
#import <AppKit/AppKit.h>
|
||||||
#import <DiskArbitration/DiskArbitration.h>
|
#import <DiskArbitration/DiskArbitration.h>
|
||||||
|
|
||||||
|
static void eject_callback(DADiskRef disk, DADissenterRef dissenter, void *context)
|
||||||
|
{
|
||||||
|
NSLog(@"eject successfull");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unmount_callback(DADiskRef disk, DADissenterRef dissenter, void *context)
|
||||||
|
{
|
||||||
|
//if (dissenter) {
|
||||||
|
//?
|
||||||
|
//} else {
|
||||||
|
DADiskEject(disk, kDADiskEjectOptionDefault, eject_callback, context);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
@implementation RemovableDriveManagerMM
|
@implementation RemovableDriveManagerMM
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-(instancetype) init
|
-(instancetype) init
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
@ -59,9 +71,17 @@
|
||||||
CFTypeRef mediaEjectableKey = CFDictionaryGetValue(descDict,kDADiskDescriptionMediaEjectableKey);
|
CFTypeRef mediaEjectableKey = CFDictionaryGetValue(descDict,kDADiskDescriptionMediaEjectableKey);
|
||||||
BOOL ejectable = [mediaEjectableKey boolValue];
|
BOOL ejectable = [mediaEjectableKey boolValue];
|
||||||
CFTypeRef deviceProtocolName = CFDictionaryGetValue(descDict,kDADiskDescriptionDeviceProtocolKey);
|
CFTypeRef deviceProtocolName = CFDictionaryGetValue(descDict,kDADiskDescriptionDeviceProtocolKey);
|
||||||
|
|
||||||
CFTypeRef deviceModelKey = CFDictionaryGetValue(descDict, kDADiskDescriptionDeviceModelKey);
|
CFTypeRef deviceModelKey = CFDictionaryGetValue(descDict, kDADiskDescriptionDeviceModelKey);
|
||||||
|
//debug logging
|
||||||
|
/*
|
||||||
|
if (deviceProtocolName)
|
||||||
|
NSLog(@"%@",(CFStringRef)deviceProtocolName);
|
||||||
|
if (deviceModelKey)
|
||||||
|
NSLog(@"-%@",(CFStringRef)deviceModelKey);
|
||||||
|
*/
|
||||||
if (mediaEjectableKey != nullptr) {
|
if (mediaEjectableKey != nullptr) {
|
||||||
BOOL op = ejectable && (CFEqual(deviceProtocolName, CFSTR("USB")) || CFEqual(deviceModelKey, CFSTR("SD Card Reader")));
|
BOOL op = ejectable && (CFEqual(deviceProtocolName, CFSTR("USB")) || CFEqual(deviceModelKey, CFSTR("SD Card Reader")) || CFEqual(deviceProtocolName, CFSTR("Secure Digital")));
|
||||||
//!CFEqual(deviceModelKey, CFSTR("Disk Image"));
|
//!CFEqual(deviceModelKey, CFSTR("Disk Image"));
|
||||||
if (op)
|
if (op)
|
||||||
[result addObject:volURL.path];
|
[result addObject:volURL.path];
|
||||||
|
@ -86,7 +106,8 @@
|
||||||
if (err == 0)
|
if (err == 0)
|
||||||
disk = DADiskCreateFromVolumePath(nullptr,session,(CFURLRef)url);
|
disk = DADiskCreateFromVolumePath(nullptr,session,(CFURLRef)url);
|
||||||
if( err == 0)
|
if( err == 0)
|
||||||
DADiskUnmount(disk, kDADiskUnmountOptionDefault, nullptr, nullptr);
|
//DADiskUnmount(disk, kDADiskUnmountOptionDefault, nullptr, nullptr);
|
||||||
|
DADiskUnmount(disk, kDADiskUnmountOptionWhole | kDADiskUnmountOptionForce, unmount_callback, nullptr);
|
||||||
if (disk != nullptr)
|
if (disk != nullptr)
|
||||||
CFRelease(disk);
|
CFRelease(disk);
|
||||||
if (session != nullptr)
|
if (session != nullptr)
|
||||||
|
|
Loading…
Reference in a new issue