NSWorkspace (BSDriveRecognition)
Language: Objective-C, Author: Michele Balistreri
License: Public domain
This NSWorkspace category allows you to discern between mounted physical volumes and network volumes. Please note that currently only webdav volumes are recognized as network drives, however this can be easily fixed by simply adding some string comparisons at the end of the -isNetworkVolumeAtPath: which the desired network volumes.
NSWorkspace (BSDriveRecognition) source preview
#import "NSWorkspace+BSDriveRecognition.h" @implementation NSWorkspace (BSDriveRecognition) - (NSArray *)mountedPhysicalVolumes { NSMutableArray *volumes = [NSMutableArray array]; NSEnumerator *enu = [[self mountedLocalVolumePaths] objectEnumerator]; NSString *mountPath; while((mountPath = [enu nextObject])) { if(![self isNetworkVolumeAtPath:mountPath]) { [volumes addObject:mountPath]; } } return [NSArray arrayWithArray:volumes]; } - (BOOL)isNetworkVolumeAtPath:(NSString *)path { struct statfs buffer; NSString *fileSystemType = nil; if(statfs([path fileSystemRepresentation], &buffer) == 0) { fileSystemType = [NSString stringWithCString:buffer.f_fstypename]; } return [fileSystemType isEqualToString:@"webdav"]; } @end
NSWorkspace (BSDriveRecognition) header preview
#import <Cocoa/Cocoa.h> #include <sys/param.h> #include <sys/mount.h> @interface NSWorkspace (BSDriveRecognition) - (NSArray *)mountedPhysicalVolumes; - (BOOL)isNetworkVolumeAtPath:(NSString *)path; @endDownload Archive
Compatible with:
- Mac OS X 10.3
- Mac OS X 10.4 PPC
- Mac OS X 10.4 Intel
- Mac OS X 10.5 PPC
- Mac OS X 10.5 Intel
Comments
Comment feed
