2 * Get path to config dir/file.
5 * Returns the pointer to the ALLOCATED buffer containing the
6 * zero terminated path string. This buffer has to be FREED
9 * This file is part of MPlayer.
11 * MPlayer is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * MPlayer is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #ifdef CONFIG_MACOSX_BUNDLE
34 #include <CoreFoundation/CoreFoundation.h>
35 #include <sys/types.h>
38 #elif defined(__MINGW32__)
40 #elif defined(__CYGWIN__)
42 #include <sys/cygwin.h>
45 #include "osdep/osdep.h"
47 char *get_path(const char *filename
){
51 static char *config_dir
= "/mplayer";
53 static char *config_dir
= "/.mplayer";
56 #ifdef CONFIG_MACOSX_BUNDLE
59 CFURLRef res_url_ref
=NULL
;
60 CFURLRef bdl_url_ref
=NULL
;
61 char *res_url_path
= NULL
;
62 char *bdl_url_path
= NULL
;
65 if ((homedir
= getenv("MPLAYER_HOME")) != NULL
)
67 else if ((homedir
= getenv("HOME")) == NULL
)
68 #if defined(__MINGW32__) || defined(__CYGWIN__)
69 /* Hack to get fonts etc. loaded outside of Cygwin environment. */
73 GetModuleFileNameA(NULL
, exedir
, 260);
74 for (i
=0; i
< strlen(exedir
); i
++)
76 {exedir
[i
]='/'; imax
=i
;}
80 #elif defined(__OS2__)
85 // Get process info blocks
86 DosGetInfoBlocks(NULL
, &ppib
);
88 // Get full path of the executable
89 DosQueryModuleName(ppib
->pib_hmte
, sizeof( path
), path
);
91 // Truncate name part including last backslash
92 *strrchr(path
, '\\') = 0;
94 // Convert backslash to slash
102 len
= strlen(homedir
) + strlen(config_dir
) + 1;
103 if (filename
== NULL
) {
104 if ((buff
= malloc(len
)) == NULL
)
106 sprintf(buff
, "%s%s", homedir
, config_dir
);
108 len
+= strlen(filename
) + 1;
109 if ((buff
= malloc(len
)) == NULL
)
111 sprintf(buff
, "%s%s/%s", homedir
, config_dir
, filename
);
114 #ifdef CONFIG_MACOSX_BUNDLE
115 if (stat(buff
, &dummy
)) {
117 res_url_ref
=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
118 bdl_url_ref
=CFBundleCopyBundleURL(CFBundleGetMainBundle());
120 if (res_url_ref
&&bdl_url_ref
) {
122 res_url_path
=malloc(maxlen
);
123 bdl_url_path
=malloc(maxlen
);
125 while (!CFURLGetFileSystemRepresentation(res_url_ref
, true, res_url_path
, maxlen
)) {
127 res_url_path
=realloc(res_url_path
, maxlen
);
129 CFRelease(res_url_ref
);
131 while (!CFURLGetFileSystemRepresentation(bdl_url_ref
, true, bdl_url_path
, maxlen
)) {
133 bdl_url_path
=realloc(bdl_url_path
, maxlen
);
135 CFRelease(bdl_url_ref
);
137 if (strcmp(res_url_path
, bdl_url_path
) == 0)
141 if (res_url_path
&&filename
) {
142 if ((strlen(filename
)+strlen(res_url_path
)+2)>maxlen
) {
143 maxlen
=strlen(filename
)+strlen(res_url_path
)+2;
146 buff
= malloc(maxlen
);
147 strcpy(buff
, res_url_path
);
150 strcat(buff
, filename
);
154 mp_msg(MSGT_GLOBAL
,MSGL_V
,"get_path('%s') -> '%s'\n",filename
,buff
);
158 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
159 void set_path_env(void)
161 /*make our codec dirs available for LoadLibraryA()*/
162 char win32path
[MAX_PATH
];
164 cygwin_conv_to_full_win32_path(BINARY_CODECS_PATH
, win32path
);
166 /* Expand to absolute path unless it's already absolute */
167 if (!strstr(BINARY_CODECS_PATH
,":") && BINARY_CODECS_PATH
[0] != '\\') {
168 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
169 strcpy(strrchr(win32path
, '\\') + 1, BINARY_CODECS_PATH
);
171 else strcpy(win32path
, BINARY_CODECS_PATH
);
172 #endif /*__CYGWIN__*/
173 mp_msg(MSGT_WIN32
, MSGL_V
, "Setting PATH to %s\n", win32path
);
174 if (!SetEnvironmentVariableA("PATH", win32path
))
175 mp_msg(MSGT_WIN32
, MSGL_WARN
, "Cannot set PATH!");
177 #endif /* (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL) */
179 char *codec_path
= BINARY_CODECS_PATH
;
181 static int needs_free
= 0;
183 void set_codec_path(const char *path
)
188 codec_path
= BINARY_CODECS_PATH
;
192 codec_path
= malloc(strlen(path
) + 1);
193 strcpy(codec_path
, path
);