X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fdarwin_specific.c;h=f962c1def3f02f66900d0b2e635577173d694580;hb=a9d773c1af2d3f021b4aa371d30d0a5f30369af2;hp=69695c8e143d92b8c19aa38acea81408fd687ae8;hpb=cc3bd152f5d2166087b9e19b962e3ace06bd12ea;p=vlc diff --git a/src/misc/darwin_specific.c b/src/misc/darwin_specific.c index 69695c8e14..f962c1def3 100644 --- a/src/misc/darwin_specific.c +++ b/src/misc/darwin_specific.c @@ -23,6 +23,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include "../libvlc.h" #include /* *dir() */ @@ -32,6 +36,13 @@ #ifdef HAVE_LOCALE_H # include #endif +#ifdef HAVE_MACH_O_DYLD_H +# include +#endif + +#ifndef MAXPATHLEN +# define MAXPATHLEN 1024 +#endif /* CFLocaleCopyAvailableLocaleIdentifiers is present only on post-10.4 */ extern CFArrayRef CFLocaleCopyAvailableLocaleIdentifiers(void) __attribute__((weak_import)); @@ -49,7 +60,7 @@ static CFArrayRef copy_all_locale_indentifiers(void) while ( (file = readdir(dir)) ) { /* we should probably filter out garbage */ - /* we can't use CFStringCreateWithFileSystemRepresentation as it is + /* we can't use CFStringCreateWithFileSystemRepresentation as it is * supported only on post-10.4 (and this function is only for pre-10.4) */ CFStringRef locale = CFStringCreateWithCString( kCFAllocatorDefault, file->d_name, kCFStringEncodingUTF8 ); CFArrayAppendValue( available_locales, (void*)locale ); @@ -63,13 +74,56 @@ static CFArrayRef copy_all_locale_indentifiers(void) /***************************************************************************** * system_Init: fill in program path & retrieve language *****************************************************************************/ -void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) +void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] ) { + VLC_UNUSED(p_this); char i_dummy; - char *p_char, *p_oldchar = &i_dummy; + char *p_char = NULL; + char *p_oldchar = &i_dummy; + unsigned int i; + (void)pi_argc; /* Get the full program path and name */ - p_char = vlc_global()->psz_vlcpath = strdup( ppsz_argv[ 0 ] ); + + /* First try to see if we are linked to the framework */ + for (i = 0; i < _dyld_image_count(); i++) + { + const char * psz_img_name = _dyld_get_image_name(i); + /* Check for "VLCKit.framework/Versions/Current/VLCKit", + * as well as "VLCKit.framework/Versions/A/VLCKit" and + * "VLC.framework/Versions/B/VLCKit" */ + if( (p_char = strstr( psz_img_name, "VLCKit.framework/Versions/" )) ) + { + /* Look for the next forward slash */ + p_char += 26; /* p_char += strlen(" VLCKit.framework/Versions/" ) */ + while( *p_char != '\0' && *p_char != '/') + p_char++; + + /* If the string ends with VLC then we've found a winner */ + if ( !strcmp( p_char, "/VLCKit" ) ) + { + p_char = strdup( psz_img_name ); + break; + } + else + p_char = NULL; + } + } + + if( !p_char ) + { + char path[MAXPATHLEN+1]; + uint32_t path_len = MAXPATHLEN; + if ( !_NSGetExecutablePath(path, &path_len) ) + p_char = strdup(path); + } + if( !p_char ) + { + /* We are not linked to the VLC.framework, return the executable path */ + p_char = strdup( ppsz_argv[ 0 ] ); + } + + vlc_global()->psz_vlcpath = p_char; /* Remove trailing program name */ for( ; *p_char ; ) @@ -90,7 +144,7 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) /* Retrieve the preferred language as chosen in System Preferences.app (note that CFLocaleCopyCurrent() is not used because it returns the - prefered locale not language) + preferred locale not language) */ CFArrayRef all_locales, preferred_locales; char psz_locale[50]; @@ -122,9 +176,11 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) /***************************************************************************** * system_Configure: check for system specific configuration options. *****************************************************************************/ -void system_Configure( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) +void system_Configure( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] ) { - + (void)p_this; + (void)pi_argc; + (void)ppsz_argv; } /***************************************************************************** @@ -132,6 +188,7 @@ void system_Configure( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) *****************************************************************************/ void system_End( libvlc_int_t *p_this ) { + (void)p_this; free( vlc_global()->psz_vlcpath ); if ( vlc_global()->iconv_macosx != (vlc_iconv_t)-1 )