author | unc0rr |
Sat, 17 Oct 2009 09:31:37 +0000 | |
changeset 2519 | 78956afbd311 |
parent 2400 | 2422ea85d100 |
child 3697 | d5b30d6373fc |
permissions | -rw-r--r-- |
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
1 |
// |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
2 |
// NSWorkspace_RBAdditions.m |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
3 |
// PathProps |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
4 |
// |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
5 |
// Created by Rainer Brockerhoff on 10/04/2007. |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
6 |
// Copyright 2007 Rainer Brockerhoff. All rights reserved. |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
7 |
// |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
8 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
9 |
#import "NSWorkspace_RBAdditions.h" |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
10 |
#include <IOKit/IOKitLib.h> |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
11 |
#include <sys/mount.h> |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
12 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
13 |
NSString* NSWorkspace_RBfstypename = @"NSWorkspace_RBfstypename"; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
14 |
NSString* NSWorkspace_RBmntonname = @"NSWorkspace_RBmntonname"; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
15 |
NSString* NSWorkspace_RBmntfromname = @"NSWorkspace_RBmntfromname"; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
16 |
NSString* NSWorkspace_RBdeviceinfo = @"NSWorkspace_RBdeviceinfo"; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
17 |
NSString* NSWorkspace_RBimagefilepath = @"NSWorkspace_RBimagefilepath"; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
18 |
NSString* NSWorkspace_RBconnectiontype = @"NSWorkspace_RBconnectiontype"; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
19 |
NSString* NSWorkspace_RBpartitionscheme = @"NSWorkspace_RBpartitionscheme"; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
20 |
NSString* NSWorkspace_RBserverURL = @"NSWorkspace_RBserverURL"; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
21 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
22 |
// This static funtion concatenates two strings, but first checks several possibilities... |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
23 |
// like one or the other nil, or one containing the other already. |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
24 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
25 |
static NSString* AddPart(NSString* first,NSString* second) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
26 |
if (!second) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
27 |
return first; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
28 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
29 |
second = [second stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
30 |
if (first) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
31 |
if ([first rangeOfString:second options:NSCaseInsensitiveSearch].location==NSNotFound) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
32 |
if ([second rangeOfString:first options:NSCaseInsensitiveSearch].location==NSNotFound) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
33 |
return [NSString stringWithFormat:@"%@; %@",first,second]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
34 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
35 |
return second; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
36 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
37 |
return first; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
38 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
39 |
return second; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
40 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
41 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
42 |
// This static functions recurses "upwards" over the IO registry. Returns strings that are concatenated |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
43 |
// and ultimately end up under the NSWorkspace_RBdeviceinfo key. |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
44 |
// This isn't too robust in that it assumes that objects returned by the objectForKey methods are |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
45 |
// either strings or dictionaries. A "standard" implementations would use either only CoreFoundation and |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
46 |
// IOKit calls for this, or do more robust type checking on the returned objects. |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
47 |
// |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
48 |
// Also notice that this works as determined experimentally in 10.4.9, there's no official docs I could find. |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
49 |
// YMMV, and it may stop working in any new version of Mac OS X. |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
50 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
51 |
static NSString* CheckParents(io_object_t thing,NSString* part,NSMutableDictionary* dict) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
52 |
NSString* result = part; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
53 |
io_iterator_t parentsIterator = 0; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
54 |
kern_return_t kernResult = IORegistryEntryGetParentIterator(thing,kIOServicePlane,&parentsIterator); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
55 |
if ((kernResult==KERN_SUCCESS)&&parentsIterator) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
56 |
io_object_t nextParent = 0; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
57 |
while ((nextParent = IOIteratorNext(parentsIterator))) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
58 |
NSDictionary* props = nil; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
59 |
NSString* image = nil; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
60 |
NSString* partition = nil; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
61 |
NSString* connection = nil; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
62 |
kernResult = IORegistryEntryCreateCFProperties(nextParent,(CFMutableDictionaryRef*)&props,kCFAllocatorDefault,0); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
63 |
if (IOObjectConformsTo(nextParent,"IOApplePartitionScheme")) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
64 |
partition = [props objectForKey:@"Content Mask"]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
65 |
} else if (IOObjectConformsTo(nextParent,"IOMedia")) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
66 |
partition = [props objectForKey:@"Content"]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
67 |
} else if (IOObjectConformsTo(nextParent,"IODiskImageBlockStorageDeviceOutKernel")) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
68 |
NSData* data = nil; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
69 |
if (data = [[props objectForKey:@"Protocol Characteristics"] objectForKey:@"Virtual Interface Location Path"]) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
70 |
image = [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding] autorelease]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
71 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
72 |
} else if (IOObjectConformsTo(nextParent,"IOHDIXHDDriveInKernel")) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
73 |
image = [props objectForKey:@"KDIURLPath"]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
74 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
75 |
NSDictionary* subdict; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
76 |
if (subdict = [props objectForKey:@"Protocol Characteristics"]) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
77 |
connection = [subdict objectForKey:@"Physical Interconnect"]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
78 |
} else { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
79 |
connection = [props objectForKey:@"Physical Interconnect"]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
80 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
81 |
if (connection) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
82 |
[dict setObject:AddPart([dict objectForKey:NSWorkspace_RBconnectiontype],connection) forKey:NSWorkspace_RBconnectiontype]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
83 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
84 |
if (partition) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
85 |
[dict setObject:partition forKey:NSWorkspace_RBpartitionscheme]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
86 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
87 |
if (image) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
88 |
[dict setObject:image forKey:NSWorkspace_RBimagefilepath]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
89 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
90 |
NSString* value; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
91 |
if (subdict = [props objectForKey:@"Device Characteristics"]) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
92 |
if (value = [subdict objectForKey:@"Product Name"]) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
93 |
result = AddPart(result,value); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
94 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
95 |
if (value = [subdict objectForKey:@"Product Revision Level"]) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
96 |
result = AddPart(result,value); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
97 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
98 |
if (value = [subdict objectForKey:@"Vendor Name"]) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
99 |
result = AddPart(result,value); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
100 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
101 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
102 |
if (value = [props objectForKey:@"USB Serial Number"]) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
103 |
result = AddPart(result,value); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
104 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
105 |
if (value = [props objectForKey:@"USB Vendor Name"]) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
106 |
result = AddPart(result,value); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
107 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
108 |
NSString* cls = [(NSString*)IOObjectCopyClass(nextParent) autorelease]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
109 |
if (![cls isEqualToString:@"IOPCIDevice"]) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
110 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
111 |
// Uncomment the following line to have the device tree dumped to the console. |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
112 |
// NSLog(@"=================================> %@:%@\n",cls,props); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
113 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
114 |
result = CheckParents(nextParent,result,dict); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
115 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
116 |
IOObjectRelease(nextParent); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
117 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
118 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
119 |
if (parentsIterator) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
120 |
IOObjectRelease(parentsIterator); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
121 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
122 |
return result; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
123 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
124 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
125 |
// This formats the (partially undocumented) AFPXMountInfo info into a string. |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
126 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
127 |
static NSString* FormatAFPURL(AFPXVolMountInfoPtr mountInfo,NSString** devdesc) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
128 |
UInt8* work = ((UInt8*)mountInfo)+mountInfo->serverNameOffset; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
129 |
if (devdesc) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
130 |
*devdesc = [[[NSString alloc] initWithBytes:&work[1] length:work[0] encoding:NSUTF8StringEncoding] autorelease]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
131 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
132 |
work = ((UInt8*)mountInfo)+mountInfo->volNameOffset; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
133 |
NSString* volname = [[[NSString alloc] initWithBytes:&work[1] length:work[0] encoding:NSUTF8StringEncoding] autorelease]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
134 |
work = ((UInt8*)mountInfo)+mountInfo->alternateAddressOffset; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
135 |
AFPAlternateAddress* afpa = (AFPAlternateAddress*)work; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
136 |
AFPTagData* afpta = (AFPTagData*)(&afpa->fAddressList); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
137 |
NSString* ip = nil; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
138 |
NSString* dns = nil; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
139 |
int i = afpa->fAddressCount; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
140 |
while ((i-->0)) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
141 |
switch (afpta->fType) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
142 |
case kAFPTagTypeIP: |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
143 |
if (!ip) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
144 |
ip = [[[NSString alloc] initWithBytes:&afpta->fData[0] length:afpta->fLength-2 encoding:NSUTF8StringEncoding] autorelease]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
145 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
146 |
break; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
147 |
case kAFPTagTypeIPPort: |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
148 |
ip = [NSString stringWithFormat:@"%u.%u.%u.%u:%u",afpta->fData[0],afpta->fData[1],afpta->fData[2],afpta->fData[3],OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[4])]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
149 |
break; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
150 |
case kAFPTagTypeDNS: |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
151 |
dns = [[[NSString alloc] initWithBytes:&afpta->fData[0] length:afpta->fLength-2 encoding:NSUTF8StringEncoding] autorelease]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
152 |
break; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
153 |
case 0x07: |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
154 |
ip = [NSString stringWithFormat:@"[%x:%x:%x:%x:%x:%x:%x:%x]",OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[0]), |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
155 |
OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[2]),OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[4]), |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
156 |
OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[6]),OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[8]), |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
157 |
OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[10]),OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[12]), |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
158 |
OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[14])]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
159 |
break; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
160 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
161 |
afpta = (AFPTagData*)((char*)afpta+afpta->fLength); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
162 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
163 |
return [NSString stringWithFormat:@"afp://%@/%@",dns?:(ip?:@""),volname]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
164 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
165 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
166 |
@implementation NSWorkspace (NSWorkspace_RBAdditions) |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
167 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
168 |
// Returns a NSDictionary with properties for the path. See details in the .h file. |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
169 |
// This assumes that the length of path is less than PATH_MAX (currently 1024 characters). |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
170 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
171 |
- (NSDictionary*)propertiesForPath:(NSString*)path { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
172 |
const char* ccpath = (const char*)[path fileSystemRepresentation]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
173 |
NSMutableDictionary* result = nil; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
174 |
struct statfs fs; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
175 |
if (!statfs(ccpath,&fs)) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
176 |
NSString* from = [NSString stringWithUTF8String:fs.f_mntfromname]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
177 |
result = [NSMutableDictionary dictionaryWithObjectsAndKeys: |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
178 |
[NSString stringWithUTF8String:fs.f_fstypename],NSWorkspace_RBfstypename, |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
179 |
[NSString stringWithUTF8String:fs.f_mntonname],NSWorkspace_RBmntonname, |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
180 |
nil]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
181 |
if (strncmp(fs.f_mntfromname,"/dev/",5)==0) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
182 |
// For a local volume,get the IO registry tree and search it for further info. |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
183 |
mach_port_t masterPort = 0; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
184 |
io_iterator_t mediaIterator = 0; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
185 |
kern_return_t kernResult = IOMasterPort(bootstrap_port,&masterPort); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
186 |
if (kernResult==KERN_SUCCESS) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
187 |
CFMutableDictionaryRef classesToMatch = IOBSDNameMatching(masterPort,0,&fs.f_mntfromname[5]); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
188 |
if (classesToMatch) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
189 |
kernResult = IOServiceGetMatchingServices(masterPort,classesToMatch,&mediaIterator); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
190 |
if ((kernResult==KERN_SUCCESS)&&mediaIterator) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
191 |
io_object_t firstMedia = 0; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
192 |
while ((firstMedia = IOIteratorNext(mediaIterator))) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
193 |
NSString* stuff = CheckParents(firstMedia,nil,result); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
194 |
if (stuff) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
195 |
[result setObject:stuff forKey:NSWorkspace_RBdeviceinfo]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
196 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
197 |
IOObjectRelease(firstMedia); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
198 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
199 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
200 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
201 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
202 |
if (mediaIterator) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
203 |
IOObjectRelease(mediaIterator); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
204 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
205 |
if (masterPort) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
206 |
mach_port_deallocate(mach_task_self(),masterPort); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
207 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
208 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
209 |
//Don't need this for disk images, gets around warnings for some deprecated functions |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
210 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
211 |
/* else { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
212 |
// For a network volume, get the volume reference number and use to get the server URL. |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
213 |
FSRef ref; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
214 |
if (FSPathMakeRef((const UInt8*)ccpath,&ref,NULL)==noErr) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
215 |
FSCatalogInfo info; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
216 |
if (FSGetCatalogInfo(&ref,kFSCatInfoVolume,&info,NULL,NULL,NULL)==noErr) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
217 |
ParamBlockRec pb; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
218 |
UInt16 vmisize = 0; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
219 |
VolumeMountInfoHeaderPtr mountInfo = NULL; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
220 |
pb.ioParam.ioCompletion = NULL; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
221 |
pb.ioParam.ioNamePtr = NULL; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
222 |
pb.ioParam.ioVRefNum = info.volume; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
223 |
pb.ioParam.ioBuffer = (Ptr)&vmisize; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
224 |
pb.ioParam.ioReqCount = sizeof(vmisize); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
225 |
if ((PBGetVolMountInfoSize(&pb)==noErr)&&vmisize) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
226 |
mountInfo = (VolumeMountInfoHeaderPtr)malloc(vmisize); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
227 |
if (mountInfo) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
228 |
pb.ioParam.ioBuffer = (Ptr)mountInfo; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
229 |
pb.ioParam.ioReqCount = vmisize; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
230 |
if (PBGetVolMountInfo(&pb)==noErr) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
231 |
NSString* url = nil; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
232 |
switch (mountInfo->media) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
233 |
case AppleShareMediaType: |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
234 |
url = FormatAFPURL((AFPXVolMountInfoPtr)mountInfo,&from); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
235 |
break; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
236 |
case 'http': |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
237 |
url = from; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
238 |
break; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
239 |
case 'crbm': |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
240 |
case 'nfs_': |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
241 |
case 'cifs': |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
242 |
url = [NSString stringWithUTF8String:(char*)mountInfo+sizeof(VolumeMountInfoHeader)+sizeof(OSType)]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
243 |
break; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
244 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
245 |
if (url) { |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
246 |
[result setObject:url forKey:NSWorkspace_RBserverURL]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
247 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
248 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
249 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
250 |
free(mountInfo); |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
251 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
252 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
253 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
254 |
}*/ |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
255 |
[result setObject:from forKey:NSWorkspace_RBmntfromname]; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
256 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
257 |
return result; |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
258 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
259 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
260 |
@end |