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>
39 #define _WIN32_IE 0x0400
42 #include <sys/types.h>
44 #if defined(__CYGWIN__)
45 #include <sys/cygwin.h>
47 #elif defined(__OS2__)
52 char *get_path(const char *filename
){
56 static char *config_dir
= "/mplayer";
58 static char *config_dir
= "/.mplayer";
61 #ifdef CONFIG_MACOSX_BUNDLE
64 CFURLRef res_url_ref
=NULL
;
65 CFURLRef bdl_url_ref
=NULL
;
66 char *res_url_path
= NULL
;
67 char *bdl_url_path
= NULL
;
70 if ((homedir
= getenv("MPLAYER_HOME")) != NULL
)
72 else if ((homedir
= getenv("HOME")) == NULL
)
74 /* Hack to get fonts etc. loaded outside of Cygwin environment. */
77 struct _stat statBuffer
;
78 char exedir
[4096], config_path
[4096], appdata
[4096];
79 if (SHGetSpecialFolderPathA(NULL
, appdata
, CSIDL_APPDATA
, 1)) {
80 strncpy(exedir
, appdata
, strlen(appdata
));
82 GetModuleFileNameA(NULL
, exedir
, 4096);
84 int len
= strlen(exedir
);
85 for (i
=0; i
< len
; i
++)
89 sprintf(config_path
, "%s%s", exedir
, config_dir
);
91 if ((stat_res
= stat(config_path
, &statBuffer
)) < 0 ||
92 !(statBuffer
.st_mode
& S_IFDIR
)) {
93 GetModuleFileNameA(NULL
, exedir
, 4096);
95 for (i
=0; i
< len
; i
++)
97 {exedir
[i
]='/'; imax
=i
;}
103 #elif defined(__OS2__)
108 // Get process info blocks
109 DosGetInfoBlocks(NULL
, &ppib
);
111 // Get full path of the executable
112 DosQueryModuleName(ppib
->pib_hmte
, sizeof( path
), path
);
114 // Truncate name part including last backslash
115 *strrchr(path
, '\\') = 0;
117 // Convert backslash to slash
125 len
= strlen(homedir
) + strlen(config_dir
) + 1;
126 if (filename
== NULL
) {
127 if ((buff
= malloc(len
)) == NULL
)
129 sprintf(buff
, "%s%s", homedir
, config_dir
);
131 len
+= strlen(filename
) + 1;
132 if ((buff
= malloc(len
)) == NULL
)
134 sprintf(buff
, "%s%s/%s", homedir
, config_dir
, filename
);
137 #ifdef CONFIG_MACOSX_BUNDLE
138 if (stat(buff
, &dummy
)) {
140 res_url_ref
=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
141 bdl_url_ref
=CFBundleCopyBundleURL(CFBundleGetMainBundle());
143 if (res_url_ref
&&bdl_url_ref
) {
145 res_url_path
=malloc(maxlen
);
146 bdl_url_path
=malloc(maxlen
);
148 while (!CFURLGetFileSystemRepresentation(res_url_ref
, true, res_url_path
, maxlen
)) {
150 res_url_path
=realloc(res_url_path
, maxlen
);
152 CFRelease(res_url_ref
);
154 while (!CFURLGetFileSystemRepresentation(bdl_url_ref
, true, bdl_url_path
, maxlen
)) {
156 bdl_url_path
=realloc(bdl_url_path
, maxlen
);
158 CFRelease(bdl_url_ref
);
160 if (strcmp(res_url_path
, bdl_url_path
) == 0)
164 if (res_url_path
&&filename
) {
165 if ((strlen(filename
)+strlen(res_url_path
)+2)>maxlen
) {
166 maxlen
=strlen(filename
)+strlen(res_url_path
)+2;
169 buff
= malloc(maxlen
);
170 strcpy(buff
, res_url_path
);
173 strcat(buff
, filename
);
177 mp_msg(MSGT_GLOBAL
,MSGL_V
,"get_path('%s') -> '%s'\n",filename
,buff
);
181 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
182 void set_path_env(void)
184 /*make our codec dirs available for LoadLibraryA()*/
185 char tmppath
[MAX_PATH
*2 + 1];
186 char win32path
[MAX_PATH
];
187 char realpath
[MAX_PATH
];
189 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
190 strcpy(tmppath
,win32path
);
191 #ifdef CONFIG_REALCODECS
192 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
193 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
194 #endif /*CONFIG_REALCODECS*/
196 /* Expand to absolute path unless it's already absolute */
197 if (!strstr(WIN32_PATH
,":") && WIN32_PATH
[0] != '\\'){
198 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
199 strcpy(strrchr(win32path
, '\\') + 1, WIN32_PATH
);
201 else strcpy(win32path
,WIN32_PATH
);
202 strcpy(tmppath
,win32path
);
203 #ifdef CONFIG_REALCODECS
204 /* Expand to absolute path unless it's already absolute */
205 if (!strstr(REALCODEC_PATH
,":") && REALCODEC_PATH
[0] != '\\'){
206 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
207 strcpy(strrchr(realpath
, '\\') + 1, REALCODEC_PATH
);
209 else strcpy(realpath
,REALCODEC_PATH
);
210 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
211 #endif /*CONFIG_REALCODECS*/
212 #endif /*__CYGWIN__*/
213 mp_msg(MSGT_WIN32
, MSGL_V
,"Setting PATH to %s\n",tmppath
);
214 if (!SetEnvironmentVariableA("PATH", tmppath
))
215 mp_msg(MSGT_WIN32
, MSGL_WARN
, "Cannot set PATH!");
217 #endif /* (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL) */