forked from jessegrosjean/blocks
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBRequirement.m
More file actions
68 lines (52 loc) · 2.17 KB
/
BRequirement.m
File metadata and controls
68 lines (52 loc) · 2.17 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
//
// BRequirement.m
// Blocks
//
// Created by Jesse Grosjean on 8/21/07.
// Copyright 2007 Blocks. All rights reserved.
//
#import "BRequirement.h"
#import "BExtensionRegistry.h"
#import "BPlugin.h"
#import "Blocks.h"
@interface BExtensionRegistry (BRequirementPrivate)
- (BPlugin *)pluginFor:(NSString *)pluginID;
@end
@implementation BRequirement
#pragma mark Properties
@synthesize plugin;
@synthesize optional;
@synthesize version;
@synthesize requiredBundleIdentifier;
- (id)requiredBundle {
BPlugin *requiredLoadableObject = [[BExtensionRegistry sharedInstance] pluginFor:[self requiredBundleIdentifier]];
if (requiredLoadableObject) return requiredLoadableObject;
return [NSBundle bundleWithIdentifier:[self requiredBundleIdentifier]];
}
#pragma mark Loading
- (BOOL)isLoaded {
return [[self requiredBundle] isLoaded];
}
- (BOOL)loadAndReturnError:(NSError **)error {
NSString *errorDescription = nil;
id requiredBundle = [self requiredBundle];
if (!requiredBundle) {
errorDescription = [NSString stringWithFormat:BLocalizedString(@"The \"%@\" plugin could not be loaded because its \"%@\" requirement could not be found.", nil), plugin.label, [requiredBundleIdentifier pathExtension]];
} else {
NSArray *actualVersionComponents = [[requiredBundle version] componentsSeparatedByString:@"."];
NSArray *versionComponents = [version componentsSeparatedByString:@"."];
if (![[actualVersionComponents objectAtIndex:0] isEqualToString:[versionComponents objectAtIndex:0]] || [[actualVersionComponents objectAtIndex:0] intValue] < [[versionComponents objectAtIndex:0] intValue]) {
errorDescription = [NSString stringWithFormat:BLocalizedString(@"The \"%@\" plugin could not be loaded because it requires version %@ of \"%@\", but only version %@ is availible.", nil), plugin.label, version, [requiredBundle label], [requiredBundle version]];
}
}
if (errorDescription && error != NULL) {
*error = [NSError errorWithDomain:@"BlocksErrorDomain" code:0 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:errorDescription, NSLocalizedDescriptionKey, nil]];
return NO;
}
if ([requiredBundle loadAndReturnError:error]) {
return YES;
} else {
return NO;
}
}
@end