]> git.sesse.net Git - vlc/blobdiff - src/config/dirs_macos.c
Rename the sdi module to decklink.
[vlc] / src / config / dirs_macos.c
index 187948e1a28ff348cea151ac10151153b695ba7b..0a563d84a1ee0e270b0d8b4771dc2b541caa504c 100644 (file)
@@ -22,6 +22,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#include <CoreFoundation/CoreFoundation.h>
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 #include "../libvlc.h"
 #include <vlc_charset.h>
 #include <vlc_configuration.h>
+#include "configuration.h"
+
+static char *configdir = NULL;
+
+static pthread_once_t once = PTHREAD_ONCE_INIT;
 
+static void init_dirs( void )
+{
+    configdir = config_GetUserDir(VLC_CONFIG_DIR);
+}
 
 const char *config_GetConfDir( void )
 {
-    return config_GetUserDir (VLC_CONFIG_DIR);
+    pthread_once(&once, init_dirs);
+    return configdir;
 }
 
-const char *config_GetDataDir (void)
+char *config_GetDataDirDefault (void)
 {
-    return config_GetUserDir (VLC_DATA_DIR);
+    char *datadir;
+
+    if (asprintf (&datadir, "%s/share", psz_vlcpath) == -1)
+        return NULL;
+    return datadir;
+}
+
+const char *config_GetLibDir (void)
+{
+    abort ();
 }
 
 static char *config_GetHomeDir (void)
 {
-    /* 1/ Try $HOME  */
     const char *home = getenv ("HOME");
 
     if (home == NULL)
@@ -53,27 +73,63 @@ static char *config_GetHomeDir (void)
 
     return FromLocaleDup (home);
 }
-/*
-static char *config_GetAppDir (void)
-{
-    return config_GetUserDir (VLC_CONFIG_DIR);
-} */
 
-char *config_GetUserDir (vlc_userdir_t type)
+static char *getAppDependentDir(vlc_userdir_t type)
 {
-    char *psz_dir;
-    const 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;
+    }
+
+    // Default fallback
+    const char *name = "org.videolan.vlc";
+
+    CFBundleRef mainBundle = CFBundleGetMainBundle();
+    if (mainBundle)
+    {
+        CFStringRef identifierAsNS = CFBundleGetIdentifier(mainBundle);
+        if (identifierAsNS)
+        {
+            char identifier[256];
+            Boolean ret = CFStringGetCString(identifierAsNS, identifier, sizeof(identifier), kCFStringEncodingUTF8);
+            if (ret)
+                name = identifier;            
+        }
+    }
+
+    char *psz_parent = config_GetHomeDir ();
+    char *psz_dir;
+    if( asprintf( &psz_dir, psz_path, psz_parent, name) == -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;
@@ -95,14 +151,14 @@ 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);
     return psz_dir;
 }