forked from quicksilver/Quicksilver
/
QSPlugIn.m
724 lines (618 loc) · 22.6 KB
/
QSPlugIn.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
//
// QSPlugInInfo.m
// Quicksilver
//
// Created by Alcor on 2/5/05.
// Copyright 2005 Blacktree. All rights reserved.
//
#import "QSPlugIn.h"
#import "QSRegistry.h"
#import "QSResourceManager.h"
#import "QSPlugInManager.h"
#import "QSFoundation.h"
#import "QSExecutor.h"
#import "QSLibrarian.h"
#import "QSNotifications.h"
#import "NSString+NDUtilities.h"
#import "NSException_TraceExtensions.h"
//static
NSMutableDictionary *plugInBundlePaths = nil;
@implementation QSPlugIn
+ (void)initialize {
plugInBundlePaths = [[NSMutableDictionary alloc] init];
[self setKeys:[NSArray arrayWithObject:@"bundle"] triggerChangeNotificationsForDependentKey:@"smallIcon"];
}
- (NSString *)description {return [NSString stringWithFormat:@"<%@ %p>", [self name], self];}
- (id)initWithBundle:(NSBundle *)aBundle {
id dup = [plugInBundlePaths valueForKey:[aBundle bundlePath]];
if (dup) {
[self release];
return [dup retain];
}
if (self = [super init]) {
[self setBundle:aBundle];
}
return self;
}
- (id)initWithWebInfo:(NSDictionary *)webInfo {
if (self = [super init]) {
data = [webInfo retain];
bundle = nil;
}
return self;
}
+ (id)plugInWithBundle:(NSBundle *)aBundle {
return [[[QSPlugIn alloc] initWithBundle:aBundle] autorelease];
}
+ (id)plugInWithWebInfo:(NSDictionary *)webInfo {
return [[[QSPlugIn alloc] initWithWebInfo:webInfo] autorelease];
}
/**
Without loading the bundle, read bundle ID and version string
@param path The path to the qsplugin on file system (eg: "/Users/paul/Downloads/Email Support.qsplugin")
@param version A pointer to an \c NSString* that will be set to the version string of the plugin if present
@result An auto-released string with the bundle ID (eg: "com.blacktree.Quicksilver.QSEmailSupport")
*/
+ (NSString *)bundleIDForPluginAt:(NSString*)path andVersion:(NSString**)version {
CFBundleRef bundle = CFBundleCreate(NULL, (CFURLRef)[NSURL fileURLWithPath:path]);
if (!bundle) return nil;
if (version) {
*version = (NSString*)CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleVersionKey);
[[*version retain] autorelease];
}
NSString *bundleIdent = (NSString *)CFBundleGetIdentifier(bundle);
[[bundleIdent retain] autorelease];
CFRelease(bundle);
return bundleIdent;
}
- (void)dealloc {
[self setBundle:nil];
[bundle release];
[data release];
[super dealloc];
}
- (void)downloadFailed {
installing = NO;
[self willChangeValueForKey:@"enabled"];
[self didChangeValueForKey:@"enabled"];
}
- (NSURL *)downloadURL {
return [NSURL URLWithString:[[QSPlugInManager sharedInstance] urlStringForPlugIn:[self identifier] version:nil]];
}
- (void)install {
installing = YES;
NSString *identifier = [data objectForKey:@"CFBundleIdentifier"];
[[QSPlugInManager sharedInstance] installPlugInsForIdentifiers:[NSArray arrayWithObject:identifier]];
[self willChangeValueForKey:@"enabled"];
[self didChangeValueForKey:@"enabled"];
}
- (NSString *)shortName {
NSString *name = (bundle) ? [bundle objectForInfoDictionaryKey:(NSString *)kCFBundleNameKey] : [data objectForKey:(NSString *)kCFBundleNameKey];
if ([name hasSuffix:@" Module"]) name = [name substringToIndex:[name length] -7];
if ([name hasSuffix:@" Actions"]) name = [name substringToIndex:[name length] -8];
return name;
}
- (NSString *)name {
NSString *name = nil;
if (bundle) name = [bundle objectForInfoDictionaryKey:(NSString *)kCFBundleNameKey];
if (!name) name = [data objectForKey:(NSString *)kCFBundleNameKey];
int feature = [[[self info] valueForKeyPath:@"QSRequirements.feature"] intValue];
#ifdef DEBUG
if ([name hasSuffix:@" Module"]) name = [name substringToIndex:[name length] -7];
#endif
if (feature == 1) {
name = [name stringByAppendingFormat:@" (+) ", 0x25B8];
} else if (feature == 2) {
name = [name stringByAppendingFormat:@" (%C) ", 0x03B2];
} else if (feature>2) {
name = [name stringByAppendingFormat:@" (%C) ", 0x03B1];
}
#ifdef DEBUG
if (!data) {
name = [name stringByAppendingFormat:@" - Private", 0x03B1];
}
// if (DEBUG && [self isUniversal]) {
// name = [name stringByAppendingFormat:@" - U"];
// }
if ([self isSecret]) {
name = [name stringByAppendingFormat:@" - Secret"];
}
#endif
return name;
}
- (NSString *)status {
NSString *error = [self loadError];
NSString *status = nil;
if (!bundle) {
if (installing)
return @"Downloading";
else
return @"Downloadable";
}
if ([self isLoaded]) {
if ( [bundle isLoaded]) {
int fileSize = [[[[NSFileManager defaultManager] attributesOfItemAtPath:[bundle executablePath] error:nil] objectForKey:NSFileSize] intValue];
status = [NSString stringWithFormat:@"Loaded (%dk) ", fileSize/1024];
} else {
status = @"Loaded";
}
} else if (error) {
status = [NSString stringWithFormat:@"Error (%@) ", error];
} else {
status = @"Disabled";
}
return status;
}
- (NSString *)statusBullet {
if ([self isLoaded]) {
if ([bundle isLoaded])
return [NSString stringWithFormat:@"%C", 0x25C6];
else return [NSString stringWithFormat:@"%C", 0x25C7];
//BOOL selected = [[aTableView selectedRowIndexes] containsIndex:rowIndex];
//[aCell setTextColor:(! && !selected?[NSColor blueColor] :[NSColor blackColor])];
//
} else {
return @"";
}
return @"*";
}
- (BOOL)isUniversal {
if (![bundle executablePath])
return NO;
/* TODO: Use NSTask */
NSString *str = [NSString stringWithFormat:@"/usr/bin/lipo -info \"%@\"", [bundle executablePath]];
FILE *file = popen( [str UTF8String] , "r" );
NSString *output = nil;
NSMutableData *pipeData = [NSMutableData data];
if ( file ) {
char buffer[1024];
size_t length;
while (length = fread( buffer, 1, sizeof( buffer ), file ) )[pipeData appendBytes:buffer length:length];
output = [[[NSString alloc] initWithData:pipeData encoding:NSUTF8StringEncoding] autorelease];
pclose( file );
return [output rangeOfString:@"i386"].location != NSNotFound;
}
return NO;
// NSLog(@"output%@", output);
}
- (NSDictionary *)info {
if (bundle)
return [bundle infoDictionary];
else
return data;
}
- (NSString *)author {
return [[self info] valueForKeyPath:@"QSPlugIn.author"];
}
- (NSString *)byline {
NSString *author = [self author];
if (![author length] || [author isEqualToString:@"Blacktree, Inc."]) return @"";
return [@"by " stringByAppendingString:author];
}
- (NSString *)helpPage {
return [[self info] valueForKeyPath:@"QSPlugIn.helpPage"];
}
- (NSArray *)dependencies {
return [[self info] valueForKeyPath:@"QSRequirements.plugins"];
}
- (void)showHelp {
NSString *urlString = [NSString stringWithFormat:kHelpSearchURL, [self helpPage]];
NSLog(@"%@", urlString);
if (urlString) [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[urlString stringByReplacing:@" " with:@"+"]]];
}
- (NSDate *)createdDate {
return [NSDate date];
}
- (NSDate *)modifiedDate {
if (data) {
return [NSDate dateWithString:[data valueForKeyPath:@"QSModifiedDate"]];
return [NSDate date];
} else if (bundle) {
NSDate *buildDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:[bundle executablePath] error:nil] fileModificationDate];
if (!buildDate)
buildDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:[bundle bundlePath] error:nil] fileModificationDate];
return buildDate;
}
return nil;
}
- (NSString *)version {
if (bundle) {
NSString *version = [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
if (!version) version = [bundle objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
return version;
}
NSString *version = [data objectForKey:@"CFBundleShortVersionString"];
if (!version) version = [data objectForKey:(NSString *)kCFBundleVersionKey];
return version;
}
- (NSString *)buildVersion {
return (bundle) ? [bundle objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey] : [data objectForKey:(NSString *)kCFBundleVersionKey];
}
- (BOOL)isSecret {
return [[[self info] valueForKeyPath:@"QSPlugIn.secret"] boolValue];
}
- (BOOL)isRecommended {
if ([[[self info] valueForKeyPath:@"QSPlugIn.recommended"] boolValue]) return YES;
if ([self isInstalled] >0) return NO;
if (![self meetsFeature]) return NO;
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
NSArray *related = [self relatedBundles];
//if (!related) return YES;
for(NSString * bundleID in related) {
if ([ws absolutePathForAppBundleWithIdentifier:bundleID]) return YES;
}
return NO;
}
- (BOOL)needsUpdate {
if (!bundle) return NO;
//if (VERBOSE) NSLog(@"%@, %@->%@", [self name] , [bundle objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey] , [data objectForKey:(NSString *)kCFBundleVersionKey]);
return[[data objectForKey:(NSString *)kCFBundleVersionKey] versionCompare:
[bundle objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]]>0;
}
- (NSArray *)categories {
return [[self info] valueForKeyPath:@"QSPlugIn.categories"];
}
- (NSArray *)relatedBundles {
return [[self info] valueForKeyPath:@"QSPlugIn.relatedBundles"];
}
- (NSArray *)recommendations {
return [[self info] valueForKeyPath:@"QSPlugIn.recommendations"];
}
- (NSString *)shortDescription {
NSDictionary *plist = [self info];
return [plist valueForKeyPath:@"QSPlugIn.description"];
}
- (NSString *)infoHTML {
NSDictionary *plist = [self info];
NSString *text = [plist valueForKeyPath:@"QSPlugIn.extendedDescription"];
if (![text length]) text = [plist valueForKeyPath:@"QSPlugIn.description"];
if (!text) text = @"";
return [NSString stringWithFormat:@"<html><link rel=\"stylesheet\" href=\"resource:QSStyle.css\"><body>%@</body></html>", text];
}
- (NSComparisonResult) compare:(id)other {
return [[self name] compare:[other name]];
}
- (NSString *)text {
return [self name];
}
- (NSImage *)image {
return [self icon];
}
- (NSData *)attributedDescription {
//return nil; //[NSAttributedString attributedStringWithAttachment:;
// static NSDictionary *attributes = nil;
// if (!attributes) attributes = [[NSDictionary alloc] initWithObjectsAndKeys:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]], NSFontAttributeName, nil];
NSDictionary *plist = [self info];
NSString *text = [plist valueForKeyPath:@"QSPlugIn.extendedDescription"];
if (![text length]) text = [plist valueForKeyPath:@"QSPlugIn.description"];
if (!text) text = @"";
// NSLog(@"plist %@", text); re
text = [NSString stringWithFormat:@"<font face=\"Lucida Grande\">%@</font>", text];
NSMutableAttributedString *info = [[[NSMutableAttributedString alloc] initWithHTML:[text dataUsingEncoding:NSUTF8StringEncoding] documentAttributes:nil] autorelease];
// NSLog(@"plist %@", info);
// [info addAttributes:attributes range:NSMakeRange(0, [info length])];
// NSAttributedString *attribInfo = [[[NSAttributedString alloc] initWithString:text?text:@"" attributes:nil] autorelease];
if (!info) return [NSData data];
return [info RTFFromRange:NSMakeRange(0, [info length]) documentAttributes:nil]; ;
// [[plugInText textStorage] setAttributedString:attribInfo];
return nil;
}
- (void)clearWebData {
[self setData:nil];
}
- (NSImage *)icon {
if (!icon) {
NSDictionary *pDict = [[self info] objectForKey:@"QSPlugIn"];
NSString *text = [pDict objectForKey:@"icon"];
// make sure an icon set in plugin's .plist
if(text != nil) {
icon = [QSResourceManager imageNamed:text inBundle:bundle];
}
if (!icon)
{
icon = [QSResourceManager imageNamed:@"QSPlugIn"];
}
[icon setSize:QSSize32];
[icon retain];
}
return icon;
}
- (NSImage *)smallIcon {
if (!smallIcon) {
smallIcon = [[[self icon] copy] autorelease];
[smallIcon shrinkToSize:QSSize16];
[smallIcon retain];
}
return smallIcon;
}
- (int) isInstalled {
if (bundle) return 1;
else if (installing) return -1;
else return 0;
}
- (BOOL)shouldInstall {
return shouldInstall;
}
- (void)setShouldInstall:(BOOL)flag {
shouldInstall = flag;
}
- (BOOL)isHidden {
if (bundle == [NSBundle mainBundle]) return YES;
return [[[self info] valueForKeyPath:@"QSPlugIn.hidden"] boolValue];
}
- (BOOL)meetsFeature {
//return YES; // Override this for now
return [[[self info] valueForKeyPath:@"QSRequirements.feature"] intValue] <= [NSApp featureLevel];
}
- (int) isLoaded {return loaded;}
#define disabledPlugIns [[NSUserDefaults standardUserDefaults] arrayForKey:@"QSDisabledPlugIns"]
- (NSColor *)enabledColor {
return [self isInstalled] ?[NSColor blackColor] :[NSColor grayColor];
}
- (NSString *)identifier {return [[self info] valueForKey:(NSString *)kCFBundleIdentifierKey];}
- (NSString *)bundleIdentifier {return [bundle bundleIdentifier];}
- (NSString *)path {return [bundle bundlePath];}
- (NSString *)bundlePath {return [bundle bundlePath];}
- (int) enabled {
if (!bundle)
return installing?-1:0;
return ![disabledPlugIns containsObject:[bundle bundleIdentifier]];
}
- (void)setEnabled:(BOOL)flag {
if (bundle) {
NSString *identifier = [bundle bundleIdentifier];
NSMutableSet *disabledPlugInsSet = [[NSMutableSet alloc] init];
[disabledPlugInsSet addObjectsFromArray:disabledPlugIns];
if (flag) {
[disabledPlugInsSet removeObject:identifier];
} else {
[disabledPlugInsSet addObject:identifier];
}
[[NSUserDefaults standardUserDefaults] setObject:[disabledPlugInsSet allObjects] forKey:@"QSDisabledPlugIns"];
[disabledPlugInsSet release];
if (flag) {
[[QSPlugInManager sharedInstance] liveLoadPlugIn:self];
[[QSPlugInManager sharedInstance] checkForUnmetDependencies];
}
} else if (![self isInstalled]) {
[self install];
}
}
- (BOOL)canBeDisabled {
// NSLog(@"%@ path", [bundle bundlePath]);
return ![[bundle bundlePath] hasPrefix:[[NSBundle mainBundle] bundlePath]];
}
- (BOOL)reveal {
return [[NSWorkspace sharedWorkspace] selectFile:[bundle bundlePath]
inFileViewerRootedAtPath:@""];
}
- (BOOL)delete {
NSString *ident/*, *path*/;
if(bundle) {
ident = [bundle bundleIdentifier];
// path = [bundle bundlePath];
} else {
ident = [data objectForKey:@"CFBundleIdentifier"];
// path = nil;
}
id manager = [QSPlugInManager sharedInstance];
[[manager localPlugIns] removeObjectForKey:ident];
[[manager knownPlugIns] removeObjectForKey:ident];
return [[NSFileManager defaultManager] removeItemAtPath:[bundle bundlePath] error:nil];
}
//------------------------
- (NSBundle *)bundle { return bundle; }
- (void)setBundle:(NSBundle *)newBundle {
if ([newBundle isKindOfClass:[QSPlugIn class]]) {
NSBeep();
}
[icon release];icon = nil;
[smallIcon release];smallIcon = nil;
[self retain];
if (bundle) {
[self retain];
[plugInBundlePaths removeObjectForKey:[bundle bundlePath]];
[bundle autorelease];
}
bundle = [newBundle retain];
if (bundle) {
[[[plugInBundlePaths objectForKey:[bundle bundlePath]] retain] autorelease]; // old plugin needs to be retained, because it will be released once it's replaced in plugInBundlePaths-list
[plugInBundlePaths setObject:self forKey:[bundle bundlePath]];
[self release];
}
[self release];
}
- (NSMutableDictionary *)data { return data; }
- (void)setData:(NSMutableDictionary *)newData {
if(newData != data){
[data release];
data = [newData retain];
}
}
- (NSString *)loadError { return loadError; }
- (void)setLoadError:(NSString *)newLoadError {
[loadError autorelease];
loadError = [newLoadError retain];
}
@end
@implementation QSPlugIn (Registry)
- (NSArray *)unmetDependencies {
NSArray *plugIns = [self dependencies];
NSMutableArray *unmet = [NSMutableArray array];
for(NSDictionary * plugInDict in plugIns) {
NSString *identifier = [plugInDict objectForKey:@"id"];
if (![[[QSPlugInManager sharedInstance] loadedPlugIns] objectForKey:identifier]) {
// NSString *name = [plugInDict objectForKey:@"id"];
//if (error) *error = [NSString stringWithFormat:@"Requires PlugIn '%@'", name?name:identifier];
//NSLog(@"%@ requires %@", [self name] , name);
[unmet addObject:plugInDict];
}
}
return unmet;
}
- (BOOL)meetsRequirements:(NSString **)error {
NSDictionary *requirementsDict = [bundle dictionaryForFileOrPlistKey:@"QSRequirements"];
*error = nil;
//NSString *ident = [self bundleIdentifier];
// NSString *restriction = [[self restrictionsDict] objectForKey:ident];
// if (restriction) {
// NSString *curVersion = [bundle objectForInfoDictionaryKey:@"CFBundleVersion"];
// if ([curVersion versionCompare:restriction] <0) {
// if (error) *error = [NSString stringWithFormat:@"Newer Version Required: %@ (%@) %d", restriction, curVersion, [curVersion versionCompare:restriction]];
// return NO;
// }
// }
if (requirementsDict) {
NSArray *bundles = [requirementsDict objectForKey:@"bundles"];
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"QSIgnorePlugInBundleRequirements"]) {
for(NSDictionary * bundleDict in bundles) {
break;
NSString *identifier = [bundleDict objectForKey:@"id"];
NSString *path = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:identifier];
if (!path) {
NSString *name = [bundleDict objectForKey:@"name"];
if (error) *error = [NSString stringWithFormat:@"Requires Bundle '%@'", name?name:identifier];
return NO;
}
#warning add support for version checking
}
}
{
NSArray *frameworks = [requirementsDict objectForKey:@"frameworks"];
for(NSDictionary * frameworkDict in frameworks) {
NSString *identifier = [frameworkDict objectForKey:@"id"];
NSString *resource = [frameworkDict objectForKey:@"resource"];
NSString *path = [[QSResourceManager sharedInstance] pathWithLocatorInformation:resource];
//path = @"/Volumes/Lore/Applications/Colloquy.app/Contents/Frameworks/AGRegex.framework";
NSBundle *pathBundle = [NSBundle bundleWithPath:path];
[pathBundle load];
//CFBundleRef b = CFBundleCreate(NULL, [NSURL fileURLWithPath:path]);
//int err = CFBundleLoadExecutable(b);
NSLog(@"path %@ %@ %@", path, resource, pathBundle);
if (!path) {
NSString *name = [frameworkDict objectForKey:@"name"];
if (error) *error = [NSString stringWithFormat:@"Requires Framework '%@'", name?name:identifier];
return NO;
}
}
}
NSArray *paths = [requirementsDict objectForKey:@"paths"];
for(NSString * path in paths) {
if (![[NSFileManager defaultManager] fileExistsAtPath:[path stringByStandardizingPath]]) {
if (error) *error = [NSString stringWithFormat:@"Path not found: '%@'", path];
return NO;
}
}
NSString *qsVersion = [requirementsDict objectForKey:@"version"];
if (qsVersion) {
NSComparisonResult sorting = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] versionCompare:qsVersion];
if (sorting<0) {
if (error) *error = [NSString stringWithFormat:@"Requires Quicksiver Build %@", qsVersion];
return NO;
}
}
// int feature = [[requirementsDict objectForKey:@"feature"] intValue];
// if (feature>[NSApp featureLevel]) {
// if (error) *error = @"Feature Level not Met";
// return NO;
// }
}
return YES;
}
//- (BOOL)liveLoadPlugIn:(NSBundle *)bundle {
// NSArray *disabledBundles = [[NSUserDefaults standardUserDefaults] objectForKey:@"QSDisabledPlugIns"];
//
// if ([disabledBundles containsObject:[self bundleIdentifier]]) return YES;
// if (![[QSPlugInManager sharedInstance] shouldLoadPlugIn:self inGroup:nil]) return NO;
//#warning this should be implemented internally
// return [self registerPlugIn];
//}
//- (BOOL)loadOldActionProviders:(NSArray *)providerClasses {
// NSEnumerator *e = [providerClasses objectEnumerator];
// NSString *className;
// while(className = [e nextObject]) {
// id instance = [QSReg getClassInstance:className];
// [QSExec registerActions:instance];
// }
// return YES;
//}
- (void)registerPlugInFrameworks {
return;
NSFileManager *fm = [NSFileManager defaultManager];
NSString *frameworksPath = [[bundle bundlePath] stringByAppendingPathComponent:@"Contents/Frameworks"];
if ([fm fileExistsAtPath:frameworksPath]) {
char *var = getenv("DYLD_FRAMEWORK_PATH");
NSString *frameworkVar = var?[NSString stringWithUTF8String:var] :@"";
frameworkVar = [frameworkVar stringByAppendingFormat:@":%@", frameworksPath];
setenv("DYLD_FRAMEWORK_PATH", [frameworkVar UTF8String] , YES);
NSLog(@"Adding Framework Search Path: %@", frameworksPath);
// NSString *testpath = [frameworksPath stringByAppendingPathComponent:[[fm contentsOfDirectoryAtPath:frameworksPath error:nil] lastObject]];
// NSLog(@"bund %@", [NSBundle bundleWithPath:testpath]);
//[[NSBundle bundleWithPath:testpath] load];
// NSLog(@"%s", getenv("DYLD_FRAMEWORK_PATH") );
}
NSString *librariesPath = [[bundle bundlePath] stringByAppendingPathComponent:@"Contents/Libraries"];
if ([fm fileExistsAtPath:librariesPath]) {
char *var = getenv("DYLD_FRAMEWORK_PATH");
NSString *libraryVar = var?[NSString stringWithUTF8String:getenv("DYLD_FRAMEWORK_PATH")] :@"";
libraryVar = [libraryVar stringByAppendingFormat:@":%@", librariesPath];
setenv("DYLD_FRAMEWORK_PATH", [libraryVar UTF8String] , YES);
NSLog(@"Adding Library Search Path:\r%@", librariesPath);
}
//NSLog(@"DYLD %s", dyld_framework_path);
}
- (BOOL)_registerPlugIn {
if (!bundle) return NO;
#ifdef DEBUG
if (DEBUG_PLUGINS)
NSLog(@"Loading PlugIn: %@ (%@) ", [[[bundle bundlePath] lastPathComponent] stringByDeletingPathExtension] , [bundle objectForInfoDictionaryKey:@"CFBundleVersion"]);
#endif
[QSReg registerBundle:bundle];
[self registerPlugInFrameworks];
if ([[bundle objectForInfoDictionaryKey:@"NSAppleScriptEnabled"] boolValue])
[[NSScriptSuiteRegistry sharedScriptSuiteRegistry] loadSuitesFromBundle:bundle];
BOOL loadNow = ![QSReg handleRegistration:bundle];
id value;
id handler;
foreachkey(key, handlerClass, [QSReg tableNamed:kQSPlugInInfoHandlers]) {
value = [bundle dictionaryForFileOrPlistKey:key];
if (!value) continue;
//NSLog(@"----> Registering %@ for %@", key, [self name]);
handler = [QSReg getClassInstance:handlerClass];
if ([handler respondsToSelector:@selector(handleInfo:ofType:fromBundle:)])
[handler handleInfo:value ofType:key fromBundle:[self bundle]];
}
loadNow |= [[bundle objectForInfoDictionaryKey:@"QSLoadImmediately"] boolValue];
Class currPrincipalClass;
if (loadNow) {
currPrincipalClass = [bundle principalClass];
if (currPrincipalClass) {
#ifdef DEBUG
if (DEBUG_PLUGINS) NSLog(@"Forcing Load of Class %@", currPrincipalClass);
#endif
if ([currPrincipalClass respondsToSelector:@selector(loadPlugIn)])
[currPrincipalClass loadPlugIn];
}
}
//if (complete)
[[NSNotificationCenter defaultCenter] postNotificationName:QSPlugInLoadedNotification object:self];
loaded = YES;
return YES;
}
- (BOOL)registerPlugIn {
//NSLog(@"%s", __PRETTY_FUNCTION__) ;
NS_DURING
[self _registerPlugIn];
NS_HANDLER
NSString *errorMessage = [NSString stringWithFormat:@"An error ocurred while loading plug-in \"%@\": %@", self, localException];
#ifdef DEBUG
if (VERBOSE) {
NSLog(@"%@", errorMessage);
[localException printStackTrace];
}
#endif
[self setLoadError:[localException reason]];
NS_ENDHANDLER
return YES;
}
@end