| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
#ifdef HAVE_CONFIG_H |
|---|
| 27 |
# include "config.h" |
|---|
| 28 |
#endif |
|---|
| 29 |
|
|---|
| 30 |
#include <vlc_common.h> |
|---|
| 31 |
#include "../libvlc.h" |
|---|
| 32 |
#include <dirent.h> |
|---|
| 33 |
|
|---|
| 34 |
#include <CoreFoundation/CoreFoundation.h> |
|---|
| 35 |
|
|---|
| 36 |
#ifdef HAVE_LOCALE_H |
|---|
| 37 |
# include <locale.h> |
|---|
| 38 |
#endif |
|---|
| 39 |
#ifdef HAVE_MACH_O_DYLD_H |
|---|
| 40 |
# include <mach-o/dyld.h> |
|---|
| 41 |
#endif |
|---|
| 42 |
|
|---|
| 43 |
#ifndef MAXPATHLEN |
|---|
| 44 |
# define MAXPATHLEN 1024 |
|---|
| 45 |
#endif |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
extern CFArrayRef CFLocaleCopyAvailableLocaleIdentifiers(void) __attribute__((weak_import)); |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
static CFArrayRef copy_all_locale_indentifiers(void) |
|---|
| 52 |
{ |
|---|
| 53 |
CFMutableArrayRef available_locales; |
|---|
| 54 |
DIR * dir; |
|---|
| 55 |
struct dirent *file; |
|---|
| 56 |
|
|---|
| 57 |
dir = opendir( "/usr/share/locale" ); |
|---|
| 58 |
available_locales = CFArrayCreateMutable( kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks ); |
|---|
| 59 |
|
|---|
| 60 |
while ( (file = readdir(dir)) ) |
|---|
| 61 |
{ |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
CFStringRef locale = CFStringCreateWithCString( kCFAllocatorDefault, file->d_name, kCFStringEncodingUTF8 ); |
|---|
| 66 |
CFArrayAppendValue( available_locales, (void*)locale ); |
|---|
| 67 |
CFRelease( locale ); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
closedir( dir ); |
|---|
| 71 |
return available_locales; |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] ) |
|---|
| 78 |
{ |
|---|
| 79 |
VLC_UNUSED(p_this); |
|---|
| 80 |
char i_dummy; |
|---|
| 81 |
char *p_char = NULL; |
|---|
| 82 |
char *p_oldchar = &i_dummy; |
|---|
| 83 |
unsigned int i; |
|---|
| 84 |
(void)pi_argc; |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
for (i = 0; i < _dyld_image_count(); i++) |
|---|
| 90 |
{ |
|---|
| 91 |
const char * psz_img_name = _dyld_get_image_name(i); |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
if( (p_char = strstr( psz_img_name, "VLCKit.framework/Versions/" )) ) |
|---|
| 96 |
{ |
|---|
| 97 |
|
|---|
| 98 |
p_char += 26; |
|---|
| 99 |
while( *p_char != '\0' && *p_char != '/') |
|---|
| 100 |
p_char++; |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
if ( !strcmp( p_char, "/VLCKit" ) ) |
|---|
| 104 |
{ |
|---|
| 105 |
p_char = strdup( psz_img_name ); |
|---|
| 106 |
break; |
|---|
| 107 |
} |
|---|
| 108 |
else |
|---|
| 109 |
p_char = NULL; |
|---|
| 110 |
} |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
if( !p_char ) |
|---|
| 114 |
{ |
|---|
| 115 |
char path[MAXPATHLEN+1]; |
|---|
| 116 |
uint32_t path_len = MAXPATHLEN; |
|---|
| 117 |
if ( !_NSGetExecutablePath(path, &path_len) ) |
|---|
| 118 |
p_char = strdup(path); |
|---|
| 119 |
} |
|---|
| 120 |
if( !p_char ) |
|---|
| 121 |
{ |
|---|
| 122 |
|
|---|
| 123 |
p_char = strdup( ppsz_argv[ 0 ] ); |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
vlc_global()->psz_vlcpath = p_char; |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
for( ; *p_char ; ) |
|---|
| 130 |
{ |
|---|
| 131 |
if( *p_char == '/' ) |
|---|
| 132 |
{ |
|---|
| 133 |
*p_oldchar = '/'; |
|---|
| 134 |
*p_char = '\0'; |
|---|
| 135 |
p_oldchar = p_char; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
p_char++; |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
if ( (p_char = getenv("LANG")) == NULL ) |
|---|
| 143 |
{ |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
CFArrayRef all_locales, preferred_locales; |
|---|
| 150 |
char psz_locale[50]; |
|---|
| 151 |
|
|---|
| 152 |
if( CFLocaleCopyAvailableLocaleIdentifiers ) |
|---|
| 153 |
all_locales = CFLocaleCopyAvailableLocaleIdentifiers(); |
|---|
| 154 |
else |
|---|
| 155 |
all_locales = copy_all_locale_indentifiers(); |
|---|
| 156 |
|
|---|
| 157 |
preferred_locales = CFBundleCopyLocalizationsForPreferences( all_locales, NULL ); |
|---|
| 158 |
|
|---|
| 159 |
if ( preferred_locales ) |
|---|
| 160 |
{ |
|---|
| 161 |
if ( CFArrayGetCount( preferred_locales ) ) |
|---|
| 162 |
{ |
|---|
| 163 |
CFStringRef user_language_string_ref = CFArrayGetValueAtIndex( preferred_locales, 0 ); |
|---|
| 164 |
CFStringGetCString( user_language_string_ref, psz_locale, sizeof(psz_locale), kCFStringEncodingUTF8 ); |
|---|
| 165 |
setenv( "LANG", psz_locale, 1 ); |
|---|
| 166 |
} |
|---|
| 167 |
CFRelease( preferred_locales ); |
|---|
| 168 |
} |
|---|
| 169 |
CFRelease( all_locales ); |
|---|
| 170 |
} |
|---|
| 171 |
} |
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
void system_Configure( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] ) |
|---|
| 177 |
{ |
|---|
| 178 |
(void)p_this; |
|---|
| 179 |
(void)pi_argc; |
|---|
| 180 |
(void)ppsz_argv; |
|---|
| 181 |
} |
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
void system_End( libvlc_int_t *p_this ) |
|---|
| 187 |
{ |
|---|
| 188 |
(void)p_this; |
|---|
| 189 |
free( vlc_global()->psz_vlcpath ); |
|---|
| 190 |
} |
|---|
| 191 |
|
|---|