From a57a4a64dead1bf8a477a7fa04bf021573703f1f Mon Sep 17 00:00:00 2001 From: Pierre d'Herbemont Date: Wed, 30 Dec 2009 02:27:08 +0100 Subject: [PATCH] config: On Mac OS use the app identifier for app dependent config dirs. This may hopefully spare us some conflicts with VLCKit/libvlc users. --- src/config/dirs_macos.c | 49 +++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/src/config/dirs_macos.c b/src/config/dirs_macos.c index a411fc67de..fdb272a6da 100644 --- a/src/config/dirs_macos.c +++ b/src/config/dirs_macos.c @@ -22,6 +22,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ +#include + #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -31,6 +33,7 @@ #include "../libvlc.h" #include #include +#include "configuration.h" static char *configdir = NULL; static char *datadir = NULL; @@ -65,21 +68,50 @@ static char *config_GetHomeDir (void) return FromLocaleDup (home); } -char *config_GetUserDir (vlc_userdir_t type) +static char *getAppDependentDir(vlc_userdir_t type) { - char *psz_dir; - char *psz_parent = config_GetHomeDir (); const char *psz_path; - switch (type) { case VLC_CONFIG_DIR: - psz_path = "%s/Library/Preferences/VLC"; + psz_path = "%s/Library/Preferences/%s"; break; case VLC_TEMPLATES_DIR: case VLC_DATA_DIR: - psz_path = "%s/Library/Application Support/VLC"; + psz_path = "%s/Library/Application Support/%s"; + break; + case VLC_CACHE_DIR: + psz_path = "%s/Library/Caches/%s"; + break; + default: + assert(0); break; + } + + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFStringRef identifierAsNS = CFBundleGetIdentifier(mainBundle); + const char *identifier = CFStringGetCStringPtr(identifierAsNS, kCFStringEncodingUTF8); + + char *psz_parent = config_GetHomeDir (); + char *psz_dir; + if( asprintf( &psz_dir, psz_path, psz_parent, identifier) == -1 ) + psz_dir = NULL; + free(psz_parent); + + return psz_dir; +} + +char *config_GetUserDir (vlc_userdir_t type) +{ + const char *psz_path; + switch (type) + { + case VLC_CONFIG_DIR: + case VLC_TEMPLATES_DIR: + case VLC_DATA_DIR: + case VLC_CACHE_DIR: + return getAppDependentDir(type); + case VLC_DESKTOP_DIR: psz_path = "%s/Desktop"; break; @@ -101,13 +133,12 @@ char *config_GetUserDir (vlc_userdir_t type) case VLC_PUBLICSHARE_DIR: psz_path = "%s/Public"; break; - case VLC_CACHE_DIR: - psz_path = "%s/Library/Caches/org.videolan.vlc"; - break; case VLC_HOME_DIR: default: psz_path = "%s"; } + char *psz_parent = config_GetHomeDir (); + char *psz_dir; if( asprintf( &psz_dir, psz_path, psz_parent ) == -1 ) psz_dir = NULL; free(psz_parent); -- 2.39.5