Oolite
Loading...
Searching...
No Matches
NSBundle+Override.m
Go to the documentation of this file.
1/*
2 * NSBundle+Override.m
3 *
4 * Oolite Core Framework Override
5 * Bypasses standard plist loading to manually locate and parse info-gnustep.plist
6 * across Windows and Linux environments safely at boot.
7 */
8
10#import <Foundation/NSDictionary.h>
11#import <Foundation/NSFileManager.h>
12#import <Foundation/NSPathUtilities.h>
13
14#ifdef __clang__
15#pragma clang diagnostic push
16#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
17#endif
18@implementation NSBundle (Override)
19
20- (NSDictionary*)infoDictionary
21{
22 NSFileManager* fileManager = [NSFileManager defaultManager];
23 NSString* startingDir = [fileManager currentDirectoryPath]; // Start from cwd
24
25 NSString* primaryResourcesPath = [startingDir stringByAppendingPathComponent:@"Resources"];
26 BOOL isDir = NO;
27
28 NSString* resourcesFolder = nil;
29 if ([fileManager fileExistsAtPath:primaryResourcesPath isDirectory:&isDir] && isDir) {
30 resourcesFolder = primaryResourcesPath;
31 } else {
32 // Fallback: Look in startingDir / ../share/oolite/Resources (Standard Linux system layout)
33 NSString* fallbackPath = [[startingDir stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"share/oolite/Resources"];
34 resourcesFolder = [fallbackPath stringByStandardizingPath];
35 }
36
37 // Append the target file name to the resolved path root
38 NSString* plistPath = [resourcesFolder stringByAppendingPathComponent:@"Info-gnustep.plist"];
39
40 // Load the target configuration file
41 NSDictionary* gnustepPlist = [NSDictionary dictionaryWithContentsOfFile:plistPath];
42 NSMutableDictionary* workingDict = nil;
43
44 if (gnustepPlist) {
45 workingDict = [gnustepPlist mutableCopy];
46 } else {
47 // Fallback block prevents runtime crashes if files are missing during dev/build refactors
48 workingDict = [[NSMutableDictionary alloc] init];
49 NSLog(@"[Oolite-Core] Warning: Failed to find info-gnustep.plist at calculated path: %@", plistPath);
50 }
51
52 // Return the dictionary cleanly managed for memory
53 return [workingDict autorelease];
54}
55
56@end
57#ifdef __clang__
58#pragma clang diagnostic pop
59#endif
#define NSLog(format,...)
Definition OOLogging.h:148
return nil
NSDictionary * infoDictionary()