57{
59 NSDictionary *requiresPList =
nil;
60 NSSet *knownKeys =
nil;
61 NSMutableSet *actualKeys =
nil;
62 NSString *version =
nil,
64 NSArray *ooVersionComponents =
nil,
65 *versionComponents =
nil,
66 *maxVersionComponents =
nil;
67
68 fileScanner = [[self verifier] fileScannerStage];
69 requiresPList = [fileScanner
plistNamed:@"requires.plist"
73
74 if (requiresPList ==
nil)
return;
75
76
77 if (![requiresPList isKindOfClass:[NSDictionary class]])
78 {
79 OOLog(
@"verifyOXP.requiresPList.notDict",
@"%@",
@"***** ERROR: requires.plist is not a dictionary.");
80 return;
81 }
82
83
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
95 version = [requiresPList objectForKey:@"version"];
97 {
98 if (![version isKindOfClass:[NSString class]])
99 {
100 OOLog(
@"verifyOXP.requiresPList.badValue",
@"%@",
@"***** ERROR: Value for 'version' is not a string.");
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.");
112 }
113 }
114
115 if (version !=
nil || maxVersion !=
nil)
116 {
118 if (ooVersionComponents ==
nil)
119 {
120 OOLog(
@"verifyOXP.requiresPList.cantFindOoliteVersion",
@"%@",
@"----- WARNING: could not find Oolite's version for requires.plist sanity check.");
121 }
123 {
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 {
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}
#define OOLog(class, format,...)
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)