Load .lovr files from the macOS app bundle;

This commit is contained in:
bjorn 2019-09-24 21:37:44 -07:00
parent 403b217781
commit 0129a80b27
1 changed files with 22 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include <stdio.h>
#ifdef __APPLE__
#include <mach-o/dyld.h>
#include <objc/objc-runtime.h>
#endif
#if _WIN32
#include <windows.h>
@ -58,6 +59,23 @@ bool lovrFilesystemInit(const char* argExe, const char* argGame, const char* arg
// Try to mount either an archive fused to the executable or an archive from the command line
lovrFilesystemGetExecutablePath(state.source, LOVR_PATH_MAX);
if (!lovrFilesystemMount(state.source, NULL, 1, argRoot)) { // Attempt to load fused. If that fails...
#ifdef __APPLE__
// NSString* path = [[NSBundle mainBundle] pathForResource:nil ofType:@"lovr"]
// if (!path || !lovrFilesystemMount(path.UTF8string, NULL, 1, argRoot)) {
//
// }
id lovrNSString = objc_msgSend((id) objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), "lovr");
id mainBundle = objc_msgSend((id) objc_getClass("NSBundle"), sel_registerName("mainBundle"));
id resource = objc_msgSend(mainBundle, sel_registerName("pathForResource:ofType:"), nil, lovrNSString);
const char* resourcePath = NULL;
if (resource != nil) {
object_getInstanceVariable(resource, "UTF8String", (void**) &resourcePath);
}
if (!resourcePath || !lovrFilesystemMount(resourcePath, NULL, 1, argRoot)) {
#endif
state.fused = false;
if (argGame) {
@ -69,6 +87,10 @@ bool lovrFilesystemInit(const char* argExe, const char* argGame, const char* arg
free(state.source); // Couldn't load from argProject, so apparently it isn't the source
state.source = NULL;
#ifdef __APPLE__
}
#endif
}
return true;