浏览代码

libobs/util: Allow ability to get base config path

This allows you to for example, get your base home directory or base
%appdata% directory.
jp9000 10 年之前
父节点
当前提交
bf37258469
共有 3 个文件被更改,包括 23 次插入4 次删除
  1. 5 1
      libobs/util/platform-cocoa.m
  2. 14 3
      libobs/util/platform-nix.c
  3. 4 0
      libobs/util/platform-windows.c

+ 5 - 1
libobs/util/platform-cocoa.m

@@ -78,7 +78,11 @@ int os_get_config_path(char *dst, size_t size, const char *name)
 
 	NSString *application_support = paths[0];
 	const char *base_path = [application_support UTF8String];
-	return snprintf(dst, size, "%s/%s", base_path, name);
+
+	if (!name || !*name)
+		return snprintf(dst, size, "%s", base_path);
+	else
+		return snprintf(dst, size, "%s/%s", base_path, name);
 }
 
 char *os_get_config_path_ptr(const char *name)

+ 14 - 3
libobs/util/platform-nix.c

@@ -167,16 +167,27 @@ int os_get_config_path(char *dst, size_t size, const char *name)
 		if (home_ptr == NULL)
 			bcrash("Could not get $HOME\n");
 
-		return snprintf(dst, size, "%s/.config/%s", home_ptr, name);
+		if (!name || !*name) {
+			return snprintf(dst, size, "%s/.config", home_ptr);
+		} else {
+			return snprintf(dst, size, "%s/.config/%s", home_ptr,
+					name);
+		}
 	} else {
-		return snprintf(dst, size, "%s/%s", xdg_ptr, name);
+		if (!name || !*name)
+			return snprintf(dst, size, "%s", xdg_ptr);
+		else
+			return snprintf(dst, size, "%s/%s", xdg_ptr, name);
 	}
 #else
 	char *path_ptr = getenv("HOME");
 	if (path_ptr == NULL)
 		bcrash("Could not get $HOME\n");
 
-	return snprintf(dst, size, "%s/.%s", path_ptr, name);
+	if (!name || !*name)
+		return snprintf(dst, size, "%s", path_ptr);
+	else
+		return snprintf(dst, size, "%s/.%s", path_ptr, name);
 #endif
 }
 

+ 4 - 0
libobs/util/platform-windows.c

@@ -199,6 +199,10 @@ int os_get_config_path(char *dst, size_t size, const char *name)
 			path_utf16);
 
 	if (os_wcs_to_utf8(path_utf16, 0, dst, size) != 0) {
+		if (!name || !*name) {
+			return (int)strlen(dst);
+		}
+
 		if (strcat_s(dst, size, "\\") == 0) {
 			if (strcat_s(dst, size, name) == 0) {
 				return (int)strlen(dst);