Oolite
Loading...
Searching...
No Matches
ResourceManager Class Reference

#include <ResourceManager.h>

Inheritance diagram for ResourceManager:
Collaboration diagram for ResourceManager:

Class Methods

(void) + reset
(void) + resetManifestKnowledgeForOXZManager
(NSArray *) + rootPaths
(NSArray *) + userRootPaths
(NSString *) + builtInPath
(NSArray *) + pathsWithAddOns
(NSArray *) + paths
(NSArray *) + maskUserNameInPathArray:
(NSString *) + maskUserName:inPath:
(NSString *) + useAddOns
(NSArray *) + OXPsWithMessagesFound
(void) + setUseAddOns:
(void) + addExternalPath:
(NSEnumerator *) + pathEnumerator
(NSEnumerator *) + reversePathEnumerator
(NSDictionary *) + manifestForIdentifier:
(BOOL) + checkVersionCompatibility:forOXP:
(BOOL) + manifestHasConflicts:logErrors:
(BOOL) + manifestHasMissingDependencies:logErrors:
(BOOL) + manifest:HasUnmetDependency:logErrors:
(BOOL) + matchVersions:withVersion:
(void) + handleEquipmentListMerging:forLookupIndex:
(void) + handleEquipmentOverrides:
(void) + handleStarNebulaListMerging:
(NSString *) + errors
(NSString *) + pathForFileNamed:inFolder:
(NSString *) + pathForFileNamed:inFolder:cache:
(BOOL) + corePlist:excludedAt:
(NSDictionary *) + dictionaryFromFilesNamed:inFolder:andMerge:
(NSDictionary *) + dictionaryFromFilesNamed:inFolder:mergeMode:cache:
(NSArray *) + arrayFromFilesNamed:inFolder:andMerge:
(NSArray *) + arrayFromFilesNamed:inFolder:andMerge:cache:
(NSDictionary *) + whitelistDictionary
(NSDictionary *) + shaderBindingTypesDictionary
(NSDictionary *) + logControlDictionary
(NSDictionary *) + roleCategoriesDictionary
(OOSystemDescriptionManager *) + systemDescriptionManager
(OOSound *) + ooSoundNamed:inFolder:
(OOMusic *) + ooMusicNamed:inFolder:
(NSString *) + stringFromFilesNamed:inFolder:
(NSString *) + stringFromFilesNamed:inFolder:cache:
(NSDictionary *) + loadScripts
(BOOL) + writeDiagnosticData:toFileNamed:
(BOOL) + writeDiagnosticString:toFileNamed:
(BOOL) + writeDiagnosticPList:toFileNamed:
(NSString *) + diagnosticFileLocation
(NSDictionary *) + materialDefaults
(void) + clearCaches
(void) + preloadFileLists [implementation]
(void) + preloadFileListFromOXZ:forFolders: [implementation]
(void) + preloadFileListFromFolder:forFolders: [implementation]
(void) + preloadFilePathFor:inFolder:atPath: [implementation]
(void) + checkOXPMessagesInPath: [implementation]
(void) + checkPotentialPath:searchPaths: [implementation]
(BOOL) + validateManifest:forOXP: [implementation]
(BOOL) + areRequirementsFulfilled:forOXP:andFile: [implementation]
(void) + filterSearchPathsForConflicts: [implementation]
(BOOL) + filterSearchPathsForRequirements: [implementation]
(void) + filterSearchPathsToExcludeScenarioOnlyPaths: [implementation]
(void) + filterSearchPathsByScenario: [implementation]
(BOOL) + manifestAllowedByScenario: [implementation]
(BOOL) + manifestAllowedByScenario:withIdentifier: [implementation]
(BOOL) + manifestAllowedByScenario:withTag: [implementation]
(void) + addErrorWithKey:param1:param2: [implementation]
(BOOL) + checkCacheUpToDateForPaths: [implementation]
(static NSString *) + LogClassKeyRoot [implementation]
(void) + mergeRoleCategories:intoDictionary: [implementation]
(id) + retrieveFileNamed:inFolder:cache:key:class:usePathCache: [implementation]
(BOOL) + directoryExists:create: [implementation]
(void) + logPaths [implementation]

Detailed Description

Definition at line 53 of file ResourceManager.h.

Method Documentation

◆ addErrorWithKey:param1:param2:

+ (void) addErrorWithKey: (NSString*) descriptionKey
param1: (id) param1
param2: (id) param2 
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 985 of file ResourceManager.m.

985 :(NSString*)descriptionKey param1:(id)param1 param2:(id)param2
986{
987 if (descriptionKey != nil) {
988 if (sErrors == nil)
989 sErrors = [[NSMutableArray alloc] init];
990 [sErrors addObject:[NSArray arrayWithObjects:descriptionKey, param1 ?: (id) @"", param2 ?: (id) @"", nil]];
991 }
992}
return nil
static NSMutableArray * sErrors

References nil, and sErrors.

Referenced by checkPotentialPath:searchPaths:, manifest:HasUnmetDependency:logErrors:, manifestHasConflicts:logErrors:, and validateManifest:forOXP:.

Here is the caller graph for this function:

◆ addExternalPath:

+ (void) addExternalPath: (NSString*) fileName

Definition at line 494 of file ResourceManager.m.

494 :(NSString*)path
495{
496 if (sSearchPaths == nil)
497 sSearchPaths = [[NSMutableArray alloc] init];
498 if (![sSearchPaths containsObject:path]) {
499 [sSearchPaths addObject:path];
500
501 if (sExternalPaths == nil)
502 sExternalPaths = [[NSMutableArray alloc] init];
503 [sExternalPaths addObject:path];
504 }
505}
static NSMutableArray * sSearchPaths
static NSMutableArray * sExternalPaths

References nil, sExternalPaths, and sSearchPaths.

Referenced by GameController::applicationDidFinishLaunching:.

Here is the caller graph for this function:

◆ areRequirementsFulfilled:forOXP:andFile:

+ (BOOL) areRequirementsFulfilled: (NSDictionary*) requirements
forOXP: (NSString*) path
andFile: (NSString*) file 
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 659 of file ResourceManager.m.

659 :(NSDictionary*)requirements forOXP:(NSString*)path andFile:(NSString*)file
660{
661 BOOL OK = YES;
662 NSString* requiredVersion = nil;
663 NSString* maxVersion = nil;
664 unsigned conditionsHandled = 0;
665 static NSArray* ooVersionComponents = nil;
666 NSArray* oxpVersionComponents = nil;
667
668 if (requirements == nil)
669 return YES;
670
671 if (ooVersionComponents == nil) {
672 ooVersionComponents = ComponentsFromVersionString([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]);
673 [ooVersionComponents retain];
674 }
675
676 // Check "version" (minimum version)
677 if (OK) {
678 // Not oo_stringForKey:, because we need to be able to complain about non-strings.
679 requiredVersion = [requirements objectForKey:@"version"];
680 if (requiredVersion != nil) {
681 ++conditionsHandled;
682 if ([requiredVersion isKindOfClass:[NSString class]]) {
683 oxpVersionComponents = ComponentsFromVersionString(requiredVersion);
684 if (NSOrderedAscending == CompareVersions(ooVersionComponents, oxpVersionComponents))
685 OK = NO;
686 } else {
687 OOLog(@"requirements.wrongType", @"Expected %@ entry \"%@\" to be string, but got %@ in OXP %@.", file, @"version", [requirements class], [path lastPathComponent]);
688 OK = NO;
689 }
690 }
691 }
692
693 // Check "max_version" (minimum max_version)
694 if (OK) {
695 // Not oo_stringForKey:, because we need to be able to complain about non-strings.
696 maxVersion = [requirements objectForKey:@"max_version"];
697 if (maxVersion != nil) {
698 ++conditionsHandled;
699 if ([maxVersion isKindOfClass:[NSString class]]) {
700 oxpVersionComponents = ComponentsFromVersionString(maxVersion);
701 if (NSOrderedDescending == CompareVersions(ooVersionComponents, oxpVersionComponents))
702 OK = NO;
703 } else {
704 OOLog(@"requirements.wrongType", @"Expected %@ entry \"%@\" to be string, but got %@ in OXP %@.", file, @"max_version", [requirements class], [path lastPathComponent]);
705 OK = NO;
706 }
707 }
708 }
709
710 if (OK && conditionsHandled < [requirements count]) {
711 // There are unknown requirement keys - don't support. NOTE: this check was not made pre 1.69!
712 OOLog(@"requirements.unknown", @"requires.plist for OXP %@ contains unknown keys, rejecting.", [path lastPathComponent]);
713 OK = NO;
714 }
715
716 return OK;
717}
#define OOLog(class, format,...)
Definition OOLogging.h:84
unsigned count
NSArray * ComponentsFromVersionString(NSString *string)
NSComparisonResult CompareVersions(NSArray *version1, NSArray *version2)

References CompareVersions(), ComponentsFromVersionString(), count, nil, and OOLog.

Referenced by checkPotentialPath:searchPaths:, and checkVersionCompatibility:forOXP:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ arrayFromFilesNamed:inFolder:andMerge:

+ (NSArray *) arrayFromFilesNamed: (NSString*) fileName
inFolder: (NSString*) folderName
andMerge: (BOOL) mergeFiles 

Definition at line 1191 of file ResourceManager.m.

1191 :(NSString*)fileName inFolder:(NSString*)folderName andMerge:(BOOL)mergeFiles
1192{
1193 return [self arrayFromFilesNamed:fileName inFolder:folderName andMerge:mergeFiles cache:YES];
1194}

References arrayFromFilesNamed:inFolder:andMerge:cache:.

Referenced by OOProbabilisticTextureManager::initWithPListName:options:anisotropy:lodBias:seed:, Universe(OOPrivate)::loadScenarios, roleCategoriesDictionary, and Universe::setUpSettings.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ arrayFromFilesNamed:inFolder:andMerge:cache:

+ (NSArray *) arrayFromFilesNamed: (NSString*) fileName
inFolder: (NSString*) folderName
andMerge: (BOOL) mergeFiles
cache: (BOOL) useCache 

Definition at line 1196 of file ResourceManager.m.

1196 :(NSString*)fileName inFolder:(NSString*)folderName andMerge:(BOOL)mergeFiles cache:(BOOL)useCache
1197{
1198 id result = nil;
1199 NSMutableArray* results = nil;
1200 NSString* cacheKey = nil;
1201 OOCacheManager* cache = [OOCacheManager sharedCache];
1202 NSEnumerator* enumerator = nil;
1203 NSString* path = nil;
1204 NSString* arrayPath = nil;
1205 NSMutableArray* array = nil;
1206 NSArray* arrayNonEditable = nil;
1207
1208 if (fileName == nil)
1209 return nil;
1210
1211 if (useCache) {
1212 cacheKey = [NSString stringWithFormat:@"%@%@ merge:%@", (folderName != nil) ? [folderName stringByAppendingString:@"/"] : (NSString*)@"", fileName, mergeFiles ? @"yes" : @"no"];
1213 result = [cache objectForKey:cacheKey inCache:@"arrays"];
1214 if (result != nil)
1215 return result;
1216 }
1217
1218 if (!mergeFiles) {
1219 // Find "last" matching array
1220 for (enumerator = [ResourceManager reversePathEnumerator]; (path = [enumerator nextObject]);) {
1221 if (folderName != nil) {
1222 arrayPath = [[path stringByAppendingPathComponent:folderName] stringByAppendingPathComponent:fileName];
1223 arrayNonEditable = OOArrayFromFile(arrayPath);
1224 if (arrayNonEditable != nil)
1225 break;
1226 }
1227 arrayPath = [path stringByAppendingPathComponent:fileName];
1228 arrayNonEditable = OOArrayFromFile(arrayPath);
1229 if (arrayNonEditable != nil)
1230 break;
1231 }
1232 result = arrayNonEditable;
1233 } else {
1234 // Find all matching arrays
1235 results = [NSMutableArray array];
1236 for (enumerator = [ResourceManager pathEnumerator]; (path = [enumerator nextObject]);) {
1237 if ([ResourceManager corePlist:fileName excludedAt:path]) {
1238 continue;
1239 }
1240
1241 arrayPath = [path stringByAppendingPathComponent:fileName];
1242 array = [[OOArrayFromFile(arrayPath) mutableCopy] autorelease];
1243 if (array != nil)
1244 [results addObject:array];
1245
1246 // Special handling for arrays merging. Currently, only equipment.plist, nebulatextures.plist and
1247 // startextures.plist gets their objects merged.
1248 // A lookup index is required. For the equipment.plist items, this is the index corresponding to the
1249 // EQ_* string, which describes the role of an equipment item and is unique.
1250 // For nebula and star textures, this is the texture filename, although it can be overridden with a
1251 // "key" property
1252 if ([array count] != 0 && ([[fileName lowercaseString] isEqualToString:@"nebulatextures.plist"] || [[fileName lowercaseString] isEqualToString:@"startextures.plist"]))
1253 [self handleStarNebulaListMerging:results];
1254
1255 if ([array count] != 0 && [[array objectAtIndex:0] isKindOfClass:[NSArray class]]) {
1256 if ([[fileName lowercaseString] isEqualToString:@"equipment.plist"])
1257 [self handleEquipmentListMerging:results forLookupIndex:3]; // Index 3 is the role string (EQ_*).
1258 }
1259 if (folderName != nil) {
1260 arrayPath = [[path stringByAppendingPathComponent:folderName] stringByAppendingPathComponent:fileName];
1261 array = [[OOArrayFromFile(arrayPath) mutableCopy] autorelease];
1262 if (array != nil)
1263 [results addObject:array];
1264
1265 if ([array count] != 0 && ([[fileName lowercaseString] isEqualToString:@"nebulatextures.plist"] || [[fileName lowercaseString] isEqualToString:@"startextures.plist"]))
1266 [self handleStarNebulaListMerging:results];
1267
1268 if ([array count] != 0 && [[array objectAtIndex:0] isKindOfClass:[NSArray class]]) {
1269 if ([[fileName lowercaseString] isEqualToString:@"equipment.plist"])
1270 [self handleEquipmentListMerging:results forLookupIndex:3]; // Index 3 is the role string (EQ_*).
1271 }
1272 }
1273 }
1274
1275 if ([results count] == 0)
1276 return nil;
1277
1278 // Merge result
1279 result = [NSMutableArray array];
1280
1281 for (enumerator = [results objectEnumerator]; (array = [enumerator nextObject]);) {
1282 [result addObjectsFromArray:array];
1283 }
1284 // if we're doing equipment.plist, do equipment overrides now, while the array is still mutable
1285 if ([[fileName lowercaseString] isEqualToString:@"equipment.plist"]) {
1286 [self handleEquipmentOverrides:result];
1287 }
1288 result = [[result copy] autorelease]; // Make immutable
1289 }
1290
1291 if (useCache && result != nil)
1292 [cache setObject:result forKey:cacheKey inCache:@"arrays"];
1293
1294 return [NSArray arrayWithArray:result];
1295}
NSArray * OOArrayFromFile(NSString *path)
id objectForKey:inCache:(NSString *inKey,[inCache] NSString *inCacheKey)
OOCacheManager * sharedCache()
NSEnumerator * reversePathEnumerator()
NSEnumerator * pathEnumerator()

References count, handleEquipmentListMerging:forLookupIndex:, handleEquipmentOverrides:, handleStarNebulaListMerging:, nil, OOCacheManager::objectForKey:inCache:, OOArrayFromFile(), pathEnumerator, reversePathEnumerator, OOCacheManager::setObject:forKey:inCache:, and OOCacheManager::sharedCache.

Referenced by arrayFromFilesNamed:inFolder:andMerge:, OOShipRegistry(OODataLoader)::loadDemoShipConditions, and OOShipRegistry(OODataLoader)::loadDemoShips.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ builtInPath

+ (NSString *) builtInPath

Definition at line 192 of file ResourceManager.m.

193{
194 NSFileManager* fileManager = [NSFileManager defaultManager];
195
196#if OOLITE_MAC_COCOA_UI
197 return [[NSBundle mainBundle] resourcePath]; // Use resourcePath directly
198#else
199 NSString* startingDir = [fileManager currentDirectoryPath]; // Start from cwd
200#endif
201 // Look for a "Resources" folder (Windows & Linux)
202 NSString* primaryResourcesPath = [startingDir stringByAppendingPathComponent:@"Resources"];
203 BOOL isDir = NO;
204 if ([fileManager fileExistsAtPath:primaryResourcesPath isDirectory:&isDir] && isDir) {
205 return primaryResourcesPath;
206 }
207 // Fallback: Look in startingDir/../share/oolite/Resources
208 NSString* fallbackPath = [[startingDir stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"share/oolite/Resources"];
209 return [fallbackPath stringByStandardizingPath];
210}

References builtInPath.

Referenced by builtInPath, corePlist:excludedAt:, Universe::descriptions, MyOpenGLView::initSplashScreen, OOOXPVerifier(OOPrivate)::initWithPath:, LoadExplicitSettings(), logControlDictionary, pathsWithAddOns, rootPaths, shaderBindingTypesDictionary, and whitelistDictionary.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkCacheUpToDateForPaths:

+ (BOOL) checkCacheUpToDateForPaths: (NSArray*) searchPaths
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 994 of file ResourceManager.m.

994 :(NSArray*)searchPaths
995{
996 /* Check if caches are up to date.
997 The strategy is to use a two-entry cache. One entry is an array
998 containing the search paths, the other an array of modification dates
999 (in the same order). If either fails to match the correct settings,
1000 we delete both.
1001 */
1002 OOCacheManager* cacheMgr = [OOCacheManager sharedCache];
1003 NSFileManager* fmgr = [NSFileManager defaultManager];
1004 BOOL upToDate = YES;
1005 id oldPaths = nil;
1006 NSMutableArray* modDates = nil;
1007 NSString* path = nil;
1008 id modDate = nil;
1009
1010 if (EXPECT_NOT([[NSUserDefaults standardUserDefaults] boolForKey:@"always-flush-cache"])) {
1011 OOLog(kOOLogCacheExplicitFlush, @"%@", @"Cache explicitly flushed with always-flush-cache preference. Rebuilding from scratch.");
1012 upToDate = NO;
1013 } else if ([MyOpenGLView pollShiftKey]) {
1014 OOLog(kOOLogCacheExplicitFlush, @"%@", @"Cache explicitly flushed with shift key. Rebuilding from scratch.");
1015 upToDate = NO;
1016 }
1017
1018 oldPaths = [cacheMgr objectForKey:kOOCacheKeySearchPaths inCache:kOOCacheSearchPathModDates];
1019 if (upToDate && ![oldPaths isEqual:searchPaths]) {
1020 // OXPs added/removed
1021 if (oldPaths != nil)
1022 OOLog(kOOLogCacheStalePaths, @"%@", @"Cache is stale (search paths have changed). Rebuilding from scratch.");
1023 upToDate = NO;
1024 }
1025
1026 // Build modification date list. (We need this regardless of whether the search paths matched.)
1027
1028 modDates = [NSMutableArray arrayWithCapacity:[searchPaths count]];
1029 foreach (path, searchPaths) {
1030 modDate = [[fmgr oo_fileAttributesAtPath:path traverseLink:YES] objectForKey:NSFileModificationDate];
1031 if (modDate != nil) {
1032 // Converts to double because I'm not sure the cache can deal with dates under GNUstep.
1033 modDate = [NSNumber numberWithDouble:[modDate timeIntervalSince1970]];
1034 [modDates addObject:modDate];
1035 }
1036 }
1037
1038 if (upToDate && ![[cacheMgr objectForKey:kOOCacheKeyModificationDates inCache:kOOCacheSearchPathModDates] isEqual:modDates]) {
1039 OOLog(kOOLogCacheStaleDates, @"%@", @"Cache is stale (modification dates have changed). Rebuilding from scratch.");
1040 upToDate = NO;
1041 }
1042
1043 if (!upToDate) {
1044 [cacheMgr clearAllCaches];
1045 [cacheMgr setObject:searchPaths forKey:kOOCacheKeySearchPaths inCache:kOOCacheSearchPathModDates];
1046 [cacheMgr setObject:modDates forKey:kOOCacheKeyModificationDates inCache:kOOCacheSearchPathModDates];
1047 } else
1048 OOLog(kOOLogCacheUpToDate, @"%@", @"Data cache is up to date.");
1049
1050 return upToDate;
1051}
#define EXPECT_NOT(x)
static NSString *const kOOLogCacheUpToDate
static NSString *const kOOLogCacheStalePaths
static NSString *const kOOCacheSearchPathModDates
static NSString *const kOOLogCacheStaleDates
static NSString *const kOOLogCacheExplicitFlush
static NSString *const kOOCacheKeyModificationDates
void setObject:forKey:inCache:(id inElement,[forKey] NSString *inKey,[inCache] NSString *inCacheKey)

References OOCacheManager::clearAllCaches, EXPECT_NOT, kOOCacheKeyModificationDates, kOOCacheSearchPathModDates, kOOLogCacheExplicitFlush, kOOLogCacheStaleDates, kOOLogCacheStalePaths, kOOLogCacheUpToDate, nil, OOCacheManager::objectForKey:inCache:, OOLog, OOCacheManager::setObject:forKey:inCache:, and OOCacheManager::sharedCache.

Referenced by pathsWithAddOns, and setUseAddOns:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkOXPMessagesInPath:

+ (void) checkOXPMessagesInPath: (NSString*) path
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 527 of file ResourceManager.m.

527 :(NSString*)path
528{
529 NSArray* OXPMessageArray = OOArrayFromFile([path stringByAppendingPathComponent:@"OXPMessages.plist"]);
530
531 if ([OXPMessageArray count] > 0) {
532 unsigned i;
533 for (i = 0; i < [OXPMessageArray count]; i++) {
534 NSString* oxpMessage = [OXPMessageArray oo_stringAtIndex:i];
535 if (oxpMessage) {
536 OOLog(@"oxp.message", @"%@: %@", path, oxpMessage);
537 }
538 }
540 sOXPsWithMessagesFound = [[NSMutableArray alloc] init];
541 [sOXPsWithMessagesFound addObject:[path lastPathComponent]];
542 }
543}
static NSMutableArray * sOXPsWithMessagesFound

References count, nil, OOArrayFromFile(), OOLog, and sOXPsWithMessagesFound.

Referenced by pathsWithAddOns.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkPotentialPath:searchPaths:

+ (void) checkPotentialPath: (NSString*) path
searchPaths: (NSMutableArray*) searchPaths 
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 546 of file ResourceManager.m.

546 :(NSString*)path searchPaths:(NSMutableArray*)searchPaths
547{
548 NSDictionary* requirements = nil;
549 NSDictionary* manifest = nil;
550 BOOL requirementsMet = YES;
551
552 if (![[[path pathExtension] lowercaseString] isEqualToString:@"oxz"]) {
553 // OXZ format ignores requires.plist
554 requirements = OODictionaryFromFile([path stringByAppendingPathComponent:@"requires.plist"]);
555 requirementsMet = [self areRequirementsFulfilled:requirements forOXP:path andFile:@"requires.plist"];
556 }
557 if (!requirementsMet) {
558 NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
559 OOLog(@"oxp.versionMismatch", @"OXP %@ is incompatible with version %@ of Oolite.", path, version);
560 [self addErrorWithKey:@"oxp-is-incompatible" param1:[path lastPathComponent] param2:version];
561 return;
562 }
563
564 manifest = OODictionaryFromFile([path stringByAppendingPathComponent:@"manifest.plist"]);
565 if (manifest == nil) {
566 if ([[[path pathExtension] lowercaseString] isEqualToString:@"oxz"]) {
567 OOLog(@"oxp.noManifest", @"OXZ %@ has no manifest.plist", path);
568 [self addErrorWithKey:@"oxz-lacks-manifest" param1:[path lastPathComponent] param2:nil];
569 return;
570 } else {
571 if ([[[path pathExtension] lowercaseString] isEqualToString:@"oxp"]) {
572 OOStandardsError([NSString stringWithFormat:@"OXP %@ has no manifest.plist", path]);
573 if (OOEnforceStandards()) {
574 [self addErrorWithKey:@"oxp-lacks-manifest" param1:[path lastPathComponent] param2:nil];
575 return;
576 }
577 }
578 // make up a basic manifest in relaxed mode or for base folders
579 manifest = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"__oolite.tmp.%@", path], kOOManifestIdentifier, @"1", kOOManifestVersion, @"OXP without manifest", kOOManifestTitle, @"1", kOOManifestRequiredOoliteVersion, nil];
580 }
581 }
582
583 requirementsMet = [self validateManifest:manifest forOXP:path];
584
585 if (requirementsMet) {
586 [searchPaths addObject:path];
587 }
588}
BOOL OOEnforceStandards(void)
void OOStandardsError(NSString *message)
NSDictionary * OODictionaryFromFile(NSString *path)

References addErrorWithKey:param1:param2:, areRequirementsFulfilled:forOXP:andFile:, nil, OODictionaryFromFile(), OOEnforceStandards(), OOLog, OOStandardsError(), and validateManifest:forOXP:.

Referenced by pathsWithAddOns.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkVersionCompatibility:forOXP:

+ (BOOL) checkVersionCompatibility: (NSDictionary*) manifest
forOXP: (NSString*) title 

Definition at line 647 of file ResourceManager.m.

647 :(NSDictionary*)manifest forOXP:(NSString*)title
648{
649 NSString* required = [manifest oo_stringForKey:kOOManifestRequiredOoliteVersion defaultValue:nil];
650 NSString* maxRequired = [manifest oo_stringForKey:kOOManifestMaximumOoliteVersion defaultValue:nil];
651 // ignore empty max version string rather than treating as "version 0"
652 if (maxRequired == nil || [maxRequired length] == 0) {
653 return [self areRequirementsFulfilled:[NSDictionary dictionaryWithObjectsAndKeys:required, @"version", nil] forOXP:title andFile:@"manifest.plist"];
654 } else {
655 return [self areRequirementsFulfilled:[NSDictionary dictionaryWithObjectsAndKeys:required, @"version", maxRequired, @"max_version", nil] forOXP:title andFile:@"manifest.plist"];
656 }
657}

References areRequirementsFulfilled:forOXP:andFile:, and nil.

Referenced by validateManifest:forOXP:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearCaches

+ (void) clearCaches

Definition at line 1988 of file ResourceManager.m.

1989{
1990 [sSoundCache release];
1991 sSoundCache = nil;
1992 [sStringCache release];
1993 sStringCache = nil;
1994}
static NSMutableDictionary * sSoundCache
static NSMutableDictionary * sStringCache

References clearCaches, nil, sSoundCache, and sStringCache.

Referenced by clearCaches, OOOXZManager::gui, and setUseAddOns:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ corePlist:excludedAt:

+ (BOOL) corePlist: (NSString*) fileName
excludedAt: (NSString*) path 

Definition at line 1061 of file ResourceManager.m.

1061 :(NSString*)fileName excludedAt:(NSString*)path
1062{
1063 if (![path isEqualToString:[self builtInPath]]) {
1064 // non-core paths always okay
1065 return NO;
1066 }
1067 NSString* uaoBit = nil;
1068 foreach (uaoBit, sUseAddOnsParts) {
1069 if ([uaoBit hasPrefix:SCENARIO_OXP_DEFINITION_NOPLIST]) {
1070 NSString* plist = [uaoBit substringFromIndex:[SCENARIO_OXP_DEFINITION_NOPLIST length]];
1071 if ([plist isEqualToString:fileName]) {
1072 // this core plist file should not be loaded at all
1073 return YES;
1074 }
1075 }
1076 }
1077 // then not excluded
1078 return NO;
1079}
#define SCENARIO_OXP_DEFINITION_NOPLIST
static NSArray * sUseAddOnsParts
NSString * builtInPath()

References builtInPath, nil, SCENARIO_OXP_DEFINITION_NOPLIST, and sUseAddOnsParts.

Here is the call graph for this function:

◆ diagnosticFileLocation

+ (NSString *) diagnosticFileLocation

Definition at line 1969 of file ResourceManager.m.

1970{
1972}
NSString * OOLogHandlerGetLogBasePath(void)

References diagnosticFileLocation, and OOLogHandlerGetLogBasePath().

Referenced by diagnosticFileLocation, and writeDiagnosticData:toFileNamed:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dictionaryFromFilesNamed:inFolder:andMerge:

+ (NSDictionary *) dictionaryFromFilesNamed: (NSString*) fileName
inFolder: (NSString*) folderName
andMerge: (BOOL) mergeFiles 

Definition at line 1081 of file ResourceManager.m.

1081 :(NSString*)fileName
1082 inFolder:(NSString*)folderName
1083 andMerge:(BOOL)mergeFiles
1084{
1085 return [ResourceManager dictionaryFromFilesNamed:fileName inFolder:folderName mergeMode:mergeFiles ? MERGE_BASIC : MERGE_NONE cache:YES];
1086}

Referenced by CompileSystemDescriptions(), HeadUpDisplay(Private)::crosshairDefinitionForWeaponType:, ExportSystemDescriptions(), GlobalAutoAIForRole(), GlobalAutoAIForRole(), GuiDisplayGen::init, HeadUpDisplay::InitTextEngine(void), Universe::initWithGameView:, Universe(OOPrivate)::loadDescriptions, OOOpenGLExtensionManager(OOPrivate)::lookUpPerGPUSettingsWithVersionString:extensionsString:, materialDefaults, Universe::reinitAndShowDemo:, ReportJSError(), OOCheckShipDataPListVerifierStage::run, HeadUpDisplay::setCrosshairDefinition:, ShipEntity(Private)::setUpOneEscort:inGroup:withRole:atPosition:andCount:, Universe::setUpSettings, and PlayerEntity::switchHudTo:.

Here is the caller graph for this function:

◆ dictionaryFromFilesNamed:inFolder:mergeMode:cache:

+ (NSDictionary *) dictionaryFromFilesNamed: (NSString*) fileName
inFolder: (NSString*) folderName
mergeMode: (OOResourceMergeMode) mergeMode
cache: (BOOL) useCache 

Definition at line 1088 of file ResourceManager.m.

1088 :(NSString*)fileName
1089 inFolder:(NSString*)folderName
1090 mergeMode:(OOResourceMergeMode)mergeMode
1091 cache:(BOOL)cache
1092{
1093 id result = nil;
1094 NSMutableArray* results = nil;
1095 NSString* cacheKey = nil;
1096 NSString* mergeType = nil;
1097 OOCacheManager* cacheMgr = [OOCacheManager sharedCache];
1098 NSEnumerator* enumerator = nil;
1099 NSString* path = nil;
1100 NSString* dictPath = nil;
1101 NSDictionary* dict = nil;
1102
1103 if (fileName == nil)
1104 return nil;
1105
1106 switch (mergeMode) {
1107 case MERGE_NONE:
1108 mergeType = @"none";
1109 break;
1110
1111 case MERGE_BASIC:
1112 mergeType = @"basic";
1113 break;
1114
1115 case MERGE_SMART:
1116 mergeType = @"smart";
1117 break;
1118 }
1119 if (mergeType == nil) {
1120 OOLog(kOOLogParameterError, @"Unknown dictionary merge mode %u for %@. (This is an internal programming error, please report it.)", mergeMode, fileName);
1121 return nil;
1122 }
1123
1124 if (cache) {
1125
1126 if (folderName != nil) {
1127 cacheKey = [NSString stringWithFormat:@"%@/%@ merge:%@", folderName, fileName, mergeType];
1128 } else {
1129 cacheKey = [NSString stringWithFormat:@"%@ merge:%@", fileName, mergeType];
1130 }
1131 result = [cacheMgr objectForKey:cacheKey inCache:@"dictionaries"];
1132 if (result != nil)
1133 return result;
1134 }
1135
1136 if (mergeMode == MERGE_NONE) {
1137 // Find "last" matching dictionary
1138 for (enumerator = [ResourceManager reversePathEnumerator]; (path = [enumerator nextObject]);) {
1139 if (folderName != nil) {
1140 dictPath = [[path stringByAppendingPathComponent:folderName] stringByAppendingPathComponent:fileName];
1141 dict = OODictionaryFromFile(dictPath);
1142 if (dict != nil)
1143 break;
1144 }
1145 dictPath = [path stringByAppendingPathComponent:fileName];
1146 dict = OODictionaryFromFile(dictPath);
1147 if (dict != nil)
1148 break;
1149 }
1150 result = dict;
1151 } else {
1152 // Find all matching dictionaries
1153 results = [NSMutableArray array];
1154 for (enumerator = [ResourceManager pathEnumerator]; (path = [enumerator nextObject]);) {
1155 if ([ResourceManager corePlist:fileName excludedAt:path]) {
1156 continue;
1157 }
1158 dictPath = [path stringByAppendingPathComponent:fileName];
1159 dict = OODictionaryFromFile(dictPath);
1160 if (dict != nil)
1161 [results addObject:dict];
1162 if (folderName != nil) {
1163 dictPath = [[path stringByAppendingPathComponent:folderName] stringByAppendingPathComponent:fileName];
1164 dict = OODictionaryFromFile(dictPath);
1165 if (dict != nil)
1166 [results addObject:dict];
1167 }
1168 }
1169
1170 if ([results count] == 0)
1171 return nil;
1172
1173 // Merge result
1174 result = [NSMutableDictionary dictionary];
1175
1176 for (enumerator = [results objectEnumerator]; (dict = [enumerator nextObject]);) {
1177 if (mergeMode == MERGE_SMART)
1178 [result mergeEntriesFromDictionary:dict];
1179 else
1180 [result addEntriesFromDictionary:dict];
1181 }
1182 result = [[result copy] autorelease]; // Make immutable
1183 }
1184
1185 if (cache && result != nil)
1186 [cacheMgr setObject:result forKey:cacheKey inCache:@"dictionaries"];
1187
1188 return result;
1189}
NSString *const kOOLogParameterError
Definition OOLogging.m:596
OOResourceMergeMode
@ MERGE_SMART
@ MERGE_NONE
@ MERGE_BASIC

References count, kOOLogParameterError, MERGE_BASIC, MERGE_NONE, MERGE_SMART, nil, OOCacheManager::objectForKey:inCache:, OODictionaryFromFile(), OOLog, pathEnumerator, reversePathEnumerator, OOCacheManager::setObject:forKey:inCache:, and OOCacheManager::sharedCache.

Referenced by handleEquipmentOverrides:, OOCommodities::init, PlayerEntity(KeyMapper)::initCheckingDictionary, PlayerEntity(Controls)::initKeyConfigSettings, MyOpenGLView(Input)::initKeyMappingData, PlayerEntity(KeyMapperInternal)::keyboardDescription:, PlayerEntity(KeyMapper)::keyboardLayoutList, OOShipRegistry(OODataLoader)::loadAndApplyShipDataOverrides:, OOShipRegistry(OODataLoader)::loadAndMergeShipyard:, OOShipRegistry(OODataLoader)::loadShipData, and Universe::setUpSettings.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ directoryExists:create:

+ (BOOL) directoryExists: (NSString*) inPath
create: (BOOL) inCreate 
implementation

Definition at line 1946 of file ResourceManager.m.

1946 :(NSString*)inPath create:(BOOL)inCreate
1947{
1948 BOOL exists, directory;
1949 NSFileManager* fmgr = [NSFileManager defaultManager];
1950
1951 exists = [fmgr fileExistsAtPath:inPath isDirectory:&directory];
1952
1953 if (exists && !directory) {
1954 OOLog(@"resourceManager.write.buildPath.failed", @"Expected %@ to be a folder, but it is a file.", inPath);
1955 return NO;
1956 }
1957 if (!exists) {
1958 if (!inCreate)
1959 return NO;
1960 if (![fmgr oo_createDirectoryAtPath:inPath attributes:nil]) {
1961 OOLog(@"resourceManager.write.buildPath.failed", @"Could not create folder %@.", inPath);
1962 return NO;
1963 }
1964 }
1965
1966 return YES;
1967}

References nil, and OOLog.

◆ errors

+ (NSString *) errors

Definition at line 123 of file ResourceManager.m.

124{
125 NSArray* error = nil;
126 NSUInteger i, count;
127 NSMutableArray* result = nil;
128 NSString* errStr = nil;
129
130 count = [sErrors count];
131 if (count == 0)
132 return nil;
133
134 // Expand error messages. This is deferred for localizability.
135 result = [NSMutableArray arrayWithCapacity:count];
136 for (i = 0; i != count; ++i) {
137 error = [sErrors objectAtIndex:i];
138 errStr = [UNIVERSE descriptionForKey:[error oo_stringAtIndex:0]];
139 if (errStr != nil) {
140 errStr = [NSString stringWithFormat:errStr, [error objectAtIndex:1], [error objectAtIndex:2]];
141 [result addObject:errStr];
142 }
143 }
144
145 [sErrors release];
146 sErrors = nil;
147
148 return [result componentsJoinedByString:@"\n"];
149}

References count, errors, nil, and sErrors.

Referenced by errors, and PlayerEntity::setGuiToIntroFirstGo:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filterSearchPathsByScenario:

+ (void) filterSearchPathsByScenario: (NSMutableArray*) searchPaths
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 896 of file ResourceManager.m.

896 :(NSMutableArray*)searchPaths
897{
898 NSDictionary* manifest = nil;
899 NSString* identifier = nil;
900 NSArray* identifiers = [sOXPManifests allKeys];
901
902 // take a copy because we'll mutate the original
903 // foreach identified add-on
904 foreach (identifier, identifiers) {
905 manifest = [sOXPManifests objectForKey:identifier];
906 if (manifest != nil) {
907 if (![ResourceManager manifestAllowedByScenario:manifest]) {
908 // then we don't need this one
909 [searchPaths removeObject:[manifest oo_stringForKey:kOOManifestFilePath]];
910 [sOXPManifests removeObjectForKey:identifier];
911 }
912 }
913 }
914}

References nil.

Referenced by pathsWithAddOns.

Here is the caller graph for this function:

◆ filterSearchPathsForConflicts:

+ (void) filterSearchPathsForConflicts: (NSMutableArray*) searchPaths
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 749 of file ResourceManager.m.

749 :(NSMutableArray*)searchPaths
750{
751 NSDictionary* manifest = nil;
752 NSString* identifier = nil;
753 NSArray* identifiers = [sOXPManifests allKeys];
754
755 // take a copy because we'll mutate the original
756 // foreach identified add-on
757 foreach (identifier, identifiers) {
758 manifest = [sOXPManifests objectForKey:identifier];
759 if (manifest != nil) {
760 if ([self manifestHasConflicts:manifest logErrors:YES]) {
761 // then we have a conflict, so remove this path
762 [searchPaths removeObject:[manifest oo_stringForKey:kOOManifestFilePath]];
763 [sOXPManifests removeObjectForKey:identifier];
764 }
765 }
766 }
767}

References nil.

Referenced by pathsWithAddOns.

Here is the caller graph for this function:

◆ filterSearchPathsForRequirements:

+ (BOOL) filterSearchPathsForRequirements: (NSMutableArray*) searchPaths
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 828 of file ResourceManager.m.

828 :(NSMutableArray*)searchPaths
829{
830 NSDictionary* manifest = nil;
831 NSString* identifier = nil;
832 NSArray* identifiers = [sOXPManifests allKeys];
833
834 sAllMet = YES;
835
836 // take a copy because we'll mutate the original
837 // foreach identified add-on
838 foreach (identifier, identifiers) {
839 manifest = [sOXPManifests objectForKey:identifier];
840 if (manifest != nil) {
841 if ([self manifestHasMissingDependencies:manifest logErrors:YES]) {
842 // then we have a missing requirement, so remove this path
843 [searchPaths removeObject:[manifest oo_stringForKey:kOOManifestFilePath]];
844 [sOXPManifests removeObjectForKey:identifier];
845 sAllMet = NO;
846 }
847 }
848 }
849
850 return sAllMet;
851}
static BOOL sAllMet

References nil, and sAllMet.

◆ filterSearchPathsToExcludeScenarioOnlyPaths:

+ (void) filterSearchPathsToExcludeScenarioOnlyPaths: (NSMutableArray*) searchPaths
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 877 of file ResourceManager.m.

877 :(NSMutableArray*)searchPaths
878{
879 NSDictionary* manifest = nil;
880 NSString* identifier = nil;
881 NSArray* identifiers = [sOXPManifests allKeys];
882
883 // take a copy because we'll mutate the original
884 // foreach identified add-on
885 foreach (identifier, identifiers) {
886 manifest = [sOXPManifests objectForKey:identifier];
887 if (manifest != nil) {
888 if ([[manifest oo_arrayForKey:kOOManifestTags] containsObject:kOOManifestTagScenarioOnly]) {
889 [searchPaths removeObject:[manifest oo_stringForKey:kOOManifestFilePath]];
890 [sOXPManifests removeObjectForKey:identifier];
891 }
892 }
893 }
894}
static NSString *const kOOManifestTags
static NSString *const kOOManifestTagScenarioOnly

References kOOManifestTags, kOOManifestTagScenarioOnly, and nil.

Referenced by pathsWithAddOns.

Here is the caller graph for this function:

◆ handleEquipmentListMerging:forLookupIndex:

+ (void) handleEquipmentListMerging: (NSMutableArray*) arrayToProcess
forLookupIndex: (unsigned) lookupIndex 

Definition at line 1300 of file ResourceManager.m.

1300 :(NSMutableArray*)arrayToProcess forLookupIndex:(unsigned)lookupIndex
1301{
1302 NSUInteger i, j, k;
1303 NSMutableArray* refArray = [arrayToProcess objectAtIndex:[arrayToProcess count] - 1];
1304
1305 // Any change to refArray will directly modify arrayToProcess.
1306
1307 for (i = 0; i < [refArray count]; i++) {
1308 for (j = 0; j < [arrayToProcess count] - 1; j++) {
1309 NSUInteger count = [[arrayToProcess oo_arrayAtIndex:j] count];
1310 if (count == 0)
1311 continue;
1312
1313 for (k = 0; k < count; k++) {
1314 id processValue = [[[arrayToProcess oo_arrayAtIndex:j] oo_arrayAtIndex:k] oo_objectAtIndex:lookupIndex defaultValue:nil];
1315 id refValue = [[refArray oo_arrayAtIndex:i] oo_objectAtIndex:lookupIndex defaultValue:nil];
1316
1317 if ([processValue isEqual:refValue]) {
1318 [[arrayToProcess objectAtIndex:j] replaceObjectAtIndex:k withObject:[refArray objectAtIndex:i]];
1319 [refArray removeObjectAtIndex:i];
1320 }
1321 }
1322 }
1323 }
1324 // arrayToProcess has been processed at this point. Any necessary merging has been done.
1325}

References count.

Referenced by arrayFromFilesNamed:inFolder:andMerge:cache:.

Here is the caller graph for this function:

◆ handleEquipmentOverrides:

+ (void) handleEquipmentOverrides: (NSMutableArray*) arrayToProcess

Definition at line 1331 of file ResourceManager.m.

1331 :(NSMutableArray*)arrayToProcess
1332{
1333 NSEnumerator* equipKeyEnum = nil;
1334 NSString* equipKey = nil;
1335 NSDictionary* overrides = nil;
1336 NSDictionary* overridesEntry = nil;
1337 int i;
1338
1339 overrides = [ResourceManager dictionaryFromFilesNamed:@"equipment-overrides.plist"
1340 inFolder:@"Config"
1341 mergeMode:MERGE_SMART
1342 cache:NO];
1343
1344 // cycle through all the equipment keys found in override files
1345 for (equipKeyEnum = [overrides keyEnumerator]; (equipKey = [equipKeyEnum nextObject]);) {
1346 overridesEntry = [overrides objectForKey:equipKey];
1347 // loop through our data array to find a match
1348 for (i = 0; i < [arrayToProcess count]; i++) {
1349 NSMutableArray* equipArray = [[[arrayToProcess objectAtIndex:i] mutableCopy] autorelease];
1350 id refValue = [equipArray oo_objectAtIndex:EQUIPMENT_KEY_INDEX defaultValue:nil];
1351 // does the overridden equipment item exist in the equipment array? if so, get working
1352 if ([equipKey isEqual:refValue]) {
1353 NSEnumerator* infoKeyEnum = nil;
1354 NSString* infoKey;
1355 // cycle through all the properties found for this equipment key in the overrides file
1356 for (infoKeyEnum = [overridesEntry keyEnumerator]; (infoKey = [infoKeyEnum nextObject]);) {
1357 // special cases for the array items that don't have a direct keyname
1358 if ([infoKey isEqualToString:@"techlevel"])
1359 [equipArray replaceObjectAtIndex:EQUIPMENT_TECH_LEVEL_INDEX withObject:[overridesEntry objectForKey:infoKey]];
1360 else if ([infoKey isEqualToString:@"price"])
1361 [equipArray replaceObjectAtIndex:EQUIPMENT_PRICE_INDEX withObject:[overridesEntry objectForKey:infoKey]];
1362 else if ([infoKey isEqualToString:@"short_description"])
1363 [equipArray replaceObjectAtIndex:EQUIPMENT_SHORT_DESC_INDEX withObject:[overridesEntry objectForKey:infoKey]];
1364 else if ([infoKey isEqualToString:@"name"])
1365 [equipArray replaceObjectAtIndex:EQUIPMENT_SHORT_DESC_INDEX withObject:[overridesEntry objectForKey:infoKey]];
1366 else if ([infoKey isEqualToString:@"long_description"])
1367 [equipArray replaceObjectAtIndex:EQUIPMENT_LONG_DESC_INDEX withObject:[overridesEntry objectForKey:infoKey]];
1368 else if ([infoKey isEqualToString:@"description"])
1369 [equipArray replaceObjectAtIndex:EQUIPMENT_LONG_DESC_INDEX withObject:[overridesEntry objectForKey:infoKey]];
1370 else {
1371 NSMutableDictionary* extra = nil;
1372 // for everything else
1373 // do we actually have an extras dictionary?
1374 if (![equipArray oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX]) {
1375 // if not, create a blank one we can add to
1376 extra = [NSMutableDictionary dictionary];
1377 } else {
1378 extra = [[equipArray oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX] mutableCopy];
1379 }
1380 // special case for weapon_info && script_info, which are child dictionaries
1381 if ([infoKey isEqualToString:@"weapon_info"] || [infoKey isEqualToString:@"script_info"]) {
1382 NSEnumerator* subEnum = nil;
1383 NSString* subKey;
1384 NSMutableDictionary* subInfo = nil;
1385 NSDictionary* subOverrides = nil;
1386 // do we actually have a weapon_info/script_info dictionary?
1387 if (![extra oo_dictionaryForKey:infoKey]) {
1388 // if not, create a blank dictionary we can add to
1389 subInfo = [NSMutableDictionary dictionary];
1390 } else {
1391 subInfo = [[extra oo_dictionaryForKey:infoKey] mutableCopy];
1392 }
1393 subOverrides = [overridesEntry oo_dictionaryForKey:infoKey];
1394 // cycle through all the sub keys found in the overrides file for this equipment key item
1395 for (subEnum = [subOverrides keyEnumerator]; (subKey = [subEnum nextObject]);) {
1396 [subInfo setObject:[subOverrides objectForKey:subKey] forKey:subKey];
1397 }
1398 [extra setObject:[[subInfo copy] autorelease] forKey:infoKey];
1399 } else {
1400 // for all other keys in the extras dictionary
1401 [extra setObject:[overridesEntry objectForKey:infoKey] forKey:infoKey];
1402 }
1403 [equipArray replaceObjectAtIndex:EQUIPMENT_EXTRA_INFO_INDEX withObject:[[extra copy] autorelease]];
1404 }
1405 }
1406 [arrayToProcess replaceObjectAtIndex:i withObject:equipArray];
1407 }
1408 }
1409 }
1410}
@ EQUIPMENT_EXTRA_INFO_INDEX
Definition Universe.h:79
NSDictionary * dictionaryFromFilesNamed:inFolder:mergeMode:cache:(NSString *fileName,[inFolder] NSString *folderName,[mergeMode] OOResourceMergeMode mergeMode,[cache] BOOL useCache)

References dictionaryFromFilesNamed:inFolder:mergeMode:cache:, EQUIPMENT_EXTRA_INFO_INDEX, and nil.

Referenced by arrayFromFilesNamed:inFolder:andMerge:cache:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleStarNebulaListMerging:

+ (void) handleStarNebulaListMerging: (NSMutableArray*) arrayToProcess

Definition at line 1414 of file ResourceManager.m.

1414 :(NSMutableArray*)arrayToProcess
1415{
1416 NSUInteger i, j, k;
1417 NSMutableArray* refArray = [arrayToProcess objectAtIndex:[arrayToProcess count] - 1];
1418
1419 // Any change to refArray will directly modify arrayToProcess.
1420 for (i = 0; i < [refArray count]; i++) {
1421 for (j = 0; j < [arrayToProcess count] - 1; j++) {
1422 NSUInteger count = [[arrayToProcess oo_arrayAtIndex:j] count];
1423 if (count == 0)
1424 continue;
1425
1426 for (k = 0; k < count; k++) {
1427 id processValue = [[arrayToProcess oo_arrayAtIndex:j] oo_objectAtIndex:k defaultValue:nil];
1428 id refValue = [refArray oo_objectAtIndex:i defaultValue:nil];
1429 NSString* key1 = nil;
1430 NSString* key2 = nil;
1431
1432 if ([processValue isKindOfClass:[NSString class]]) {
1433 key1 = processValue;
1434 } else if ([processValue isKindOfClass:[NSDictionary class]]) {
1435 if (![processValue objectForKey:@"key"]) {
1436 key1 = [processValue objectForKey:@"texture"];
1437 } else {
1438 key1 = [processValue objectForKey:@"key"];
1439 }
1440 }
1441 if (!key1)
1442 continue;
1443
1444 if ([refValue isKindOfClass:[NSString class]]) {
1445 key2 = refValue;
1446 } else if ([refValue isKindOfClass:[NSDictionary class]]) {
1447 if (![refValue objectForKey:@"key"]) {
1448 key2 = [refValue objectForKey:@"texture"];
1449 } else {
1450 key2 = [refValue objectForKey:@"key"];
1451 }
1452 }
1453 if (!key2)
1454 continue;
1455
1456 if ([key1 isEqual:key2]) {
1457 [[arrayToProcess objectAtIndex:j] replaceObjectAtIndex:k withObject:[refArray objectAtIndex:i]];
1458 [refArray removeObjectAtIndex:i];
1459 }
1460 }
1461 }
1462 }
1463 // arrayToProcess has been processed at this point. Any necessary merging has been done.
1464}

References count, and nil.

Referenced by arrayFromFilesNamed:inFolder:andMerge:cache:.

Here is the caller graph for this function:

◆ loadScripts

+ (NSDictionary *) loadScripts

Definition at line 1831 of file ResourceManager.m.

1832{
1833 NSMutableDictionary* loadedScripts = nil;
1834 NSArray* results = nil;
1835 NSArray* paths = nil;
1836 NSString* path = nil;
1837 OOScript* script = nil;
1838 NSString* name = nil;
1839 NSAutoreleasePool* pool = nil;
1840
1841 OOLog(@"script.load.world.begin", @"%@", @"Loading world scripts...");
1842
1843 loadedScripts = [NSMutableDictionary dictionary];
1845 foreach (path, paths) {
1846 // excluding world-scripts.plist also excludes script.js / script.plist
1847 // though as those core files don't and won't exist this is not
1848 // a problem.
1849 if (![ResourceManager corePlist:@"world-scripts.plist" excludedAt:path]) {
1850 pool = [[NSAutoreleasePool alloc] init];
1851
1852 @try {
1853 results = [OOScript worldScriptsAtPath:[path stringByAppendingPathComponent:@"Config"]];
1854 if (results == nil)
1855 results = [OOScript worldScriptsAtPath:path];
1856 if (results != nil) {
1857 foreach (script, results) {
1858 name = [script name];
1859 if (name != nil)
1860 [loadedScripts setObject:script forKey:name];
1861 else
1862 OOLog(@"script.load.unnamed", @"Discarding anonymous script %@", script);
1863 }
1864 }
1865 }
1866 @catch (NSException* exception) {
1867 OOLog(@"script.load.exception", @"***** %s encountered exception %@ (%@) while trying to load script from %@ -- ignoring this location.", __PRETTY_FUNCTION__, [exception name], [exception reason], path);
1868 // Ignore exception and keep loading other scripts.
1869 }
1870
1871 [pool release];
1872 }
1873 }
1874
1875 if (OOLogWillDisplayMessagesInClass(@"script.load.world.listAll")) {
1876 NSUInteger count = [loadedScripts count];
1877 if (count != 0) {
1878 NSMutableArray* displayNames = nil;
1879 OOScript* script = nil;
1880 NSString* displayString = nil;
1881
1882 displayNames = [NSMutableArray arrayWithCapacity:count];
1883
1884 foreach (script, [loadedScripts allValues]) {
1885 [displayNames addObject:[script displayName]];
1886 }
1887
1888 displayString = [[displayNames sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] componentsJoinedByString:@"\n "];
1889 OOLog(@"script.load.world.listAll", @"Loaded %zu world scripts:\n %@", count, displayString);
1890 } else {
1891 OOLog(@"script.load.world.listAll", @"%@", @"*** No world scripts loaded.");
1892 }
1893 }
1894
1895 return loadedScripts;
1896}
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
Definition OOLogging.m:136
NSString * name()
Definition OOScript.m:232
NSArray * worldScriptsAtPath:(NSString *path)
Definition OOScript.m:45
NSString * displayName()
Definition OOScript.m:250

References count, OOScript::displayName, loadScripts, OOScript::name, nil, OOLog, OOLogWillDisplayMessagesInClass(), paths, and OOScript::worldScriptsAtPath:.

Referenced by loadScripts, and PlayerEntity::setUpAndConfirmOK:saveGame:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LogClassKeyRoot

+ (NSString *) LogClassKeyRoot (NSString *) key
implementation

Definition at line 1484 of file ResourceManager.m.

1485{
1486 NSRange dot = [key rangeOfString:@"."];
1487 if (dot.location != NSNotFound) {
1488 return [key substringToIndex:dot.location];
1489 } else {
1490 return key;
1491 }
1492}

Referenced by logControlDictionary.

Here is the caller graph for this function:

◆ logControlDictionary

+ (NSDictionary *) logControlDictionary

Definition at line 1494 of file ResourceManager.m.

1495{
1496 // Load built-in copy of logcontrol.plist.
1497 NSString* path = [[[ResourceManager builtInPath] stringByAppendingPathComponent:@"Config"]
1498 stringByAppendingPathComponent:@"logcontrol.plist"];
1499 NSMutableDictionary* logControl = [NSMutableDictionary dictionaryWithDictionary:OODictionaryFromFile(path)];
1500 if (logControl == nil)
1501 logControl = [NSMutableDictionary dictionary];
1502
1503 // Build list of root log message classes that appear in the built-in list.
1504 NSMutableSet* coreRoots = [NSMutableSet set];
1505 NSString* key = nil;
1506 foreachkey(key, logControl)
1507 {
1508 [coreRoots addObject:LogClassKeyRoot(key)];
1509 }
1510
1511 NSArray* rootPaths = [self rootPaths];
1512 NSString* configPath = nil;
1513 NSDictionary* dict = nil;
1514
1515 // Look for logcontrol.plists inside OXPs (but not in root paths). These are not allowed to define keys in hierarchies used by the build-in one.
1516 foreach (path, [self pathEnumerator]) {
1517 if ([rootPaths containsObject:path])
1518 continue;
1519
1520 configPath = [[path stringByAppendingPathComponent:@"Config"]
1521 stringByAppendingPathComponent:@"logcontrol.plist"];
1522 dict = OODictionaryFromFile(configPath);
1523 if (dict == nil) {
1524 configPath = [path stringByAppendingPathComponent:@"logcontrol.plist"];
1525 dict = OODictionaryFromFile(configPath);
1526 }
1527 foreachkey(key, dict)
1528 {
1529 if (![coreRoots containsObject:LogClassKeyRoot(key)]) {
1530 [logControl setObject:[dict objectForKey:key] forKey:key];
1531 }
1532 }
1533 }
1534
1535 // Now, look for logcontrol.plists in root paths, i.e. not within OXPs. These are allowed to override the built-in copy.
1536 foreach (path, rootPaths) {
1537 configPath = [[path stringByAppendingPathComponent:@"Config"]
1538 stringByAppendingPathComponent:@"logcontrol.plist"];
1539 dict = OODictionaryFromFile(configPath);
1540 if (dict == nil) {
1541 configPath = [path stringByAppendingPathComponent:@"logcontrol.plist"];
1542 dict = OODictionaryFromFile(configPath);
1543 }
1544 foreachkey(key, dict)
1545 {
1546 [logControl setObject:[dict objectForKey:key] forKey:key];
1547 }
1548 }
1549
1550 // Finally, look in preferences, which can override all of the above.
1551 dict = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"logging-enable"];
1552 if (dict != nil)
1553 [logControl addEntriesFromDictionary:dict];
1554
1555 return logControl;
1556}
#define foreachkey(VAR, DICT)
static NSString * LogClassKeyRoot(NSString *key)

References builtInPath, foreachkey, LogClassKeyRoot, logControlDictionary, nil, OODictionaryFromFile(), pathEnumerator, and rootPaths.

Referenced by LoadExplicitSettings(), and logControlDictionary.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logPaths

+ (void) logPaths
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 1974 of file ResourceManager.m.

1975{
1976 NSMutableArray* displayPaths = nil;
1977 NSString* path = nil;
1978
1979 // Prettify paths for logging.
1980 displayPaths = [NSMutableArray arrayWithCapacity:[sSearchPaths count]];
1981 foreach (path, sSearchPaths) {
1982 [displayPaths addObject:[[path stringByStandardizingPath] stringByAbbreviatingWithTildeInPath]];
1983 }
1984
1985 OOLog(@"searchPaths.dumpAll", @"Resource paths: %@\n %@", sUseAddOns, [displayPaths componentsJoinedByString:@"\n "]);
1986}
static NSString * sUseAddOns

References logPaths, nil, OOLog, sSearchPaths, and sUseAddOns.

Referenced by logPaths, and setUseAddOns:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ manifest:HasUnmetDependency:logErrors:

+ (BOOL) manifest: (NSDictionary*) manifest
HasUnmetDependency: (NSDictionary*) required
logErrors: (BOOL) logErrors 

Definition at line 787 of file ResourceManager.m.

787 :(NSDictionary*)manifest HasUnmetDependency:(NSDictionary*)required logErrors:(BOOL)logErrors
788{
789 NSString* requiredID = [required oo_stringForKey:kOOManifestRelationIdentifier];
790 NSMutableDictionary* requiredManifest = [sOXPManifests objectForKey:requiredID];
791 // if the other OXP is in the list
792 BOOL requirementsMet = NO;
793 if (requiredManifest != nil) {
794 // then check versions
795 if ([self matchVersions:required withVersion:[requiredManifest oo_stringForKey:kOOManifestVersion]]) {
796 requirementsMet = YES;
797 /* Mark the requiredManifest as a dependency of the
798 * requiring manifest */
799 NSSet* reqby = [requiredManifest oo_setForKey:kOOManifestRequiredBy defaultValue:[NSSet set]];
800 NSUInteger reqbycount = [reqby count];
801 /* then add this manifest to its required set. This is
802 * done without checking if it's already there, because
803 * the list of nested requirements may have changed. */
804 reqby = [reqby setByAddingObject:[manifest oo_stringForKey:kOOManifestIdentifier]];
805 // *and* anything that requires this OXP to be installed
806 reqby = [reqby setByAddingObjectsFromSet:[manifest oo_setForKey:kOOManifestRequiredBy]];
807 if (reqbycount < [reqby count]) {
808 /* Then the set has increased in size. To handle
809 * potential cases with nested dependencies, need to
810 * re-run the requirement filter until all the sets
811 * stabilise. */
812 sAllMet = NO;
813 }
814 // and push back into the requiring manifest
815 [requiredManifest setObject:reqby forKey:kOOManifestRequiredBy];
816 }
817 }
818 if (!requirementsMet) {
819 if (logErrors) {
820 [self addErrorWithKey:@"oxp-required" param1:[manifest oo_stringForKey:kOOManifestTitle] param2:[required oo_stringForKey:kOOManifestRelationDescription defaultValue:[required oo_stringForKey:kOOManifestRelationIdentifier]]];
821 OOLog(@"oxp.requirementMissing", @"OXP %@ had unmet requirements and was removed from the loading list", [[manifest oo_stringForKey:kOOManifestFilePath] lastPathComponent]);
822 }
823 return YES;
824 }
825 return NO;
826}
static NSString *const kOOManifestVersion
static NSString *const kOOManifestFilePath

References addErrorWithKey:param1:param2:, count, kOOManifestFilePath, kOOManifestVersion, nil, OOLog, and sAllMet.

Here is the call graph for this function:

◆ manifestAllowedByScenario:

+ (BOOL) manifestAllowedByScenario: (NSDictionary*) manifest
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 916 of file ResourceManager.m.

916 :(NSDictionary*)manifest
917{
918 /* Checks for a couple of "never happens" cases */
919#ifndef NDEBUG
920 // test string
921 if ([sUseAddOns isEqualToString:SCENARIO_OXP_DEFINITION_ALL]) {
922 OOLog(@"scenario.check", @"%@", @"Checked scenario allowances in all state - this is an internal error; please report this");
923 return YES;
924 }
925 if ([sUseAddOns isEqualToString:SCENARIO_OXP_DEFINITION_NONE]) {
926 OOLog(@"scenario.check", @"%@", @"Checked scenario allowances in none state - this is an internal error; please report this");
927 return NO;
928 }
929#endif
930 if ([[manifest oo_stringForKey:kOOManifestIdentifier] isEqualToString:@"org.oolite.oolite"]) {
931 // the core data is always allowed!
932 return YES;
933 }
934
935 NSString* uaoBit = nil;
936 BOOL result = NO;
937 foreach (uaoBit, sUseAddOnsParts) {
938 if ([uaoBit hasPrefix:SCENARIO_OXP_DEFINITION_BYID]) {
939 result |= [ResourceManager manifestAllowedByScenario:manifest withIdentifier:[uaoBit substringFromIndex:[SCENARIO_OXP_DEFINITION_BYID length]]];
940 } else if ([uaoBit hasPrefix:SCENARIO_OXP_DEFINITION_BYTAG]) {
941 result |= [ResourceManager manifestAllowedByScenario:manifest withTag:[uaoBit substringFromIndex:[SCENARIO_OXP_DEFINITION_BYTAG length]]];
942 }
943 }
944 return result;
945}
static NSString *const kOOManifestIdentifier
#define SCENARIO_OXP_DEFINITION_BYID
#define SCENARIO_OXP_DEFINITION_NONE
#define SCENARIO_OXP_DEFINITION_ALL
#define SCENARIO_OXP_DEFINITION_BYTAG
BOOL manifestAllowedByScenario:withTag:(NSDictionary *manifest, [withTag] NSString *tag)
BOOL manifestAllowedByScenario:withIdentifier:(NSDictionary *manifest, [withIdentifier] NSString *identifier)

References kOOManifestIdentifier, manifestAllowedByScenario:withIdentifier:, manifestAllowedByScenario:withTag:, nil, OOLog, SCENARIO_OXP_DEFINITION_ALL, SCENARIO_OXP_DEFINITION_BYID, SCENARIO_OXP_DEFINITION_BYTAG, SCENARIO_OXP_DEFINITION_NONE, sUseAddOns, and sUseAddOnsParts.

Here is the call graph for this function:

◆ manifestAllowedByScenario:withIdentifier:

+ (BOOL) manifestAllowedByScenario: (NSDictionary*) manifest
withIdentifier: (NSString*) identifier 
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 947 of file ResourceManager.m.

947 :(NSDictionary*)manifest withIdentifier:(NSString*)identifier
948{
949 if ([[manifest oo_stringForKey:kOOManifestIdentifier] isEqualToString:identifier]) {
950 // manifest has the identifier - easy
951 return YES;
952 }
953 // manifest is also allowed if a manifest with that identifier
954 // requires it to be installed
955 if ([[manifest oo_setForKey:kOOManifestRequiredBy] containsObject:identifier]) {
956 return YES;
957 }
958 // otherwise, no
959 return NO;
960}
static NSString *const kOOManifestRequiredBy

References kOOManifestIdentifier, and kOOManifestRequiredBy.

Referenced by manifestAllowedByScenario:.

Here is the caller graph for this function:

◆ manifestAllowedByScenario:withTag:

+ (BOOL) manifestAllowedByScenario: (NSDictionary*) manifest
withTag: (NSString*) tag 
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 962 of file ResourceManager.m.

962 :(NSDictionary*)manifest withTag:(NSString*)tag
963{
964 if ([[manifest oo_arrayForKey:kOOManifestTags] containsObject:tag]) {
965 // manifest has the tag - easy
966 return YES;
967 }
968 // manifest is also allowed if a manifest with that tag
969 // requires it to be installed
970 NSSet* reqby = [manifest oo_setForKey:kOOManifestRequiredBy];
971 if (reqby != nil) {
972 NSString* identifier = nil;
973 foreach (identifier, reqby) {
974 NSDictionary* reqManifest = [sOXPManifests oo_dictionaryForKey:identifier defaultValue:nil];
975 // need to check for nil as this one may already have been ruled out
976 if (reqManifest != nil && [[reqManifest oo_arrayForKey:kOOManifestTags] containsObject:tag]) {
977 return YES;
978 }
979 }
980 }
981 // otherwise, no
982 return NO;
983}

References kOOManifestTags, and nil.

Referenced by manifestAllowedByScenario:.

Here is the caller graph for this function:

◆ manifestForIdentifier:

+ (NSDictionary *) manifestForIdentifier: (NSString*) identifier

Definition at line 522 of file ResourceManager.m.

522 :(NSString*)identifier
523{
524 return [sOXPManifests objectForKey:identifier];
525}

Referenced by OOOXZManager(NSURLConnectionDataDelegate)::installableState:, and OOOXZManager::showInstallOptions.

Here is the caller graph for this function:

◆ manifestHasConflicts:logErrors:

+ (BOOL) manifestHasConflicts: (NSDictionary*) manifest
logErrors: (BOOL) logErrors 

Definition at line 719 of file ResourceManager.m.

719 :(NSDictionary*)manifest logErrors:(BOOL)logErrors
720{
721 NSDictionary* conflicting = nil;
722 NSDictionary* conflictManifest = nil;
723 NSString* conflictID = nil;
724 NSArray* conflicts = nil;
725
726 conflicts = [manifest oo_arrayForKey:kOOManifestConflictOXPs defaultValue:nil];
727 // if it has a non-empty conflict_oxps list
728 if (conflicts != nil && [conflicts count] > 0) {
729 // iterate over that list
730 foreach (conflicting, conflicts) {
731 conflictID = [conflicting oo_stringForKey:kOOManifestRelationIdentifier];
732 conflictManifest = [sOXPManifests objectForKey:conflictID];
733 // if the other OXP is in the list
734 if (conflictManifest != nil) {
735 // then check versions
736 if ([self matchVersions:conflicting withVersion:[conflictManifest oo_stringForKey:kOOManifestVersion]]) {
737 if (logErrors) {
738 [self addErrorWithKey:@"oxp-conflict" param1:[manifest oo_stringForKey:kOOManifestTitle] param2:[conflictManifest oo_stringForKey:kOOManifestTitle]];
739 OOLog(@"oxp.conflict", @"OXP %@ conflicts with %@ and was removed from the loading list", [[manifest oo_stringForKey:kOOManifestFilePath] lastPathComponent], [[conflictManifest oo_stringForKey:kOOManifestFilePath] lastPathComponent]);
740 }
741 return YES;
742 }
743 }
744 }
745 }
746 return NO;
747}

References addErrorWithKey:param1:param2:, count, kOOManifestFilePath, kOOManifestVersion, nil, and OOLog.

Here is the call graph for this function:

◆ manifestHasMissingDependencies:logErrors:

+ (BOOL) manifestHasMissingDependencies: (NSDictionary*) manifest
logErrors: (BOOL) logErrors 

Definition at line 769 of file ResourceManager.m.

769 :(NSDictionary*)manifest logErrors:(BOOL)logErrors
770{
771 NSDictionary* required = nil;
772 NSArray* requireds = nil;
773
774 requireds = [manifest oo_arrayForKey:kOOManifestRequiresOXPs defaultValue:nil];
775 // if it has a non-empty required_oxps list
776 if (requireds != nil && [requireds count] > 0) {
777 // iterate over that list
778 foreach (required, requireds) {
779 if ([ResourceManager manifest:manifest HasUnmetDependency:required logErrors:logErrors]) {
780 return YES;
781 }
782 }
783 }
784 return NO;
785}

References count, and nil.

◆ maskUserName:inPath:

+ (NSString *) maskUserName: (NSString*) name
inPath: (NSString*) path 

Definition at line 444 of file ResourceManager.m.

444 :(NSString*)name inPath:(NSString*)path
445{
446 NSMutableString* result = [NSMutableString stringWithString:path];
447 if (result && name)
448 [result replaceOccurrencesOfString:name
449 withString:@"*"
450 options:NSLiteralSearch
451 range:NSMakeRange(0, [result length])];
452 return [NSString stringWithString:result];
453}

Referenced by maskUserNameInPathArray:.

Here is the caller graph for this function:

◆ maskUserNameInPathArray:

+ (NSArray *) maskUserNameInPathArray: (NSArray*) inputPathArray

Definition at line 426 of file ResourceManager.m.

426 :(NSArray*)inputPathArray
427{
428 NSString* path = nil;
429 NSMutableArray* maskedArray = [NSMutableArray arrayWithCapacity:[inputPathArray count]];
430 const char* userNamePathEnvVar =
431#if OOLITE_WINDOWS
432 SDL_getenv("USERPROFILE");
433#else
434 SDL_getenv("HOME");
435#endif
436 NSString* userName = [[NSString stringWithFormat:@"%s", userNamePathEnvVar] lastPathComponent];
437 foreach (path, inputPathArray) {
438 path = [self maskUserName:userName inPath:path];
439 [maskedArray addObject:path];
440 }
441 return maskedArray;
442}

References maskUserName:inPath:, and nil.

Referenced by OoliteGetProperty(), and OoliteGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ matchVersions:withVersion:

+ (BOOL) matchVersions: (NSDictionary*) rangeDict
withVersion: (NSString*) version 

Definition at line 853 of file ResourceManager.m.

853 :(NSDictionary*)rangeDict withVersion:(NSString*)version
854{
855 NSString* minimum = [rangeDict oo_stringForKey:kOOManifestRelationVersion defaultValue:nil];
856 NSString* maximum = [rangeDict oo_stringForKey:kOOManifestRelationMaxVersion defaultValue:nil];
857 NSArray* isVersionComponents = ComponentsFromVersionString(version);
858 NSArray* reqVersionComponents = nil;
859 if (minimum != nil) {
860 reqVersionComponents = ComponentsFromVersionString(minimum);
861 if (NSOrderedAscending == CompareVersions(isVersionComponents, reqVersionComponents)) {
862 // earlier than minimum version
863 return NO;
864 }
865 }
866 if (maximum != nil) {
867 reqVersionComponents = ComponentsFromVersionString(maximum);
868 if (NSOrderedDescending == CompareVersions(isVersionComponents, reqVersionComponents)) {
869 // later than maximum version
870 return NO;
871 }
872 }
873 // either version was okay, or no version info so an unconditional match
874 return YES;
875}

References CompareVersions(), ComponentsFromVersionString(), and nil.

Here is the call graph for this function:

◆ materialDefaults

+ (NSDictionary *) materialDefaults

Definition at line 1941 of file ResourceManager.m.

1942{
1943 return [self dictionaryFromFilesNamed:@"material-defaults.plist" inFolder:@"Config" andMerge:YES];
1944}

References dictionaryFromFilesNamed:inFolder:andMerge:, and materialDefaults.

Referenced by materialDefaults, OODefaultShipShaderMacros(), OOMesh::placeholderMaterial, ShipSetMaterialsInternal(), ShipSetMaterialsInternal(), VisualEffectSetMaterialsInternal(), and VisualEffectSetMaterialsInternal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mergeRoleCategories:intoDictionary:

+ (void) mergeRoleCategories: (NSDictionary*) catData
intoDictionary: (NSMutableDictionary*) categories 
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 1589 of file ResourceManager.m.

1589 :(NSDictionary*)catData intoDictionary:(NSMutableDictionary*)categories
1590{
1591 NSMutableSet* contents = nil;
1592 NSArray* catDataEntry = nil;
1593 NSString* key;
1594 foreachkey(key, catData)
1595 {
1596 contents = [categories objectForKey:key];
1597 if (contents == nil) {
1598 contents = [NSMutableSet setWithCapacity:16];
1599 [categories setObject:contents forKey:key];
1600 }
1601 catDataEntry = [catData oo_arrayForKey:key];
1602 OOLog(@"shipData.load.roleCategories", @"Adding %ld entries for category %@", (unsigned long)[catDataEntry count], key);
1603 [contents addObjectsFromArray:catDataEntry];
1604 }
1605}

References count, foreachkey, nil, and OOLog.

Referenced by roleCategoriesDictionary.

Here is the caller graph for this function:

◆ ooMusicNamed:inFolder:

+ (OOMusic *) ooMusicNamed: (NSString*) fileName
inFolder: (NSString*) folderName 

Definition at line 1777 of file ResourceManager.m.

1777 :(NSString*)fileName inFolder:(NSString*)folderName
1778{
1779 return [self retrieveFileNamed:fileName
1780 inFolder:folderName
1781 cache:NULL // Don't cache music objects; minimizing latency isn't really important.
1782 key:[NSString stringWithFormat:@"OOMusic:%@:%@", folderName, fileName]
1783 class:[OOMusic class]
1784 usePathCache:YES];
1785}

References retrieveFileNamed:inFolder:cache:key:class:usePathCache:.

Referenced by OOMusicController::playMusicNamed:loop:gain:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ooSoundNamed:inFolder:

+ (OOSound *) ooSoundNamed: (NSString*) fileName
inFolder: (NSString*) folderName 

Definition at line 1787 of file ResourceManager.m.

1787 :(NSString*)fileName inFolder:(NSString*)folderName
1788{
1789 return [self retrieveFileNamed:fileName
1790 inFolder:folderName
1791 cache:&sSoundCache
1792 key:[NSString stringWithFormat:@"OOSound:%@:%@", folderName, fileName]
1793 class:[OOSound class]
1794 usePathCache:YES];
1795}

References retrieveFileNamed:inFolder:cache:key:class:usePathCache:.

Referenced by GetNamedSound(), Universe::PreloadOneSound, PlayerEntity(Sound)::setUpSound, and OOSound(OOCustomSounds)::soundWithCustomSoundKey:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OXPsWithMessagesFound

+ (NSArray *) OXPsWithMessagesFound

Definition at line 517 of file ResourceManager.m.

518{
519 return [[sOXPsWithMessagesFound copy] autorelease];
520}

References OXPsWithMessagesFound.

Referenced by OXPsWithMessagesFound, and PlayerEntity::setGuiToIntroFirstGo:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pathEnumerator

+ (NSEnumerator *) pathEnumerator

Definition at line 507 of file ResourceManager.m.

508{
509 return [[self paths] objectEnumerator];
510}

References pathEnumerator, and paths.

Referenced by arrayFromFilesNamed:inFolder:andMerge:cache:, dictionaryFromFilesNamed:inFolder:mergeMode:cache:, logControlDictionary, pathEnumerator, roleCategoriesDictionary, and systemDescriptionManager.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pathForFileNamed:inFolder:

+ (NSString *) pathForFileNamed: (NSString*) fileName
inFolder: (NSString*) folderName 

Definition at line 1687 of file ResourceManager.m.

1687 :(NSString*)fileName inFolder:(NSString*)folderName
1688{
1689 return [self pathForFileNamed:fileName inFolder:folderName cache:YES];
1690}

References pathForFileNamed:inFolder:cache:.

Referenced by OOScript::jsAIScriptFromFileNamed:properties:, OOScript::jsScriptFromFileNamed:properties:, LoadCompatibilityScript(), OOTextureLoader::loaderWithTextureSpecifier:extraOptions:folder:, AI(OOPrivate)::loadStateMachine:jsName:, OOFileScannerVerifierStage::pathForFile:inFolder:referencedFrom:checkBuiltIn:, OOScript::scriptsFromFileNamed:, ShipEntity(AI)::setAITo:, PlayerEntity(LoadSave)::startScenario, and OOTexture::textureWithName:inFolder:options:anisotropy:lodBias:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pathForFileNamed:inFolder:cache:

+ (NSString *) pathForFileNamed: (NSString*) fileName
inFolder: (NSString*) folderName
cache: (BOOL) useCache 

Definition at line 1693 of file ResourceManager.m.

1693 :(NSString*)fileName inFolder:(NSString*)folderName cache:(BOOL)useCache
1694{
1695 NSString* result = nil;
1696 NSString* cacheKey = nil;
1697 OOCacheManager* cache = [OOCacheManager sharedCache];
1698 NSString* path = nil;
1699 NSString* filePath = nil;
1700 NSFileManager* fmgr = nil;
1701
1702 if (fileName == nil)
1703 return nil;
1704
1705 if (cache) {
1706 if (folderName != nil)
1707 cacheKey = [NSString stringWithFormat:@"%@/%@", folderName, fileName];
1708 else
1709 cacheKey = fileName;
1710 result = [cache objectForKey:cacheKey inCache:@"resolved paths"];
1711 if (result != nil)
1712 return result;
1713 }
1714
1715 // Search for file
1716 fmgr = [NSFileManager defaultManager];
1717 // reverse object enumerator allows OXPs to override core
1718 foreach (path, [[ResourceManager paths] reverseObjectEnumerator]) {
1719 filePath = [[path stringByAppendingPathComponent:folderName] stringByAppendingPathComponent:fileName];
1720 if ([fmgr oo_oxzFileExistsAtPath:filePath]) {
1721 result = filePath;
1722 break;
1723 }
1724
1725 filePath = [path stringByAppendingPathComponent:fileName];
1726 if ([fmgr oo_oxzFileExistsAtPath:filePath]) {
1727 result = filePath;
1728 break;
1729 }
1730 }
1731
1732 if (result != nil) {
1733 OOLog(@"resourceManager.foundFile", @"Found %@/%@ at %@", folderName, fileName, filePath);
1734 if (useCache) {
1735 [cache setObject:result forKey:cacheKey inCache:@"resolved paths"];
1736 }
1737 }
1738 return result;
1739}

References nil, OOCacheManager::objectForKey:inCache:, OOLog, paths, OOCacheManager::setObject:forKey:inCache:, and OOCacheManager::sharedCache.

Referenced by pathForFileNamed:inFolder:, retrieveFileNamed:inFolder:cache:key:class:usePathCache:, and stringFromFilesNamed:inFolder:cache:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paths

+ (NSArray *) paths

Definition at line 418 of file ResourceManager.m.

419{
420 if (EXPECT_NOT(sSearchPaths == nil)) {
421 sSearchPaths = [[NSMutableArray alloc] init];
422 }
423 return [self pathsWithAddOns];
424}

References EXPECT_NOT, nil, paths, pathsWithAddOns, and sSearchPaths.

Referenced by loadScripts, OoliteGetProperty(), OoliteGetProperty(), pathEnumerator, pathForFileNamed:inFolder:cache:, paths, preloadFileLists, OOOpenGLExtensionManager::reset, reversePathEnumerator, and setUseAddOns:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pathsWithAddOns

+ (NSArray *) pathsWithAddOns

Definition at line 212 of file ResourceManager.m.

213{
214 if ([sSearchPaths count] > 0)
215 return sSearchPaths;
216
217 if (sUseAddOns == nil) {
218 sUseAddOns = [[NSString alloc] initWithString:SCENARIO_OXP_DEFINITION_ALL];
219 sUseAddOnsParts = [[sUseAddOns componentsSeparatedByString:@";"] retain];
220 }
221
222 /* Handle special case of 'strict mode' efficiently */
223 // testing actual string
224 if ([sUseAddOns isEqualToString:SCENARIO_OXP_DEFINITION_NONE]) {
225 return (NSArray*)[NSArray arrayWithObject:[self builtInPath]];
226 }
227
228 [sErrors release];
229 sErrors = nil;
230
231 NSFileManager* fmgr = [NSFileManager defaultManager];
232 NSArray* rootPaths = nil;
233 NSMutableArray* existingRootPaths = nil;
234 NSString* root = nil;
235 NSDirectoryEnumerator* dirEnum = nil;
236 NSString* subPath = nil;
237 NSString* path = nil;
238 BOOL isDirectory;
239
240 // Copy those root paths that actually exist to search paths.
241 rootPaths = [self rootPaths];
242 existingRootPaths = [NSMutableArray arrayWithCapacity:[rootPaths count]];
243 foreach (root, rootPaths) {
244 if ([fmgr fileExistsAtPath:root isDirectory:&isDirectory] && isDirectory) {
245 [existingRootPaths addObject:root];
246 }
247 }
248
249 // validate default search paths
251 sSearchPaths = [NSMutableArray new];
252 foreach (path, existingRootPaths) {
253 [self checkPotentialPath:path searchPaths:sSearchPaths];
254 }
255
256 // Iterate over root paths.
257 foreach (root, existingRootPaths) {
258 // Iterate over each root path's contents.
259 if ([fmgr fileExistsAtPath:root isDirectory:&isDirectory] && isDirectory) {
260 for (dirEnum = [fmgr enumeratorAtPath:root]; (subPath = [dirEnum nextObject]);) {
261 // Check if it's a directory.
262 path = [root stringByAppendingPathComponent:subPath];
263 if ([fmgr fileExistsAtPath:path isDirectory:&isDirectory]) {
264 if (isDirectory) {
265 // If it is, is it an OXP?.
266 if ([[[path pathExtension] lowercaseString] isEqualToString:@"oxp"]) {
267 [self checkPotentialPath:path searchPaths:sSearchPaths];
268 if ([sSearchPaths containsObject:path])
269 [self checkOXPMessagesInPath:path];
270 } else {
271 // If not, don't search subdirectories.
272 [dirEnum skipDescendents];
273 }
274 } else {
275 // If not a directory, is it an OXZ?
276 if ([[[path pathExtension] lowercaseString] isEqualToString:@"oxz"]) {
277 [self checkPotentialPath:path searchPaths:sSearchPaths];
278 if ([sSearchPaths containsObject:path])
279 [self checkOXPMessagesInPath:path];
280 }
281 }
282 }
283 }
284 }
285 }
286
287 foreach (path, sExternalPaths) {
288 [self checkPotentialPath:path searchPaths:sSearchPaths];
289 if ([sSearchPaths containsObject:path])
290 [self checkOXPMessagesInPath:path];
291 }
292
293 /* If a scenario restriction is *not* in place, remove
294 * scenario-only OXPs. */
295 // test string
296 if ([sUseAddOns isEqualToString:SCENARIO_OXP_DEFINITION_ALL]) {
297 [self filterSearchPathsToExcludeScenarioOnlyPaths:sSearchPaths];
298 }
299
300 /* This is a conservative filter. It probably gets rid of more
301 * OXPs than it technically needs to in certain situations with
302 * dependency chains, but really any conflict here needs to be
303 * resolved by the user rather than Oolite. The point is to avoid
304 * loading OXPs which we shouldn't; if doing so takes out other
305 * OXPs which would have been safe, that's not important. */
306 [self filterSearchPathsForConflicts:sSearchPaths];
307
308 /* This one needs to be run repeatedly to be sure. Take the chain
309 * A depends on B depends on C. A and B are installed. A is
310 * checked first, and depends on B, which is thought to be
311 * okay. So A is kept. Then B is checked and removed. A must then
312 * be rechecked. This function therefore is run repeatedly until a
313 * run of it removes no further items.
314 *
315 * There may well be more elegant and efficient ways to do this
316 * but this is already fast enough for most purposes.
317 */
318 while (![self filterSearchPathsForRequirements:sSearchPaths]) { }
319
320 /* If a scenario restriction is in place, restrict OXPs to the
321 * ones valid for the scenario only. */
322 // test string
323 if (![sUseAddOns isEqualToString:SCENARIO_OXP_DEFINITION_ALL]) {
324 [self filterSearchPathsByScenario:sSearchPaths];
325 }
326
327 [self checkCacheUpToDateForPaths:sSearchPaths];
328
329 return sSearchPaths;
330}
#define DESTROY(x)

References builtInPath, checkCacheUpToDateForPaths:, checkOXPMessagesInPath:, checkPotentialPath:searchPaths:, count, DESTROY, filterSearchPathsByScenario:, filterSearchPathsForConflicts:, filterSearchPathsToExcludeScenarioOnlyPaths:, nil, pathsWithAddOns, rootPaths, SCENARIO_OXP_DEFINITION_ALL, SCENARIO_OXP_DEFINITION_NONE, sErrors, sExternalPaths, sSearchPaths, sUseAddOns, and sUseAddOnsParts.

Referenced by paths, pathsWithAddOns, and resetManifestKnowledgeForOXZManager.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ preloadFileListFromFolder:forFolders:

+ (void) preloadFileListFromFolder: (NSString*) path
forFolders: (NSArray*) folders 
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 388 of file ResourceManager.m.

388 :(NSString*)path forFolders:(NSArray*)folders
389{
390 NSFileManager* fmgr = [NSFileManager defaultManager];
391 NSString* subFolder = nil;
392 NSString* subFolderPath = nil;
393 NSArray* fileList = nil;
394 NSString* fileName = nil;
395
396 // search each subfolder for files
397 foreach (subFolder, folders) {
398 subFolderPath = [path stringByAppendingPathComponent:subFolder];
399 fileList = [fmgr oo_directoryContentsAtPath:subFolderPath];
400 foreach (fileName, fileList) {
401 [self preloadFilePathFor:fileName inFolder:subFolder atPath:[subFolderPath stringByAppendingPathComponent:fileName]];
402 }
403 }
404}

References nil, and preloadFilePathFor:inFolder:atPath:.

Referenced by preloadFileLists.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ preloadFileListFromOXZ:forFolders:

+ (void) preloadFileListFromOXZ: (NSString*) path
forFolders: (NSArray*) folders 
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 349 of file ResourceManager.m.

349 :(NSString*)path forFolders:(NSArray*)folders
350{
351 unzFile uf = NULL;
352 const char* zipname = [path UTF8String];
353 char componentName[512];
354
355 if (zipname != NULL) {
356 uf = unzOpen64(zipname);
357 }
358 if (uf == NULL) {
359 OOLog(@"resourceManager.error", @"Could not open .oxz at %@ as zip file", path);
360 return;
361 }
362 if (unzGoToFirstFile(uf) == UNZ_OK) {
363 do {
365 componentName, 512,
366 NULL, 0,
367 NULL, 0);
368 NSString* zipEntry = [NSString stringWithUTF8String:componentName];
369 NSArray* pathBits = [zipEntry pathComponents];
370 if ([pathBits count] >= 2) {
371 NSString* folder = [pathBits oo_stringAtIndex:0];
372 if ([folders containsObject:folder]) {
373 NSRange bitRange;
374 bitRange.location = 1;
375 bitRange.length = [pathBits count] - 1;
376 NSString* file = [NSString pathWithComponents:[pathBits subarrayWithRange:bitRange]];
377 NSString* fullPath = [[path stringByAppendingPathComponent:folder] stringByAppendingPathComponent:file];
378
379 [self preloadFilePathFor:file inFolder:folder atPath:fullPath];
380 }
381 }
382
383 } while (unzGoToNextFile(uf) == UNZ_OK);
384 }
385 unzClose(uf);
386}
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:1058
int ZEXPORT unzGoToFirstFile(unzFile file)
Definition unzip.c:1109
unzFile ZEXPORT unzOpen64(const void *path)
Definition unzip.c:758
int ZEXPORT unzGoToNextFile(unzFile file)
Definition unzip.c:1130
int ZEXPORT unzClose(unzFile file)
Definition unzip.c:768
voidp unzFile
Definition unzip.h:72
#define UNZ_OK
Definition unzip.h:75

References count, OOLog, preloadFilePathFor:inFolder:atPath:, UNZ_OK, unzClose(), unzGetCurrentFileInfo64(), unzGoToFirstFile(), unzGoToNextFile(), and unzOpen64().

Referenced by preloadFileLists.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ preloadFileLists

+ (void) preloadFileLists
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 332 of file ResourceManager.m.

333{
334 NSString* path = nil;
335 NSEnumerator* pathEnum = nil;
336
337 // folders which may contain files to be cached
338 NSArray* folders = [NSArray arrayWithObjects:@"AIs", @"Images", @"Models", @"Music", @"Scenarios", @"Scripts", @"Shaders", @"Sounds", @"Textures", nil];
339
340 for (pathEnum = [[ResourceManager paths] reverseObjectEnumerator]; (path = [pathEnum nextObject]);) {
341 if ([path hasSuffix:@".oxz"]) {
342 [self preloadFileListFromOXZ:path forFolders:folders];
343 } else {
344 [self preloadFileListFromFolder:path forFolders:folders];
345 }
346 }
347}

References nil, paths, preloadFileListFromFolder:forFolders:, preloadFileListFromOXZ:forFolders:, and preloadFileLists.

Referenced by preloadFileLists, and setUseAddOns:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ preloadFilePathFor:inFolder:atPath:

+ (void) preloadFilePathFor: (NSString*) fileName
inFolder: (NSString*) subFolder
atPath: (NSString*) path 
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 406 of file ResourceManager.m.

406 :(NSString*)fileName inFolder:(NSString*)subFolder atPath:(NSString*)path
407{
408 OOCacheManager* cache = [OOCacheManager sharedCache];
409 NSString* cacheKey = [NSString stringWithFormat:@"%@/%@", subFolder, fileName];
410 NSString* result = [cache objectForKey:cacheKey inCache:@"resolved paths"];
411 // if nil, not found in another OXP already
412 if (result == nil) {
413 OOLog(@"resourceManager.foundFile.preLoad", @"Found %@/%@ at %@", subFolder, fileName, path);
414 [cache setObject:path forKey:cacheKey inCache:@"resolved paths"];
415 }
416}

References nil, OOCacheManager::objectForKey:inCache:, OOLog, OOCacheManager::setObject:forKey:inCache:, and OOCacheManager::sharedCache.

Referenced by preloadFileListFromFolder:forFolders:, and preloadFileListFromOXZ:forFolders:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset

+ (void) reset

Definition at line 102 of file ResourceManager.m.

103{
104 sFirstRun = YES;
112}
static NSMutableDictionary * sOXPManifests
static BOOL sFirstRun

References DESTROY, reset, sErrors, sExternalPaths, sFirstRun, sOXPManifests, sOXPsWithMessagesFound, sSearchPaths, sUseAddOns, and sUseAddOnsParts.

Referenced by OOOXZManager::isRestarting, reset, and setUseAddOns:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetManifestKnowledgeForOXZManager

+ (void) resetManifestKnowledgeForOXZManager

Definition at line 114 of file ResourceManager.m.

References DESTROY, pathsWithAddOns, resetManifestKnowledgeForOXZManager, sOXPManifests, sSearchPaths, sUseAddOns, and sUseAddOnsParts.

Referenced by OOOXZManager::managedOXZs, OOOXZManager(NSURLConnectionDataDelegate)::processDownloadedOXZ, and resetManifestKnowledgeForOXZManager.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ retrieveFileNamed:inFolder:cache:key:class:usePathCache:

+ (id) retrieveFileNamed: (NSString*) fileName
inFolder: (NSString*) folderName
cache: (NSMutableDictionary**) ioCache
key: (NSString*) key
class: (Class) class
usePathCache: (BOOL) useCache 
implementation

Definition at line 1743 of file ResourceManager.m.

1743 :(NSString*)fileName
1744 inFolder:(NSString*)folderName
1745 cache:(NSMutableDictionary**)ioCache
1746 key:(NSString*)key
1747 class:(Class)class
1748 usePathCache:(BOOL)useCache
1749{
1750 id result = nil;
1751 NSString* path = nil;
1752
1753 if (ioCache) {
1754 if (key == nil)
1755 key = [NSString stringWithFormat:@"%@:%@", folderName, fileName];
1756 if (*ioCache != nil) {
1757 // return the cached object, if any
1758 result = [*ioCache objectForKey:key];
1759 if (result)
1760 return result;
1761 }
1762 }
1763
1764 path = [self pathForFileNamed:fileName inFolder:folderName cache:useCache];
1765 if (path != nil)
1766 result = [[[class alloc] initWithContentsOfFile:path] autorelease];
1767
1768 if (result != nil && ioCache != NULL) {
1769 if (*ioCache == nil)
1770 *ioCache = [[NSMutableDictionary alloc] init];
1771 [*ioCache setObject:result forKey:key];
1772 }
1773
1774 return result;
1775}

References nil, and pathForFileNamed:inFolder:cache:.

Referenced by ooMusicNamed:inFolder:, and ooSoundNamed:inFolder:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reversePathEnumerator

+ (NSEnumerator *) reversePathEnumerator

Definition at line 512 of file ResourceManager.m.

513{
514 return [[self paths] reverseObjectEnumerator];
515}

References paths, and reversePathEnumerator.

Referenced by arrayFromFilesNamed:inFolder:andMerge:cache:, dictionaryFromFilesNamed:inFolder:mergeMode:cache:, and reversePathEnumerator.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ roleCategoriesDictionary

+ (NSDictionary *) roleCategoriesDictionary

Definition at line 1558 of file ResourceManager.m.

1559{
1560 NSMutableDictionary* roleCategories = [NSMutableDictionary dictionaryWithCapacity:16];
1561
1562 NSString* path = nil;
1563 NSString* configPath = nil;
1564 NSDictionary* categories = nil;
1565
1566 foreach (path, [self pathEnumerator]) {
1567 if ([ResourceManager corePlist:@"role-categories.plist" excludedAt:path]) {
1568 continue;
1569 }
1570
1571 configPath = [[path stringByAppendingPathComponent:@"Config"]
1572 stringByAppendingPathComponent:@"role-categories.plist"];
1573 categories = OODictionaryFromFile(configPath);
1574 if (categories != nil) {
1575 [ResourceManager mergeRoleCategories:categories intoDictionary:roleCategories];
1576 }
1577 }
1578
1579 /* If the old pirate-victim-roles files exist, merge them in */
1580 NSArray* pirateVictims = [ResourceManager arrayFromFilesNamed:@"pirate-victim-roles.plist" inFolder:@"Config" andMerge:YES];
1581 if (OOEnforceStandards() && [pirateVictims count] > 0) {
1582 OOStandardsDeprecated(@"pirate-victim-roles.plist is still being used.");
1583 }
1584 [ResourceManager mergeRoleCategories:[NSDictionary dictionaryWithObject:pirateVictims forKey:@"oolite-pirate-victim"] intoDictionary:roleCategories];
1585
1586 return [[roleCategories copy] autorelease];
1587}
void OOStandardsDeprecated(NSString *message)
NSArray * arrayFromFilesNamed:inFolder:andMerge:(NSString *fileName,[inFolder] NSString *folderName,[andMerge] BOOL mergeFiles)
void mergeRoleCategories:intoDictionary:(NSDictionary *catData, [intoDictionary] NSMutableDictionary *categories)

References arrayFromFilesNamed:inFolder:andMerge:, count, mergeRoleCategories:intoDictionary:, nil, OODictionaryFromFile(), OOEnforceStandards(), OOStandardsDeprecated(), pathEnumerator, and roleCategoriesDictionary.

Referenced by roleCategoriesDictionary, and Universe::setUpSettings.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rootPaths

+ (NSArray *) rootPaths

Definition at line 151 of file ResourceManager.m.

152{
153 static NSArray* sRootPaths = nil;
154 if (sRootPaths == nil) {
155 /* Built-in data, then managed OXZs, then manually installed ones,
156 * which may be useful for debugging/testing purposes. */
157 sRootPaths = [NSArray arrayWithObjects:[self builtInPath], [[OOOXZManager sharedManager] installPath], nil];
158 sRootPaths = [[sRootPaths arrayByAddingObjectsFromArray:[self userRootPaths]] retain];
159 }
160 return sRootPaths;
161}
NSString * installPath()
OOOXZManager * sharedManager()

References builtInPath, OOOXZManager::installPath, nil, rootPaths, OOOXZManager::sharedManager, and userRootPaths.

Referenced by logControlDictionary, pathsWithAddOns, and rootPaths.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUseAddOns:

+ (void) setUseAddOns: (NSString*) useAddOns

Definition at line 460 of file ResourceManager.m.

460 :(NSString*)useAddOns
461{
462 if (sFirstRun || ![useAddOns isEqualToString:sUseAddOns]) {
463 [self reset];
464 sFirstRun = NO;
467 sUseAddOns = [useAddOns retain];
468 sUseAddOnsParts = [[sUseAddOns componentsSeparatedByString:@";"] retain];
469
472
473 OOCacheManager* cmgr = [OOCacheManager sharedCache];
474 /* only allow cache writes for the "all OXPs" default
475 *
476 * cache should be less necessary for restricted sets anyway */
477 // testing the actual string here
478 if ([sUseAddOns isEqualToString:SCENARIO_OXP_DEFINITION_ALL]) {
479 [cmgr reloadAllCaches];
480 [cmgr setAllowCacheWrites:YES];
481 } else {
482 [cmgr clearAllCaches];
483 [cmgr setAllowCacheWrites:NO];
484 }
485
486 [self checkCacheUpToDateForPaths:[self paths]];
487 [self logPaths];
488 /* preloading the file lists at this stage helps efficiency a
489 * lot when many OXZs are installed */
490 [self preloadFileLists];
491 }
492}
void OOHUDResetTextEngine(void)
void setAllowCacheWrites:(BOOL flag)
NSString * useAddOns()

References checkCacheUpToDateForPaths:, OOCacheManager::clearAllCaches, clearCaches, DESTROY, logPaths, OOHUDResetTextEngine(), paths, preloadFileLists, OOCacheManager::reloadAllCaches, reset, SCENARIO_OXP_DEFINITION_ALL, OOCacheManager::setAllowCacheWrites:, sFirstRun, OOCacheManager::sharedCache, sUseAddOns, sUseAddOnsParts, and useAddOns.

Referenced by Universe::initWithGameView:, Universe::reinitAndShowDemo:, and OOOXPVerifier(OOPrivate)::run.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shaderBindingTypesDictionary

+ (NSDictionary *) shaderBindingTypesDictionary

Definition at line 1646 of file ResourceManager.m.

1647{
1649
1651 NSAutoreleasePool* pool = [NSAutoreleasePool new];
1652
1653 NSString* path = [[[ResourceManager builtInPath] stringByAppendingPathComponent:@"Config"] stringByAppendingPathComponent:@"shader-uniform-bindings.plist"];
1654 NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithContentsOfFile:path];
1655 NSArray* keys = [dict allKeys];
1656
1657 // Resolve all $inherit keys.
1658 unsigned changeCount = 0;
1659 do {
1660 changeCount = 0;
1661 NSString* key = nil;
1662 foreach (key, keys) {
1663 NSDictionary* value = [dict oo_dictionaryForKey:key];
1664 NSString* inheritKey = [value oo_stringForKey:@"$w2"];
1665 if (inheritKey != nil) {
1666 changeCount++;
1667 NSMutableDictionary* mutableValue = [[value mutableCopy] autorelease];
1668 [mutableValue removeObjectForKey:@"$w3"];
1669 NSDictionary* inherited = [dict oo_dictionaryForKey:inheritKey];
1670 if (inherited != nil) {
1671 [mutableValue addEntriesFromDictionary:inherited];
1672 }
1673
1674 [dict setObject:[[mutableValue copy] autorelease] forKey:key];
1675 }
1676 }
1677 } while (changeCount != 0);
1678
1679 shaderBindingTypesDictionary = [dict copy];
1680
1681 [pool release];
1682 }
1683
1685}
NSDictionary * shaderBindingTypesDictionary()

References builtInPath, nil, and shaderBindingTypesDictionary.

Referenced by shaderBindingTypesDictionary, and OODefaultShaderSynthesizer::writeLightMaps.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stringFromFilesNamed:inFolder:

+ (NSString *) stringFromFilesNamed: (NSString*) fileName
inFolder: (NSString*) folderName 

Definition at line 1797 of file ResourceManager.m.

1797 :(NSString*)fileName inFolder:(NSString*)folderName
1798{
1799 return [self stringFromFilesNamed:fileName inFolder:folderName cache:YES];
1800}

References stringFromFilesNamed:inFolder:cache:.

Referenced by GetShaderSource().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stringFromFilesNamed:inFolder:cache:

+ (NSString *) stringFromFilesNamed: (NSString*) fileName
inFolder: (NSString*) folderName
cache: (BOOL) useCache 

Definition at line 1802 of file ResourceManager.m.

1802 :(NSString*)fileName inFolder:(NSString*)folderName cache:(BOOL)useCache
1803{
1804 id result = nil;
1805 NSString* path = nil;
1806 NSString* key = nil;
1807
1808 if (useCache) {
1809 key = [NSString stringWithFormat:@"%@:%@", folderName, fileName];
1810 if (sStringCache != nil) {
1811 // return the cached object, if any
1812 result = [sStringCache objectForKey:key];
1813 if (result)
1814 return result;
1815 }
1816 }
1817
1818 path = [self pathForFileNamed:fileName inFolder:folderName cache:YES];
1819 if (path != nil)
1820 result = [NSString stringWithContentsOfUnicodeFile:path];
1821
1822 if (result != nil && useCache) {
1823 if (sStringCache == nil)
1824 sStringCache = [[NSMutableDictionary alloc] init];
1825 [sStringCache setObject:result forKey:key];
1826 }
1827
1828 return result;
1829}

References nil, pathForFileNamed:inFolder:cache:, and sStringCache.

Referenced by OOMesh(Private)::loadData:scaleFactor:, and stringFromFilesNamed:inFolder:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ systemDescriptionManager

+ (OOSystemDescriptionManager *) systemDescriptionManager

Definition at line 1607 of file ResourceManager.m.

1608{
1609 OOLog(@"resourceManager.planetinfo.load", @"%@", @"Initialising manager");
1610 OOSystemDescriptionManager* manager = [[OOSystemDescriptionManager alloc] init];
1611
1612 NSString* path = nil;
1613 NSString* configPath = nil;
1614 NSDictionary* categories = nil;
1615 NSString* systemKey = nil;
1616
1617 foreach (path, [self pathEnumerator]) {
1618 if ([ResourceManager corePlist:@"planetinfo.plist" excludedAt:path]) {
1619 continue;
1620 }
1621 configPath = [[path stringByAppendingPathComponent:@"Config"]
1622 stringByAppendingPathComponent:@"planetinfo.plist"];
1623 categories = OODictionaryFromFile(configPath);
1624 if (categories != nil) {
1625 foreachkey(systemKey, categories)
1626 {
1627 NSDictionary* values = [categories oo_dictionaryForKey:systemKey defaultValue:nil];
1628 if (values != nil) {
1629 if ([systemKey isEqualToString:PLANETINFO_UNIVERSAL_KEY]) {
1630 [manager setUniversalProperties:values];
1631 } else if ([systemKey isEqualToString:PLANETINFO_INTERSTELLAR_KEY]) {
1632 [manager setInterstellarProperties:values];
1633 } else {
1634 [manager setProperties:values forSystemKey:systemKey];
1635 }
1636 }
1637 }
1638 }
1639 }
1640 OOLog(@"resourceManager.planetinfo.load", @"%@", @"Caching routes");
1641 [manager buildRouteCache];
1642 OOLog(@"resourceManager.planetinfo.load", @"%@", @"Initialised manager");
1643 return [manager autorelease];
1644}
#define PLANETINFO_UNIVERSAL_KEY
Definition Universe.h:145
#define PLANETINFO_INTERSTELLAR_KEY
Definition Universe.h:146
void setUniversalProperties:(NSDictionary *properties)
void setProperties:forSystemKey:(NSDictionary *properties,[forSystemKey] NSString *key)
void setInterstellarProperties:(NSDictionary *properties)

References OOSystemDescriptionManager::buildRouteCache, foreachkey, nil, OODictionaryFromFile(), OOLog, pathEnumerator, PLANETINFO_INTERSTELLAR_KEY, PLANETINFO_UNIVERSAL_KEY, OOSystemDescriptionManager::setInterstellarProperties:, OOSystemDescriptionManager::setProperties:forSystemKey:, OOSystemDescriptionManager::setUniversalProperties:, and systemDescriptionManager.

Referenced by Universe::setUpSettings, and systemDescriptionManager.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useAddOns

+ (NSString *) useAddOns

Definition at line 455 of file ResourceManager.m.

456{
457 return sUseAddOns;
458}

References sUseAddOns, and useAddOns.

Referenced by setUseAddOns:, useAddOns, and GameController::validateMenuItem:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ userRootPaths

+ (NSArray *) userRootPaths

Definition at line 163 of file ResourceManager.m.

164{
165 static NSArray* sUserRootPaths = nil;
166
167 if (sUserRootPaths == nil) {
168 NSString* cwd = [[NSFileManager defaultManager] currentDirectoryPath];
169 // the paths are now in order of preference as per yesterday's talk. -- Kaks 2010-05-05
170 NSArray* defaultAddOnsPaths = [NSArray arrayWithObjects:
171#if OOLITE_MAC_OS_X
172 [[[[NSHomeDirectory() stringByAppendingPathComponent:@"Library"]
173 stringByAppendingPathComponent:@"Application Support"]
174 stringByAppendingPathComponent:@"Oolite"]
175 stringByAppendingPathComponent:@"AddOns"],
176 [[[[NSBundle mainBundle] bundlePath]
177 stringByDeletingLastPathComponent]
178 stringByAppendingPathComponent:@"AddOns"],
179#else
180 [[cwd stringByDeletingLastPathComponent]
181 stringByAppendingPathComponent:@"share/oolite/AddOns"],
182#endif
183 [cwd stringByAppendingPathComponent:@"AddOns"],
185 nil];
186 sUserRootPaths = [[[[OOOXZManager sharedManager] additionalAddOnsPaths] arrayByAddingObjectsFromArray:defaultAddOnsPaths] retain];
187 }
188 OOLog(@"searchPaths.debug", @"%@", sUserRootPaths);
189 return sUserRootPaths;
190}
NSString * extractAddOnsPath()
NSArray * additionalAddOnsPaths()

References OOOXZManager::additionalAddOnsPaths, OOOXZManager::extractAddOnsPath, nil, OOLog, OOOXZManager::sharedManager, and userRootPaths.

Referenced by OOOXZManager(NSURLConnectionDataDelegate)::extractionBasePathForIdentifier:andVersion:, rootPaths, GameController::showAddOnsAction:, and userRootPaths.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateManifest:forOXP:

+ (BOOL) validateManifest: (NSDictionary*) manifest
forOXP: (NSString*) path 
implementation

Provided by category ResourceManager(OOPrivate).

Definition at line 590 of file ResourceManager.m.

590 :(NSDictionary*)manifest forOXP:(NSString*)path
591{
592 if (EXPECT_NOT(sOXPManifests == nil)) {
593 sOXPManifests = [[NSMutableDictionary alloc] initWithCapacity:32];
594 }
595
596 BOOL OK = YES;
597 NSString* identifier = [manifest oo_stringForKey:kOOManifestIdentifier defaultValue:nil];
598 NSString* version = [manifest oo_stringForKey:kOOManifestVersion defaultValue:nil];
599 NSString* required = [manifest oo_stringForKey:kOOManifestRequiredOoliteVersion defaultValue:nil];
600 NSString* title = [manifest oo_stringForKey:kOOManifestTitle defaultValue:nil];
601
602 if (identifier == nil) {
603 OOLog(@"oxp.noManifest", @"OXZ %@ manifest.plist has no '%@' field.", path, kOOManifestIdentifier);
604 [self addErrorWithKey:@"oxp-manifest-incomplete" param1:title param2:kOOManifestIdentifier];
605 OK = NO;
606 }
607 if (version == nil) {
608 OOLog(@"oxp.noManifest", @"OXZ %@ manifest.plist has no '%@' field.", path, kOOManifestVersion);
609 [self addErrorWithKey:@"oxp-manifest-incomplete" param1:title param2:kOOManifestVersion];
610 OK = NO;
611 }
612 if (required == nil) {
613 OOLog(@"oxp.noManifest", @"OXZ %@ manifest.plist has no '%@' field.", path, kOOManifestRequiredOoliteVersion);
614 [self addErrorWithKey:@"oxp-manifest-incomplete" param1:title param2:kOOManifestRequiredOoliteVersion];
615 OK = NO;
616 }
617 if (title == nil) {
618 OOLog(@"oxp.noManifest", @"OXZ %@ manifest.plist has no '%@' field.", path, kOOManifestTitle);
619 [self addErrorWithKey:@"oxp-manifest-incomplete" param1:title param2:kOOManifestTitle];
620 OK = NO;
621 }
622 if (!OK) {
623 return NO;
624 }
625 OK = [self checkVersionCompatibility:manifest forOXP:title];
626
627 if (!OK) {
628 NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
629 OOLog(@"oxp.versionMismatch", @"OXP %@ is incompatible with version %@ of Oolite.", path, version);
630 [self addErrorWithKey:@"oxp-is-incompatible" param1:[path lastPathComponent] param2:version];
631 return NO;
632 }
633
634 NSDictionary* duplicate = [sOXPManifests objectForKey:identifier];
635 if (duplicate != nil) {
636 OOLog(@"oxp.duplicate", @"OXP %@ has the same identifier (%@) as %@ which has already been loaded.", path, identifier, [duplicate oo_stringForKey:kOOManifestFilePath]);
637 [self addErrorWithKey:@"oxp-manifest-duplicate" param1:path param2:[duplicate oo_stringForKey:kOOManifestFilePath]];
638 return NO;
639 }
640 NSMutableDictionary* mData = [NSMutableDictionary dictionaryWithDictionary:manifest];
641 [mData setObject:path forKey:kOOManifestFilePath];
642 // add an extra key
643 [sOXPManifests setObject:mData forKey:identifier];
644 return YES;
645}
static NSString *const kOOManifestRequiredOoliteVersion
static NSString *const kOOManifestTitle

References addErrorWithKey:param1:param2:, checkVersionCompatibility:forOXP:, EXPECT_NOT, kOOManifestFilePath, kOOManifestIdentifier, kOOManifestRequiredOoliteVersion, kOOManifestTitle, kOOManifestVersion, nil, OOLog, and sOXPManifests.

Referenced by checkPotentialPath:searchPaths:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ whitelistDictionary

+ (NSDictionary *) whitelistDictionary

Definition at line 1466 of file ResourceManager.m.

1467{
1468 static id whitelistDictionary = nil;
1469
1470 if (whitelistDictionary == nil) {
1471 NSString* path = [[[ResourceManager builtInPath] stringByAppendingPathComponent:@"Config"] stringByAppendingPathComponent:@"whitelist.plist"];
1472 whitelistDictionary = [NSDictionary dictionaryWithContentsOfFile:path];
1473 if (whitelistDictionary == nil)
1474 whitelistDictionary = [NSNull null];
1475
1476 [whitelistDictionary retain];
1477 }
1478
1479 if (whitelistDictionary == [NSNull null])
1480 return nil;
1481 return whitelistDictionary;
1482}
NSDictionary * whitelistDictionary()

References builtInPath, nil, and whitelistDictionary.

Referenced by HeadUpDisplay::addDial:, AI(OOPrivate)::cleanActions:forHandler:state:stateMachine:, LookUpLegacySelector(), OOUniformBindingPermitted(), OOAIStateMachineVerifierStage::run, SanitizeActionMethod(), SanitizeQueryMethod(), and whitelistDictionary.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeDiagnosticData:toFileNamed:

+ (BOOL) writeDiagnosticData: (NSData*) data
toFileNamed: (NSString*) name 

Definition at line 1898 of file ResourceManager.m.

1898 :(NSData*)data toFileNamed:(NSString*)name
1899{
1900 if (data == nil || name == nil)
1901 return NO;
1902
1903 NSString* directory = [self diagnosticFileLocation];
1904 if (directory == nil)
1905 return NO;
1906
1907 NSArray* nameComponents = [name componentsSeparatedByString:@"/"];
1908 NSUInteger count = [nameComponents count];
1909 if (count > 1) {
1910 name = [nameComponents lastObject];
1911
1912 for (NSUInteger i = 0; i < count - 1; i++) {
1913 NSString* component = [nameComponents objectAtIndex:i];
1914 if ([component hasPrefix:@"."]) {
1915 component = [@"!" stringByAppendingString:[component substringFromIndex:1]];
1916 }
1917 directory = [directory stringByAppendingPathComponent:component];
1918 [[NSFileManager defaultManager] oo_createDirectoryAtPath:directory attributes:nil];
1919 }
1920 }
1921
1922 return [data writeToFile:[directory stringByAppendingPathComponent:name] atomically:YES];
1923}

References count, diagnosticFileLocation, and nil.

Referenced by writeDiagnosticPList:toFileNamed:, and writeDiagnosticString:toFileNamed:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeDiagnosticPList:toFileNamed:

+ (BOOL) writeDiagnosticPList: (id) plist
toFileNamed: (NSString*) name 

Definition at line 1930 of file ResourceManager.m.

1930 :(id)plist toFileNamed:(NSString*)name
1931{
1932 NSData* data = [plist oldSchoolPListFormatWithErrorDescription:NULL];
1933 if (data == nil)
1934 [NSPropertyListSerialization dataFromPropertyList:plist format:NSPropertyListXMLFormat_v1_0 errorDescription:NULL];
1935 if (data == nil)
1936 return NO;
1937
1938 return [self writeDiagnosticData:data toFileNamed:name];
1939}

References nil, and writeDiagnosticData:toFileNamed:.

Here is the call graph for this function:

◆ writeDiagnosticString:toFileNamed:

+ (BOOL) writeDiagnosticString: (NSString*) string
toFileNamed: (NSString*) name 

Definition at line 1925 of file ResourceManager.m.

1925 :(NSString*)string toFileNamed:(NSString*)name
1926{
1927 return [self writeDiagnosticData:[string dataUsingEncoding:NSUTF8StringEncoding] toFileNamed:name];
1928}

References writeDiagnosticData:toFileNamed:.

Referenced by OOOXPVerifier(OOPrivate)::dumpDebugGraphviz, and SVGDumpEnd().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: