Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOOXZManager(NSURLConnectionDataDelegate) Category Reference

Instance Methods

(NSString *) - manifestPath
 
(NSString *) - downloadPath
 
(NSString *) - extractionBasePathForIdentifier:andVersion:
 
(NSString *) - dataURL
 
(NSString *) - humanSize:
 
(BOOL) - ensureInstallPath
 
(BOOL) - beginDownload:
 
(BOOL) - processDownloadedManifests
 
(BOOL) - processDownloadedOXZ
 
(OXZInstallableState- installableState:
 
(OOColor *) - colorForManifest:
 
(NSString *) - installStatusForManifest:
 
(BOOL) - validateFilter:
 
(void) - setOXZList:
 
(void) - setFilteredList:
 
(NSArray *) - applyCurrentFilter:
 
(void) - setCurrentDownload:withLabel:
 
(void) - setProgressStatus:
 
(BOOL) - installOXZ:
 
(BOOL) - updateAllOXZ
 
(BOOL) - removeOXZ:
 
(NSArray *) - installOptions
 
(NSArray *) - removeOptions
 
(NSString *) - extractOXZ:
 
(void) - connection:didFailWithError:
 
(void) - connection:didReceiveResponse:
 
(void) - connection:didReceiveData:
 
(void) - connectionDidFinishLoading:
 

Detailed Description

Definition at line 126 of file OOOXZManager.m.

Method Documentation

◆ applyCurrentFilter:

- (NSArray *) applyCurrentFilter: (NSArray *) list

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

370 :(NSArray *)list
371{
372 SEL filterSelector = @selector(applyFilterByNoFilter:);
373 NSString *parameter = nil;
374 if ([_currentFilter isEqualToString:kOOOXZFilterUpdates])
375 {
376 filterSelector = @selector(applyFilterByUpdateRequired:);
377 }
378 else if ([_currentFilter isEqualToString:kOOOXZFilterInstallable])
379 {
380 filterSelector = @selector(applyFilterByInstallable:);
381 }
382 else if ([_currentFilter hasPrefix:kOOOXZFilterKeyword])
383 {
384 filterSelector = @selector(applyFilterByKeyword:keyword:);
385 parameter = [_currentFilter substringFromIndex:[kOOOXZFilterKeyword length]];
386 }
387 else if ([_currentFilter hasPrefix:kOOOXZFilterAuthor])
388 {
389 filterSelector = @selector(applyFilterByAuthor:author:);
390 parameter = [_currentFilter substringFromIndex:[kOOOXZFilterAuthor length]];
391 }
392 else if ([_currentFilter hasPrefix:kOOOXZFilterDays])
393 {
394 filterSelector = @selector(applyFilterByDays:days:);
395 parameter = [_currentFilter substringFromIndex:[kOOOXZFilterDays length]];
396 }
397 else if ([_currentFilter hasPrefix:kOOOXZFilterTag])
398 {
399 filterSelector = @selector(applyFilterByTag:tag:);
400 parameter = [_currentFilter substringFromIndex:[kOOOXZFilterTag length]];
401 }
402 else if ([_currentFilter hasPrefix:kOOOXZFilterCategory])
403 {
404 filterSelector = @selector(applyFilterByCategory:category:);
405 parameter = [_currentFilter substringFromIndex:[kOOOXZFilterCategory length]];
406 }
407
408 NSMutableArray *filteredList = [NSMutableArray arrayWithCapacity:[list count]];
409 NSDictionary *manifest = nil;
410 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:filterSelector]];
411 [invocation setSelector:filterSelector];
412 [invocation setTarget:self];
413 if (parameter != nil)
414 {
415 [invocation setArgument:&parameter atIndex:3];
416 }
417
418 foreach(manifest, list)
419 {
420 [invocation setArgument:&manifest atIndex:2];
421 [invocation invoke];
422 BOOL filterAccepted = NO;
423 [invocation getReturnValue:&filterAccepted];
424 if (filterAccepted)
425 {
426 [filteredList addObject:manifest];
427 }
428 }
429 // any bad filter that gets this far is also treated as '*'
430 // so don't need to explicitly test for '*' or ''
431 return [[filteredList copy] autorelease];
432}
static NSString *const kOOOXZFilterDays
static NSString *const kOOOXZFilterTag
static NSString *const kOOOXZFilterKeyword
static NSString *const kOOOXZFilterUpdates
static NSString *const kOOOXZFilterCategory
static NSString *const kOOOXZFilterInstallable
static NSString *const kOOOXZFilterAuthor
return nil

◆ beginDownload:

- (BOOL) beginDownload: (NSMutableURLRequest *) request

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

595 :(NSMutableURLRequest *)request
596{
597 NSString *userAgent = [NSString stringWithFormat:@"Oolite/%@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]];
598 [request setValue:userAgent forHTTPHeaderField:@"User-Agent"];
599 NSURLConnection *download = [[NSURLConnection alloc] initWithRequest:request delegate:self];
600 if (download)
601 {
602 _downloadProgress = 0;
603 _downloadExpected = 0;
604 NSString *label = DESC(@"oolite-oxzmanager-download-label-list");
605 if (_interfaceState != OXZ_STATE_UPDATING)
606 {
607 NSDictionary *expectedManifest = nil;
608 expectedManifest = [_filteredList objectAtIndex:_item];
609
610 label = [expectedManifest oo_stringForKey:kOOManifestTitle defaultValue:DESC(@"oolite-oxzmanager-download-label-oxz")];
611 }
612
613 [self setCurrentDownload:download withLabel:label]; // retains it
614 [download release];
615 OOLog(kOOOXZDebugLog,@"Download request received, using %@ and downloading to %@",[request URL],[self downloadPath]);
616 return YES;
617 }
618 else
619 {
620 OOLog(kOOOXZErrorLog,@"Unable to start downloading file at %@",[request URL]);
621 _downloadStatus = OXZ_DOWNLOAD_ERROR;
622 return NO;
623 }
624}
#define OOLog(class, format,...)
Definition OOLogging.h:88
@ OXZ_STATE_UPDATING
@ OXZ_DOWNLOAD_ERROR
static NSString *const kOOOXZErrorLog
static NSString *const kOOOXZDebugLog
#define DESC(key)
Definition Universe.h:846

◆ colorForManifest:

- (OOColor *) colorForManifest: (NSDictionary *) manifest

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

1059 :(NSDictionary *)manifest
1060{
1061 switch ([self installableState:manifest])
1062 {
1064 return [OOColor yellowColor];
1066 return [OOColor cyanColor];
1068 return [OOColor orangeColor];
1070 return [OOColor brownColor];
1072 return [OOColor whiteColor];
1074 return [OOColor redColor];
1076 return [OOColor grayColor];
1078 return [OOColor blueColor];
1079 }
1080 return [OOColor yellowColor]; // never
1081}
@ OXZ_INSTALLABLE_UPDATE
@ OXZ_INSTALLABLE_DEPENDENCIES
@ OXZ_INSTALLABLE_CONFLICTS
@ OXZ_INSTALLABLE_OKAY
@ OXZ_UNINSTALLABLE_VERSION
@ OXZ_UNINSTALLABLE_ALREADY
@ OXZ_UNINSTALLABLE_NOREMOTE
@ OXZ_UNINSTALLABLE_MANUAL
OOColor * cyanColor()
Definition OOColor.m:286
OOColor * orangeColor()
Definition OOColor.m:304
OOColor * redColor()
Definition OOColor.m:268
OOColor * blueColor()
Definition OOColor.m:280
OOColor * grayColor()
Definition OOColor.m:262
OOColor * whiteColor()
Definition OOColor.m:256
OOColor * brownColor()
Definition OOColor.m:316
OOColor * yellowColor()
Definition OOColor.m:292

◆ connection:didFailWithError:

- (void) connection: (NSURLConnection *) connection
didFailWithError: (NSError *) error 

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

2343 :(NSURLConnection *)connection didFailWithError:(NSError *)error
2344{
2345 _downloadStatus = OXZ_DOWNLOAD_ERROR;
2346 OOLog(kOOOXZErrorLog,@"Error downloading file: %@",[error description]);
2347 [_fileWriter closeFile];
2348 DESTROY(_fileWriter);
2349 DESTROY(_currentDownload);
2350}
#define DESTROY(x)
Definition OOCocoa.h:77

◆ connection:didReceiveData:

- (void) connection: (NSURLConnection *) connection
didReceiveData: (NSData *) data 

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

2285 :(NSURLConnection *)connection didReceiveData:(NSData *)data
2286{
2287 OOLog(kOOOXZDebugLog,@"Downloaded %lu bytes",[data length]);
2288 [_fileWriter seekToEndOfFile];
2289 [_fileWriter writeData:data];
2290 _downloadProgress += [data length];
2291 [self gui]; // update GUI
2292#if OOLITE_WINDOWS
2293 /* Irritating fix to issue https://github.com/OoliteProject/oolite/issues/95
2294 *
2295 * The problem is that on MINGW, GNUStep makes all socket streams
2296 * blocking, which causes problems with the run loop. Calling this
2297 * method of the run loop forces it to execute all already
2298 * scheduled items with a time in the past, before any more items
2299 * are placed on it, which means that the main game update gets a
2300 * chance to run.
2301 *
2302 * This stops the interface freezing - and Oolite appearing to
2303 * have stopped responding to the OS - when downloading large
2304 * (>20Mb) OXZ files.
2305 *
2306 * CIM 6 July 2014
2307 */
2308 [[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];
2309#endif
2310}

◆ connection:didReceiveResponse:

- (void) connection: (NSURLConnection *) connection
didReceiveResponse: (NSURLResponse *) response 

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

2267 :(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
2268{
2269 _downloadStatus = OXZ_DOWNLOAD_RECEIVING;
2270 OOLog(kOOOXZDebugLog, @"%@", @"Download receiving");
2271 _downloadExpected = [response expectedContentLength];
2272 _downloadProgress = 0;
2273 DESTROY(_fileWriter);
2274 [[NSFileManager defaultManager] createFileAtPath:[self downloadPath] contents:nil attributes:nil];
2275 _fileWriter = [[NSFileHandle fileHandleForWritingAtPath:[self downloadPath]] retain];
2276 if (_fileWriter == nil)
2277 {
2278 // file system is full or read-only or something
2279 OOLog(kOOOXZErrorLog, @"%@", @"Unable to create download file");
2280 [self cancelUpdate];
2281 }
2282}
@ OXZ_DOWNLOAD_RECEIVING

◆ connectionDidFinishLoading:

- (void) connectionDidFinishLoading: (NSURLConnection *) connection

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

2313 :(NSURLConnection *)connection
2314{
2315 _downloadStatus = OXZ_DOWNLOAD_COMPLETE;
2316 OOLog(kOOOXZDebugLog, @"%@", @"Download complete");
2317 [_fileWriter synchronizeFile];
2318 [_fileWriter closeFile];
2319 DESTROY(_fileWriter);
2320 DESTROY(_currentDownload);
2321 if (_interfaceState == OXZ_STATE_UPDATING)
2322 {
2323 if (![self processDownloadedManifests])
2324 {
2325 _downloadStatus = OXZ_DOWNLOAD_ERROR;
2326 }
2327 }
2328 else if (_interfaceState == OXZ_STATE_INSTALLING)
2329 {
2330 if (![self processDownloadedOXZ])
2331 {
2332 _downloadStatus = OXZ_DOWNLOAD_ERROR;
2333 }
2334 }
2335 else
2336 {
2337 OOLog(kOOOXZErrorLog,@"Error: download completed in unexpected state %d. This is an internal error - please report it.",_interfaceState);
2338 _downloadStatus = OXZ_DOWNLOAD_ERROR;
2339 }
2340}
@ OXZ_STATE_INSTALLING
@ OXZ_DOWNLOAD_COMPLETE

◆ dataURL

- (NSString *) dataURL

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

312{
313 /* Not expected to be set in general, but might be useful for some users */
314 NSString *url = [[NSUserDefaults standardUserDefaults] stringForKey:kOOOXZDataConfig];
315 if (url != nil)
316 {
317 return url;
318 }
319 return kOOOXZDataURL;
320}
static NSString *const kOOOXZDataURL

◆ downloadPath

- (NSString *) downloadPath

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

299{
300 if (_interfaceState == OXZ_STATE_UPDATING)
301 {
302 return [[[OOCacheManager sharedCache] cacheDirectoryPathCreatingIfNecessary:YES] stringByAppendingPathComponent:kOOOXZTmpPlistPath];
303 }
304 else
305 {
306 return [[[OOCacheManager sharedCache] cacheDirectoryPathCreatingIfNecessary:YES] stringByAppendingPathComponent:kOOOXZTmpPath];
307 }
308}
NSString * cacheDirectoryPathCreatingIfNecessary:(BOOL create)
OOCacheManager * sharedCache()

◆ ensureInstallPath

- (BOOL) ensureInstallPath

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

264{
265 BOOL exists, directory;
266 NSFileManager *fmgr = [NSFileManager defaultManager];
267 NSString *path = [self installPath];
268
269 exists = [fmgr fileExistsAtPath:path isDirectory:&directory];
270
271 if (exists && !directory)
272 {
273 OOLog(kOOOXZErrorLog, @"Expected %@ to be a folder, but it is a file.", path);
274 return NO;
275 }
276 if (!exists)
277 {
278 if (![fmgr oo_createDirectoryAtPath:path attributes:nil])
279 {
280 OOLog(kOOOXZErrorLog, @"Could not create folder %@.", path);
281 return NO;
282 }
283 }
284
285 return YES;
286}

◆ extractionBasePathForIdentifier:andVersion:

- (NSString *) extractionBasePathForIdentifier: (NSString *) identifier
andVersion: (NSString *) version 

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

253 :(NSString *)identifier andVersion:(NSString *)version
254{
255 NSString *basePath = [[ResourceManager userRootPaths] lastObject];
256 NSString *rawMainDir = [NSString stringWithFormat:@"%@-%@.off",identifier,version];
257
258 NSCharacterSet *blacklist = [NSCharacterSet characterSetWithCharactersInString:@"'#%^&{}[]/~|\\?<,:\" "];
259 return [[[basePath stringByAppendingPathComponent:[[rawMainDir componentsSeparatedByCharactersInSet:blacklist] componentsJoinedByString:@""]] retain] autorelease];
260}
NSArray * userRootPaths()

◆ extractOXZ:

- (NSString *) extractOXZ: (NSUInteger) item

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

2132 :(NSUInteger)item
2133{
2134 NSFileManager *fmgr = [NSFileManager defaultManager];
2135 NSMutableString *extractionLog = [[NSMutableString alloc] init];
2136 NSDictionary *manifest = [_filteredList oo_dictionaryAtIndex:item];
2137 NSString *version = [manifest oo_stringForKey:kOOManifestVersion];
2138 NSString *identifier = [manifest oo_stringForKey:kOOManifestIdentifier];
2139 NSString *path = [self extractionBasePathForIdentifier:identifier andVersion:version];
2140
2141 // OXZ errors should really never happen unless someone is messing
2142 // directly with the managed folder while Oolite is running, but
2143 // it's possible.
2144
2145 NSString *oxzfile = [manifest oo_stringForKey:kOOManifestFilePath];
2146 if (![fmgr fileExistsAtPath:oxzfile])
2147 {
2148 OOLog(kOOOXZErrorLog,@"OXZ %@ could not be found",oxzfile);
2149 [extractionLog appendString:DESC(@"oolite-oxzmanager-extract-log-no-original")];
2150 return [extractionLog autorelease];
2151 }
2152 const char* zipname = [oxzfile UTF8String];
2153 unzFile uf = NULL;
2154 uf = unzOpen64(zipname);
2155 if (uf == NULL)
2156 {
2157 OOLog(kOOOXZErrorLog,@"Could not open .oxz at %@ as zip file",path);
2158 [extractionLog appendString:DESC(@"oolite-oxzmanager-extract-log-bad-original")];
2159 return [extractionLog autorelease];
2160 }
2161
2162 if ([fmgr fileExistsAtPath:path])
2163 {
2164 OOLog(kOOOXZErrorLog,@"Path %@ already exists",path);
2165 [extractionLog appendString:DESC(@"oolite-oxzmanager-extract-log-main-exists")];
2166 unzClose(uf);
2167 return [extractionLog autorelease];
2168 }
2169 if (![fmgr oo_createDirectoryAtPath:path attributes:nil])
2170 {
2171 OOLog(kOOOXZErrorLog,@"Path %@ could not be created",path);
2172 [extractionLog appendString:DESC(@"oolite-oxzmanager-extract-log-main-unmakeable")];
2173 unzClose(uf);
2174 return [extractionLog autorelease];
2175 }
2176 [extractionLog appendString:DESC(@"oolite-oxzmanager-extract-log-main-created")];
2177 NSUInteger counter = 0;
2178 char rawComponentName[512];
2179 BOOL error = NO;
2180 unz_file_info64 file_info = {0};
2181 if (unzGoToFirstFile(uf) == UNZ_OK)
2182 {
2183 do
2184 {
2185 unzGetCurrentFileInfo64(uf, &file_info,
2186 rawComponentName, 512,
2187 NULL, 0,
2188 NULL, 0);
2189 NSString *componentName = [NSString stringWithUTF8String:rawComponentName];
2190 if ([componentName hasSuffix:@"/"])
2191 {
2192 // folder
2193 if (![fmgr oo_createDirectoryAtPath:[path stringByAppendingPathComponent:componentName] attributes:nil])
2194 {
2195 OOLog(kOOOXZErrorLog,@"Subpath %@ could not be created",componentName);
2196 [extractionLog appendString:DESC(@"oolite-oxzmanager-extract-log-sub-failed")];
2197 error = YES;
2198 break;
2199 }
2200 else
2201 {
2202 OOLog(kOOOXZDebugLog,@"Subpath %@ created OK",componentName);
2203 }
2204 }
2205 else
2206 {
2207 // file
2208 // usually folder must now exist, but just in case...
2209 NSString *folder = [[path stringByAppendingPathComponent:componentName] stringByDeletingLastPathComponent];
2210 if ([folder length] > 0 && ![fmgr fileExistsAtPath:folder] && ![fmgr oo_createDirectoryAtPath:folder attributes:nil])
2211 {
2212 OOLog(kOOOXZErrorLog,@"Subpath %@ could not be created",folder);
2213 [extractionLog appendString:DESC(@"oolite-oxzmanager-extract-log-sub-failed")];
2214 error = YES;
2215 break;
2216 }
2217
2218
2219 // This is less efficient in memory use than just
2220 // streaming out of the ZIP file onto disk
2221 // but it makes error handling easier
2222 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
2223 NSData *tmp = [NSData oo_dataWithOXZFile:[oxzfile stringByAppendingPathComponent:componentName]];
2224 if (tmp == nil)
2225 {
2226 OOLog(kOOOXZErrorLog,@"Sub file %@ could not be extracted from the OXZ",componentName);
2227 [extractionLog appendString:DESC(@"oolite-oxzmanager-extract-log-sub-failed")];
2228 error = YES;
2229 [pool release];
2230 break;
2231 }
2232 else
2233 {
2234 if (![tmp writeToFile:[path stringByAppendingPathComponent:componentName] atomically:YES])
2235 {
2236 OOLog(kOOOXZErrorLog,@"Sub file %@ could not be created",componentName);
2237 [extractionLog appendString:DESC(@"oolite-oxzmanager-extract-log-sub-failed")];
2238 error = YES;
2239 [pool release];
2240 break;
2241 }
2242 else
2243 {
2244 ++counter;
2245 }
2246 }
2247 [pool release];
2248
2249 }
2250 }
2251 while (unzGoToNextFile(uf) == UNZ_OK);
2252 }
2253 unzClose(uf);
2254
2255 if (!error)
2256 {
2257 [extractionLog appendFormat:DESC(@"oolite-oxzmanager-extract-log-num-u-extracted"),counter];
2258 [extractionLog appendFormat:DESC(@"oolite-oxzmanager-extract-log-extracted-to-@"),path];
2259 }
2260
2261 return [extractionLog autorelease];
2262}
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
Definition unzip.c:1130
int ZEXPORT unzGoToFirstFile(unzFile file)
Definition unzip.c:1184
unzFile ZEXPORT unzOpen64(const void *path)
Definition unzip.c:801
int ZEXPORT unzGoToNextFile(unzFile file)
Definition unzip.c:1205
int ZEXPORT unzClose(unzFile file)
Definition unzip.c:811
voidp unzFile
Definition unzip.h:70
#define UNZ_OK
Definition unzip.h:74

◆ humanSize:

- (NSString *) humanSize: (NSUInteger) bytes

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

323 :(NSUInteger)bytes
324{
325 if (bytes == 0)
326 {
327 return DESC(@"oolite-oxzmanager-missing-field");
328 }
329 else if (bytes < 1024)
330 {
331 return @"<1 kB";
332 }
333 else if (bytes < 1024*1024)
334 {
335 return [NSString stringWithFormat:@"%lu kB",bytes>>10];
336 }
337 else
338 {
339 return [NSString stringWithFormat:@"%.2f MB",((float)(bytes>>10))/1024];
340 }
341}

◆ installableState:

- (OXZInstallableState) installableState: (NSDictionary *) manifest

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

992 :(NSDictionary *)manifest
993{
994 NSString *title = [manifest oo_stringForKey:kOOManifestTitle defaultValue:nil];
995 NSString *identifier = [manifest oo_stringForKey:kOOManifestIdentifier defaultValue:nil];
996 /* Check Oolite version */
997 if (![ResourceManager checkVersionCompatibility:manifest forOXP:title])
998 {
1000 }
1001 /* Check for current automated install */
1002 NSDictionary *installed = [self installedManifestForIdentifier:identifier];
1003 if (installed == nil)
1004 {
1005 // check for manual install
1006 installed = [ResourceManager manifestForIdentifier:identifier];
1007 }
1008
1009 if (installed != nil)
1010 {
1011 if (![[installed oo_stringForKey:kOOManifestFilePath] hasPrefix:[self installPath]])
1012 {
1013 // installed manually
1015 }
1016 if ([[installed oo_stringForKey:kOOManifestVersion] isEqualToString:[manifest oo_stringForKey:kOOManifestAvailableVersion defaultValue:[manifest oo_stringForKey:kOOManifestVersion]]]
1017 && [[NSFileManager defaultManager] fileExistsAtPath:[installed oo_stringForKey:kOOManifestFilePath]])
1018 {
1019 // installed this exact version already, and haven't
1020 // uninstalled it since entering the manager, and it's
1021 // still available
1023 }
1024 else if ([installed oo_stringForKey:kOOManifestAvailableVersion defaultValue:nil] == nil)
1025 {
1026 // installed, but no remote copy is indexed any more
1028 }
1029 }
1030 /* Check for dependencies being met */
1031 if ([ResourceManager manifestHasConflicts:manifest logErrors:NO])
1032 {
1034 }
1035 if (installed != nil)
1036 {
1037 NSString *availableVersion = [manifest oo_stringForKey:kOOManifestAvailableVersion];
1038 if (availableVersion == nil)
1039 {
1040 availableVersion = [manifest oo_stringForKey:kOOManifestVersion];
1041 }
1042 NSString *installedVersion = [installed oo_stringForKey:kOOManifestVersion];
1043 OOLog(@"version.debug",@"%@ mv:%@ mav:%@",identifier,installedVersion,availableVersion);
1044 if (CompareVersions(ComponentsFromVersionString(installedVersion),ComponentsFromVersionString(availableVersion)) == NSOrderedDescending)
1045 {
1046 // the installed copy is more recent than the server copy
1048 }
1050 }
1051 if ([ResourceManager manifestHasMissingDependencies:manifest logErrors:NO])
1052 {
1054 }
1055 return OXZ_INSTALLABLE_OKAY;
1056}
static NSString *const kOOManifestAvailableVersion
static NSString *const kOOManifestVersion
static NSString *const kOOManifestFilePath
NSArray * ComponentsFromVersionString(NSString *string)
NSComparisonResult CompareVersions(NSArray *version1, NSArray *version2)
NSDictionary * manifestForIdentifier:(NSString *identifier)

◆ installOptions

- (NSArray *) installOptions

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

1712{
1713 NSUInteger start = _offset;
1714 if (start >= [_filteredList count])
1715 {
1716 start = 0;
1717 _offset = 0;
1718 }
1719 NSUInteger end = start + OXZ_GUI_NUM_LISTROWS;
1720 if (end > [_filteredList count])
1721 {
1722 end = [_filteredList count];
1723 }
1724 return [_filteredList subarrayWithRange:NSMakeRange(start,end-start)];
1725}
@ OXZ_GUI_NUM_LISTROWS
unsigned count

◆ installOXZ:

- (BOOL) installOXZ: (NSUInteger) item

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

1644 :(NSUInteger)item
1645{
1646 NSArray *picklist = _filteredList;
1647
1648 if ([picklist count] <= item)
1649 {
1650 return NO;
1651 }
1652 NSDictionary *manifest = [picklist objectAtIndex:item];
1653 _item = item;
1654
1655 if ([self installableState:manifest] >= OXZ_UNINSTALLABLE_ALREADY)
1656 {
1657 OOLog(kOOOXZDebugLog,@"Cannot install %@",manifest);
1658 // can't be installed on this version of Oolite, or already is installed
1659 return NO;
1660 }
1661 NSString *url = [manifest objectForKey:kOOManifestDownloadURL];
1662 if (url == nil)
1663 {
1664 OOLog(kOOOXZErrorLog, @"%@", @"Manifest does not have a download URL - cannot install");
1665 return NO;
1666 }
1667 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
1668 if (_downloadStatus != OXZ_DOWNLOAD_NONE)
1669 {
1670 return NO;
1671 }
1672 _downloadStatus = OXZ_DOWNLOAD_STARTED;
1673 _interfaceState = OXZ_STATE_INSTALLING;
1674
1675 [self setProgressStatus:@""];
1676 return [self beginDownload:request];
1677}
@ OXZ_DOWNLOAD_STARTED
@ OXZ_DOWNLOAD_NONE

◆ installStatusForManifest:

- (NSString *) installStatusForManifest: (NSDictionary *) manifest

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

1084 :(NSDictionary *)manifest
1085{
1086 switch ([self installableState:manifest])
1087 {
1089 return DESC(@"oolite-oxzmanager-installable-okay");
1091 return DESC(@"oolite-oxzmanager-installable-update");
1093 return DESC(@"oolite-oxzmanager-installable-depend");
1095 return DESC(@"oolite-oxzmanager-installable-conflicts");
1097 return DESC(@"oolite-oxzmanager-installable-already");
1099 return DESC(@"oolite-oxzmanager-installable-manual");
1101 return DESC(@"oolite-oxzmanager-installable-version");
1103 return DESC(@"oolite-oxzmanager-installable-noremote");
1104 }
1105 return nil; // never
1106}

◆ manifestPath

- (NSString *) manifestPath

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

290{
291 return [[[OOCacheManager sharedCache] cacheDirectoryPathCreatingIfNecessary:YES] stringByAppendingPathComponent:kOOOXZManifestCache];
292}

◆ processDownloadedManifests

- (BOOL) processDownloadedManifests

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

717{
718 if (_downloadStatus != OXZ_DOWNLOAD_COMPLETE)
719 {
720 return NO;
721 }
722 [self setOXZList:OOArrayFromFile([self downloadPath])];
723 if (_oxzList != nil)
724 {
725 [_oxzList writeToFile:[self manifestPath] atomically:YES];
726 // and clean up the temp file
727 [[NSFileManager defaultManager] oo_removeItemAtPath:[self downloadPath]];
728 // invalidate the managed list
729 DESTROY(_managedList);
730 _interfaceState = OXZ_STATE_TASKDONE;
731 [self gui];
732 return YES;
733 }
734 else
735 {
736 _downloadStatus = OXZ_DOWNLOAD_ERROR;
737 OOLog(kOOOXZErrorLog,@"Downloaded manifest was not a valid plist, has been left in %@",[self downloadPath]);
738 // revert to the old one
739 [self setOXZList:OOArrayFromFile([self manifestPath])];
740 _interfaceState = OXZ_STATE_TASKDONE;
741 [self gui];
742 return NO;
743 }
744}
@ OXZ_STATE_TASKDONE

◆ processDownloadedOXZ

- (BOOL) processDownloadedOXZ

If downloadedManifest is in _dependencyStack, remove it Get downloadedManifest requires_oxp list Add entries ones to _dependencyStack If _dependencyStack has contents, update _progressStatus ...and start the download of the 'first' item in _dependencyStack ...which isn't already installed (_dependencyStack is unordered ...so 'first' isn't really defined)

...if the item in _dependencyStack is not findable (e.g. wrong ...version) then stop here.

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

748{
749 if (_downloadStatus != OXZ_DOWNLOAD_COMPLETE)
750 {
751 return NO;
752 }
753
754 NSDictionary *downloadedManifest = OODictionaryFromFile([[self downloadPath] stringByAppendingPathComponent:@"manifest.plist"]);
755 if (downloadedManifest == nil)
756 {
757 _downloadStatus = OXZ_DOWNLOAD_ERROR;
758 OOLog(kOOOXZErrorLog,@"Downloaded OXZ does not contain a manifest.plist, has been left in %@",[self downloadPath]);
759 _interfaceState = OXZ_STATE_TASKDONE;
760 [self gui];
761 return NO;
762 }
763 NSDictionary *expectedManifest = nil;
764 expectedManifest = [_filteredList objectAtIndex:_item];
765
766 if (expectedManifest == nil ||
767 (![[downloadedManifest oo_stringForKey:kOOManifestIdentifier] isEqualToString:[expectedManifest oo_stringForKey:kOOManifestIdentifier]]) ||
768 (![[downloadedManifest oo_stringForKey:kOOManifestVersion] isEqualToString:[expectedManifest oo_stringForKey:kOOManifestAvailableVersion defaultValue:[expectedManifest oo_stringForKey:kOOManifestVersion]]])
769 )
770 {
771 _downloadStatus = OXZ_DOWNLOAD_ERROR;
772 OOLog(kOOOXZErrorLog, @"%@", @"Downloaded OXZ does not have the same identifer and version as expected. This might be due to your manifests list being out of date - try updating it.");
773 _interfaceState = OXZ_STATE_TASKDONE;
774 [self gui];
775 return NO;
776 }
777 // this appears to be the OXZ we expected
778 // filename is going to be identifier.oxz
779 NSString *filename = [[downloadedManifest oo_stringForKey:kOOManifestIdentifier] stringByAppendingString:@".oxz"];
780
781 if (![self ensureInstallPath])
782 {
783 _downloadStatus = OXZ_DOWNLOAD_ERROR;
784 OOLog(kOOOXZErrorLog, @"%@", @"Unable to create installation folder.");
785 _interfaceState = OXZ_STATE_TASKDONE;
786 [self gui];
787 return NO;
788 }
789
790 // delete filename if it exists from OXZ folder
791 NSString *destination = [[self installPath] stringByAppendingPathComponent:filename];
792 [[NSFileManager defaultManager] oo_removeItemAtPath:destination];
793
794 // move the temp file on to it
795 if (![[NSFileManager defaultManager] oo_moveItemAtPath:[self downloadPath] toPath:destination])
796 {
797 _downloadStatus = OXZ_DOWNLOAD_ERROR;
798 OOLog(kOOOXZErrorLog, @"%@", @"Downloaded OXZ could not be installed.");
799 _interfaceState = OXZ_STATE_TASKDONE;
800 [self gui];
801 return NO;
802 }
803 _changesMade = YES;
804 DESTROY(_managedList); // will need updating
805 // do this now to cope with circular dependencies on download
807
820 NSArray *requires = [downloadedManifest oo_arrayForKey:kOOManifestRequiresOXPs defaultValue:nil];
821 if (requires == nil)
822 {
823 // just in case the requirements are only specified in the online copy
824 requires = [expectedManifest oo_arrayForKey:kOOManifestRequiresOXPs defaultValue:nil];
825 }
826 NSDictionary *requirement = nil;
827 NSMutableString *progress = [NSMutableString stringWithCapacity:2048];
828 OOLog(kOOOXZDebugLog,@"Dependency stack has %lu elements",[_dependencyStack count]);
829
830 if ([_dependencyStack count] > 0)
831 {
832 // will remove as iterate, so create a temp copy to iterate over
833 NSSet *tempStack = [NSSet setWithSet:_dependencyStack];
834 foreach (requirement, tempStack)
835 {
836 OOLog(kOOOXZDebugLog,@"Dependency stack: checking %@",[requirement oo_stringForKey:kOOManifestRelationIdentifier]);
837 if (![ResourceManager manifest:downloadedManifest HasUnmetDependency:requirement logErrors:NO]
838 && requires != nil && [requires containsObject:requirement])
839 {
840 // it was unmet, but now it's met
841 [progress appendFormat:DESC(@"oolite-oxzmanager-progress-now-has-@"),[requirement oo_stringForKey:kOOManifestRelationDescription defaultValue:[requirement oo_stringForKey:kOOManifestRelationIdentifier]]];
842 [_dependencyStack removeObject:requirement];
843 OOLog(kOOOXZDebugLog, @"%@", @"Dependency stack: requirement met");
844 } else if ([[requirement oo_stringForKey:kOOManifestRelationIdentifier] isEqualToString:[downloadedManifest oo_stringForKey:kOOManifestIdentifier]]) {
845 // remove the requirement for the just downloaded OXP
846 [_dependencyStack removeObject:requirement];
847 }
848 }
849 }
850 if (requires != nil)
851 {
852 foreach (requirement, requires)
853 {
854 if ([ResourceManager manifest:downloadedManifest HasUnmetDependency:requirement logErrors:NO])
855 {
856 OOLog(kOOOXZDebugLog,@"Dependency stack: adding %@",[requirement oo_stringForKey:kOOManifestRelationIdentifier]);
857 [_dependencyStack addObject:requirement];
858 [progress appendFormat:DESC(@"oolite-oxzmanager-progress-requires-@"),[requirement oo_stringForKey:kOOManifestRelationDescription defaultValue:[requirement oo_stringForKey:kOOManifestRelationIdentifier]]];
859 }
860 }
861 }
862 if ([_dependencyStack count] > 0)
863 {
864 // get an object from the requirements list, and download it
865 // if it can be found
866 BOOL undownloadedRequirement = NO;
867 NSDictionary *availableDownload = nil;
868 BOOL foundDownload = NO;
869 NSUInteger index = 0;
870 NSString *needsIdentifier = nil;
871
872 do
873 {
874 undownloadedRequirement = YES;
875 requirement = [_dependencyStack anyObject];
876 OOLog(kOOOXZDebugLog,@"Dependency stack: next is %@",[requirement oo_stringForKey:kOOManifestRelationIdentifier]);
877
878 if (!_downloadAllDependencies)
879 {
880 [progress appendString:DESC(@"oolite-oxzmanager-progress-get-required")];
881 }
882 needsIdentifier = [requirement oo_stringForKey:kOOManifestRelationIdentifier];
883
884 foreach (availableDownload, _oxzList)
885 {
886 if ([[availableDownload oo_stringForKey:kOOManifestIdentifier] isEqualToString:needsIdentifier])
887 {
888 if ([ResourceManager matchVersions:requirement withVersion:[availableDownload oo_stringForKey:kOOManifestVersion]])
889 {
890 OOLog(kOOOXZDebugLog, @"%@", @"Dependency stack: found download for next item");
891 foundDownload = YES;
892 index = [_oxzList indexOfObject:availableDownload];
893 break;
894 }
895 }
896 }
897
898 if (foundDownload)
899 {
900 if ([self installableState:[_oxzList objectAtIndex:index]] == OXZ_UNINSTALLABLE_ALREADY)
901 {
902 OOLog(kOOOXZDebugLog,@"Dependency stack: %@ is downloaded but not yet loadable, removing from list.",[requirement oo_stringForKey:kOOManifestRelationIdentifier]);
903 // then this has already been downloaded, but
904 // can't be configured yet presumably because
905 // another dependency is still to be loaded
906 [_dependencyStack removeObject:requirement];
907 if ([_dependencyStack count] > 0)
908 {
909 // try again
910 undownloadedRequirement = NO;
911 }
912 else
913 {
914 // this case should probably never happen
915 // is handled below just in case
916 foundDownload = NO;
917 }
918 }
919 }
920 }
921 while (!undownloadedRequirement);
922
923 if (foundDownload)
924 {
925 // must clear filters entirely at this point
926 [self setFilteredList:_oxzList];
927 // then download that item
928 _downloadStatus = OXZ_DOWNLOAD_NONE;
929 if (_downloadAllDependencies)
930 {
931 OOLog(kOOOXZDebugLog,@"Dependency stack: installing %lu from list",index);
932 if (![self installOXZ:index]) {
933 // if a required dependency is somehow uninstallable
934 // e.g. required+maximum version don't match this Oolite
935 [progress appendFormat:DESC(@"oolite-oxzmanager-progress-required-@-not-found"),[requirement oo_stringForKey:kOOManifestRelationDescription defaultValue:[requirement oo_stringForKey:kOOManifestRelationIdentifier]]];
936 [self setProgressStatus:progress];
937 OOLog(kOOOXZErrorLog,@"OXZ dependency %@ could not be found for automatic download.",needsIdentifier);
938 _downloadStatus = OXZ_DOWNLOAD_ERROR;
939 OOLog(kOOOXZErrorLog, @"%@", @"Downloaded OXZ could not be installed.");
940 _interfaceState = OXZ_STATE_TASKDONE;
941 [self gui];
942 return NO;
943 }
944 }
945 else
946 {
947 _interfaceState = OXZ_STATE_DEPENDENCIES;
948 _item = index;
949 }
950 [self setProgressStatus:progress];
951 [self gui];
952 return YES;
953 }
954 // this is probably always the case, see above
955 else if ([_dependencyStack count] > 0)
956 {
957 [progress appendFormat:DESC(@"oolite-oxzmanager-progress-required-@-not-found"),[requirement oo_stringForKey:kOOManifestRelationDescription defaultValue:[requirement oo_stringForKey:kOOManifestRelationIdentifier]]];
958 [self setProgressStatus:progress];
959 OOLog(kOOOXZErrorLog,@"OXZ dependency %@ could not be found for automatic download.",needsIdentifier);
960 _downloadStatus = OXZ_DOWNLOAD_ERROR;
961 OOLog(kOOOXZErrorLog, @"%@", @"Downloaded OXZ could not be installed.");
962 _interfaceState = OXZ_STATE_TASKDONE;
963 [self gui];
964 return NO;
965 }
966 }
967
968 [self setProgressStatus:@""];
969 _interfaceState = OXZ_STATE_TASKDONE;
970 [_dependencyStack removeAllObjects]; // just in case
971 _downloadAllDependencies = NO;
972 [self gui];
973 return YES;
974}
static NSString *const kOOManifestRelationIdentifier
static NSString *const kOOManifestIdentifier
@ OXZ_STATE_DEPENDENCIES
NSDictionary * OODictionaryFromFile(NSString *path)
void resetManifestKnowledgeForOXZManager()
const char * filename
Definition ioapi.h:133

◆ removeOptions

- (NSArray *) removeOptions

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

1933{
1934 NSArray *remList = _filteredList;
1935 if ([remList count] == 0)
1936 {
1937 return nil;
1938 }
1939 NSUInteger start = _offset;
1940 if (start >= [remList count])
1941 {
1942 start = 0;
1943 _offset = 0;
1944 }
1945 NSUInteger end = start + OXZ_GUI_NUM_LISTROWS;
1946 if (end > [remList count])
1947 {
1948 end = [remList count];
1949 }
1950 return [remList subarrayWithRange:NSMakeRange(start,end-start)];
1951}

◆ removeOXZ:

- (BOOL) removeOXZ: (NSUInteger) item

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

1904 :(NSUInteger)item
1905{
1906 NSArray *remList = _filteredList;
1907 if ([remList count] <= item)
1908 {
1909 OOLog(kOOOXZDebugLog, @"Unable to remove item %lu as only %lu in list", (unsigned long)item, (unsigned long)[remList count]);
1910 return NO;
1911 }
1912 NSString *filename = [[remList objectAtIndex:item] oo_stringForKey:kOOManifestFilePath];
1913 if (filename == nil)
1914 {
1915 OOLog(kOOOXZDebugLog, @"Unable to remove item %lu as filename not found", (unsigned long)item);
1916 return NO;
1917 }
1918
1919 if (![[NSFileManager defaultManager] oo_removeItemAtPath:filename])
1920 {
1921 OOLog(kOOOXZErrorLog, @"Unable to remove file %@", filename);
1922 return NO;
1923 }
1924 _changesMade = YES;
1925 DESTROY(_managedList); // will need updating
1926 _interfaceState = OXZ_STATE_REMOVING;
1927 [self gui];
1928 return YES;
1929}
@ OXZ_STATE_REMOVING

◆ setCurrentDownload:withLabel:

- (void) setCurrentDownload: (NSURLConnection *) download
withLabel: (NSString *) label 

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

562 :(NSURLConnection *)download withLabel:(NSString *)label
563{
564 if (_currentDownload != nil)
565 {
566 [_currentDownload cancel]; // releases via delegate
567 }
568 _currentDownload = [download retain];
569 DESTROY(_currentDownloadName);
570 _currentDownloadName = [label copy];
571}

◆ setFilteredList:

- (void) setFilteredList: (NSArray *) list

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

356 :(NSArray *)list
357{
358 DESTROY(_filteredList);
359 _filteredList = [list copy]; // copy retains
360}

◆ setOXZList:

- (void) setOXZList: (NSArray *) list

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

344 :(NSArray *)list
345{
346 DESTROY(_oxzList);
347 if (list != nil)
348 {
349 _oxzList = [[list sortedArrayUsingFunction:oxzSort context:NULL] retain];
350 // needed for update to available versions
351 DESTROY(_managedList);
352 }
353}

◆ setProgressStatus:

- (void) setProgressStatus: (NSString *) newStatus

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

574 :(NSString *)new
575{
576 DESTROY(_progressStatus);
577 _progressStatus = [new copy];
578}

◆ updateAllOXZ

- (BOOL) updateAllOXZ

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

1681{
1682 [_dependencyStack removeAllObjects];
1683 _downloadAllDependencies = YES;
1684 [self setFilteredList:_oxzList];
1685 NSDictionary *manifest = nil;
1686
1687 foreach (manifest,_oxzList)
1688 {
1689 if ([self installableState:manifest] == OXZ_INSTALLABLE_UPDATE)
1690 {
1691 OOLog(kOOOXZDebugLog, @"Queuing in for update: %@", manifest);
1692 [_dependencyStack addObject:manifest];
1693 }
1694 }
1695 NSDictionary *first = [_dependencyStack anyObject];
1696 NSString* identifier = [first oo_stringForKey:kOOManifestRelationIdentifier];
1697 NSUInteger item = NSUIntegerMax;
1698 NSDictionary *availableDownload = nil;
1699 foreach (availableDownload, _oxzList)
1700 {
1701 if ([[availableDownload oo_stringForKey:kOOManifestIdentifier] isEqualToString:identifier])
1702 {
1703 item = [_oxzList indexOfObject:availableDownload];
1704 break;
1705 }
1706 }
1707 return [self installOXZ:item];
1708}

◆ validateFilter:

- (BOOL) validateFilter: (NSString *) input

Extends class OOOXZManager.

Definition at line 2358 of file OOOXZManager.m.

541 :(NSString *)input
542{
543 NSString *filter = [input lowercaseString];
544 if (([filter length] == 0) // empty is valid
545 || ([filter isEqualToString:kOOOXZFilterAll])
546 || ([filter isEqualToString:kOOOXZFilterUpdates])
547 || ([filter isEqualToString:kOOOXZFilterInstallable])
548 || ([filter hasPrefix:kOOOXZFilterKeyword] && [filter length] > [kOOOXZFilterKeyword length])
549 || ([filter hasPrefix:kOOOXZFilterAuthor] && [filter length] > [kOOOXZFilterAuthor length])
550 || ([filter hasPrefix:kOOOXZFilterDays] && [[filter substringFromIndex:[kOOOXZFilterDays length]] intValue] > 0)
551 || ([filter hasPrefix:kOOOXZFilterTag] && [filter length] > [kOOOXZFilterTag length])
552 || ([filter hasPrefix:kOOOXZFilterCategory] && [filter length] > [kOOOXZFilterCategory length])
553 )
554 {
555 return YES;
556 }
557
558 return NO;
559}
static NSString *const kOOOXZFilterAll

The documentation for this category was generated from the following file: