-
Notifications
You must be signed in to change notification settings - Fork 1
/
KinemeStructureFromFile.m
71 lines (58 loc) · 1.66 KB
/
KinemeStructureFromFile.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
#import "KinemeStructureFromFile.h"
@implementation KinemeStructureFromFile : QCPatch
+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)fp8
{
return kQCPatchExecutionModeProvider;
}
+ (BOOL)allowsSubpatchesWithIdentifier:(id)fp8
{
return NO;
}
+ (QCPatchTimeMode)timeModeWithIdentifier:(id)fp8
{
return kQCPatchTimeModeNone;
}
- (id)initWithIdentifier:(id)fp8
{
if(self=[super initWithIdentifier:fp8])
{
[inputFile setStringValue:@"~/Desktop/Structure.plist"];
[[self userInfo] setObject:@"Kineme Structure From File" forKey:@"name"];
}
return self;
}
- (BOOL)execute:(QCOpenGLContext *)context time:(double)time arguments:(NSDictionary *)arguments
{
if([inputSignal wasUpdated] && [inputSignal booleanValue] && [[inputFile stringValue] length] > 0)
{
QCStructure *structure = nil;
NSString *path = KIExpandPath(self,[inputFile stringValue]);
NSData *data = [NSData dataWithContentsOfFile:path];
if(!data)
{
[outputStructure setStructureValue:nil];
return YES;
}
@try
{
NSKeyedUnarchiver *coder = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
structure = [[QCStructure alloc] initWithCoder:coder];
[coder finishDecoding];
[coder release];
}
@catch(NSException *exception)
{
// KeyedUnarchival failed, so this might be an NSDictionary-stored-as-plist
NSDictionary *fileDict = (NSDictionary *)
[NSPropertyListSerialization propertyListFromData:data
mutabilityOption:NSPropertyListImmutable
format:NULL
errorDescription:nil];
structure = [[QCStructure alloc] initWithDictionary:fileDict];
}
[outputStructure setStructureValue:structure];
[structure release];
}
return YES;
}
@end