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.
32 #ifdef CONFIG_MACOSX_BUNDLE
33 #include <CoreFoundation/CoreFoundation.h>
34 #include <sys/types.h>
37 #elif defined(__MINGW32__)
39 #elif defined(__CYGWIN__)
41 #include <sys/cygwin.h>
42 #elif defined(__OS2__)
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 tmppath
[MAX_PATH
*2 + 1];
163 char win32path
[MAX_PATH
];
164 char realpath
[MAX_PATH
];
166 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
167 strcpy(tmppath
,win32path
);
168 #ifdef CONFIG_REALCODECS
169 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
170 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
171 #endif /*CONFIG_REALCODECS*/
173 /* Expand to absolute path unless it's already absolute */
174 if (!strstr(WIN32_PATH
,":") && WIN32_PATH
[0] != '\\'){
175 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
176 strcpy(strrchr(win32path
, '\\') + 1, WIN32_PATH
);
178 else strcpy(win32path
,WIN32_PATH
);
179 strcpy(tmppath
,win32path
);
180 #ifdef CONFIG_REALCODECS
181 /* Expand to absolute path unless it's already absolute */
182 if (!strstr(REALCODEC_PATH
,":") && REALCODEC_PATH
[0] != '\\'){
183 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
184 strcpy(strrchr(realpath
, '\\') + 1, REALCODEC_PATH
);
186 else strcpy(realpath
,REALCODEC_PATH
);
187 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
188 #endif /*CONFIG_REALCODECS*/
189 #endif /*__CYGWIN__*/
190 mp_msg(MSGT_WIN32
, MSGL_V
,"Setting PATH to %s\n",tmppath
);
191 if (!SetEnvironmentVariableA("PATH", tmppath
))
192 mp_msg(MSGT_WIN32
, MSGL_WARN
, "Cannot set PATH!");
194 #endif /* (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL) */