-
Notifications
You must be signed in to change notification settings - Fork 1
/
KinemeFileType.m
95 lines (78 loc) · 2.84 KB
/
KinemeFileType.m
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "stdio.h"
#import "KinemeFileType.h"
@implementation KinemeFileType
+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)fp8
{
return kQCPatchExecutionModeProvider;
}
+ (BOOL)allowsSubpatchesWithIdentifier:(id)fp8
{
return FALSE;
}
- (id)initWithIdentifier:(id)fp8
{
if(self=[super initWithIdentifier:fp8])
{
[[self userInfo] setObject:@"Kineme File Type" forKey:@"name"];
}
return self;
}
- (BOOL)execute:(id)openglcontext time:(double)time arguments:(id)arguments
{
if( [inputFilePath wasUpdated] )
{
NSURL *fileURL;
if( [[inputFilePath stringValue] compare:@"file://" options:0 range:NSMakeRange(0,7)] == NSOrderedSame )
fileURL=[NSURL URLWithString: [inputFilePath stringValue]];
else
{
NSString *expandedPath = KIExpandPath(self,[inputFilePath stringValue]);
if(!expandedPath)
return YES;
fileURL=[NSURL fileURLWithPath:expandedPath isDirectory:NO];
}
[outputUTI setStringValue:@""];
FSRef ref;
// Declares a Launch Services item information record. You need this data structure later to get extension and type information for a file.
LSItemInfoRecord outInfo;
CFURLRef cfURLRef = (CFURLRef)fileURL;
// Get the FSRef for the URL
if (CFURLGetFSRef(cfURLRef, &ref) == TRUE)
{
outInfo.extension = NULL;
// Calls the Launch Services function to obtain the extension and type information for the file.
// The function LSCopyItemInfoForRef fills the outInfo data structure with the requested information.
if (LSCopyItemInfoForRef(&ref, kLSRequestExtension|kLSRequestTypeCreator, &outInfo) == noErr)
{
CFStringRef itemUTI = NULL;
// Checks to see if the file has an extension.
// If it does, the code creates a Uniform Type Identifier (UTI) for the extension
// by calling the function UTTypeCreatePreferredIdentifierForTag.
// The Uniform Type Identifier is specified as a CFString object.
if (outInfo.extension != NULL)
{
itemUTI = UTTypeCreatePreferredIdentifierForTag (kUTTagClassFilenameExtension,outInfo.extension, NULL);
CFRelease(outInfo.extension);
}
else
{
// If the file does not have an extension, the code creates a UTI from the file type.
// The file type must first be converted to a CFString object by calling the function UTCreateStringForOSType.
// Then you can call the function UTTypeCreatePreferredIdentifierForTag to create a UTI.
CFStringRef typeString = UTCreateStringForOSType(outInfo.filetype);
itemUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, typeString, NULL);
CFRelease( typeString );
}
// Checks to make sure a UTI was created.
if (itemUTI != NULL)
{
[outputUTI setStringValue:(NSString *)itemUTI];
// Releases the UTI, which is specified as a CFString object.
CFRelease (itemUTI);
}
}
}
}
return YES;
}
@end