libobs/util: Add os_get_program_data_path* functions
Allows getting the system-local program data path. Typically: Windows: C:\ProgramData Mac: /Library/Application Support Linux: /usr/local/share
This commit is contained in:
parent
81adb13f59
commit
4f4d7cde7e
@ -69,11 +69,12 @@ uint64_t os_gettime_ns(void)
|
||||
return f();
|
||||
}
|
||||
|
||||
/* gets the location ~/Library/Application Support/[name] */
|
||||
int os_get_config_path(char *dst, size_t size, const char *name)
|
||||
/* gets the location [domain mask]/Library/Application Support/[name] */
|
||||
static int os_get_path_internal(char *dst, size_t size, const char *name,
|
||||
NSSearchPathDomainMask domainMask)
|
||||
{
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||
NSApplicationSupportDirectory, domainMask, YES);
|
||||
|
||||
if([paths count] == 0)
|
||||
bcrash("Could not get home directory (platform-cocoa)");
|
||||
@ -87,10 +88,11 @@ int os_get_config_path(char *dst, size_t size, const char *name)
|
||||
return snprintf(dst, size, "%s/%s", base_path, name);
|
||||
}
|
||||
|
||||
char *os_get_config_path_ptr(const char *name)
|
||||
static char *os_get_path_ptr_internal(const char *name,
|
||||
NSSearchPathDomainMask domainMask)
|
||||
{
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||
NSApplicationSupportDirectory, domainMask, YES);
|
||||
|
||||
if([paths count] == 0)
|
||||
bcrash("Could not get home directory (platform-cocoa)");
|
||||
@ -113,6 +115,26 @@ char *os_get_config_path_ptr(const char *name)
|
||||
return path.array;
|
||||
}
|
||||
|
||||
int os_get_config_path(char *dst, size_t size, const char *name)
|
||||
{
|
||||
return os_get_path_internal(dst, size, name, NSUserDomainMask);
|
||||
}
|
||||
|
||||
char *os_get_config_path_ptr(const char *name)
|
||||
{
|
||||
return os_get_path_ptr_internal(name, NSUserDomainMask);
|
||||
}
|
||||
|
||||
int os_get_program_data_path(char *dst, size_t size, const char *name)
|
||||
{
|
||||
return os_get_path_internal(dst, size, name, NSLocalDomainMask);
|
||||
}
|
||||
|
||||
char *os_get_program_data_path_ptr(const char *name)
|
||||
{
|
||||
return os_get_path_ptr_internal(name, NSLocalDomainMask);
|
||||
}
|
||||
|
||||
struct os_cpu_usage_info {
|
||||
int64_t last_cpu_time;
|
||||
int64_t last_sys_time;
|
||||
|
@ -241,6 +241,20 @@ char *os_get_config_path_ptr(const char *name)
|
||||
#endif
|
||||
}
|
||||
|
||||
int os_get_program_data_path(char *dst, size_t size, const char *name)
|
||||
{
|
||||
return snprintf(dst, size, "/usr/local/share/%s", !!name ? name : "");
|
||||
}
|
||||
|
||||
char *os_get_program_data_path_ptr(const char *name)
|
||||
{
|
||||
size_t len = snprintf(NULL, 0, "/usr/local/share/%s", !!name ? name : "");
|
||||
char *str = bmalloc(len + 1);
|
||||
snprintf(str, len + 1, "/usr/local/share/%s", !!name ? name : "");
|
||||
str[len] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool os_file_exists(const char *path)
|
||||
|
@ -208,12 +208,13 @@ uint64_t os_gettime_ns(void)
|
||||
return (uint64_t)time_val;
|
||||
}
|
||||
|
||||
/* returns %appdata%\[name] on windows */
|
||||
int os_get_config_path(char *dst, size_t size, const char *name)
|
||||
/* returns [folder]\[name] on windows */
|
||||
static int os_get_path_internal(char *dst, size_t size, const char *name,
|
||||
int folder)
|
||||
{
|
||||
wchar_t path_utf16[MAX_PATH];
|
||||
|
||||
SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
|
||||
SHGetFolderPathW(NULL, folder, NULL, SHGFP_TYPE_CURRENT,
|
||||
path_utf16);
|
||||
|
||||
if (os_wcs_to_utf8(path_utf16, 0, dst, size) != 0) {
|
||||
@ -231,13 +232,13 @@ int os_get_config_path(char *dst, size_t size, const char *name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *os_get_config_path_ptr(const char *name)
|
||||
static char *os_get_path_ptr_internal(const char *name, int folder)
|
||||
{
|
||||
char *ptr;
|
||||
wchar_t path_utf16[MAX_PATH];
|
||||
struct dstr path;
|
||||
|
||||
SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
|
||||
SHGetFolderPathW(NULL, folder, NULL, SHGFP_TYPE_CURRENT,
|
||||
path_utf16);
|
||||
|
||||
os_wcs_to_utf8_ptr(path_utf16, 0, &ptr);
|
||||
@ -247,6 +248,26 @@ char *os_get_config_path_ptr(const char *name)
|
||||
return path.array;
|
||||
}
|
||||
|
||||
int os_get_config_path(char *dst, size_t size, const char *name)
|
||||
{
|
||||
return os_get_path_internal(dst, size, name, CSIDL_APPDATA);
|
||||
}
|
||||
|
||||
char *os_get_config_path_ptr(const char *name)
|
||||
{
|
||||
return os_get_path_ptr_internal(name, CSIDL_APPDATA);
|
||||
}
|
||||
|
||||
int os_get_program_data_path(char *dst, size_t size, const char *name)
|
||||
{
|
||||
return os_get_path_internal(dst, size, name, CSIDL_COMMON_APPDATA);
|
||||
}
|
||||
|
||||
char *os_get_program_data_path_ptr(const char *name)
|
||||
{
|
||||
return os_get_path_ptr_internal(name, CSIDL_COMMON_APPDATA);
|
||||
}
|
||||
|
||||
bool os_file_exists(const char *path)
|
||||
{
|
||||
WIN32_FIND_DATAW wfd;
|
||||
|
@ -108,6 +108,9 @@ EXPORT uint64_t os_gettime_ns(void);
|
||||
EXPORT int os_get_config_path(char *dst, size_t size, const char *name);
|
||||
EXPORT char *os_get_config_path_ptr(const char *name);
|
||||
|
||||
EXPORT int os_get_program_data_path(char *dst, size_t size, const char *name);
|
||||
EXPORT char *os_get_program_data_path_ptr(const char *name);
|
||||
|
||||
EXPORT bool os_file_exists(const char *path);
|
||||
|
||||
EXPORT size_t os_get_abs_path(const char *path, char *abspath, size_t size);
|
||||
|
Loading…
x
Reference in New Issue
Block a user