public
Description:
Homepage:
Clone URL: git://github.com/jessegrosjean/bscripts.git
bscripts / TenThreeCompatibility.m
100644 72 lines (58 sloc) 2.825 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// TenThreeCompatibility.m
// CocoaScriptMenu
//
// Created by James Tuley on 10/10/05.
// Copyright 2005 __MyCompanyName__. All rights reserved.
//
 
#import "TenThreeCompatibility.h"
 
NSSearchPathDirectory TTCApplicationSupportDirectory = NSApplicationSupportDirectory;
 
 
id TTCConstantIfAvailible(void** aConst, id aKnownValue){
    if(aConst!=NULL){
        return *aConst;
    }else{
        return aKnownValue;
    }
}
 
BOOL TTCRunningLessThan10_4O(){
    SInt32 vers;
    Gestalt( gestaltSystemVersion, &vers);
    return (vers < 0x00001040);
}
 
NSArray* TTCSearchPathForDirectoriesInDomains (NSSearchPathDirectory directory, NSSearchPathDomainMask domainMask, BOOL expandTilde){
    NSString* tSuffix = nil;
    NSSearchPathDirectory tDirectory = directory;
    
    if(tDirectory ==TTCApplicationSupportDirectory && TTCRunningLessThan10_4O() ){
        tDirectory = NSLibraryDirectory;
        tSuffix = @"Application Support";
    }
 
    NSArray* tArray =NSSearchPathForDirectoriesInDomains (tDirectory, domainMask, expandTilde);
    
    //I should just make STEnum a requirement and make this a collect
    if(tSuffix !=nil){
        NSEnumerator* tEnumerator = [tArray objectEnumerator];
        NSString* tBasePath;
        NSMutableArray *tNewArray =[NSMutableArray array];
        while(tBasePath = [tEnumerator nextObject]){
            [tNewArray addObject:[tBasePath stringByAppendingPathComponent:tSuffix]];
        }
        tArray =[[tNewArray copy] autorelease];
    }
    
    return tArray;
}
 
//returns the most basic type in 10.3 enviornments as conforms to won't work if they aren't declared, not really useful out side of CocoaScriptMenu
//will need to edit if you add other specializ types to CocoaScriptMenu and you want them to function under 10.3
extern CFStringRef TTCTypeCreatePreferredIdentifierForTag(CFStringRef inTagClass,CFStringRef inTag, CFStringRef inConformingToUTI){
    if (TTCRunningLessThan10_4O()){
        NSArray* tShellFileIdents = [NSArray arrayWithObjects:@"sh",@"command",@"csh",@"pl",@"pm",@"py",@"rb",nil];
        NSArray* tAppleScriptFileIdents = [NSArray arrayWithObjects:@"applescript",@"scpt",@"osas",nil];
        NSArray* tAppFileIdents = [NSArray arrayWithObjects:@"app",@"APPL",@"APPC",@"APPD",@"APPE",@"appe",@"CDEV",@"cdev",@"dfil",nil];
        
        if([tShellFileIdents containsObject:(NSString*)inTag]){
            return(CFStringRef) @"public.shell-script";
        }else if([tAppleScriptFileIdents containsObject:(NSString*)inTag]){
            return (CFStringRef) @"com.apple.applescript.script";
        }else if([tAppFileIdents containsObject:(NSString*)inTag]){
            return (CFStringRef) @"com.apple.application";
        }
    }
    return UTTypeCreatePreferredIdentifierForTag(inTagClass,inTag,inConformingToUTI);
}