QTfrontend/NSWorkspace_RBAdditions.m
author Xeli
Sat, 04 Feb 2012 16:22:46 +0100
changeset 6622 01889d5bc79b
parent 6479 4f08821cbff5
permissions -rw-r--r--
Rewrote the Ammomenu: Added landscape ammomenu At the moment MOBILE indicates landscape, but we could just as easily make a variable out of it Draw to texture once uVariables.AmmoMenuInvalidated indicates a new ammo menu needs to be drawn, see uTeams and uAmmos Slot/Cellsize is dependent on uConsts.AMSlotSize this should make it easier to scale the ammo menu on smaller screens AmmoRect AmmoRect indicates where and how big the ammo menu is, this makes positioning a bit easier imo, because you only need to change the position at one single point needs testing on the iphone (and other systems as well ofcourse..)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4f08821cbff5 minor cleanup
koda
parents: 3697
diff changeset
    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) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    27
	if (!second) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    28
		return first;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    29
	}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    30
	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
    31
	if (first) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    32
		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
    33
			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
    34
				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
    35
			}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    36
			return second;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    37
		}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    38
		return first;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    39
	}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    40
	return second;
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) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    53
	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
    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) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    57
		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
    58
		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
    59
			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
    60
			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
    61
			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
    62
			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
    63
			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
    64
			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
    65
				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
    66
			} 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
    67
				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
    68
			} 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
    69
				NSData* data = nil;
6479
4f08821cbff5 minor cleanup
koda
parents: 3697
diff changeset
    70
                                if ((data = [[props objectForKey:@"Protocol Characteristics"] objectForKey:@"Virtual Interface Location Path"])) {
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    71
					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
    72
				}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    73
			} 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
    74
				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
    75
			}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    76
			NSDictionary* subdict;
6479
4f08821cbff5 minor cleanup
koda
parents: 3697
diff changeset
    77
                        if ((subdict = [props objectForKey:@"Protocol Characteristics"])) {
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    78
				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
    79
			} else {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    80
				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
    81
			}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    82
			if (connection) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    83
				[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
    84
			}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    85
			if (partition) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    86
				[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
    87
			}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    88
			if (image) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    89
				[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
    90
			}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    91
			NSString* value;
6479
4f08821cbff5 minor cleanup
koda
parents: 3697
diff changeset
    92
                        if ((subdict = [props objectForKey:@"Device Characteristics"])) {
4f08821cbff5 minor cleanup
koda
parents: 3697
diff changeset
    93
                                if ((value = [subdict objectForKey:@"Product Name"])) {
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    94
					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
    95
				}
6479
4f08821cbff5 minor cleanup
koda
parents: 3697
diff changeset
    96
                                if ((value = [subdict objectForKey:@"Product Revision Level"])) {
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
    97
					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
    98
				}
6479
4f08821cbff5 minor cleanup
koda
parents: 3697
diff changeset
    99
                                if ((value = [subdict objectForKey:@"Vendor Name"])) {
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   100
					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
   101
				}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   102
			}
6479
4f08821cbff5 minor cleanup
koda
parents: 3697
diff changeset
   103
                        if ((value = [props objectForKey:@"USB Serial Number"])) {
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   104
				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
   105
			}
6479
4f08821cbff5 minor cleanup
koda
parents: 3697
diff changeset
   106
                        if ((value = [props objectForKey:@"USB Vendor Name"])) {
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   107
				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
   108
			}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   109
			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
   110
			if (![cls isEqualToString:@"IOPCIDevice"]) {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2400
diff changeset
   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.
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   113
//				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
   114
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   115
				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
   116
			}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   117
			IOObjectRelease(nextParent);
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
    }
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) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   121
		IOObjectRelease(parentsIterator);
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   122
    }
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   123
	return result;
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
4f08821cbff5 minor cleanup
koda
parents: 3697
diff changeset
   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) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   130
	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
   131
	if (devdesc) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   132
		*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
   133
	}
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->volNameOffset;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   135
	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
   136
	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
   137
	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
   138
	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
   139
	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
   140
	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
   141
	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
   142
	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
   143
		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
   144
			case kAFPTagTypeIP:
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   145
				if (!ip) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   146
					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
   147
				}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   148
				break;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   149
			case kAFPTagTypeIPPort:
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
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])];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   151
				break;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   152
			case kAFPTagTypeDNS:
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   153
				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
   154
				break;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   155
			case 0x07:
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   156
				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
   157
					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
   158
					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
   159
					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
   160
					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
   161
				break;
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
		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
   164
	}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   165
	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
   166
}
6479
4f08821cbff5 minor cleanup
koda
parents: 3697
diff changeset
   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 {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   175
	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
   176
	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
   177
	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
   178
	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
   179
		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
   180
		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
   181
			[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
   182
			[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
   183
			nil];
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   184
		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
   185
// 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
   186
			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
   187
			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
   188
			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
   189
			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
   190
				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
   191
				if (classesToMatch) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   192
					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
   193
					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
   194
						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
   195
						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
   196
							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
   197
							if (stuff) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   198
								[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
   199
							}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   200
							IOObjectRelease(firstMedia);
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
					}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   203
				}
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 (mediaIterator) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   206
				IOObjectRelease(mediaIterator);
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
			if (masterPort) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   209
				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
   210
			}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   211
		}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   212
		//Don't need this for disk images, gets around warnings for some deprecated functions
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2400
diff changeset
   213
2400
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   214
		/* else {
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.
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   216
			FSRef ref;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   217
			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
   218
				FSCatalogInfo info;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   219
				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
   220
					ParamBlockRec pb;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   221
					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
   222
					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
   223
					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
   224
					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
   225
					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
   226
					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
   227
					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
   228
					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
   229
						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
   230
						if (mountInfo) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   231
							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
   232
							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
   233
							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
   234
								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
   235
								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
   236
								case AppleShareMediaType:
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   237
									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
   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 'http':
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   240
									url = from;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   241
									break;
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   242
								case 'crbm':
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   243
								case 'nfs_':
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   244
								case 'cifs':
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   245
									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
   246
									break;
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
								if (url) {
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   249
									[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
   250
								}
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
						free(mountInfo);
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
				}
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
		}*/
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   258
		[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
   259
	}
2422ea85d100 added a utility that warns the user to install hedgewars when it's run from the diskimage
koda
parents:
diff changeset
   260
	return result;
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