author | sheepluva |
Sat, 03 Dec 2016 09:09:16 +0100 | |
changeset 12103 | 966a9739812f |
parent 8440 | ea4d6a7a2937 |
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> |
6479 | 12 |
#include <mach/mach.h> |
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
13 |
|
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_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
|
15 |
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
|
16 |
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
|
17 |
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
|
18 |
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
|
19 |
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
|
20 |
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
|
21 |
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
|
22 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
23 |
// 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
|
24 |
// 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
|
25 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
26 |
static NSString* AddPart(NSString* first,NSString* second) { |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
27 |
if (!second) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
28 |
return first; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
29 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
30 |
second = [second stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
31 |
if (first) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
32 |
if ([first rangeOfString:second options:NSCaseInsensitiveSearch].location==NSNotFound) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
33 |
if ([second rangeOfString:first options:NSCaseInsensitiveSearch].location==NSNotFound) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
34 |
return [NSString stringWithFormat:@"%@; %@",first,second]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
35 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
36 |
return second; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
37 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
38 |
return first; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
39 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
40 |
return second; |
2400
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 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
43 |
// 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
|
44 |
// 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
|
45 |
// 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
|
46 |
// 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
|
47 |
// 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
|
48 |
// |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
49 |
// 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
|
50 |
// 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
|
51 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
52 |
static NSString* CheckParents(io_object_t thing,NSString* part,NSMutableDictionary* dict) { |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
53 |
NSString* result = part; |
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
54 |
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
|
55 |
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
|
56 |
if ((kernResult==KERN_SUCCESS)&&parentsIterator) { |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
57 |
io_object_t nextParent = 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
58 |
while ((nextParent = IOIteratorNext(parentsIterator))) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
59 |
NSDictionary* props = nil; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
60 |
NSString* image = nil; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
61 |
NSString* partition = nil; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
62 |
NSString* connection = nil; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
63 |
kernResult = IORegistryEntryCreateCFProperties(nextParent,(CFMutableDictionaryRef*)&props,kCFAllocatorDefault,0); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
64 |
if (IOObjectConformsTo(nextParent,"IOApplePartitionScheme")) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
65 |
partition = [props objectForKey:@"Content Mask"]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
66 |
} else if (IOObjectConformsTo(nextParent,"IOMedia")) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
67 |
partition = [props objectForKey:@"Content"]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
68 |
} else if (IOObjectConformsTo(nextParent,"IODiskImageBlockStorageDeviceOutKernel")) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
69 |
NSData* data = nil; |
6479 | 70 |
if ((data = [[props objectForKey:@"Protocol Characteristics"] objectForKey:@"Virtual Interface Location Path"])) { |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
71 |
image = [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding] autorelease]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
72 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
73 |
} else if (IOObjectConformsTo(nextParent,"IOHDIXHDDriveInKernel")) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
74 |
image = [props objectForKey:@"KDIURLPath"]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
75 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
76 |
NSDictionary* subdict; |
6479 | 77 |
if ((subdict = [props objectForKey:@"Protocol Characteristics"])) { |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
78 |
connection = [subdict objectForKey:@"Physical Interconnect"]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
79 |
} else { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
80 |
connection = [props objectForKey:@"Physical Interconnect"]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
81 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
82 |
if (connection) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
83 |
[dict setObject:AddPart([dict objectForKey:NSWorkspace_RBconnectiontype],connection) forKey:NSWorkspace_RBconnectiontype]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
84 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
85 |
if (partition) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
86 |
[dict setObject:partition forKey:NSWorkspace_RBpartitionscheme]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
87 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
88 |
if (image) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
89 |
[dict setObject:image forKey:NSWorkspace_RBimagefilepath]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
90 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
91 |
NSString* value; |
6479 | 92 |
if ((subdict = [props objectForKey:@"Device Characteristics"])) { |
93 |
if ((value = [subdict objectForKey:@"Product Name"])) { |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
94 |
result = AddPart(result,value); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
95 |
} |
6479 | 96 |
if ((value = [subdict objectForKey:@"Product Revision Level"])) { |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
97 |
result = AddPart(result,value); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
98 |
} |
6479 | 99 |
if ((value = [subdict objectForKey:@"Vendor Name"])) { |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
100 |
result = AddPart(result,value); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
101 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
102 |
} |
6479 | 103 |
if ((value = [props objectForKey:@"USB Serial Number"])) { |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
104 |
result = AddPart(result,value); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
105 |
} |
6479 | 106 |
if ((value = [props objectForKey:@"USB Vendor Name"])) { |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
107 |
result = AddPart(result,value); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
108 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
109 |
NSString* cls = [(NSString*)IOObjectCopyClass(nextParent) autorelease]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
110 |
if (![cls isEqualToString:@"IOPCIDevice"]) { |
3697 | 111 |
|
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
112 |
// Uncomment the following line to have the device tree dumped to the console. |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
113 |
// NSLog(@"=================================> %@:%@\n",cls,props); |
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
114 |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
115 |
result = CheckParents(nextParent,result,dict); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
116 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
117 |
IOObjectRelease(nextParent); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
118 |
} |
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
119 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
120 |
if (parentsIterator) { |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
121 |
IOObjectRelease(parentsIterator); |
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
122 |
} |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
123 |
return result; |
2400
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 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
126 |
// 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
|
127 |
|
6479 | 128 |
/* |
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
129 |
static NSString* FormatAFPURL(AFPXVolMountInfoPtr mountInfo,NSString** devdesc) { |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
130 |
UInt8* work = ((UInt8*)mountInfo)+mountInfo->serverNameOffset; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
131 |
if (devdesc) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
132 |
*devdesc = [[[NSString alloc] initWithBytes:&work[1] length:work[0] encoding:NSUTF8StringEncoding] autorelease]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
133 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
134 |
work = ((UInt8*)mountInfo)+mountInfo->volNameOffset; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
135 |
NSString* volname = [[[NSString alloc] initWithBytes:&work[1] length:work[0] encoding:NSUTF8StringEncoding] autorelease]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
136 |
work = ((UInt8*)mountInfo)+mountInfo->alternateAddressOffset; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
137 |
AFPAlternateAddress* afpa = (AFPAlternateAddress*)work; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
138 |
AFPTagData* afpta = (AFPTagData*)(&afpa->fAddressList); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
139 |
NSString* ip = nil; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
140 |
NSString* dns = nil; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
141 |
int i = afpa->fAddressCount; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
142 |
while ((i-->0)) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
143 |
switch (afpta->fType) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
144 |
case kAFPTagTypeIP: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
145 |
if (!ip) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
146 |
ip = [[[NSString alloc] initWithBytes:&afpta->fData[0] length:afpta->fLength-2 encoding:NSUTF8StringEncoding] autorelease]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
147 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
148 |
break; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
149 |
case kAFPTagTypeIPPort: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
150 |
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])]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
151 |
break; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
152 |
case kAFPTagTypeDNS: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
153 |
dns = [[[NSString alloc] initWithBytes:&afpta->fData[0] length:afpta->fLength-2 encoding:NSUTF8StringEncoding] autorelease]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
154 |
break; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
155 |
case 0x07: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
156 |
ip = [NSString stringWithFormat:@"[%x:%x:%x:%x:%x:%x:%x:%x]",OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[0]), |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
157 |
OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[2]),OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[4]), |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
158 |
OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[6]),OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[8]), |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
159 |
OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[10]),OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[12]), |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
160 |
OSSwapBigToHostInt16(*(UInt16*)&afpta->fData[14])]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
161 |
break; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
162 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
163 |
afpta = (AFPTagData*)((char*)afpta+afpta->fLength); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
164 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
165 |
return [NSString stringWithFormat:@"afp://%@/%@",dns?:(ip?:@""),volname]; |
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
166 |
} |
6479 | 167 |
*/ |
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
168 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
169 |
@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
|
170 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
171 |
// 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
|
172 |
// 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
|
173 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
174 |
- (NSDictionary*)propertiesForPath:(NSString*)path { |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
175 |
const char* ccpath = (const char*)[path fileSystemRepresentation]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
176 |
NSMutableDictionary* result = nil; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
177 |
struct statfs fs; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
178 |
if (!statfs(ccpath,&fs)) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
179 |
NSString* from = [NSString stringWithUTF8String:fs.f_mntfromname]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
180 |
result = [NSMutableDictionary dictionaryWithObjectsAndKeys: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
181 |
[NSString stringWithUTF8String:fs.f_fstypename],NSWorkspace_RBfstypename, |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
182 |
[NSString stringWithUTF8String:fs.f_mntonname],NSWorkspace_RBmntonname, |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
183 |
nil]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
184 |
if (strncmp(fs.f_mntfromname,"/dev/",5)==0) { |
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
185 |
// For a local volume,get the IO registry tree and search it for further info. |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
186 |
mach_port_t masterPort = 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
187 |
io_iterator_t mediaIterator = 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
188 |
kern_return_t kernResult = IOMasterPort(bootstrap_port,&masterPort); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
189 |
if (kernResult==KERN_SUCCESS) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
190 |
CFMutableDictionaryRef classesToMatch = IOBSDNameMatching(masterPort,0,&fs.f_mntfromname[5]); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
191 |
if (classesToMatch) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
192 |
kernResult = IOServiceGetMatchingServices(masterPort,classesToMatch,&mediaIterator); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
193 |
if ((kernResult==KERN_SUCCESS)&&mediaIterator) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
194 |
io_object_t firstMedia = 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
195 |
while ((firstMedia = IOIteratorNext(mediaIterator))) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
196 |
NSString* stuff = CheckParents(firstMedia,nil,result); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
197 |
if (stuff) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
198 |
[result setObject:stuff forKey:NSWorkspace_RBdeviceinfo]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
199 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
200 |
IOObjectRelease(firstMedia); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
201 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
202 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
203 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
204 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
205 |
if (mediaIterator) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
206 |
IOObjectRelease(mediaIterator); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
207 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
208 |
if (masterPort) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
209 |
mach_port_deallocate(mach_task_self(),masterPort); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
210 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
211 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
212 |
//Don't need this for disk images, gets around warnings for some deprecated functions |
3697 | 213 |
|
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
214 |
/* else { |
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
215 |
// For a network volume, get the volume reference number and use to get the server URL. |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
216 |
FSRef ref; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
217 |
if (FSPathMakeRef((const UInt8*)ccpath,&ref,NULL)==noErr) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
218 |
FSCatalogInfo info; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
219 |
if (FSGetCatalogInfo(&ref,kFSCatInfoVolume,&info,NULL,NULL,NULL)==noErr) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
220 |
ParamBlockRec pb; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
221 |
UInt16 vmisize = 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
222 |
VolumeMountInfoHeaderPtr mountInfo = NULL; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
223 |
pb.ioParam.ioCompletion = NULL; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
224 |
pb.ioParam.ioNamePtr = NULL; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
225 |
pb.ioParam.ioVRefNum = info.volume; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
226 |
pb.ioParam.ioBuffer = (Ptr)&vmisize; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
227 |
pb.ioParam.ioReqCount = sizeof(vmisize); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
228 |
if ((PBGetVolMountInfoSize(&pb)==noErr)&&vmisize) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
229 |
mountInfo = (VolumeMountInfoHeaderPtr)malloc(vmisize); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
230 |
if (mountInfo) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
231 |
pb.ioParam.ioBuffer = (Ptr)mountInfo; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
232 |
pb.ioParam.ioReqCount = vmisize; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
233 |
if (PBGetVolMountInfo(&pb)==noErr) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
234 |
NSString* url = nil; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
235 |
switch (mountInfo->media) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
236 |
case AppleShareMediaType: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
237 |
url = FormatAFPURL((AFPXVolMountInfoPtr)mountInfo,&from); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
238 |
break; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
239 |
case 'http': |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
240 |
url = from; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
241 |
break; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
242 |
case 'crbm': |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
243 |
case 'nfs_': |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
244 |
case 'cifs': |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
245 |
url = [NSString stringWithUTF8String:(char*)mountInfo+sizeof(VolumeMountInfoHeader)+sizeof(OSType)]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
246 |
break; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
247 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
248 |
if (url) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
249 |
[result setObject:url forKey:NSWorkspace_RBserverURL]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
250 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
251 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
252 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
253 |
free(mountInfo); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
254 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
255 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
256 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
257 |
}*/ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
258 |
[result setObject:from forKey:NSWorkspace_RBmntfromname]; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
259 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8381
diff
changeset
|
260 |
return result; |
2400
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
261 |
} |
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
262 |
|
2422ea85d100
added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff
changeset
|
263 |
@end |