libobs/util: Allow ability to get base config path

This allows you to for example, get your base home directory or base
%appdata% directory.
This commit is contained in:
jp9000 2015-07-08 09:19:35 -07:00
parent ba02e065fe
commit bf37258469
3 changed files with 23 additions and 4 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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);