2004-07-23 16:35:20 +00:00
|
|
|
/*
|
|
|
|
* Get path to config dir/file.
|
|
|
|
*
|
|
|
|
* Return Values:
|
|
|
|
* Returns the pointer to the ALLOCATED buffer containing the
|
|
|
|
* zero terminated path string. This buffer has to be FREED
|
|
|
|
* by the caller.
|
2010-01-30 23:24:23 +00:00
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-07-23 16:35:20 +00:00
|
|
|
*/
|
2007-08-28 11:20:24 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-02-18 09:29:05 +00:00
|
|
|
#include "config.h"
|
2007-08-28 11:20:24 +00:00
|
|
|
#include "mp_msg.h"
|
2010-03-20 23:38:27 +00:00
|
|
|
#include "path.h"
|
2007-08-28 11:20:24 +00:00
|
|
|
|
2008-08-07 12:20:50 +00:00
|
|
|
#ifdef CONFIG_MACOSX_BUNDLE
|
2005-04-22 12:45:29 +00:00
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
2005-04-13 11:46:35 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2009-01-30 23:29:39 +00:00
|
|
|
#elif defined(__MINGW32__)
|
2007-08-29 09:31:44 +00:00
|
|
|
#include <windows.h>
|
2009-01-30 23:29:39 +00:00
|
|
|
#elif defined(__CYGWIN__)
|
2008-10-13 14:55:01 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <sys/cygwin.h>
|
2008-02-24 12:41:51 +00:00
|
|
|
#endif
|
|
|
|
|
2010-03-10 10:00:59 +00:00
|
|
|
#include "osdep/osdep.h"
|
|
|
|
|
2006-07-03 23:27:37 +00:00
|
|
|
char *get_path(const char *filename){
|
2001-10-30 17:04:59 +00:00
|
|
|
char *homedir;
|
|
|
|
char *buff;
|
2007-08-29 09:43:00 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
static char *config_dir = "/mplayer";
|
2003-04-18 18:17:05 +00:00
|
|
|
#else
|
2001-10-30 17:04:59 +00:00
|
|
|
static char *config_dir = "/.mplayer";
|
2003-04-18 18:17:05 +00:00
|
|
|
#endif
|
2001-10-30 17:04:59 +00:00
|
|
|
int len;
|
2008-08-07 12:20:50 +00:00
|
|
|
#ifdef CONFIG_MACOSX_BUNDLE
|
2005-04-13 11:46:35 +00:00
|
|
|
struct stat dummy;
|
2005-06-03 14:52:15 +00:00
|
|
|
CFIndex maxlen=256;
|
|
|
|
CFURLRef res_url_ref=NULL;
|
|
|
|
CFURLRef bdl_url_ref=NULL;
|
|
|
|
char *res_url_path = NULL;
|
|
|
|
char *bdl_url_path = NULL;
|
2005-04-13 11:46:35 +00:00
|
|
|
#endif
|
2001-10-30 17:04:59 +00:00
|
|
|
|
2005-10-29 12:16:46 +00:00
|
|
|
if ((homedir = getenv("MPLAYER_HOME")) != NULL)
|
|
|
|
config_dir = "";
|
|
|
|
else if ((homedir = getenv("HOME")) == NULL)
|
2007-08-29 09:43:00 +00:00
|
|
|
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
|
|
|
/* Hack to get fonts etc. loaded outside of Cygwin environment. */
|
2003-04-18 18:17:05 +00:00
|
|
|
{
|
2007-08-29 09:43:00 +00:00
|
|
|
int i,imax=0;
|
|
|
|
char exedir[260];
|
|
|
|
GetModuleFileNameA(NULL, exedir, 260);
|
|
|
|
for (i=0; i< strlen(exedir); i++)
|
|
|
|
if (exedir[i] =='\\')
|
|
|
|
{exedir[i]='/'; imax=i;}
|
|
|
|
exedir[imax]='\0';
|
|
|
|
homedir = exedir;
|
2003-04-18 18:17:05 +00:00
|
|
|
}
|
2008-02-24 12:41:51 +00:00
|
|
|
#elif defined(__OS2__)
|
|
|
|
{
|
|
|
|
PPIB ppib;
|
|
|
|
char path[260];
|
|
|
|
|
|
|
|
// Get process info blocks
|
|
|
|
DosGetInfoBlocks(NULL, &ppib);
|
|
|
|
|
|
|
|
// Get full path of the executable
|
|
|
|
DosQueryModuleName(ppib->pib_hmte, sizeof( path ), path);
|
|
|
|
|
|
|
|
// Truncate name part including last backslash
|
|
|
|
*strrchr(path, '\\') = 0;
|
|
|
|
|
|
|
|
// Convert backslash to slash
|
|
|
|
_fnslashify(path);
|
|
|
|
|
|
|
|
homedir = path;
|
|
|
|
}
|
2003-04-18 18:17:05 +00:00
|
|
|
#else
|
2007-08-29 09:43:00 +00:00
|
|
|
return NULL;
|
|
|
|
#endif
|
2001-10-30 17:04:59 +00:00
|
|
|
len = strlen(homedir) + strlen(config_dir) + 1;
|
|
|
|
if (filename == NULL) {
|
2007-07-19 13:52:39 +00:00
|
|
|
if ((buff = malloc(len)) == NULL)
|
2001-10-30 17:04:59 +00:00
|
|
|
return NULL;
|
|
|
|
sprintf(buff, "%s%s", homedir, config_dir);
|
|
|
|
} else {
|
|
|
|
len += strlen(filename) + 1;
|
2007-07-19 13:52:39 +00:00
|
|
|
if ((buff = malloc(len)) == NULL)
|
2001-10-30 17:04:59 +00:00
|
|
|
return NULL;
|
|
|
|
sprintf(buff, "%s%s/%s", homedir, config_dir, filename);
|
|
|
|
}
|
2005-04-13 11:46:35 +00:00
|
|
|
|
2008-08-07 12:20:50 +00:00
|
|
|
#ifdef CONFIG_MACOSX_BUNDLE
|
2007-08-29 09:43:00 +00:00
|
|
|
if (stat(buff, &dummy)) {
|
|
|
|
|
2005-06-03 14:52:15 +00:00
|
|
|
res_url_ref=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
|
|
|
|
bdl_url_ref=CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
2007-08-29 09:43:00 +00:00
|
|
|
|
|
|
|
if (res_url_ref&&bdl_url_ref) {
|
2005-04-13 11:46:35 +00:00
|
|
|
|
2005-06-03 14:52:15 +00:00
|
|
|
res_url_path=malloc(maxlen);
|
|
|
|
bdl_url_path=malloc(maxlen);
|
|
|
|
|
2007-08-29 09:43:00 +00:00
|
|
|
while (!CFURLGetFileSystemRepresentation(res_url_ref, true, res_url_path, maxlen)) {
|
2005-06-03 14:52:15 +00:00
|
|
|
maxlen*=2;
|
|
|
|
res_url_path=realloc(res_url_path, maxlen);
|
|
|
|
}
|
|
|
|
CFRelease(res_url_ref);
|
2007-08-29 09:43:00 +00:00
|
|
|
|
|
|
|
while (!CFURLGetFileSystemRepresentation(bdl_url_ref, true, bdl_url_path, maxlen)) {
|
2005-04-13 11:46:35 +00:00
|
|
|
maxlen*=2;
|
2005-06-03 14:52:15 +00:00
|
|
|
bdl_url_path=realloc(bdl_url_path, maxlen);
|
2005-04-13 11:46:35 +00:00
|
|
|
}
|
2005-06-03 14:52:15 +00:00
|
|
|
CFRelease(bdl_url_ref);
|
2007-08-29 09:43:00 +00:00
|
|
|
|
|
|
|
if (strcmp(res_url_path, bdl_url_path) == 0)
|
2005-06-03 14:52:15 +00:00
|
|
|
res_url_path = NULL;
|
2005-04-13 11:46:35 +00:00
|
|
|
}
|
2007-08-29 09:43:00 +00:00
|
|
|
|
|
|
|
if (res_url_path&&filename) {
|
|
|
|
if ((strlen(filename)+strlen(res_url_path)+2)>maxlen) {
|
2005-06-03 14:52:15 +00:00
|
|
|
maxlen=strlen(filename)+strlen(res_url_path)+2;
|
2005-04-13 11:46:35 +00:00
|
|
|
}
|
2005-06-03 14:52:15 +00:00
|
|
|
free(buff);
|
2007-07-19 13:52:39 +00:00
|
|
|
buff = malloc(maxlen);
|
2005-06-03 14:52:15 +00:00
|
|
|
strcpy(buff, res_url_path);
|
2007-08-29 09:43:00 +00:00
|
|
|
|
2005-04-13 11:46:35 +00:00
|
|
|
strcat(buff,"/");
|
|
|
|
strcat(buff, filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2001-12-25 20:41:04 +00:00
|
|
|
mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff);
|
2001-10-30 17:04:59 +00:00
|
|
|
return buff;
|
|
|
|
}
|
2005-10-16 19:14:09 +00:00
|
|
|
|
2008-10-13 16:23:55 +00:00
|
|
|
#if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
|
2009-05-04 17:35:26 +00:00
|
|
|
void set_path_env(void)
|
2005-10-16 19:14:09 +00:00
|
|
|
{
|
|
|
|
/*make our codec dirs available for LoadLibraryA()*/
|
|
|
|
char win32path[MAX_PATH];
|
|
|
|
#ifdef __CYGWIN__
|
2010-03-14 16:13:32 +00:00
|
|
|
cygwin_conv_to_full_win32_path(BINARY_CODECS_PATH, win32path);
|
2005-10-16 19:14:09 +00:00
|
|
|
#else /*__CYGWIN__*/
|
|
|
|
/* Expand to absolute path unless it's already absolute */
|
2010-03-14 16:13:32 +00:00
|
|
|
if (!strstr(BINARY_CODECS_PATH,":") && BINARY_CODECS_PATH[0] != '\\') {
|
2005-10-16 19:14:09 +00:00
|
|
|
GetModuleFileNameA(NULL, win32path, MAX_PATH);
|
2010-03-14 16:13:32 +00:00
|
|
|
strcpy(strrchr(win32path, '\\') + 1, BINARY_CODECS_PATH);
|
2005-10-16 19:14:09 +00:00
|
|
|
}
|
2010-03-14 16:13:32 +00:00
|
|
|
else strcpy(win32path, BINARY_CODECS_PATH);
|
2005-10-16 19:14:09 +00:00
|
|
|
#endif /*__CYGWIN__*/
|
2010-03-14 23:42:03 +00:00
|
|
|
mp_msg(MSGT_WIN32, MSGL_V, "Setting PATH to %s\n", win32path);
|
|
|
|
if (!SetEnvironmentVariableA("PATH", win32path))
|
2005-10-16 19:14:09 +00:00
|
|
|
mp_msg(MSGT_WIN32, MSGL_WARN, "Cannot set PATH!");
|
|
|
|
}
|
2008-10-13 16:23:55 +00:00
|
|
|
#endif /* (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL) */
|
2010-03-20 23:27:07 +00:00
|
|
|
|
2010-03-23 18:01:00 +00:00
|
|
|
char *codec_path = BINARY_CODECS_PATH;
|
2010-03-20 23:27:07 +00:00
|
|
|
|
|
|
|
static int needs_free = 0;
|
|
|
|
|
2010-03-21 08:34:09 +00:00
|
|
|
void set_codec_path(const char *path)
|
2010-03-20 23:27:07 +00:00
|
|
|
{
|
|
|
|
if (needs_free)
|
2010-03-23 18:01:00 +00:00
|
|
|
free(codec_path);
|
2010-03-20 23:27:07 +00:00
|
|
|
if (path == 0) {
|
2010-03-23 18:01:00 +00:00
|
|
|
codec_path = BINARY_CODECS_PATH;
|
2010-03-20 23:27:07 +00:00
|
|
|
needs_free = 0;
|
|
|
|
return;
|
|
|
|
}
|
2010-03-23 18:01:00 +00:00
|
|
|
codec_path = malloc(strlen(path) + 1);
|
|
|
|
strcpy(codec_path, path);
|
2010-03-20 23:27:07 +00:00
|
|
|
needs_free = 1;
|
|
|
|
}
|