diff --git modules/lua/vlc.c modules/lua/vlc.c index df235d0..b753346 100644 --- modules/lua/vlc.c +++ modules/lua/vlc.c @@ -232,10 +232,22 @@ int vlclua_dir_list( const char *luadirname, char ***pppsz_dir_list ) i++; #if defined(__APPLE__) - if( likely(asprintf( &ppsz_dir_list[i], + if( strcasestr (psz_datapath, "/share") == NULL + && likely(asprintf( &ppsz_dir_list[i], "%s"DIR_SEP"share"DIR_SEP"lua"DIR_SEP"%s", psz_datapath, luadirname ) != -1) ) i++; + // When installed through MacPorts (or Fink, or HomeBrew, or...?) we do have + // meta/reader under LibDir/lua (/opt/local/lib/vlc/lua for MacPorts's standard install prefix) + // so we add that location at the end. + char *psz_libpath = config_GetLibDir(); + if( likely(psz_libpath != NULL) ) + { + if( likely(asprintf( &ppsz_dir_list[i], "%s"DIR_SEP"lua"DIR_SEP"%s", + psz_libpath, luadirname ) != -1) ) + i++; + free( psz_libpath ); + } #endif free( psz_datapath ); } diff --git src/darwin/dirs.c src/darwin/dirs.c index 381729c..9174602 100644 --- src/darwin/dirs.c +++ src/darwin/dirs.c @@ -43,14 +43,20 @@ # define MAXPATHLEN 1024 #endif -char *config_GetLibDir (void) +// 20150205: we should do case-insensitive filename comparisons. HFS is case-insensitive by default, +// and while it strives to preserve case there is no guarantee that case folding will never occur, +// especially in directory components. + +// @p libDirIsPosix is set to true in if getLibDir() detects we're installed +// in a (linux-specific) posix way, like e.g. MacPorts would do. +char *getLibDir (bool *libDirIsPosix) { + *libDirIsPosix = FALSE; /* Get the full program path and name */ /* First try to see if we are linked to the framework */ - for (unsigned i = 0; i < _dyld_image_count(); i++) - { + for (unsigned i = 0; i < _dyld_image_count(); i++) { const char *psz_img_name = _dyld_get_image_name(i); - const char *p = strstr( psz_img_name, "VLCKit.framework/Versions/" ); + const char *p = strcasestr( psz_img_name, "VLCKit.framework/Versions/" ); /* Check for "VLCKit.framework/Versions/Current/VLCKit", * as well as "VLCKit.framework/Versions/A/VLCKit" and @@ -61,18 +67,18 @@ char *config_GetLibDir (void) p += strcspn( p, "/" ); /* If the string ends with VLCKit then we've found a winner */ - if (!strcmp( p, "/VLCKit")) + if (!strcasecmp( p, "/VLCKit")) return strdup( dirname(psz_img_name) ); } - /* Do we end by "VLC"? If so we are the legacy VLC.app that doesn't + /* Do we end by "MacOS/VLC"? If so we are the legacy VLC.app that doesn't * link to VLCKit. */ size_t len = strlen(psz_img_name); - if (len >= 3 && !strcmp( psz_img_name + len - 3, "VLC")) + if (len >= 9 && !strcasecmp( psz_img_name + len - 9, "MacOS/VLC")) return strdup( dirname(psz_img_name) ); /* Do we end by "VLC-Plugin"? oh, we must be the NPAPI plugin */ - if (len >= 10 && !strcmp( psz_img_name + len - 10, "VLC-Plugin")) + if (len >= 10 && !strcasecmp( psz_img_name + len - 10, "VLC-Plugin")) return strdup( dirname(psz_img_name) ); } @@ -84,6 +90,7 @@ char *config_GetLibDir (void) char *path = NULL; asprintf(&path, "%s/"PACKAGE, incompletepath); free(incompletepath); + *libDirIsPosix = TRUE; return path; } @@ -91,15 +98,37 @@ char *config_GetLibDir (void) abort (); } +char *config_GetLibDir (void) +{ + bool isPosixStub; + return getLibDir (&isPosixStub); +} + char *config_GetDataDir (void) { const char *path = getenv ("VLC_DATA_PATH"); if (path) return strdup (path); - char *vlcpath = config_GetLibDir (); - char *datadir; + bool libDirIsPosix; + char *vlcpath = getLibDir (&libDirIsPosix); + char *datadir = NULL; + if (libDirIsPosix) { + // vlcpath should point to something like /opt/local/lib/vlc + // if so, we can chop off the /lib/vlc bit, and then add /share + // like we would otherwise. + char *p = strcasestr(vlcpath, "/lib/"); + if (p != NULL) { + *p = '\0'; + } + else { + // something else ... return PKGDATADIR + free(vlcpath); + datadir = strdup(PKGDATADIR); + return datadir; + } + } if (asprintf (&datadir, "%s/share", vlcpath) == -1) datadir = NULL; @@ -137,16 +166,24 @@ static char *getAppDependentDir(vlc_userdir_t type) } // 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 name[256] = "org.videolan.vlc"; + bool libDirIsPosix; + char *vlcpath = getLibDir(&libDirIsPosix); + if (vlcpath) { + free(vlcpath); + } + + if (!libDirIsPosix) { + CFBundleRef mainBundle = CFBundleGetMainBundle(); + if (mainBundle) { + CFStringRef identifierAsNS = CFBundleGetIdentifier(mainBundle); + if (identifierAsNS) { + char identifier[256]; + Boolean ret = CFStringGetCString(identifierAsNS, identifier, sizeof(identifier), kCFStringEncodingUTF8); + // Don't use an empty identifier (= the application that links to us doesn't have a CFBundleIdentifier set). + if (ret && strlen(identifier)) + strcpy(name, identifier); + } } }