Oolite 1.91.0.7604-240417-a536cbe
Loading...
Searching...
No Matches
OOCheckRequiresPListVerifierStage.m
Go to the documentation of this file.
1/*
2
3OOCheckRequiresPListVerifierStage.m
4
5
6Oolite
7Copyright (C) 2004-2013 Giles C Williams and contributors
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22MA 02110-1301, USA.
23
24*/
25
27
28#if OO_OXP_VERIFIER_ENABLED
29
31#import "OOStringParsing.h"
32
33static NSString * const kStageName = @"Checking requires.plist";
34
35
37
38- (NSString *)name
39{
40 return kStageName;
41}
42
43
44- (BOOL)shouldRun
45{
46 OOFileScannerVerifierStage *fileScanner = nil;
47
48 fileScanner = [[self verifier] fileScannerStage];
49 return [fileScanner fileExists:@"requires.plist"
50 inFolder:@"Config"
52 checkBuiltIn:NO];
53}
54
55
56- (void)run
57{
58 OOFileScannerVerifierStage *fileScanner = nil;
59 NSDictionary *requiresPList = nil;
60 NSSet *knownKeys = nil;
61 NSMutableSet *actualKeys = nil;
62 NSString *version = nil,
63 *maxVersion = nil;
64 NSArray *ooVersionComponents = nil,
65 *versionComponents = nil,
66 *maxVersionComponents = nil;
67
68 fileScanner = [[self verifier] fileScannerStage];
69 requiresPList = [fileScanner plistNamed:@"requires.plist"
70 inFolder:@"Config"
72 checkBuiltIn:NO];
73
74 if (requiresPList == nil) return;
75
76 // Check that it's a dictionary
77 if (![requiresPList isKindOfClass:[NSDictionary class]])
78 {
79 OOLog(@"verifyOXP.requiresPList.notDict", @"%@", @"***** ERROR: requires.plist is not a dictionary.");
80 return;
81 }
82
83 // Check that all the keys are known.
84 knownKeys = [[self verifier] configurationSetForKey:@"requiresPListSupportedKeys"];
85 actualKeys = [NSMutableSet setWithArray:[requiresPList allKeys]];
86 [actualKeys minusSet:knownKeys];
87
88 if ([actualKeys count] != 0)
89 {
90
91 OOLog(@"verifyOXP.requiresPList.unknownKeys", @"----- WARNING: requires.plist contains unknown keys. This OXP will not be loaded by this version of Oolite. Unknown keys are: %@.", [[actualKeys allObjects] componentsJoinedByString:@", "]);
92 }
93
94 // Sanity check the known keys.
95 version = [requiresPList objectForKey:@"version"];
96 if (version != nil)
97 {
98 if (![version isKindOfClass:[NSString class]])
99 {
100 OOLog(@"verifyOXP.requiresPList.badValue", @"%@", @"***** ERROR: Value for 'version' is not a string.");
101 version = nil;
102 }
103 }
104
105 maxVersion = [requiresPList objectForKey:@"max_version"];
106 if (maxVersion != nil)
107 {
108 if (![maxVersion isKindOfClass:[NSString class]])
109 {
110 OOLog(@"verifyOXP.requiresPList.badValue", @"%@", @"***** ERROR: Value for 'max_version' is not a string.");
111 maxVersion = nil;
112 }
113 }
114
115 if (version != nil || maxVersion != nil)
116 {
117 ooVersionComponents = ComponentsFromVersionString([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]);
118 if (ooVersionComponents == nil)
119 {
120 OOLog(@"verifyOXP.requiresPList.cantFindOoliteVersion", @"%@", @"----- WARNING: could not find Oolite's version for requires.plist sanity check.");
121 }
122 if (version != nil)
123 {
124 versionComponents = ComponentsFromVersionString(version);
125 if (versionComponents == nil)
126 {
127 OOLog(@"verifyOXP.requiresPList.badValue", @"***** ERROR: could not interpret version string \"%@\" as version number.", version);
128 }
129 else if (ooVersionComponents != nil)
130 {
131 if (CompareVersions(ooVersionComponents, versionComponents) == NSOrderedAscending)
132 {
133 OOLog(@"verifyOXP.requiresPList.oxpRequiresNewerOolite", @"----- WARNING: this OXP requires a newer version of Oolite (%@) to work.", version);
134 }
135 }
136 }
137 if (maxVersion != nil)
138 {
139 maxVersionComponents = ComponentsFromVersionString(maxVersion);
140 if (maxVersionComponents == nil)
141 {
142 OOLog(@"verifyOXP.requiresPList.badValue", @"***** ERROR: could not interpret max_version string \"%@\" as version number.", maxVersion);
143 }
144 else if (ooVersionComponents != nil)
145 {
146 if (CompareVersions(ooVersionComponents, maxVersionComponents) == NSOrderedDescending)
147 {
148 OOLog(@"verifyOXP.requiresPList.oxpRequiresOlderOolite", @"----- WARNING: this OXP requires an older version of Oolite (%@) to work.", maxVersion);
149 }
150 }
151 }
152
153 if (versionComponents != nil && maxVersionComponents != nil)
154 {
155 if (CompareVersions(versionComponents, maxVersionComponents) == NSOrderedDescending)
156 {
157 OOLog(@"verifyOXP.requiresPList.noVersionsInRange", @"***** ERROR: this OXP's maximum version (%@) is less than its minimum version (%@).", maxVersion, version);
158 }
159 }
160 }
161}
162
163@end
164
165#endif
static NSString *const kStageName
static NSString *const kStageName
#define OOLog(class, format,...)
Definition OOLogging.h:88
unsigned count
return nil
NSArray * ComponentsFromVersionString(NSString *string)
NSComparisonResult CompareVersions(NSArray *version1, NSArray *version2)
id plistNamed:inFolder:referencedFrom:checkBuiltIn:(NSString *file,[inFolder] NSString *folder,[referencedFrom] NSString *context,[checkBuiltIn] BOOL checkBuiltIn)
BOOL fileExists:inFolder:referencedFrom:checkBuiltIn:(NSString *file,[inFolder] NSString *folder,[referencedFrom] NSString *context,[checkBuiltIn] BOOL checkBuiltIn)