2007-01-01 21:11:21 +00:00
|
|
|
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
|
2009-05-19 17:19:53 +00:00
|
|
|
2009 Markus Hitter (mah@jump-ing.de)
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
#import <Foundation/NSArray.h>
|
2006-12-22 04:41:44 +00:00
|
|
|
#import <Foundation/NSBundle.h>
|
2020-05-11 15:52:05 +00:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSError.h>
|
|
|
|
#import <Foundation/NSFileManager.h>
|
2008-02-08 03:51:09 +00:00
|
|
|
#import <Foundation/NSLocale.h>
|
2006-12-22 04:41:44 +00:00
|
|
|
#import <Foundation/NSMapTable.h>
|
|
|
|
#import <Foundation/NSPathUtilities.h>
|
2020-05-11 15:52:05 +00:00
|
|
|
#import <Foundation/NSPlatform.h>
|
2006-12-22 04:41:44 +00:00
|
|
|
#import <Foundation/NSProcessInfo.h>
|
|
|
|
#import <Foundation/NSRaise.h>
|
2020-05-11 15:52:05 +00:00
|
|
|
#import <Foundation/NSRaiseException.h>
|
2012-06-26 16:29:01 +00:00
|
|
|
#import <Foundation/NSString.h>
|
2014-02-21 18:47:44 +00:00
|
|
|
#import <Foundation/NSURL.h>
|
2013-09-23 20:11:03 +00:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2009-04-07 00:17:26 +00:00
|
|
|
#import <objc/runtime.h>
|
2015-05-01 02:32:28 +00:00
|
|
|
#if defined(__APPLE__)
|
2020-05-11 15:52:05 +00:00
|
|
|
#import "OBJCRegisterModule_Darwin.h"
|
2010-12-17 10:10:14 +00:00
|
|
|
#endif
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2010-03-18 01:22:56 +00:00
|
|
|
#import <objc/objc.h>
|
2012-01-13 11:27:09 +00:00
|
|
|
#include <stdio.h>
|
2010-03-18 01:22:56 +00:00
|
|
|
|
|
|
|
typedef void *NSModuleHandle;
|
|
|
|
|
2012-06-26 16:29:01 +00:00
|
|
|
OBJC_EXPORT NSModuleHandle NSLoadModule(const char *path, NSError **error);
|
2010-03-18 01:22:56 +00:00
|
|
|
OBJC_EXPORT BOOL NSUnloadModule(NSModuleHandle handle);
|
|
|
|
OBJC_EXPORT const char *NSLastModuleError(void);
|
|
|
|
OBJC_EXPORT void *NSSymbolInModule(NSModuleHandle handle, const char *symbol);
|
|
|
|
|
|
|
|
#ifdef WIN32
|
2012-01-13 11:27:09 +00:00
|
|
|
#include <windows.h>
|
2010-03-18 01:22:56 +00:00
|
|
|
#else
|
2012-01-13 11:27:09 +00:00
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <stdlib.h>
|
2020-05-11 15:52:05 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <sys/param.h>
|
2012-01-13 11:27:09 +00:00
|
|
|
#include <unistd.h>
|
2010-03-18 01:22:56 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-31 04:53:55 +00:00
|
|
|
#import <objc/dyld.h>
|
2012-01-13 11:32:20 +00:00
|
|
|
|
|
|
|
#if defined(GCC_RUNTIME_3) || defined(APPLE_RUNTIME_4)
|
|
|
|
|
2015-05-31 04:53:55 +00:00
|
|
|
#if defined(LINUX)
|
2012-01-13 11:32:20 +00:00
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
static inline unsigned int processMaps(char *maps, const char **soNames) {
|
2012-01-13 11:32:20 +00:00
|
|
|
unsigned int count = 0;
|
|
|
|
char *cur = maps;
|
|
|
|
char *eod = maps + strlen(maps);
|
|
|
|
char *lastName = NULL;
|
|
|
|
size_t lastNameLength = 0;
|
|
|
|
do {
|
|
|
|
char *eol = strchr(cur, '\n');
|
|
|
|
if (!eol) {
|
|
|
|
eol = eod;
|
|
|
|
}
|
|
|
|
*eol = 0;
|
|
|
|
char *name = strrchr(cur, ' ');
|
|
|
|
if (name) {
|
|
|
|
name++;
|
|
|
|
} else {
|
|
|
|
name = cur;
|
|
|
|
}
|
|
|
|
int nameLength = eol - name;
|
2020-05-11 15:52:05 +00:00
|
|
|
if (name && nameLength > 2 &&
|
|
|
|
(strcmp(eol - 3, ".so") == 0 || strstr(name, ".so.")) &&
|
|
|
|
(lastName == NULL || lastNameLength != nameLength ||
|
|
|
|
strncmp(lastName, name, lastNameLength) != 0)) {
|
2012-01-13 11:32:20 +00:00
|
|
|
lastName = name;
|
|
|
|
lastNameLength = nameLength;
|
|
|
|
if (soNames) {
|
|
|
|
soNames[count] = name;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (!soNames) {
|
|
|
|
*eol = '\n';
|
|
|
|
}
|
|
|
|
cur = eol + 1;
|
|
|
|
} while (cur < eod);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
static const char **objc_copyImageNames(unsigned int *count) {
|
2012-01-13 11:32:20 +00:00
|
|
|
*count = 0;
|
|
|
|
FILE *f = fopen("/proc/self/maps", "r");
|
|
|
|
if (f) {
|
|
|
|
#define SLICE_LENGTH 0xFFFE
|
|
|
|
long length = 0;
|
|
|
|
long pos = 0;
|
|
|
|
long lastSlice = 0;
|
|
|
|
char *maps = NULL;
|
|
|
|
|
|
|
|
do {
|
|
|
|
pos = length;
|
|
|
|
length += SLICE_LENGTH;
|
|
|
|
maps = realloc(maps, length + 1);
|
2020-05-11 15:52:05 +00:00
|
|
|
} while ((lastSlice = fread(maps + pos, 1, SLICE_LENGTH, f)) ==
|
|
|
|
SLICE_LENGTH);
|
2012-01-13 11:32:20 +00:00
|
|
|
maps[pos + lastSlice] = 0;
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
*count = processMaps(maps, NULL);
|
|
|
|
if (*count > 0) {
|
2020-05-11 15:52:05 +00:00
|
|
|
int namesSize = (*count + 1) * sizeof(char *);
|
2012-01-13 11:32:20 +00:00
|
|
|
void *mem = calloc(1, namesSize + length + 1);
|
|
|
|
const char **names = mem;
|
|
|
|
char *newMaps = mem + namesSize;
|
|
|
|
memcpy(newMaps, maps, length + 1);
|
|
|
|
if (names != NULL) {
|
|
|
|
processMaps(newMaps, names);
|
|
|
|
return names;
|
|
|
|
} else {
|
|
|
|
*count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(maps);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
#endif // LINUX
|
|
|
|
#endif // GCC_RUNTIME_3 || APPLE_RUNTIME_4
|
2012-01-13 11:32:20 +00:00
|
|
|
|
2010-03-18 01:22:56 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
|
|
|
|
static char *lastErrorString(DWORD error) {
|
|
|
|
LPVOID lpMsgBuf;
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
2020-05-12 18:51:39 +00:00
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
2020-05-11 15:52:05 +00:00
|
|
|
NULL, error,
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
|
|
|
(LPTSTR) &lpMsgBuf, 0, NULL);
|
2010-03-18 01:22:56 +00:00
|
|
|
|
|
|
|
return lpMsgBuf;
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
void OBJCRaiseWin32Failure(const char *name, const char *format, ...) {
|
|
|
|
DWORD lastError = GetLastError();
|
|
|
|
va_list arguments;
|
2010-03-18 01:22:56 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
va_start(arguments, format);
|
2010-03-18 01:22:56 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
fprintf(stderr, "ObjC:Win32:%ld,%s:", lastError, name);
|
|
|
|
vfprintf(stderr, format, arguments);
|
|
|
|
fprintf(stderr, "...\n");
|
|
|
|
fflush(stderr);
|
2010-03-18 01:22:56 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
fprintf(stderr, "ObjC:Win32: ... %s\n", lastErrorString(lastError));
|
|
|
|
fflush(stderr);
|
|
|
|
va_end(arguments);
|
2010-03-18 01:22:56 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
// only frameworks need to call this from DllMain, NSLoadModule will do it for
|
|
|
|
// loaded object files (i.e. bundles)
|
|
|
|
int OBJCRegisterDLL(HINSTANCE handle) {
|
|
|
|
int i, bufferCapacity = 32767;
|
|
|
|
uint16_t buffer[bufferCapacity + 1];
|
|
|
|
DWORD bufferSize = GetModuleFileNameW(handle, buffer, bufferCapacity);
|
2010-03-18 01:22:56 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (bufferSize == 0) {
|
|
|
|
OBJCRaiseWin32Failure("OBJCModuleFailed",
|
|
|
|
"OBJCInitializeModule, GetModuleFileName failed");
|
|
|
|
return 1;
|
|
|
|
}
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
for (i = 0; i < bufferSize; i++)
|
|
|
|
if (buffer[i] == '\\')
|
|
|
|
buffer[i] = '/';
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
int size = WideCharToMultiByte(CP_UTF8, 0, buffer, bufferSize, NULL, 0,
|
|
|
|
NULL, NULL);
|
|
|
|
char path[size + 1];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
size = WideCharToMultiByte(CP_UTF8, 0, buffer, bufferSize, path, size, NULL,
|
|
|
|
NULL);
|
|
|
|
path[size] = '\0';
|
2010-10-29 03:03:10 +00:00
|
|
|
|
2010-03-18 01:22:56 +00:00
|
|
|
OBJCLinkQueuedModulesToObjectFileWithPath(path);
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return 1;
|
2010-03-18 01:22:56 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 16:29:01 +00:00
|
|
|
NSModuleHandle NSLoadModule(const char *path, NSError **error) {
|
2020-05-11 15:52:05 +00:00
|
|
|
NSModuleHandle handle;
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
OBJCResetModuleQueue();
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
handle = LoadLibrary(path);
|
2010-03-18 01:22:56 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (handle != NULL) {
|
2012-06-26 16:29:01 +00:00
|
|
|
OBJCRegisterDLL(handle);
|
2020-05-11 15:52:05 +00:00
|
|
|
} else {
|
2012-06-26 16:29:01 +00:00
|
|
|
if (error != NULL) {
|
2020-05-11 15:52:05 +00:00
|
|
|
*error = [NSError errorWithDomain: NSWin32ErrorDomain
|
|
|
|
code: GetLastError()
|
|
|
|
userInfo: nil];
|
2012-06-26 16:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return handle;
|
2010-03-18 01:22:56 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
2012-06-26 16:29:01 +00:00
|
|
|
NSModuleHandle NSLoadModule(const char *path, NSError **error) {
|
2020-05-11 15:52:05 +00:00
|
|
|
NSModuleHandle handle;
|
2010-03-18 01:22:56 +00:00
|
|
|
|
2012-03-07 07:59:37 +00:00
|
|
|
// dlopen doesn't accept partial paths.
|
|
|
|
if (path[0] != '/' && path[0] != '.') {
|
|
|
|
char buf[MAXPATHLEN];
|
2010-03-18 01:22:56 +00:00
|
|
|
|
2012-03-07 07:59:37 +00:00
|
|
|
if (getcwd(buf, MAXPATHLEN) != NULL) {
|
2012-03-07 08:06:16 +00:00
|
|
|
if (strlen(buf) < MAXPATHLEN - (1 + strlen(path))) {
|
|
|
|
strncat(buf, "/", 1);
|
|
|
|
strncat(buf, path, MAXPATHLEN - (1 + strlen(buf)));
|
|
|
|
path = buf;
|
|
|
|
} else {
|
2020-05-11 15:52:05 +00:00
|
|
|
NSCLog("NSLoadModule: resulting path '%s/%s' exceeds "
|
|
|
|
"MAXPATHLEN (%d)",
|
|
|
|
buf, path, MAXPATHLEN);
|
2012-03-07 08:06:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-03-07 07:59:37 +00:00
|
|
|
} else {
|
2020-05-11 15:52:05 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
*error = [NSError
|
2020-05-12 18:51:39 +00:00
|
|
|
errorWithDomain: NSPOSIXErrorDomain
|
|
|
|
code: 0
|
|
|
|
userInfo:
|
|
|
|
[NSDictionary
|
|
|
|
dictionaryWithObject:
|
|
|
|
@"NSLoadModule: cannot "
|
|
|
|
@"find cwd and "
|
|
|
|
@"relative path "
|
|
|
|
@"specified"
|
|
|
|
forKey: NSLocalizedDescriptionKey]];
|
2020-05-11 15:52:05 +00:00
|
|
|
}
|
2012-03-07 07:59:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2010-03-18 01:22:56 +00:00
|
|
|
|
2012-03-07 07:59:37 +00:00
|
|
|
handle = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
|
|
|
|
if (handle == NULL) {
|
2020-05-11 15:52:05 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
*error = [NSError
|
2020-05-12 18:51:39 +00:00
|
|
|
errorWithDomain: NSPOSIXErrorDomain
|
|
|
|
code: 0
|
|
|
|
userInfo:
|
|
|
|
[NSDictionary
|
|
|
|
dictionaryWithObject:
|
|
|
|
[NSString
|
|
|
|
stringWithFormat:
|
|
|
|
@"%s",
|
|
|
|
NSLastModuleError()]
|
|
|
|
forKey: NSLocalizedDescriptionKey]];
|
2020-05-11 15:52:05 +00:00
|
|
|
}
|
2012-03-07 07:59:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
#ifdef __APPLE__
|
2010-12-17 10:10:14 +00:00
|
|
|
OBJCRegisterModule_Darwin(path);
|
|
|
|
#endif
|
2010-03-18 01:22:56 +00:00
|
|
|
|
2012-03-07 07:59:37 +00:00
|
|
|
return handle;
|
2010-03-18 01:22:56 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BOOL NSUnloadModule(NSModuleHandle handle) {
|
|
|
|
#ifdef WIN32
|
2020-05-11 15:52:05 +00:00
|
|
|
return NO;
|
2010-03-18 01:22:56 +00:00
|
|
|
#else
|
2020-05-11 15:52:05 +00:00
|
|
|
if (dlclose(handle))
|
|
|
|
return NO;
|
2010-03-18 01:22:56 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return YES;
|
2010-03-18 01:22:56 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *NSLastModuleError(void) {
|
|
|
|
#ifdef WIN32
|
2020-05-11 15:52:05 +00:00
|
|
|
return NULL;
|
2010-03-18 01:22:56 +00:00
|
|
|
#else
|
2020-05-11 15:52:05 +00:00
|
|
|
return dlerror();
|
2010-03-18 01:22:56 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void *NSSymbolInModule(NSModuleHandle handle, const char *symbol) {
|
|
|
|
#ifdef WIN32
|
2020-05-11 15:52:05 +00:00
|
|
|
return NULL;
|
2010-03-18 01:22:56 +00:00
|
|
|
#else
|
2020-05-11 15:52:05 +00:00
|
|
|
return dlsym(handle, symbol);
|
2010-03-18 01:22:56 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *const NSBundleDidLoadNotification = @"NSBundleDidLoadNotification";
|
|
|
|
NSString *const NSLoadedClasses = @"NSLoadedClasses";
|
2006-12-22 04:41:44 +00:00
|
|
|
|
|
|
|
@implementation NSBundle
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
static NSMutableArray *_allBundles = nil;
|
|
|
|
static NSMutableArray *_allFrameworks = nil;
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
static NSBundle *mainBundle = nil;
|
|
|
|
static NSMapTable *nameToBundle = NULL;
|
|
|
|
static NSMapTable *pathToObject = NULL;
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (void) _setLoaded: (BOOL) loaded {
|
|
|
|
_isLoaded = loaded;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Executables support:
|
|
|
|
MyProgram.app/Contents/<platform>/MyProgram[.exe]
|
|
|
|
or
|
2012-01-13 11:29:24 +00:00
|
|
|
MyProgram[.exe]
|
|
|
|
MyProgram.app/Contents/
|
2012-06-26 16:29:01 +00:00
|
|
|
or
|
|
|
|
MyProgram.app/MyProgram[.exe]
|
|
|
|
[MyProgram.app/Resources]
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2006-12-22 04:41:44 +00:00
|
|
|
*/
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (NSString *) bundlePathFromModulePath: (NSString *) path {
|
2012-09-27 07:54:32 +00:00
|
|
|
path = [path stringByStandardizingPath];
|
|
|
|
|
2012-01-13 11:29:24 +00:00
|
|
|
NSString *result = nil;
|
|
|
|
NSString *directory = [path stringByDeletingLastPathComponent];
|
|
|
|
NSString *extension = [[path pathExtension] lowercaseString];
|
|
|
|
NSString *name = [[path lastPathComponent] stringByDeletingPathExtension];
|
2020-05-11 15:52:05 +00:00
|
|
|
NSRange version = [name rangeOfString: @"."];
|
2012-01-13 11:29:24 +00:00
|
|
|
|
|
|
|
if (version.location != NSNotFound) {
|
2020-05-11 15:52:05 +00:00
|
|
|
name = [name substringToIndex: version.location];
|
2012-01-13 11:29:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (![extension isEqualToString: NSPlatformLoadableObjectFileExtension]) {
|
2012-06-26 16:29:01 +00:00
|
|
|
// Support for MyProgram.app/MyProgram[.exe]
|
2020-05-11 15:52:05 +00:00
|
|
|
if ([[directory lastPathComponent]
|
2020-05-12 18:51:39 +00:00
|
|
|
isEqualToString: [NSString stringWithFormat: @"%@.app",
|
|
|
|
name]] ==
|
|
|
|
YES) {
|
2012-06-26 16:29:01 +00:00
|
|
|
return directory;
|
2020-05-11 15:52:05 +00:00
|
|
|
} else {
|
|
|
|
NSString *check = [[directory stringByAppendingPathComponent: name]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByAppendingPathExtension: @"app"];
|
2020-05-11 15:52:05 +00:00
|
|
|
|
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath: check]) {
|
2012-06-26 16:29:01 +00:00
|
|
|
result = check;
|
|
|
|
} else {
|
2020-05-11 15:52:05 +00:00
|
|
|
result = [[directory stringByDeletingLastPathComponent]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByDeletingLastPathComponent];
|
2012-06-26 16:29:01 +00:00
|
|
|
}
|
2012-01-13 11:29:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NSString *loadablePrefix = NSPlatformLoadableObjectFilePrefix;
|
|
|
|
NSString *check;
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if ([loadablePrefix length] > 0 && [name hasPrefix: loadablePrefix]) {
|
|
|
|
name = [name substringFromIndex: [loadablePrefix length]];
|
2012-01-13 11:29:24 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
|
|
|
|
if ([[directory lastPathComponent]
|
2020-05-12 18:51:39 +00:00
|
|
|
isEqualToString: [NSString stringWithFormat: @"%@.bundle",
|
|
|
|
name]] ==
|
|
|
|
YES) {
|
2012-06-26 16:29:01 +00:00
|
|
|
return directory;
|
2020-05-11 15:52:05 +00:00
|
|
|
} else {
|
|
|
|
check = [[directory stringByAppendingPathComponent: name]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByAppendingPathExtension: @"framework"];
|
2020-05-11 15:52:05 +00:00
|
|
|
|
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath: check]) {
|
2012-01-13 11:29:24 +00:00
|
|
|
result = check;
|
|
|
|
} else {
|
2020-05-11 15:52:05 +00:00
|
|
|
check = [[[directory stringByDeletingLastPathComponent]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByAppendingPathComponent: @"Frameworks"]
|
|
|
|
stringByAppendingPathComponent:
|
|
|
|
[name stringByAppendingPathExtension:
|
|
|
|
@"framework"]];
|
2020-05-11 15:52:05 +00:00
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath: check]) {
|
2012-06-26 16:29:01 +00:00
|
|
|
result = check;
|
|
|
|
} else {
|
2020-05-11 15:52:05 +00:00
|
|
|
result = [[directory stringByDeletingLastPathComponent]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByDeletingLastPathComponent];
|
2012-06-26 16:29:01 +00:00
|
|
|
}
|
2012-01-13 11:29:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (NSBundle *) bundleWithModulePath: (NSString *) path {
|
|
|
|
NSBundle *result;
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
path = [self bundlePathFromModulePath: path];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
result = [NSBundle bundleWithPath: path];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
[result _setLoaded: YES];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return result;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (void) registerFrameworks {
|
2012-01-13 11:32:20 +00:00
|
|
|
unsigned i, count;
|
2012-01-13 11:29:24 +00:00
|
|
|
const char **array = objc_copyImageNames(&count);
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2012-01-13 11:29:24 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *path = [NSString stringWithUTF8String: array[i]];
|
|
|
|
NSBundle *bundle = [NSBundle bundleWithModulePath: path];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
[_allFrameworks addObject: bundle];
|
2012-01-13 11:29:24 +00:00
|
|
|
}
|
|
|
|
free(array);
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (void) initialize {
|
2012-01-13 11:29:24 +00:00
|
|
|
if (self == [NSBundle class]) {
|
2012-03-06 15:04:58 +00:00
|
|
|
const char *module = getenv("CFProcessPath");
|
2012-01-13 11:32:20 +00:00
|
|
|
if (!module) {
|
|
|
|
#if defined(GCC_RUNTIME_3) || defined(APPLE_RUNTIME_4)
|
2012-04-18 15:23:37 +00:00
|
|
|
ssize_t bufSize = MAXPATHLEN;
|
2012-03-06 15:04:58 +00:00
|
|
|
char *executablePath = alloca(bufSize + 1);
|
|
|
|
if (_NSGetExecutablePath(executablePath, &bufSize) < 0) {
|
|
|
|
executablePath = alloca(bufSize + 1);
|
|
|
|
_NSGetExecutablePath(executablePath, &bufSize);
|
2012-01-13 11:32:20 +00:00
|
|
|
}
|
2012-03-06 15:04:58 +00:00
|
|
|
executablePath[bufSize] = 0;
|
2012-04-18 15:23:37 +00:00
|
|
|
module = executablePath;
|
2012-01-13 11:32:20 +00:00
|
|
|
#else
|
|
|
|
module = objc_mainImageName();
|
|
|
|
#endif
|
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *path = [NSString stringWithUTF8String: module];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2012-01-13 11:29:24 +00:00
|
|
|
if (module == NULL) {
|
|
|
|
NSCLog("+[NSBundle initialize]: module path for process is NULL");
|
|
|
|
}
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2012-01-13 11:29:24 +00:00
|
|
|
_allBundles = [NSMutableArray new];
|
|
|
|
_allFrameworks = [NSMutableArray new];
|
2020-05-11 15:52:05 +00:00
|
|
|
pathToObject = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 0);
|
|
|
|
nameToBundle = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 0);
|
2012-01-13 11:29:24 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
mainBundle = [NSBundle bundleWithModulePath: path];
|
2012-01-13 11:29:24 +00:00
|
|
|
|
|
|
|
[self registerFrameworks];
|
|
|
|
}
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (NSArray *) allBundles {
|
|
|
|
return _allBundles;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (NSArray *) allFrameworks {
|
|
|
|
return _allFrameworks;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (NSBundle *) mainBundle {
|
|
|
|
return mainBundle;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (NSBundle *) bundleForClass: (Class) class {
|
2012-01-13 11:29:24 +00:00
|
|
|
NSBundle *bundle = NSMapGet(nameToBundle, NSStringFromClass(class));
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2012-01-13 11:29:24 +00:00
|
|
|
if (bundle == nil) {
|
2012-01-13 11:32:20 +00:00
|
|
|
#ifdef GCC_RUNTIME_3
|
|
|
|
const char *module = NULL;
|
|
|
|
Dl_info info;
|
|
|
|
if (dladdr(class, &info)) {
|
|
|
|
module = info.dli_fname;
|
|
|
|
}
|
|
|
|
#else
|
2012-01-13 11:29:24 +00:00
|
|
|
const char *module = class_getImageName(class);
|
2012-01-13 11:32:20 +00:00
|
|
|
#endif
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2012-01-13 11:29:24 +00:00
|
|
|
if (module == NULL) {
|
|
|
|
return [self mainBundle]; // this is correct behaviour for Nil class
|
|
|
|
} else {
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *path = [NSString stringWithUTF8String: module];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
bundle = [NSBundle bundleWithModulePath: path];
|
2012-01-13 11:29:24 +00:00
|
|
|
NSMapInsert(nameToBundle, NSStringFromClass(class), bundle);
|
|
|
|
}
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2012-01-13 11:29:24 +00:00
|
|
|
return bundle;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
2008-01-02 03:31:21 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (NSBundle *) bundleWithIdentifier: (NSString *) identifier {
|
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- initWithPath: (NSString *) path {
|
2012-01-13 11:29:24 +00:00
|
|
|
NSBundle *realBundle = NSMapGet(pathToObject, path);
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2012-01-13 11:29:24 +00:00
|
|
|
if (realBundle != nil) {
|
|
|
|
[self dealloc];
|
|
|
|
return [realBundle retain];
|
|
|
|
}
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2012-09-27 07:54:32 +00:00
|
|
|
_path = [[path stringByStandardizingPath] retain];
|
2020-05-11 15:52:05 +00:00
|
|
|
_resourcePath = [_path stringByAppendingPathComponent: @"Resources"];
|
|
|
|
if (![[NSFileManager defaultManager] fileExistsAtPath: _resourcePath]) {
|
|
|
|
_resourcePath = [[_path stringByAppendingPathComponent: @"Contents"]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByAppendingPathComponent: @"Resources"];
|
2012-01-13 11:29:24 +00:00
|
|
|
}
|
|
|
|
[_resourcePath retain];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
_pluginPath = [_path stringByAppendingPathComponent: @"PlugIns"];
|
|
|
|
if (![[NSFileManager defaultManager] fileExistsAtPath: _pluginPath]) {
|
|
|
|
_pluginPath = [[_path stringByAppendingPathComponent: @"Contents"]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByAppendingPathComponent: @"PlugIns"];
|
2012-01-13 11:29:24 +00:00
|
|
|
}
|
|
|
|
[_pluginPath retain];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2012-01-13 11:29:24 +00:00
|
|
|
_infoDictionary = nil;
|
|
|
|
_localizedTables = nil;
|
|
|
|
_isLoaded = NO;
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2012-01-13 11:29:24 +00:00
|
|
|
NSMapInsert(pathToObject, path, self);
|
2006-12-22 04:41:44 +00:00
|
|
|
#ifndef WIN32
|
2020-05-11 15:52:05 +00:00
|
|
|
// Need to verify this on Win32
|
|
|
|
[_allBundles addObject: self];
|
2006-12-22 04:41:44 +00:00
|
|
|
#endif
|
2012-01-13 11:29:24 +00:00
|
|
|
return self;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (void) dealloc {
|
|
|
|
[_path release];
|
|
|
|
[_resourcePath release];
|
|
|
|
[_pluginPath release];
|
|
|
|
[_infoDictionary release];
|
|
|
|
[_localizedTables release];
|
|
|
|
[super dealloc];
|
2011-12-16 16:05:49 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (NSBundle *) bundleWithPath: (NSString *) path {
|
|
|
|
return [[[self allocWithZone: NULL] initWithPath: path] autorelease];
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (NSString *) pathForResource: (NSString *) name
|
|
|
|
ofType: (NSString *) type
|
2020-05-12 00:04:26 +00:00
|
|
|
inDirectory: (NSString *) path
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
return [[NSBundle bundleWithPath: path] pathForResource: name ofType: type];
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (NSArray *) pathsForResourcesOfType: (NSString *) type
|
2020-05-12 00:04:26 +00:00
|
|
|
inDirectory: (NSString *) path
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
return [[NSBundle bundleWithPath: path] pathsForResourcesOfType: type
|
|
|
|
inDirectory: nil];
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (NSArray *) preferredLocalizationsFromArray: (NSArray *) localizations {
|
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
+ (NSArray *) preferredLocalizationsFromArray: (NSArray *) localizations
|
2020-05-12 00:04:26 +00:00
|
|
|
forPreferences: (NSArray *) preferences
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) bundlePath {
|
|
|
|
return _path;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) resourcePath {
|
|
|
|
return _resourcePath;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) builtInPlugInsPath {
|
|
|
|
return _pluginPath;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSDictionary *) infoDictionary {
|
|
|
|
if (_infoDictionary == nil) {
|
|
|
|
|
|
|
|
NSString *path = [[[_path stringByAppendingPathComponent: @"Contents"]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByAppendingPathComponent: @"Info"]
|
|
|
|
stringByAppendingPathExtension: @"plist"];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (![[NSFileManager defaultManager] fileExistsAtPath: path])
|
|
|
|
path = nil;
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (path == nil)
|
|
|
|
path = [self pathForResource: @"Info"
|
|
|
|
ofType: @"plist"
|
|
|
|
inDirectory: @"Resources"];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (![[NSFileManager defaultManager] fileExistsAtPath: path])
|
|
|
|
path = [[_path stringByAppendingPathComponent: @"Info"]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByAppendingPathExtension: @"plist"];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-12 18:51:39 +00:00
|
|
|
_infoDictionary = [[NSDictionary allocWithZone: NULL]
|
|
|
|
initWithContentsOfFile: path];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (_infoDictionary == nil)
|
|
|
|
_infoDictionary = [NSDictionary new];
|
|
|
|
}
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return _infoDictionary;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSDictionary *) localizedInfoDictionary {
|
|
|
|
// FIXME: implement, dont uncomment NSUnimplementedMethod.
|
|
|
|
// NSUnimplementedMethod();
|
|
|
|
return [self infoDictionary];
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- objectForInfoDictionaryKey: (NSString *) key {
|
|
|
|
return [[self infoDictionary] objectForKey: key];
|
2007-04-22 18:58:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) bundleIdentifier {
|
|
|
|
return [[self infoDictionary] objectForKey: @"CFBundleIdentifier"];
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) developmentLocalization {
|
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSArray *) executableArchitectures {
|
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
2008-04-16 11:12:40 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSArray *) localizations {
|
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSArray *) preferredLocalizations {
|
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) privateFrameworksPath {
|
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) sharedFrameworksPath {
|
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) sharedSupportPath {
|
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) pathForAuxiliaryExecutable: (NSString *) executable {
|
|
|
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
|
|
NSString *path = [[self executablePath] stringByDeletingLastPathComponent];
|
2009-05-19 17:19:53 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
path = [path stringByAppendingPathComponent: executable];
|
|
|
|
if ([fm isExecutableFileAtPath: path])
|
|
|
|
return path;
|
2009-05-19 17:19:53 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
// Try to enhance compatibility with Unix-ish code.
|
|
|
|
if ([NSPlatformExecutableFileExtension length]) {
|
2020-05-12 18:51:39 +00:00
|
|
|
path = [path stringByAppendingPathExtension:
|
|
|
|
NSPlatformExecutableFileExtension];
|
2020-05-11 15:52:05 +00:00
|
|
|
if ([fm isExecutableFileAtPath: path])
|
|
|
|
return path;
|
|
|
|
}
|
2009-05-19 17:19:53 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return nil;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (Class) principalClass {
|
|
|
|
NSString *name = [[self infoDictionary] objectForKey: @"NSPrincipalClass"];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
[self load];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return (name == nil) ? Nil : NSClassFromString(name);
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (Class) classNamed: (NSString *) className {
|
|
|
|
[self load];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return NSClassFromString(className);
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (BOOL) isLoaded {
|
|
|
|
return _isLoaded;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
- (BOOL) preflightAndReturnError: (NSError **) error {
|
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
|
|
|
|
2006-12-22 04:41:44 +00:00
|
|
|
/*
|
|
|
|
Frameworks are organized as:
|
|
|
|
Executables/<shared object, e.g. dll or so>
|
2020-05-11 15:52:05 +00:00
|
|
|
Frameworks/MyFramework.framework/
|
2006-12-22 04:41:44 +00:00
|
|
|
Bundles are organized like OS X with Contents/<operating system>
|
|
|
|
*/
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) _findExecutable {
|
|
|
|
NSString *type = [_path pathExtension];
|
|
|
|
NSString *name = [[[self infoDictionary]
|
2020-05-12 18:51:39 +00:00
|
|
|
objectForKey: @"CFBundleExecutable"] stringByDeletingPathExtension];
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *checkDir;
|
|
|
|
NSArray *contents;
|
|
|
|
NSInteger i, count;
|
|
|
|
|
|
|
|
if (name == nil)
|
|
|
|
name = [[_path lastPathComponent] stringByDeletingPathExtension];
|
|
|
|
|
|
|
|
if ([type isEqualToString: @"framework"])
|
|
|
|
checkDir = [[[_path stringByDeletingLastPathComponent]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByDeletingLastPathComponent]
|
|
|
|
stringByAppendingPathComponent: @"Executables"];
|
2020-05-11 15:52:05 +00:00
|
|
|
else
|
|
|
|
checkDir = [[_path stringByAppendingPathComponent: @"Contents"]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByAppendingPathComponent: NSPlatformExecutableDirectory];
|
2020-05-11 15:52:05 +00:00
|
|
|
|
|
|
|
contents =
|
2020-05-12 18:51:39 +00:00
|
|
|
[[NSFileManager defaultManager] directoryContentsAtPath: checkDir];
|
2020-05-11 15:52:05 +00:00
|
|
|
count = [contents count];
|
|
|
|
|
|
|
|
// Need to check for <name>* versioning
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
NSString *check = [contents objectAtIndex: i];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if ([check hasPrefix: name]) {
|
|
|
|
NSString *ext = [check pathExtension];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if ([ext isEqualToString: NSPlatformLoadableObjectFileExtension] ||
|
|
|
|
[ext isEqualToString: NSPlatformExecutableFileExtension])
|
|
|
|
return [checkDir stringByAppendingPathComponent: check];
|
|
|
|
}
|
2012-06-26 16:29:01 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
if ([type isEqualToString: @"app"] == YES) {
|
|
|
|
return [[_path stringByAppendingPathComponent: name]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByAppendingPathExtension:
|
|
|
|
NSPlatformExecutableFileExtension];
|
2020-05-11 15:52:05 +00:00
|
|
|
} else {
|
|
|
|
return [[_path stringByAppendingPathComponent: name]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByAppendingPathExtension:
|
|
|
|
NSPlatformLoadableObjectFileExtension];
|
2012-06-26 16:29:01 +00:00
|
|
|
}
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) executablePath {
|
|
|
|
if (!_executablePath) {
|
|
|
|
_executablePath = [[self _findExecutable] retain];
|
|
|
|
}
|
|
|
|
return _executablePath;
|
2008-04-16 11:12:40 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (BOOL) load {
|
2012-06-26 16:29:01 +00:00
|
|
|
NSError *error = nil;
|
2020-05-11 15:52:05 +00:00
|
|
|
BOOL result = [self loadAndReturnError: &error];
|
|
|
|
|
2012-06-26 16:29:01 +00:00
|
|
|
if (result == NO) {
|
2020-05-11 15:52:05 +00:00
|
|
|
NSLog(@"load of %@ FAILED [%@]", [self executablePath],
|
|
|
|
[error localizedDescription]);
|
2012-06-26 16:29:01 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
|
2012-06-26 16:29:01 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (BOOL) loadAndReturnError: (NSError **) error {
|
|
|
|
if (!_isLoaded) {
|
|
|
|
NSString *load = [self executablePath];
|
|
|
|
|
|
|
|
if (NSLoadModule([load fileSystemRepresentation], error) == NULL) {
|
2012-06-26 16:29:01 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
2020-05-11 15:52:05 +00:00
|
|
|
_isLoaded = YES;
|
2012-06-26 16:29:01 +00:00
|
|
|
return YES;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (BOOL) unload {
|
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSArray *) lookInDirectories {
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2013-09-23 20:31:28 +00:00
|
|
|
if (_lookInDirectories == nil) {
|
2015-08-10 14:31:20 +00:00
|
|
|
NSLocale *cl = [NSLocale currentLocale];
|
2014-02-14 17:13:20 +00:00
|
|
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
|
|
NSMutableArray *validDirectories = [NSMutableArray array];
|
|
|
|
|
|
|
|
BOOL isDirectory = NO;
|
2020-05-11 15:52:05 +00:00
|
|
|
if (_resourcePath &&
|
|
|
|
[fm fileExistsAtPath: _resourcePath isDirectory: &isDirectory] &&
|
|
|
|
isDirectory) {
|
2014-02-14 17:13:20 +00:00
|
|
|
// Check if there's an override on the language preference.
|
2015-08-10 14:31:20 +00:00
|
|
|
NSString *localeid = nil;
|
2014-02-14 17:13:20 +00:00
|
|
|
NSString *language = nil;
|
2015-08-10 14:31:20 +00:00
|
|
|
NSString *longlang = nil;
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
// NSUserDefaults uses the NSBundle system during initialization so
|
|
|
|
// to avoid a recursion of doom we'll only check the preferred
|
|
|
|
// language once the defaults are available.
|
2015-08-10 14:31:20 +00:00
|
|
|
if ([NSUserDefaults standardUserDefaultsAvailable])
|
2020-05-11 15:52:05 +00:00
|
|
|
language = [[NSUserDefaults standardUserDefaults]
|
2020-05-12 18:51:39 +00:00
|
|
|
objectForKey: @"PreferredLanguage"];
|
2020-05-11 15:52:05 +00:00
|
|
|
|
2014-02-14 17:13:20 +00:00
|
|
|
if (language == nil || [language isEqualToString: @""]) {
|
2020-05-11 15:52:05 +00:00
|
|
|
// FIXME: This should be based on language preference order, and
|
|
|
|
// tested for presence in bundle before adding
|
|
|
|
localeid = [[cl objectForKey: NSLocaleIdentifier]
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByAppendingPathExtension: @"lproj"];
|
2020-05-11 15:52:05 +00:00
|
|
|
language = [cl objectForKey: NSLocaleLanguageCode];
|
2015-08-10 14:31:20 +00:00
|
|
|
if ([language isEqualToString: @"de"])
|
2020-05-11 15:52:05 +00:00
|
|
|
longlang = @"German.lproj";
|
2015-08-10 14:31:20 +00:00
|
|
|
else if ([language isEqualToString: @"fr"])
|
2020-05-11 15:52:05 +00:00
|
|
|
longlang = @"French.lproj";
|
2015-08-10 14:31:20 +00:00
|
|
|
else if ([language isEqualToString: @"jp"])
|
2020-05-11 15:52:05 +00:00
|
|
|
longlang = @"Japanese.lproj";
|
|
|
|
// anything else, including 'en', would default to en.lproj or
|
|
|
|
// English.lproj anyway.
|
2014-02-14 17:13:20 +00:00
|
|
|
}
|
2015-08-10 14:31:20 +00:00
|
|
|
|
2014-02-14 17:13:20 +00:00
|
|
|
NSArray *lookInDirectories = nil;
|
2015-08-10 14:31:20 +00:00
|
|
|
if (localeid)
|
2020-05-11 15:52:05 +00:00
|
|
|
if (longlang)
|
|
|
|
lookInDirectories = [NSArray
|
2020-05-12 18:51:39 +00:00
|
|
|
arrayWithObjects:
|
|
|
|
localeid,
|
|
|
|
[language stringByAppendingPathExtension:
|
|
|
|
@"lproj"],
|
|
|
|
longlang, @"en.lproj", @"English.lproj",
|
|
|
|
@"", nil];
|
2020-05-11 15:52:05 +00:00
|
|
|
else
|
|
|
|
lookInDirectories = [NSArray
|
2020-05-12 18:51:39 +00:00
|
|
|
arrayWithObjects:
|
|
|
|
localeid,
|
|
|
|
[language stringByAppendingPathExtension:
|
|
|
|
@"lproj"],
|
|
|
|
@"en.lproj", @"English.lproj", @"", nil];
|
2020-05-11 15:52:05 +00:00
|
|
|
else if ([language isEqualToString: @"English"])
|
2020-05-12 18:51:39 +00:00
|
|
|
lookInDirectories =
|
|
|
|
[NSArray arrayWithObjects: @"English.lproj",
|
|
|
|
@"en.lproj", @"", nil];
|
2014-02-14 17:13:20 +00:00
|
|
|
else
|
2020-05-11 15:52:05 +00:00
|
|
|
lookInDirectories = [NSArray
|
2020-05-12 18:51:39 +00:00
|
|
|
arrayWithObjects:
|
|
|
|
[language stringByAppendingPathExtension:
|
|
|
|
@"lproj"],
|
|
|
|
@"en.lproj", @"English.lproj", @"", nil];
|
2015-08-10 14:31:20 +00:00
|
|
|
|
2014-02-14 17:13:20 +00:00
|
|
|
for (NSString *proj in lookInDirectories) {
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *path =
|
2020-05-12 18:51:39 +00:00
|
|
|
[_resourcePath stringByAppendingPathComponent: proj];
|
2014-02-14 17:13:20 +00:00
|
|
|
BOOL isDirectory = NO;
|
2020-05-11 15:52:05 +00:00
|
|
|
if ([fm fileExistsAtPath: path isDirectory: &isDirectory] &&
|
|
|
|
isDirectory) {
|
|
|
|
[validDirectories addObject: proj];
|
2014-02-14 17:13:20 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-10 14:31:20 +00:00
|
|
|
|
2014-02-14 17:13:20 +00:00
|
|
|
if ([NSUserDefaults standardUserDefaultsAvailable] == YES) {
|
|
|
|
// Now it's safe to cache
|
|
|
|
_lookInDirectories = [validDirectories retain];
|
|
|
|
}
|
2013-09-23 20:31:28 +00:00
|
|
|
}
|
2014-02-14 17:13:20 +00:00
|
|
|
return validDirectories;
|
2013-09-23 20:31:28 +00:00
|
|
|
} else {
|
|
|
|
return _lookInDirectories;
|
|
|
|
}
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSURL *) URLForResource: (NSString *) name withExtension: (NSString *) ext {
|
|
|
|
NSString *path = [self pathForResource: name ofType: ext inDirectory: nil];
|
|
|
|
|
|
|
|
// attention: fileURLWithPath returns a non-nil object for nil input, we
|
|
|
|
// don't want that
|
|
|
|
return path ? [NSURL fileURLWithPath: path] : nil;
|
2014-02-21 18:47:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSURL *) URLForResource: (NSString *) name
|
|
|
|
withExtension: (NSString *) ext
|
2020-05-12 00:04:26 +00:00
|
|
|
subdirectory: (NSString *) subpath
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *path = [self pathForResource: name
|
|
|
|
ofType: ext
|
|
|
|
inDirectory: subpath];
|
2014-02-21 18:47:44 +00:00
|
|
|
return [NSURL fileURLWithPath: path];
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSURL *) URLForResource: (NSString *) name
|
|
|
|
withExtension: (NSString *) ext
|
|
|
|
subdirectory: (NSString *) subpath
|
2020-05-12 00:04:26 +00:00
|
|
|
localization: (NSString *) localizationName
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *path = [self pathForResource: name
|
|
|
|
ofType: ext
|
|
|
|
inDirectory: subpath
|
|
|
|
forLocalization: localizationName];
|
2014-02-21 18:47:44 +00:00
|
|
|
return [NSURL fileURLWithPath: path];
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) pathForResourceFile: (NSString *) file
|
2020-05-12 00:04:26 +00:00
|
|
|
inDirectory: (NSString *) directory
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
NSArray *lookIn = [self lookInDirectories];
|
|
|
|
NSInteger i, count = [lookIn count];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
NSString *path = [_resourcePath
|
2020-05-12 18:51:39 +00:00
|
|
|
stringByAppendingPathComponent: [lookIn objectAtIndex: i]];
|
2020-05-11 15:52:05 +00:00
|
|
|
if (directory != nil)
|
|
|
|
path = [path stringByAppendingPathComponent: directory];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
path = [path stringByAppendingPathComponent: file];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
BOOL value = [[NSFileManager defaultManager] fileExistsAtPath: path];
|
2010-03-09 18:14:48 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (value) {
|
|
|
|
return path;
|
|
|
|
}
|
2010-03-09 18:14:48 +00:00
|
|
|
}
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return nil;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) pathForResource: (NSString *) name
|
|
|
|
ofType: (NSString *) type
|
2020-05-12 00:04:26 +00:00
|
|
|
inDirectory: (NSString *) directory
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *file, *path;
|
|
|
|
|
|
|
|
if ([type length] && [[name pathExtension] isEqualToString: type]) {
|
|
|
|
// Kill the type form the extension part if it's already there
|
|
|
|
name = [name stringByDeletingPathExtension];
|
|
|
|
}
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-12 00:04:26 +00:00
|
|
|
#if 0 // Disabled - we don't use that and it's increasing the number of files to \
|
2020-05-11 15:52:05 +00:00
|
|
|
// check for the resource
|
2011-12-16 16:05:49 +00:00
|
|
|
if(type && [type length]!=0)
|
2010-03-02 17:36:22 +00:00
|
|
|
file=[[name stringByAppendingFormat:@"-%@",NSPlatformResourceNameSuffix] stringByAppendingPathExtension:type];
|
|
|
|
else
|
|
|
|
file=[name stringByAppendingFormat:@"-%@",NSPlatformResourceNameSuffix];
|
|
|
|
|
2006-12-22 04:41:44 +00:00
|
|
|
if((path=[self pathForResourceFile:file inDirectory:directory])!=nil)
|
|
|
|
return path;
|
2014-02-14 17:13:20 +00:00
|
|
|
#endif
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (type && [type length] != 0)
|
|
|
|
file = [name stringByAppendingPathExtension: type];
|
|
|
|
else
|
|
|
|
file = name;
|
2010-03-02 17:36:22 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
path = [self pathForResourceFile: file inDirectory: directory];
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return path;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) pathForResource: (NSString *) name
|
|
|
|
ofType: (NSString *) type
|
|
|
|
inDirectory: (NSString *) path
|
2020-05-12 00:04:26 +00:00
|
|
|
forLocalization: (NSString *) localization
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) pathForResource: (NSString *) name ofType: (NSString *) type {
|
|
|
|
NSString *result = [self pathForResource: name
|
|
|
|
ofType: type
|
|
|
|
inDirectory: nil];
|
2010-03-09 18:14:48 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return result;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSArray *) pathsForResourcesOfType: (NSString *) type
|
2020-05-12 00:04:26 +00:00
|
|
|
inDirectory: (NSString *) path
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
NSMutableArray *result = [NSMutableArray array];
|
|
|
|
NSString *fullPath = [self resourcePath];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (path != nil)
|
|
|
|
fullPath = [fullPath stringByAppendingPathComponent: path];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
NSArray *allFiles =
|
2020-05-12 18:51:39 +00:00
|
|
|
[[NSFileManager defaultManager] directoryContentsAtPath: fullPath];
|
2020-05-11 15:52:05 +00:00
|
|
|
NSInteger i, count = [allFiles count];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
NSString *check = [allFiles objectAtIndex: i];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if ([type length] == 0 || [[check pathExtension] isEqualToString: type])
|
2020-05-12 18:51:39 +00:00
|
|
|
[result addObject: [fullPath
|
|
|
|
stringByAppendingPathComponent: check]];
|
2020-05-11 15:52:05 +00:00
|
|
|
}
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return result;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSArray *) pathsForResourcesOfType: (NSString *) type
|
|
|
|
inDirectory: (NSString *) path
|
2020-05-12 00:04:26 +00:00
|
|
|
forLocalization: (NSString *) localization
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
NSUnimplementedMethod();
|
|
|
|
return 0;
|
2008-01-02 03:31:21 +00:00
|
|
|
}
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) localizedStringForKey: (NSString *) key
|
|
|
|
value: (NSString *) value
|
2020-05-12 00:04:26 +00:00
|
|
|
table: (NSString *) table
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *result;
|
|
|
|
NSDictionary *dictionary;
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if ([table length] == 0)
|
|
|
|
table = @"Localizable";
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
// NSLocalizedString needs to be thread safe.
|
2010-03-09 18:14:48 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
@synchronized(self) {
|
|
|
|
dictionary = [_localizedTables objectForKey: table];
|
2010-03-09 18:14:48 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (dictionary == nil) {
|
|
|
|
NSString *path;
|
|
|
|
NSString *contents = nil;
|
2011-03-28 20:19:16 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (_localizedTables == nil)
|
|
|
|
_localizedTables = [[NSMutableDictionary alloc] init];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if ((path = [self pathForResource: table
|
|
|
|
ofType: @"strings"]) != nil)
|
|
|
|
if ((contents = [NSString stringWithContentsOfFile: path]) !=
|
|
|
|
nil) {
|
|
|
|
NS_DURING
|
|
|
|
dictionary = [contents propertyListFromStringsFileFormat];
|
|
|
|
NS_HANDLER
|
|
|
|
dictionary = nil;
|
|
|
|
NS_ENDHANDLER
|
|
|
|
}
|
2011-03-28 20:19:16 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if (dictionary == nil)
|
|
|
|
dictionary = [NSDictionary dictionary];
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
[_localizedTables setObject: dictionary forKey: table];
|
|
|
|
}
|
2011-03-28 20:19:16 +00:00
|
|
|
}
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
if ((result = [dictionary objectForKey: key]) == nil)
|
|
|
|
result = (value != nil && [value isEqual: @""] == NO) ? value : key;
|
2012-01-13 11:26:06 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
return result;
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) description {
|
|
|
|
return [NSString
|
2020-05-12 18:51:39 +00:00
|
|
|
stringWithFormat:
|
|
|
|
@"<%@[0x%lx] path: %@ resourcePath: %@ isLoaded: %@>",
|
|
|
|
[self class], self, _path, _resourcePath,
|
|
|
|
(_isLoaded ? @"YES" : @"NO")];
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *NSLocalizedString(NSString *key, NSString *comment) {
|
|
|
|
return [[NSBundle mainBundle] localizedStringForKey: key
|
|
|
|
value: nil
|
|
|
|
table: nil];
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *NSLocalizedStringFromTable(NSString *key, NSString *table,
|
2020-05-12 00:04:26 +00:00
|
|
|
NSString *comment)
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
return [[NSBundle mainBundle] localizedStringForKey: key
|
|
|
|
value: nil
|
|
|
|
table: table];
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
NSString *NSLocalizedStringFromTableInBundle(NSString *key, NSString *table,
|
|
|
|
NSBundle *bundle,
|
2020-05-12 00:04:26 +00:00
|
|
|
NSString *comment)
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
return [bundle localizedStringForKey: key value: nil table: table];
|
2006-12-22 04:41:44 +00:00
|
|
|
}
|