diff options
author | Brian Cully <bjc@kublai.com> | 2008-04-14 21:45:08 -0400 |
---|---|---|
committer | Brian Cully <github.20.shmit@spamgourmet.com> | 2008-04-14 21:45:08 -0400 |
commit | 17349a5e426dc7acf1216a3767a22f69974cbca0 (patch) | |
tree | 20029d02f07ab6257cccec36d34fb312f796e1d1 /Plugins/BuiltInFunctions/BDAlias | |
download | liaison-17349a5e426dc7acf1216a3767a22f69974cbca0.tar.gz liaison-17349a5e426dc7acf1216a3767a22f69974cbca0.zip |
Initial commit.
Diffstat (limited to 'Plugins/BuiltInFunctions/BDAlias')
-rw-r--r-- | Plugins/BuiltInFunctions/BDAlias/BDAlias/BDAlias.h | 72 | ||||
-rw-r--r-- | Plugins/BuiltInFunctions/BDAlias/BDAlias/BDAlias.m | 316 | ||||
-rw-r--r-- | Plugins/BuiltInFunctions/BDAlias/BDAlias/BDAlias.rtf | 162 | ||||
-rw-r--r-- | Plugins/BuiltInFunctions/BDAlias/BDAlias/License.rtf | 21 |
4 files changed, 571 insertions, 0 deletions
diff --git a/Plugins/BuiltInFunctions/BDAlias/BDAlias/BDAlias.h b/Plugins/BuiltInFunctions/BDAlias/BDAlias/BDAlias.h new file mode 100644 index 0000000..7d923df --- /dev/null +++ b/Plugins/BuiltInFunctions/BDAlias/BDAlias/BDAlias.h @@ -0,0 +1,72 @@ +/* + Copyright (c) 2001-2002, bDistributed.com, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, are permitted provided that the following + conditions are met: + + * Redistributions of source code must retain the above + copyright notice, this list of conditions and the following + disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + + * Neither the name of bDistributed.com, Inc. nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + OF SUCH DAMAGE. +*/ + +#import <Foundation/Foundation.h> +#import <CoreServices/CoreServices.h> + +@interface BDAlias : NSObject +{ + AliasHandle _alias; +} + +- (id)initWithAliasHandle:(AliasHandle)alias; // designated initializer +- (id)initWithData:(NSData *)data; +- (id)initWithPath:(NSString *)fullPath; +- (id)initWithPath:(NSString *)path relativeToPath:(NSString *)relPath; +- (id)initWithFSRef:(FSRef *)ref; +- (id)initWithFSRef:(FSRef *)ref relativeToFSRef:(FSRef *)relRef; + +- (void)dealloc; + +- (AliasHandle)alias; +- (void)setAlias:(AliasHandle)newAlias; + +- (NSData *)aliasData; +- (void)setAliasData:(NSData *)newAliasData; + +- (NSString *)fullPath; +- (NSString *)fullPathRelativeToPath:(NSString *)relPath; + ++ (BDAlias *)aliasWithAliasHandle:(AliasHandle)alias; ++ (BDAlias *)aliasWithData:(NSData *)data; ++ (BDAlias *)aliasWithPath:(NSString *)fullPath; ++ (BDAlias *)aliasWithPath:(NSString *)path relativeToPath:(NSString *)relPath; ++ (BDAlias *)aliasWithFSRef:(FSRef *)ref; ++ (BDAlias *)aliasWithFSRef:(FSRef *)ref relativeToFSRef:(FSRef *)relRef; + +@property (getter=alias) AliasHandle _alias; +@end diff --git a/Plugins/BuiltInFunctions/BDAlias/BDAlias/BDAlias.m b/Plugins/BuiltInFunctions/BDAlias/BDAlias/BDAlias.m new file mode 100644 index 0000000..2cf7d1d --- /dev/null +++ b/Plugins/BuiltInFunctions/BDAlias/BDAlias/BDAlias.m @@ -0,0 +1,316 @@ +/* + Copyright (c) 2001-2002, bDistributed.com, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or + without modification, are permitted provided that the following + conditions are met: + + * Redistributions of source code must retain the above + copyright notice, this list of conditions and the following + disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + + * Neither the name of bDistributed.com, Inc. nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + OF SUCH DAMAGE. +*/ + +#include <assert.h> + +#import "BDAlias.h" + + +static Handle DataToHandle(CFDataRef inData); +static CFDataRef HandleToData(Handle inHandle); + +static OSStatus PathToFSRef(CFStringRef inPath, FSRef *outRef); +static CFStringRef FSRefToPathCopy(const FSRef *inRef); + + +static Handle DataToHandle(CFDataRef inData) +{ + CFIndex len; + Handle handle = NULL; + + if (inData == NULL) { + return NULL; + } + + len = CFDataGetLength(inData); + + handle = NewHandle(len); + + if ((handle != NULL) && (len > 0)) { + HLock(handle); + BlockMoveData(CFDataGetBytePtr(inData), *handle, len); + HUnlock(handle); + } + + return handle; +} + +static CFDataRef HandleToData(Handle inHandle) +{ + CFDataRef data = NULL; + CFIndex len; + SInt8 handleState; + + if (inHandle == NULL) { + return NULL; + } + + len = GetHandleSize(inHandle); + + handleState = HGetState(inHandle); + + HLock(inHandle); + + data = CFDataCreate(kCFAllocatorDefault, (const UInt8 *) *inHandle, len); + + HSetState(inHandle, handleState); + + return data; +} + +static OSStatus PathToFSRef(CFStringRef inPath, FSRef *outRef) +{ + CFURLRef tempURL = NULL; + Boolean gotRef = false; + + tempURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, inPath, + kCFURLPOSIXPathStyle, false); + + if (tempURL == NULL) { + return fnfErr; + } + + gotRef = CFURLGetFSRef(tempURL, outRef); + + CFRelease(tempURL); + + if (gotRef == false) { + return fnfErr; + } + + return noErr; +} + +static CFStringRef FSRefToPathCopy(const FSRef *inRef) +{ + CFURLRef tempURL = NULL; + CFStringRef result = NULL; + + if (inRef != NULL) { + tempURL = CFURLCreateFromFSRef(kCFAllocatorDefault, inRef); + + if (tempURL == NULL) { + return NULL; + } + + result = CFURLCopyFileSystemPath(tempURL, kCFURLPOSIXPathStyle); + + CFRelease(tempURL); + } + + return result; +} + + +@implementation BDAlias + +- (id)initWithAliasHandle:(AliasHandle)alias +{ + id ret = [super init]; + + if (ret != nil) { + _alias = alias; + } + + return ret; +} + +- (id)initWithData:(NSData *)data +{ + return [self initWithAliasHandle:(AliasHandle)DataToHandle((CFDataRef) data)]; +} + +- (id)initWithPath:(NSString *)fullPath +{ + OSStatus anErr = noErr; + FSRef ref; + + anErr = PathToFSRef((CFStringRef) fullPath, &ref); + + if (anErr != noErr) { + return nil; + } + + return [self initWithFSRef:&ref];; +} + +- (id)initWithPath:(NSString *)path relativeToPath:(NSString *)relPath +{ + OSStatus anErr = noErr; + FSRef ref, relRef; + + anErr = PathToFSRef((CFStringRef) [relPath stringByAppendingPathComponent:path], + &ref); + + if (anErr != noErr) { + return nil; + } + + anErr = PathToFSRef((CFStringRef) relPath, &relRef); + + if (anErr != noErr) { + return nil; + } + + return [self initWithFSRef:&ref relativeToFSRef:&relRef]; +} + +- (id)initWithFSRef:(FSRef *)ref +{ + return [self initWithFSRef:ref relativeToFSRef:NULL]; +} + +- (id)initWithFSRef:(FSRef *)ref relativeToFSRef:(FSRef *)relRef +{ + OSStatus anErr = noErr; + AliasHandle alias = NULL; + + anErr = FSNewAlias(relRef, ref, &alias); + + if (anErr != noErr) { + return nil; + } + + return [self initWithAliasHandle:alias]; +} + +- (void)dealloc +{ + if (_alias != NULL) { + DisposeHandle((Handle) _alias); + _alias = NULL; + } + + [super dealloc]; +} + +- (AliasHandle)alias +{ + return _alias; +} + +- (void)setAlias:(AliasHandle)newAlias +{ + if (_alias != NULL) { + DisposeHandle((Handle) _alias); + } + + _alias = newAlias; +} + +- (NSData *)aliasData +{ + NSData *result; + + result = (NSData *)HandleToData((Handle) _alias); + + return [result autorelease]; +} + +- (void)setAliasData:(NSData *)newAliasData +{ + [self setAlias:(AliasHandle) DataToHandle((CFDataRef) newAliasData)]; +} + +- (NSString *)fullPath +{ + return [self fullPathRelativeToPath:nil]; +} + +- (NSString *)fullPathRelativeToPath:(NSString *)relPath +{ + OSStatus anErr = noErr; + FSRef relPathRef; + FSRef tempRef; + NSString *result = nil; + Boolean wasChanged; + + if (_alias != NULL) { + if (relPath != nil) { + anErr = PathToFSRef((CFStringRef)relPath, &relPathRef); + + if (anErr != noErr) { + return NULL; + } + + anErr = FSResolveAlias(&relPathRef, _alias, &tempRef, &wasChanged); + } else { + anErr = FSResolveAlias(NULL, _alias, &tempRef, &wasChanged); + } + + if (anErr != noErr) { + return NULL; + } + + result = (NSString *)FSRefToPathCopy(&tempRef); + } + + return [result autorelease]; +} + ++ (BDAlias *)aliasWithAliasHandle:(AliasHandle)alias +{ + return [[[BDAlias alloc] initWithAliasHandle:alias] autorelease]; +} + ++ (BDAlias *)aliasWithData:(NSData *)data +{ + return [[[BDAlias alloc] initWithData:data] autorelease]; +} + ++ (BDAlias *)aliasWithPath:(NSString *)fullPath +{ + return [[[BDAlias alloc] initWithPath:fullPath] autorelease]; +} + ++ (BDAlias *)aliasWithPath:(NSString *)path relativeToPath:(NSString *)relPath +{ + return [[[BDAlias alloc] initWithPath:path relativeToPath:relPath] autorelease]; +} + ++ (BDAlias *)aliasWithFSRef:(FSRef *)ref +{ + return [[[BDAlias alloc] initWithFSRef:ref] autorelease]; +} + ++ (BDAlias *)aliasWithFSRef:(FSRef *)ref relativeToFSRef:(FSRef *)relRef +{ + return [[[BDAlias alloc] initWithFSRef:ref relativeToFSRef:relRef] autorelease]; +} + +@synthesize _alias; +@end diff --git a/Plugins/BuiltInFunctions/BDAlias/BDAlias/BDAlias.rtf b/Plugins/BuiltInFunctions/BDAlias/BDAlias/BDAlias.rtf new file mode 100644 index 0000000..a32ca81 --- /dev/null +++ b/Plugins/BuiltInFunctions/BDAlias/BDAlias/BDAlias.rtf @@ -0,0 +1,162 @@ +{\rtf1\mac\ansicpg10000\cocoartf102 +{\fonttbl\f0\fswiss\fcharset77 Helvetica;\f1\fswiss\fcharset77 Helvetica-Bold;} +{\colortbl;\red255\green255\blue255;\red255\green0\blue0;} +\margl1440\margr1440\vieww9000\viewh9000\viewkind0 +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural + +\f0\fs24 \cf0 +\f1\b\fs28 \cf2 b\cf0 Distributed.com, Inc. +\f0\b0\fs24 \ + +\fs20 2549 W. Golf Rd. #348\ + Hoffman Estates, IL 60194\ + Phone: (847) 372-3955\ + Fax: (847) 589-3738\ + Web: bdistributed.com\ + Email: info@bdistributed.com\ + +\fs24 \ +Below is a quick reference for the BDAlias class.\ +\ + +\f1\b Instance Methods +\f0\b0 \ +initWithAliasHandle:\ +initWithData:\ +initWithPath:\ +initWithPath:relativeToPath:\ +initWithFSRef:\ +initWithFSRef:relativeToFSRef:\ +dealloc\ +alias\ +setAlias:\ +aliasData\ +setAliasData:\ +fullPath\ +fullPathRelativeToPath:\ +\ + +\f1\b Class Methods +\f0\b0 \ +aliasWithAliasHandle:\ +aliasWithData:\ +aliasWithPath:\ +aliasWithPath:relativeToPath:\ +aliasWithFSRef:\ +aliasWithFSRef:relativeToFSRef:\ +\ + +\f1\b - (id)initWithAliasHandle:(AliasHandle)alias +\f0\b0 \ +Initializes an alias object with the contents of a Carbon alias handle. This is the designated initializer.\ +\ + +\f1\b - (id)initWithData:(NSData *)data +\f0\b0 \ +Initializes an alias object with the contents of a data object.\ +\ + +\f1\b - (id)initWithPath:(NSString *)fullPath +\f0\b0 \ +Initializes an alias object to point to the object at the given path in the filesystem.\ +\ + +\f1\b - (id)initWithPath:(NSString *)path relativeToPath:(NSString *)relPath +\f0\b0 \ +Initializes an alias object to point to the object at the given path in the filesystem, relative to the given relative path.\ +\ + +\f1\b - (id)initWithFSRef:(FSRef *)ref +\f0\b0 \ +Initializes an alias object to point to the object represented by the given Carbon FSRef.\ +\ + +\f1\b - (id)initWithFSRef:(FSRef *)ref relativeToFSRef:(FSRef *)relRef +\f0\b0 \ +Initializes an alias object to point to the object represented by the given Carbon FSRef, relative to the given relative Carbon FSRef.\ +\ + +\f1\b - (void)dealloc +\f0\b0 \ +Releases resources held by an instance.\ +\ + +\f1\b - (AliasHandle)alias +\f0\b0 \ +Returns the internal Carbon alias handle used by an instance.\ +\ + +\f1\b - (void)setAlias:(AliasHandle)newAlias +\f0\b0 \ +Sets the internal Carbon alias handle used by an instance, releasing the previous alias handle (if any).\ +\ + +\f1\b - (NSData *)aliasData +\f0\b0 \ +Returns an autoreleased data object containing a copy of the alias data in this object.\ +\ + +\f1\b - (void)setAliasData:(NSData *)newAliasData +\f0\b0 \ +Sets the alias to use the alias record stored in the given data object. Discards any previous data.\ +\ + +\f1\b - (NSString *)fullPath +\f0\b0 \ +Returns an autoreleased string containing the full path of the object pointed to by an alias.\ +\ + +\f1\b - (NSString *)fullPathRelativeToPath:(NSString *)relPath +\f0\b0 \ +Returns an autoreleased string containing the full path of the object pointed to by an alias, resolved relative to the other given full path.\ +\ + +\f1\b + (BDAlias *)aliasWithAliasHandle:(AliasHandle)alias\ + +\f0\b0 Creates an autoreleased alias object with the contents of the given Carbon alias handle.\ +\ + +\f1\b + (BDAlias *)aliasWithData:(NSData *)data\ + +\f0\b0 Creates an autoreleased alias object with the contents of the given NSData object.\ +\ + +\f1\b + (BDAlias *)aliasWithPath:(NSString *)fullPath\ + +\f0\b0 Creates an autoreleased alias object pointing to the object at the given full path.\ +\ + +\f1\b + (BDAlias *)aliasWithPath:(NSString *)path relativeToPath:(NSString *)relPath\ + +\f0\b0 Creates an autoreleased alias object pointing to the object at the given path, relative to the given relative path.\ +\ + +\f1\b + (BDAlias *)aliasWithFSRef:(FSRef *)ref\ + +\f0\b0 Creates an autoreleased alias object pointing to the object at the given Carbon FSRef.\ +\ + +\f1\b + (BDAlias *)aliasWithFSRef:(FSREf *)ref relativeToFSRef:(FSRef *)relRef\ + +\f0\b0 Creates an autoreleased alias object pointing to the object at the given Carbon FSRef, relative to the given relative Carbon FSRef.\ +\ + +\f1\b License Agreement\ + +\f0\b0 By using or downloading this software, you agree to be bound by the following license. If you do not agree to be bound by the license, please destroy all copies of this software.\ +\ +Copyright \'a9 2001-2002, bDistributed.com, Inc.\ +All rights reserved.\ +\ +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\ +\ +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\li580\fi-580\ql\qnatural +\cf0 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\ +\ +* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\ +\ +* Neither the name of bDistributed.com, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. \ +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural +\cf0 \ +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ +}
\ No newline at end of file diff --git a/Plugins/BuiltInFunctions/BDAlias/BDAlias/License.rtf b/Plugins/BuiltInFunctions/BDAlias/BDAlias/License.rtf new file mode 100644 index 0000000..3bbbb7b --- /dev/null +++ b/Plugins/BuiltInFunctions/BDAlias/BDAlias/License.rtf @@ -0,0 +1,21 @@ +{\rtf1\mac\ansicpg10000\cocoartf102 +{\fonttbl\f0\froman\fcharset77 TimesNewRomanPSMT;} +{\colortbl;\red255\green255\blue255;} +\vieww9000\viewh9000\viewkind0 +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural + +\f0\fs24 \cf0 Copyright \'a9 2001-2002, bDistributed.com, Inc.\ +All rights reserved.\ +\ +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\ +\ +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\li580\fi-580\ql\qnatural +\cf0 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\ +\ +* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\ +\ +* Neither the name of bDistributed.com, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. \ +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural +\cf0 \ +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ +}
\ No newline at end of file |