Created
July 22, 2015 15:56
-
-
Save jnozzi/ad9eded5e65ee900eec4 to your computer and use it in GitHub Desktop.
A simple test if a mounted volume or device at a given path is a disk image (DMG).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <DiskArbitration/DiskArbitration.h> | |
// ... | |
- (BOOL)isDMGVolumeAtURL:(NSURL *)url | |
{ | |
BOOL isDMG = NO; | |
if (url.isFileURL) { | |
DASessionRef session = DASessionCreate(kCFAllocatorDefault); | |
if (session != nil) { | |
DADiskRef disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, (__bridge CFURLRef)url); | |
if (disk != nil) { | |
NSDictionary * desc = CFBridgingRelease(DADiskCopyDescription(disk)); | |
NSString * model = desc[(NSString *)kDADiskDescriptionDeviceModelKey]; | |
isDMG = ([model isEqualToString:@"Disk Image"]); | |
CFRelease(disk); | |
} | |
CFRelease(session); | |
} | |
} | |
return isDMG; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment