diff --git a/UI/platform-osx.mm b/UI/platform-osx.mm index bc400f5d2..2586e2589 100644 --- a/UI/platform-osx.mm +++ b/UI/platform-osx.mm @@ -28,11 +28,27 @@ using namespace std; +bool isInBundle() +{ + NSRunningApplication *app = [NSRunningApplication currentApplication]; + return [app bundleIdentifier] != nil; +} + bool GetDataFilePath(const char *data, string &output) { - stringstream str; - str << OBS_DATA_PATH "/obs-studio/" << data; - output = str.str(); + if (isInBundle()) { + NSBundle *myBundle = [NSBundle mainBundle]; + NSString *path = [NSString + stringWithFormat:@"data/obs-studio/%@", + [NSString stringWithUTF8String:data]]; + NSString *absPath = [myBundle pathForResource:path ofType:nil]; + output = [absPath UTF8String]; + } else { + stringstream str; + str << OBS_DATA_PATH "/obs-studio/" << data; + output = str.str(); + } + return !access(output.c_str(), R_OK); } diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt index 868114816..0eabf608c 100644 --- a/libobs/CMakeLists.txt +++ b/libobs/CMakeLists.txt @@ -110,7 +110,7 @@ if(WIN32) endif() elseif(APPLE) set(libobs_PLATFORM_SOURCES - obs-cocoa.c + obs-cocoa.m util/threading-posix.c util/pipe-posix.c util/platform-nix.c diff --git a/libobs/obs-cocoa.c b/libobs/obs-cocoa.m similarity index 97% rename from libobs/obs-cocoa.c rename to libobs/obs-cocoa.m index 44e69eff1..7f261d093 100644 --- a/libobs/obs-cocoa.c +++ b/libobs/obs-cocoa.m @@ -29,6 +29,14 @@ #include #include +#import + +bool is_in_bundle() +{ + NSRunningApplication *app = [NSRunningApplication currentApplication]; + return [app bundleIdentifier] != nil; +} + const char *get_module_extension(void) { return ".so"; @@ -51,12 +59,45 @@ void add_default_module_paths(void) { for (int i = 0; i < module_patterns_size; i++) obs_add_module_path(module_bin[i], module_data[i]); + + if (is_in_bundle()) { + NSRunningApplication *app = + [NSRunningApplication currentApplication]; + NSURL *bundleURL = [app bundleURL]; + NSURL *pluginsURL = [bundleURL + URLByAppendingPathComponent:@"Contents/Plugins"]; + NSURL *dataURL = [bundleURL + URLByAppendingPathComponent: + @"Contents/Resources/data/obs-plugins/%module%"]; + + const char *binPath = [[pluginsURL path] + cStringUsingEncoding:NSUTF8StringEncoding]; + const char *dataPath = [[dataURL path] + cStringUsingEncoding:NSUTF8StringEncoding]; + + obs_add_module_path(binPath, dataPath); + } } char *find_libobs_data_file(const char *file) { struct dstr path; - dstr_init_copy(&path, OBS_INSTALL_DATA_PATH "/libobs/"); + + if (is_in_bundle()) { + NSRunningApplication *app = + [NSRunningApplication currentApplication]; + NSURL *bundleURL = [app bundleURL]; + NSURL *libobsDataURL = + [bundleURL URLByAppendingPathComponent: + @"Contents/Resources/data/libobs/"]; + const char *libobsDataPath = [[libobsDataURL path] + cStringUsingEncoding:NSUTF8StringEncoding]; + dstr_init_copy(&path, libobsDataPath); + dstr_cat(&path, "/"); + } else { + dstr_init_copy(&path, OBS_INSTALL_DATA_PATH "/libobs/"); + } + dstr_cat(&path, file); return path.array; }