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>
43 #elif defined(__OS2__)
48 char *get_path(const char *filename
){
52 static char *config_dir
= "/mplayer";
54 static char *config_dir
= "/.mplayer";
57 #ifdef CONFIG_MACOSX_BUNDLE
60 CFURLRef res_url_ref
=NULL
;
61 CFURLRef bdl_url_ref
=NULL
;
62 char *res_url_path
= NULL
;
63 char *bdl_url_path
= NULL
;
66 if ((homedir
= getenv("MPLAYER_HOME")) != NULL
)
68 else if ((homedir
= getenv("HOME")) == NULL
)
69 #if defined(__MINGW32__) || defined(__CYGWIN__)
70 /* Hack to get fonts etc. loaded outside of Cygwin environment. */
74 GetModuleFileNameA(NULL
, exedir
, 260);
75 for (i
=0; i
< strlen(exedir
); i
++)
77 {exedir
[i
]='/'; imax
=i
;}
81 #elif defined(__OS2__)
86 // Get process info blocks
87 DosGetInfoBlocks(NULL
, &ppib
);
89 // Get full path of the executable
90 DosQueryModuleName(ppib
->pib_hmte
, sizeof( path
), path
);
92 // Truncate name part including last backslash
93 *strrchr(path
, '\\') = 0;
95 // Convert backslash to slash
103 len
= strlen(homedir
) + strlen(config_dir
) + 1;
104 if (filename
== NULL
) {
105 if ((buff
= malloc(len
)) == NULL
)
107 sprintf(buff
, "%s%s", homedir
, config_dir
);
109 len
+= strlen(filename
) + 1;
110 if ((buff
= malloc(len
)) == NULL
)
112 sprintf(buff
, "%s%s/%s", homedir
, config_dir
, filename
);
115 #ifdef CONFIG_MACOSX_BUNDLE
116 if (stat(buff
, &dummy
)) {
118 res_url_ref
=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
119 bdl_url_ref
=CFBundleCopyBundleURL(CFBundleGetMainBundle());
121 if (res_url_ref
&&bdl_url_ref
) {
123 res_url_path
=malloc(maxlen
);
124 bdl_url_path
=malloc(maxlen
);
126 while (!CFURLGetFileSystemRepresentation(res_url_ref
, true, res_url_path
, maxlen
)) {
128 res_url_path
=realloc(res_url_path
, maxlen
);
130 CFRelease(res_url_ref
);
132 while (!CFURLGetFileSystemRepresentation(bdl_url_ref
, true, bdl_url_path
, maxlen
)) {
134 bdl_url_path
=realloc(bdl_url_path
, maxlen
);
136 CFRelease(bdl_url_ref
);
138 if (strcmp(res_url_path
, bdl_url_path
) == 0)
142 if (res_url_path
&&filename
) {
143 if ((strlen(filename
)+strlen(res_url_path
)+2)>maxlen
) {
144 maxlen
=strlen(filename
)+strlen(res_url_path
)+2;
147 buff
= malloc(maxlen
);
148 strcpy(buff
, res_url_path
);
151 strcat(buff
, filename
);
155 mp_msg(MSGT_GLOBAL
,MSGL_V
,"get_path('%s') -> '%s'\n",filename
,buff
);
159 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
160 void set_path_env(void)
162 /*make our codec dirs available for LoadLibraryA()*/
163 char tmppath
[MAX_PATH
*2 + 1];
164 char win32path
[MAX_PATH
];
165 char realpath
[MAX_PATH
];
167 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
168 strcpy(tmppath
,win32path
);
169 #ifdef CONFIG_REALCODECS
170 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
171 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
172 #endif /*CONFIG_REALCODECS*/
174 /* Expand to absolute path unless it's already absolute */
175 if (!strstr(WIN32_PATH
,":") && WIN32_PATH
[0] != '\\'){
176 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
177 strcpy(strrchr(win32path
, '\\') + 1, WIN32_PATH
);
179 else strcpy(win32path
,WIN32_PATH
);
180 strcpy(tmppath
,win32path
);
181 #ifdef CONFIG_REALCODECS
182 /* Expand to absolute path unless it's already absolute */
183 if (!strstr(REALCODEC_PATH
,":") && REALCODEC_PATH
[0] != '\\'){
184 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
185 strcpy(strrchr(realpath
, '\\') + 1, REALCODEC_PATH
);
187 else strcpy(realpath
,REALCODEC_PATH
);
188 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
189 #endif /*CONFIG_REALCODECS*/
190 #endif /*__CYGWIN__*/
191 mp_msg(MSGT_WIN32
, MSGL_V
,"Setting PATH to %s\n",tmppath
);
192 if (!SetEnvironmentVariableA("PATH", tmppath
))
193 mp_msg(MSGT_WIN32
, MSGL_WARN
, "Cannot set PATH!");
195 #endif /* (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL) */