macos device detection
This commit is contained in:
parent
fad035137f
commit
b8aa12486e
5 changed files with 96 additions and 2 deletions
|
@ -172,6 +172,9 @@ if (APPLE)
|
|||
GUI/RemovableDriveManagerMM.mm
|
||||
GUI/RemovableDriveManagerMM.h
|
||||
)
|
||||
#DK
|
||||
FIND_LIBRARY(DISKARBITRATION_LIBRARY DiskArbitration)
|
||||
|
||||
endif ()
|
||||
|
||||
add_library(libslic3r_gui STATIC ${SLIC3R_GUI_SOURCES})
|
||||
|
@ -179,6 +182,11 @@ add_library(libslic3r_gui STATIC ${SLIC3R_GUI_SOURCES})
|
|||
encoding_check(libslic3r_gui)
|
||||
|
||||
target_link_libraries(libslic3r_gui libslic3r avrdude cereal imgui GLEW::GLEW OpenGL::GL OpenGL::GLU hidapi)
|
||||
#DK
|
||||
if(APPLE)
|
||||
target_link_libraries(libslic3r_gui ${DISKARBITRATION_LIBRARY})
|
||||
endif()
|
||||
|
||||
if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
|
||||
add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE)
|
||||
endif ()
|
||||
|
|
|
@ -354,6 +354,7 @@ void RemovableDriveManager::eject_drive(const std::string &path)
|
|||
// but neither triggers "succesful safe removal messege"
|
||||
std::string command = "";
|
||||
#if __APPLE__
|
||||
//m_rdmmm->eject_device(path);
|
||||
command = "diskutil unmount ";
|
||||
#else
|
||||
command = "umount ";
|
||||
|
@ -365,6 +366,7 @@ void RemovableDriveManager::eject_drive(const std::string &path)
|
|||
std::cerr<<"Ejecting failed\n";
|
||||
return;
|
||||
}
|
||||
|
||||
m_did_eject = true;
|
||||
m_current_drives.erase(it);
|
||||
|
||||
|
|
|
@ -96,6 +96,7 @@ public:
|
|||
~RDMMMWrapper();
|
||||
void register_window();
|
||||
void list_devices();
|
||||
void eject_device(const std::string &path);
|
||||
void log(const std::string &msg);
|
||||
protected:
|
||||
void *m_imp;
|
||||
|
|
|
@ -6,4 +6,5 @@
|
|||
-(void) add_unmount_observer;
|
||||
-(void) on_device_unmount: (NSNotification*) notification;
|
||||
-(NSArray*) list_dev;
|
||||
-(void)eject_drive:(NSString *)path;
|
||||
@end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#import "RemovableDriveManager.hpp"
|
||||
#import "RemovableDriveManagerMM.h"
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <DiskArbitration/DiskArbitration.h>
|
||||
|
||||
@implementation RemovableDriveManagerMM
|
||||
|
||||
|
@ -27,9 +28,81 @@
|
|||
}
|
||||
-(NSArray*) list_dev
|
||||
{
|
||||
NSArray* devices = [[NSWorkspace sharedWorkspace] mountedRemovableMedia];
|
||||
return devices;
|
||||
// DEPRICATED:
|
||||
//NSArray* devices = [[NSWorkspace sharedWorkspace] mountedRemovableMedia];
|
||||
//return devices;
|
||||
|
||||
NSArray *mountedRemovableMedia = [[NSFileManager defaultManager] mountedVolumeURLsIncludingResourceValuesForKeys:nil options:NSVolumeEnumerationSkipHiddenVolumes];
|
||||
NSMutableArray *result = [NSMutableArray array];
|
||||
for(NSURL *volURL in mountedRemovableMedia)
|
||||
{
|
||||
int err = 0;
|
||||
DADiskRef disk;
|
||||
DASessionRef session;
|
||||
CFDictionaryRef descDict;
|
||||
session = DASessionCreate(NULL);
|
||||
if (session == NULL) {
|
||||
err = EINVAL;
|
||||
}
|
||||
if (err == 0) {
|
||||
disk = DADiskCreateFromVolumePath(NULL,session,(CFURLRef)volURL);
|
||||
if (session == NULL) {
|
||||
err = EINVAL;
|
||||
}
|
||||
}
|
||||
if (err == 0) {
|
||||
descDict = DADiskCopyDescription(disk);
|
||||
if (descDict == NULL) {
|
||||
err = EINVAL;
|
||||
}
|
||||
}
|
||||
if (err == 0) {
|
||||
CFTypeRef mediaEjectableKey = CFDictionaryGetValue(descDict,kDADiskDescriptionMediaEjectableKey);
|
||||
BOOL ejectable = [mediaEjectableKey boolValue];
|
||||
CFTypeRef deviceProtocolName = CFDictionaryGetValue(descDict,kDADiskDescriptionDeviceProtocolKey);
|
||||
CFTypeRef deviceModelKey = CFDictionaryGetValue(descDict, kDADiskDescriptionDeviceModelKey);
|
||||
if (mediaEjectableKey != NULL)
|
||||
{
|
||||
BOOL op = ejectable && (CFEqual(deviceProtocolName, CFSTR("USB")) || CFEqual(deviceModelKey, CFSTR("SD Card Reader")));
|
||||
//!CFEqual(deviceModelKey, CFSTR("Disk Image"));
|
||||
//
|
||||
if (op) {
|
||||
[result addObject:volURL.path];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (descDict != NULL) {
|
||||
CFRelease(descDict);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
-(void)eject_drive:(NSString *)path
|
||||
{
|
||||
DADiskRef disk;
|
||||
DASessionRef session;
|
||||
NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
|
||||
int err = 0;
|
||||
session = DASessionCreate(NULL);
|
||||
if (session == NULL) {
|
||||
err = EINVAL;
|
||||
}
|
||||
if (err == 0) {
|
||||
disk = DADiskCreateFromVolumePath(NULL,session,(CFURLRef)url);
|
||||
}
|
||||
if( err == 0)
|
||||
{
|
||||
DADiskUnmount(disk, kDADiskUnmountOptionDefault,
|
||||
NULL, NULL);
|
||||
}
|
||||
if (disk != NULL) {
|
||||
CFRelease(disk);
|
||||
}
|
||||
if (session != NULL) {
|
||||
CFRelease(session);
|
||||
}
|
||||
}
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
@ -66,6 +139,15 @@ void RDMMMWrapper::log(const std::string &msg)
|
|||
{
|
||||
NSLog(@"%s", msg.c_str());
|
||||
}
|
||||
void RDMMMWrapper::eject_device(const std::string &path)
|
||||
{
|
||||
if(m_imp)
|
||||
{
|
||||
NSString * pth = [NSString stringWithCString:path.c_str()
|
||||
encoding:[NSString defaultCStringEncoding]];
|
||||
[m_imp eject_drive:pth];
|
||||
}
|
||||
}
|
||||
}}//namespace Slicer::GUI
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue