Permalink
Browse files

Merge branch 'master' of github.com:uliwitness/UliKit

  • Loading branch information...
2 parents ee405de + 1ef6795 commit 4f457cf4292f175e2de0df7aae7e3695ea75a22d @uliwitness committed Dec 18, 2010
Showing with 51 additions and 34 deletions.
  1. +31 −27 NSWorkspace+TypeOfVolumeAtPath.m
  2. +6 −3 SCParamBlock.m
  3. +14 −4 UKFilePathView.m
@@ -26,7 +26,6 @@
//
#import "NSWorkspace+TypeOfVolumeAtPath.h"
-#import "NSString+CarbonUtilities.h"
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <IOKit/IOKitLib.h>
@@ -35,6 +34,7 @@
#include <IOKit/storage/IODVDMedia.h>
#include <IOKit/storage/IOStorageDeviceCharacteristics.h>
#include <IOKit/usb/IOUSBLib.h>
+#import "NSString+CarbonUtilities.h"
@@ -56,8 +56,8 @@
io_name_t className;
kern_return_t kernResult;
- if (IOObjectConformsTo(service, kIOMediaClass)) {
-
+ if( IOObjectConformsTo(service, kIOMediaClass) )
+ {
CFTypeRef wholeMedia;
// Find out whether it's a whole media:
@@ -66,16 +66,18 @@
kCFAllocatorDefault,
0);
- if (NULL == wholeMedia) {
+ if( NULL == wholeMedia )
+ {
printf("Could not retrieve Whole property\n");
}
- else {
+ else
+ {
isWholeMedia = CFBooleanGetValue(wholeMedia);
CFRelease(wholeMedia);
}
}
- if (isWholeMedia)
+ if( isWholeMedia )
{
kernResult = IOObjectGetClass(service, className);
mediaType = [NSString stringWithUTF8String: className];
@@ -96,18 +98,22 @@
kIORegistryIterateRecursively | kIORegistryIterateParents,
&iter);
- if (KERN_SUCCESS != kernResult) {
+ if (KERN_SUCCESS != kernResult)
+ {
printf("IORegistryEntryCreateIterator returned %d\n", kernResult);
}
- else if (NULL == iter) {
+ else if (IO_OBJECT_NULL == iter)
+ {
printf("IORegistryEntryCreateIterator returned a NULL iterator\n");
}
- else {
+ else
+ {
// A reference on the initial service object is released in the do-while loop below,
// so add a reference to balance
IOObjectRetain(service);
- do {
+ do
+ {
mediaType = IsWholeMedia(service);
IOObjectRelease(service);
} while ((service = IOIteratorNext(iter)) && !mediaType);
@@ -142,7 +148,6 @@ -(NSString*) typeOfVolumeAtPath: (NSString*)path
FSRef fileRef;
FSCatalogInfo catInfo;
GetVolParmsInfoBuffer volumeParms;
- HParamBlockRec pb;
kern_return_t kernResult;
if( ![path getFSRef: &fileRef] )
@@ -152,18 +157,11 @@ -(NSString*) typeOfVolumeAtPath: (NSString*)path
if( err != noErr )
NSLog( @"FSGetCatalogInfo returned %ld", err );
- // Use the volume reference number to retrieve the volume parameters. See the documentation
- // on PBHGetVolParmsSync for other possible ways to specify a volume.
- pb.ioParam.ioNamePtr = NULL;
- pb.ioParam.ioVRefNum = catInfo.volume;
- pb.ioParam.ioBuffer = (Ptr) &volumeParms;
- pb.ioParam.ioReqCount = sizeof(volumeParms);
-
// A version 4 GetVolParmsInfoBuffer contains the BSD node name in the vMDeviceID field.
// It is actually a char * value. This is mentioned in the header CoreServices/CarbonCore/Files.h.
- err = PBHGetVolParmsSync( &pb );
+ err = FSGetVolumeParms( catInfo.volume, &volumeParms, sizeof(volumeParms) );
if( err != noErr )
- NSLog( @"PBHGetVolParmsSync returned %ld", err );
+ NSLog( @"FSGetVolumeParms returned %ld", err );
char *bsdName = (char *) volumeParms.vMDeviceID;
CFMutableDictionaryRef matchingDict;
@@ -180,33 +178,39 @@ -(NSString*) typeOfVolumeAtPath: (NSString*)path
NSLog( @"IOMasterPort returned %d\n", kernResult);
}
- NSLog(@"%s",bsdName);
+ NSLog(@"volume path & BSD name: %@ %s",path,bsdName);
matchingDict = IOBSDNameMatching( gMasterPort, 0, bsdName );
- if (NULL == matchingDict) {
+ if (NULL == matchingDict)
+ {
printf("IOBSDNameMatching returned a NULL dictionary.\n");
}
else {
// Return an iterator across all objects with the matching BSD node name. Note that there
// should only be one match!
kernResult = IOServiceGetMatchingServices(gMasterPort, matchingDict, &iter);
- if (KERN_SUCCESS != kernResult) {
+ if (KERN_SUCCESS != kernResult)
+ {
printf("IOServiceGetMatchingServices returned %d\n", kernResult);
}
- else if (NULL == iter) {
+ else if (IO_OBJECT_NULL == iter)
+ {
printf("IOServiceGetMatchingServices returned a NULL iterator\n");
}
- else {
+ else
+ {
service = IOIteratorNext(iter);
// Release this now because we only expect the iterator to contain
// a single io_service_t.
IOObjectRelease(iter);
- if (NULL == service) {
+ if (IO_OBJECT_NULL == service)
+ {
printf("IOIteratorNext returned NULL\n");
}
- else {
+ else
+ {
mediaType = FindWholeMedia(service);
NSMutableDictionary* propDict = nil;
IORegistryEntryCreateCFProperties( service, (CFMutableDictionaryRef*) &propDict, kCFAllocatorDefault, 0 );
View
@@ -308,7 +308,12 @@ +(Handle) stringHandleFromData: (NSData*)theData
+(NSString*) stringFromStringHandle: (Handle)theHd
{
- return [NSString stringWithCString: *theHd encoding: NSMacOSRomanStringEncoding];
+ Size theLen = GetHandleSize(theHd);
+ if( size == 0 )
+ return @"";
+ if( (*theHd)[theLen-1] == '\0' ) // If last char is NULL terminator, don't include it.
+ theLen -= 1;
+ return [[[NSString alloc] initWithBytes: *theHd length: theLen encoding: NSMacOSRomanStringEncoding] autorelease];
}
@@ -317,6 +322,4 @@ +(NSData*) dataFromStringHandle: (Handle)theHd
return [NSData dataWithBytes: *theHd length: GetHandleSize(theHd)];
}
-
-
@end
View
@@ -680,7 +680,7 @@ -(void) revealInFinder: (id)sender
}
--(BOOL) validateMenuItem: (id<NSMenuItem>)item
+-(BOOL) validateMenuItem: (NSMenuItem*)item
{
if( [item action] == @selector(revealInFinder:)
|| [item action] == @selector(showRealNames:) )
@@ -771,6 +771,17 @@ -(NSMenu*) menuForEvent: (NSEvent*)evt
}
+-(NSWindow*) windowForSheet
+{
+ NSWindow* theWindow = [self window];
+ NSDocument* currDoc = [[NSDocumentController sharedDocumentController] documentForWindow: theWindow];
+ if( currDoc )
+ theWindow = [currDoc windowForSheet];
+
+ return theWindow;
+}
+
+
// -----------------------------------------------------------------------------
// pickFile:
// Button action for showing an open panel to fill this field with the
@@ -780,14 +791,13 @@ -(NSMenu*) menuForEvent: (NSEvent*)evt
-(IBAction) pickFile: (id)sender
{
NSOpenPanel* op = [NSOpenPanel openPanel];
-
[op setAllowsMultipleSelection: NO];
[op setCanChooseFiles: canChooseFiles];
[op setCanChooseDirectories: canChooseDirectories];
[op setTreatsFilePackagesAsDirectories: treatsFilePackagesAsDirectories];
[op beginSheetForDirectory: [filePath stringByDeletingLastPathComponent]
- file: filePath types: types modalForWindow: [self window]
+ file: filePath types: types modalForWindow: [self windowForSheet]
modalDelegate: self didEndSelector: @selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo: self];
}
@@ -806,7 +816,7 @@ -(IBAction) pickNewFile: (id)sender
[op setTreatsFilePackagesAsDirectories: treatsFilePackagesAsDirectories];
[op beginSheetForDirectory: [filePath stringByDeletingLastPathComponent]
- file: filePath modalForWindow: [self window]
+ file: filePath modalForWindow: [self windowForSheet]
modalDelegate: self didEndSelector: @selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo: self];
}

0 comments on commit 4f457cf

Please sign in to comment.