diff options
author | Damiano Galassi <[email protected]> | 2016-01-09 13:20:49 +0100 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2016-01-09 13:20:49 +0100 |
commit | 361c5143f3be4ab72bd08bed724b05007e4d108b (patch) | |
tree | 9ce605e3695b9d7f79a8dedf0d10ce7902151be7 /macosx | |
parent | a330924d670169ba78a41dd530604b9bf41a6180 (diff) |
MacGui: add bluray detection to HBDVDDetector.
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/HBDVDDetector.h | 2 | ||||
-rw-r--r-- | macosx/HBDVDDetector.m | 96 |
2 files changed, 60 insertions, 38 deletions
diff --git a/macosx/HBDVDDetector.h b/macosx/HBDVDDetector.h index 978f944da..a5bb7beae 100644 --- a/macosx/HBDVDDetector.h +++ b/macosx/HBDVDDetector.h @@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN - (HBDVDDetector *)initWithPath: (NSString *)aPath NS_DESIGNATED_INITIALIZER; @property (nonatomic, getter=isVideoDVD, readonly) BOOL videoDVD; +@property (nonatomic, getter=isVideoBluRay, readonly) BOOL videoBluRay; + @property (nonatomic, readonly, copy) NSString *devicePath; @end diff --git a/macosx/HBDVDDetector.m b/macosx/HBDVDDetector.m index 1d6c40d11..106c3230a 100644 --- a/macosx/HBDVDDetector.m +++ b/macosx/HBDVDDetector.m @@ -10,23 +10,12 @@ #include <IOKit/IOKitLib.h> #include <IOKit/storage/IOMedia.h> #include <IOKit/storage/IODVDMedia.h> +#include <IOKit/storage/IOBDMedia.h> #include <sys/mount.h> #import "HBDVDDetector.h" -@interface HBDVDDetector (Private) - -- (NSString *)bsdName; -- (BOOL)pathHasVideoTS; -- (BOOL)deviceIsDVD; -- (io_service_t)getIOKitServiceForBSDName; -- (BOOL)isDVDService: (io_service_t)service; -- (BOOL)isWholeMediaService: (io_service_t)service; - -@end - - @implementation HBDVDDetector { NSString *path; @@ -62,15 +51,60 @@ } +- (BOOL)isVideoBluRay +{ + return ( [self pathHasBDMV] && [self deviceIsBluRay] ); +} + + - (NSString *)devicePath { return [NSString stringWithFormat:@"/dev/%@", [self bsdName]]; } -@end +#pragma mark - DVD + +- (BOOL)pathHasVideoTS +{ + // Check one level under the path + if( [[NSFileManager defaultManager] fileExistsAtPath: + [path stringByAppendingPathComponent:@"VIDEO_TS"]] ) + { + return YES; + } + + // Now check above the path + return [[path pathComponents] containsObject:@"VIDEO_TS"]; +} + + +- (BOOL)deviceIsDVD +{ + return [self deviceIs:kIODVDMediaClass]; +} + +#pragma mark - BluRay +- (BOOL)pathHasBDMV +{ + // Check one level under the path + if( [[NSFileManager defaultManager] fileExistsAtPath: + [path stringByAppendingPathComponent:@"BDMV"]] ) + { + return YES; + } -@implementation HBDVDDetector (Private) + // Now check above the path + return [[path pathComponents] containsObject:@"BDMV"]; +} + + +- (BOOL)deviceIsBluRay +{ + return [self deviceIs:kIOBDMediaClass]; +} + +#pragma mark - Common - (NSString *)bsdName { @@ -80,7 +114,7 @@ } struct statfs s; - statfs([path fileSystemRepresentation], &s); + statfs(path.fileSystemRepresentation, &s); bsdName = @(s.f_mntfromname); @@ -93,28 +127,14 @@ } -- (BOOL)pathHasVideoTS -{ - // Check one level under the path - if( [[NSFileManager defaultManager] fileExistsAtPath: - [path stringByAppendingPathComponent:@"VIDEO_TS"]] ) - { - return YES; - } - - // Now check above the path - return [[path pathComponents] containsObject:@"VIDEO_TS"]; -} - - -- (BOOL)deviceIsDVD +- (BOOL)deviceIs:(const io_name_t)class { io_service_t service = [self getIOKitServiceForBSDName]; if( service == IO_OBJECT_NULL ) { return NO; } - BOOL result = [self isDVDService:service]; + BOOL result = [self isService:service class:class]; IOObjectRelease(service); return result; } @@ -136,7 +156,7 @@ } -- (BOOL)isDVDService: (io_service_t)service +- (BOOL)isService: (io_service_t)service class:(const io_name_t)class { // Find the IOMedia object that represents the entire (whole) media that the // volume is on. @@ -169,16 +189,16 @@ // so add a reference to balance. IOObjectRetain( service ); - BOOL isDVD = NO; + BOOL conformsToClass = NO; do { - isDVD = ( [self isWholeMediaService:service] && - IOObjectConformsTo(service, kIODVDMediaClass) ); + conformsToClass = ( [self isWholeMediaService:service] && + IOObjectConformsTo(service, class) ); IOObjectRelease(service); - } while( !isDVD && (service = IOIteratorNext(iter)) ); + } while( !conformsToClass && (service = IOIteratorNext(iter)) ); IOObjectRelease( iter ); - return isDVD; + return conformsToClass; } @@ -210,4 +230,4 @@ } -@end
\ No newline at end of file +@end |