| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
#ifdef HAVE_CONFIG_H |
|---|
| 25 |
# include "config.h" |
|---|
| 26 |
#endif |
|---|
| 27 |
|
|---|
| 28 |
#include <vlc_common.h> |
|---|
| 29 |
|
|---|
| 30 |
#if defined( WIN32 ) |
|---|
| 31 |
# define _WIN32_IE IE5 |
|---|
| 32 |
# include <w32api.h> |
|---|
| 33 |
# include <direct.h> |
|---|
| 34 |
# include <shlobj.h> |
|---|
| 35 |
#else |
|---|
| 36 |
# include <unistd.h> |
|---|
| 37 |
# include <pwd.h> |
|---|
| 38 |
#endif |
|---|
| 39 |
|
|---|
| 40 |
#include "../libvlc.h" |
|---|
| 41 |
#include "configuration.h" |
|---|
| 42 |
#include <vlc_charset.h> |
|---|
| 43 |
#include <vlc_configuration.h> |
|---|
| 44 |
|
|---|
| 45 |
#include <errno.h> |
|---|
| 46 |
#include <assert.h> |
|---|
| 47 |
#include <limits.h> |
|---|
| 48 |
|
|---|
| 49 |
#if defined( WIN32 ) |
|---|
| 50 |
# define DIR_SHARE "" |
|---|
| 51 |
#else |
|---|
| 52 |
# define DIR_SHARE "share" |
|---|
| 53 |
#endif |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
const char *config_GetDataDir( void ) |
|---|
| 61 |
{ |
|---|
| 62 |
#if defined (WIN32) || defined(__APPLE__) || defined (SYS_BEOS) |
|---|
| 63 |
static char path[PATH_MAX] = ""; |
|---|
| 64 |
|
|---|
| 65 |
if( *path == '\0' ) |
|---|
| 66 |
{ |
|---|
| 67 |
snprintf( path, sizeof( path ), "%s" DIR_SEP DIR_SHARE, |
|---|
| 68 |
vlc_global()->psz_vlcpath ); |
|---|
| 69 |
path[sizeof( path ) - 1] = '\0'; |
|---|
| 70 |
} |
|---|
| 71 |
return path; |
|---|
| 72 |
#else |
|---|
| 73 |
return DATA_PATH; |
|---|
| 74 |
#endif |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
static const char *GetDir( bool b_appdata, bool b_common_appdata ) |
|---|
| 78 |
{ |
|---|
| 79 |
|
|---|
| 80 |
static char homedir[PATH_MAX] = ""; |
|---|
| 81 |
|
|---|
| 82 |
#if defined (WIN32) |
|---|
| 83 |
wchar_t wdir[MAX_PATH]; |
|---|
| 84 |
|
|---|
| 85 |
# if defined (UNDER_CE) |
|---|
| 86 |
if( SHGetSpecialFolderPath( NULL, wdir, CSIDL_APPDATA, 1 ) ) |
|---|
| 87 |
# else |
|---|
| 88 |
|
|---|
| 89 |
if( S_OK == SHGetFolderPathW( NULL, |
|---|
| 90 |
( b_appdata ? CSIDL_APPDATA : |
|---|
| 91 |
( b_common_appdata ? CSIDL_COMMON_APPDATA: CSIDL_PERSONAL ) ) |
|---|
| 92 |
| CSIDL_FLAG_CREATE, |
|---|
| 93 |
NULL, SHGFP_TYPE_CURRENT, wdir ) ) |
|---|
| 94 |
# endif |
|---|
| 95 |
{ |
|---|
| 96 |
static char appdir[PATH_MAX] = ""; |
|---|
| 97 |
static char comappdir[PATH_MAX] = ""; |
|---|
| 98 |
WideCharToMultiByte (CP_UTF8, 0, wdir, -1, |
|---|
| 99 |
b_appdata ? appdir : |
|---|
| 100 |
(b_common_appdata ? comappdir :homedir), |
|---|
| 101 |
PATH_MAX, NULL, NULL); |
|---|
| 102 |
return b_appdata ? appdir : (b_common_appdata ? comappdir :homedir); |
|---|
| 103 |
} |
|---|
| 104 |
#else |
|---|
| 105 |
(void)b_appdata; |
|---|
| 106 |
(void)b_common_appdata; |
|---|
| 107 |
#endif |
|---|
| 108 |
|
|---|
| 109 |
#ifdef LIBVLC_USE_PTHREAD |
|---|
| 110 |
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; |
|---|
| 111 |
pthread_mutex_lock (&lock); |
|---|
| 112 |
#endif |
|---|
| 113 |
|
|---|
| 114 |
if (!*homedir) |
|---|
| 115 |
{ |
|---|
| 116 |
const char *psz_localhome = getenv( "HOME" ); |
|---|
| 117 |
#if defined(HAVE_GETPWUID_R) |
|---|
| 118 |
char buf[sysconf (_SC_GETPW_R_SIZE_MAX)]; |
|---|
| 119 |
if (psz_localhome == NULL) |
|---|
| 120 |
{ |
|---|
| 121 |
struct passwd pw, *res; |
|---|
| 122 |
|
|---|
| 123 |
if (!getpwuid_r (getuid (), &pw, buf, sizeof (buf), &res) && res) |
|---|
| 124 |
psz_localhome = pw.pw_dir; |
|---|
| 125 |
} |
|---|
| 126 |
#endif |
|---|
| 127 |
if (psz_localhome == NULL) |
|---|
| 128 |
psz_localhome = getenv( "TMP" ); |
|---|
| 129 |
if (psz_localhome == NULL) |
|---|
| 130 |
psz_localhome = "/tmp"; |
|---|
| 131 |
|
|---|
| 132 |
const char *uhomedir = FromLocale (psz_localhome); |
|---|
| 133 |
strncpy (homedir, uhomedir, sizeof (homedir) - 1); |
|---|
| 134 |
homedir[sizeof (homedir) - 1] = '\0'; |
|---|
| 135 |
LocaleFree (uhomedir); |
|---|
| 136 |
} |
|---|
| 137 |
#ifdef LIBVLC_USE_PTHREAD |
|---|
| 138 |
pthread_mutex_unlock (&lock); |
|---|
| 139 |
#endif |
|---|
| 140 |
return homedir; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
const char *config_GetConfDir( void ) |
|---|
| 149 |
{ |
|---|
| 150 |
#if defined (WIN32) |
|---|
| 151 |
return GetDir( false, true ); |
|---|
| 152 |
#elif defined(__APPLE__) || defined (SYS_BEOS) |
|---|
| 153 |
static char path[PATH_MAX] = ""; |
|---|
| 154 |
|
|---|
| 155 |
if( *path == '\0' ) |
|---|
| 156 |
{ |
|---|
| 157 |
snprintf( path, sizeof( path ), "%s"DIR_SEP DIR_SHARE, |
|---|
| 158 |
vlc_global()->psz_vlcpath ); |
|---|
| 159 |
path[sizeof( path ) - 1] = '\0'; |
|---|
| 160 |
} |
|---|
| 161 |
return path; |
|---|
| 162 |
#else |
|---|
| 163 |
return SYSCONFDIR; |
|---|
| 164 |
#endif |
|---|
| 165 |
} |
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
const char *config_GetHomeDir( void ) |
|---|
| 171 |
{ |
|---|
| 172 |
return GetDir (false, false); |
|---|
| 173 |
} |
|---|
| 174 |
|
|---|
| 175 |
static char *config_GetFooDir (const char *xdg_name, const char *xdg_default) |
|---|
| 176 |
{ |
|---|
| 177 |
char *psz_dir; |
|---|
| 178 |
#if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS) |
|---|
| 179 |
const char *psz_parent = GetDir (true, false); |
|---|
| 180 |
|
|---|
| 181 |
if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 ) |
|---|
| 182 |
psz_dir = NULL; |
|---|
| 183 |
|
|---|
| 184 |
(void)xdg_name; (void)xdg_default; |
|---|
| 185 |
#else |
|---|
| 186 |
char var[sizeof ("XDG__HOME") + strlen (xdg_name)]; |
|---|
| 187 |
|
|---|
| 188 |
snprintf (var, sizeof (var), "XDG_%s_HOME", xdg_name); |
|---|
| 189 |
|
|---|
| 190 |
const char *psz_home = getenv (var); |
|---|
| 191 |
psz_home = psz_home ? FromLocale (psz_home) : NULL; |
|---|
| 192 |
if( psz_home ) |
|---|
| 193 |
{ |
|---|
| 194 |
if( asprintf( &psz_dir, "%s/vlc", psz_home ) == -1 ) |
|---|
| 195 |
psz_dir = NULL; |
|---|
| 196 |
LocaleFree (psz_home); |
|---|
| 197 |
return psz_dir; |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
psz_home = config_GetHomeDir(); |
|---|
| 202 |
if( asprintf( &psz_dir, "%s/%s/vlc", psz_home, xdg_default ) == -1 ) |
|---|
| 203 |
psz_dir = NULL; |
|---|
| 204 |
#endif |
|---|
| 205 |
return psz_dir; |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
char *config_GetUserConfDir( void ) |
|---|
| 212 |
{ |
|---|
| 213 |
return config_GetFooDir ("CONFIG", ".config"); |
|---|
| 214 |
} |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
char *config_GetUserDataDir( void ) |
|---|
| 221 |
{ |
|---|
| 222 |
return config_GetFooDir ("DATA", ".local/share"); |
|---|
| 223 |
} |
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
char *config_GetCacheDir( void ) |
|---|
| 230 |
{ |
|---|
| 231 |
return config_GetFooDir ("CACHE", ".cache"); |
|---|
| 232 |
} |
|---|