Browse Source

libobs: Use native ObjectiveC methods to generate data and module paths

PatTheMav 2 years ago
parent
commit
ee1ec26de3
1 changed files with 15 additions and 30 deletions
  1. 15 30
      libobs/obs-cocoa.m

+ 15 - 30
libobs/obs-cocoa.m

@@ -43,43 +43,28 @@ const char *get_module_extension(void)
 
 
 void add_default_module_paths(void)
 void add_default_module_paths(void)
 {
 {
-	struct dstr plugin_path;
+	NSURL *pluginURL = [[NSBundle mainBundle] builtInPlugInsURL];
+	NSString *pluginModulePath = [[pluginURL path]
+		stringByAppendingString:@"/%module%.plugin/Contents/MacOS/"];
+	NSString *pluginDataPath = [[pluginURL path]
+		stringByAppendingString:@"/%module%.plugin/Contents/Resources/"];
 
 
-	dstr_init_move_array(&plugin_path, os_get_executable_path_ptr(""));
-	dstr_cat(&plugin_path, "../PlugIns");
-	char *abs_plugin_path = os_get_abs_path_ptr(plugin_path.array);
-
-	if (abs_plugin_path != NULL) {
-		dstr_move_array(&plugin_path, abs_plugin_path);
-		struct dstr plugin_data;
-		dstr_init_copy_dstr(&plugin_data, &plugin_path);
-		dstr_cat(&plugin_path, "/%module%.plugin/Contents/MacOS/");
-		dstr_cat(&plugin_data, "/%module%.plugin/Contents/Resources/");
-
-		obs_add_module_path(plugin_path.array, plugin_data.array);
-
-		dstr_free(&plugin_data);
-	}
-
-	dstr_free(&plugin_path);
+	obs_add_module_path(pluginModulePath.UTF8String,
+			    pluginDataPath.UTF8String);
 }
 }
 
 
 char *find_libobs_data_file(const char *file)
 char *find_libobs_data_file(const char *file)
 {
 {
-	struct dstr path;
-
 	NSBundle *frameworkBundle =
 	NSBundle *frameworkBundle =
 		[NSBundle bundleWithIdentifier:@"com.obsproject.libobs"];
 		[NSBundle bundleWithIdentifier:@"com.obsproject.libobs"];
-	NSURL *bundleURL = [frameworkBundle bundleURL];
-	NSURL *libobsDataURL =
-		[bundleURL URLByAppendingPathComponent:@"Resources/"];
-	const char *libobsDataPath = [[libobsDataURL path]
-		cStringUsingEncoding:NSUTF8StringEncoding];
-	dstr_init_copy(&path, libobsDataPath);
-	dstr_cat(&path, "/");
-
-	dstr_cat(&path, file);
-	return path.array;
+	NSString *libobsDataPath = [[[frameworkBundle bundleURL] path]
+		stringByAppendingFormat:@"/%@/%s", @"Resources", file];
+	size_t path_length = strlen(libobsDataPath.UTF8String);
+
+	char *path = bmalloc(path_length + 1);
+	snprintf(path, (path_length + 1), "%s", libobsDataPath.UTF8String);
+
+	return path;
 }
 }
 
 
 static void log_processor_name(void)
 static void log_processor_name(void)