diff options
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/platform/macosx/config.m | 21 | ||||
-rw-r--r-- | libhb/ports.c | 46 | ||||
-rw-r--r-- | libhb/ports.h | 2 |
3 files changed, 52 insertions, 17 deletions
diff --git a/libhb/platform/macosx/config.m b/libhb/platform/macosx/config.m index 9fa86aaaf..c30f34c4a 100644 --- a/libhb/platform/macosx/config.m +++ b/libhb/platform/macosx/config.m @@ -1,14 +1,19 @@ #import <Foundation/Foundation.h> -/* #import <Cocoa/Cocoa.h> */ -void osx_get_user_config_directory(char path[512]) +int osx_get_user_config_directory(char path[512]) { - @autoreleasepool { - NSArray *paths = NSSearchPathForDirectoriesInDomains( - NSApplicationSupportDirectory, NSUserDomainMask, YES); - NSString *dir = paths[0]; - strncpy(path, dir.UTF8String, 512); + @autoreleasepool + { + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, + NSUserDomainMask, YES); + NSString *dir = paths.firstObject; + if (dir.UTF8String == nil) + { + return -1; + } + + strncpy(path, dir.UTF8String, 511); path[511] = 0; + return 0; } } - diff --git a/libhb/ports.c b/libhb/ports.c index 6d43dc34f..e93fdb100 100644 --- a/libhb/ports.c +++ b/libhb/ports.c @@ -504,10 +504,37 @@ void hb_get_user_config_directory( char path[512] ) { /* Create the base */ #if defined( SYS_CYGWIN ) || defined( SYS_MINGW ) +#ifndef CSIDL_FLAG_DONT_UNEXPAND + /* + * XXX: some old MinGW toolchains don't have SHGetKnownFolderPath. + * + * SHGetFolderPath is deprecated, but this should be no problem in practice. + * + * Note: explicitly call the Unicode/WCHAR function SHGetFolderPathW. + */ + WCHAR wide_path[MAX_PATH]; + + if (SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, wide_path) == S_OK && + WideCharToMultiByte(CP_UTF8, 0, wide_path, -1, path, 512, NULL, NULL) != 0) + { + path[511] = 0; + return; + } +#else WCHAR *wide_path; - SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &wide_path); - WideCharToMultiByte(CP_UTF8, 0, wide_path, -1, path, 512, NULL, NULL ); - path[511] = 0; + + if (SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &wide_path) == S_OK && + WideCharToMultiByte(CP_UTF8, 0, wide_path, -1, path, 512, NULL, NULL) != 0) + { + CoTaskMemFree(wide_path); + path[511] = 0; + return; + } + else if (wide_path != NULL) + { + CoTaskMemFree(wide_path); + } +#endif // !defined CSIDL_FLAG_DONT_UNEXPAND #elif defined( SYS_LINUX ) char *p; @@ -515,6 +542,7 @@ void hb_get_user_config_directory( char path[512] ) { strncpy(path, p, 511); path[511] = 0; + return; } else if ((p = getenv("HOME")) != NULL) { @@ -523,15 +551,17 @@ void hb_get_user_config_directory( char path[512] ) int len = strlen(path); strncpy(path + len, "/.config", 511 - len - 1); path[511] = 0; + return; } - else +#elif defined( __APPLE__ ) + if (osx_get_user_config_directory(path) == 0) { - hb_error("Failed to lookup user config directory!"); - path[0] = 0; + return; } -#elif defined( __APPLE__ ) - osx_get_user_config_directory(path); #endif + + hb_error("Failed to lookup user config directory!"); + path[0] = 0; } /************************************************************************ diff --git a/libhb/ports.h b/libhb/ports.h index 9a3da7a6a..5e039809e 100644 --- a/libhb/ports.h +++ b/libhb/ports.h @@ -101,7 +101,7 @@ void hb_get_tempory_filename( hb_handle_t *, char name[1024], char * fmt, ... ); #if defined( SYS_DARWIN ) -void osx_get_user_config_directory( char path[512] ); +int osx_get_user_config_directory( char path[512] ); #endif void hb_get_user_config_directory( char path[512] ); void hb_get_user_config_filename( char name[1024], char *fmt, ... ); |