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
16 #ifdef CONFIG_MACOSX_BUNDLE
17 #include <CoreFoundation/CoreFoundation.h>
18 #include <sys/types.h>
21 #elif defined(__MINGW32__)
23 #include <sys/types.h>
25 #elif defined(__CYGWIN__)
27 #include <sys/types.h>
29 #include <sys/cygwin.h>
30 #elif defined(__OS2__)
35 char *get_path(const char *filename
){
39 static char *config_dir
= "/mplayer";
41 static char *config_dir
= "/.mplayer";
44 #ifdef CONFIG_MACOSX_BUNDLE
47 CFURLRef res_url_ref
=NULL
;
48 CFURLRef bdl_url_ref
=NULL
;
49 char *res_url_path
= NULL
;
50 char *bdl_url_path
= NULL
;
53 if ((homedir
= getenv("MPLAYER_HOME")) != NULL
)
55 else if ((homedir
= getenv("HOME")) == NULL
)
57 /* Hack to get fonts etc. loaded outside of Cygwin environment. */
60 struct _stat statBuffer
;
61 char exedir
[MAX_PATH
];
62 char config_path
[MAX_PATH
];
63 char *appdata
= getenv("appdata");
64 if (appdata
&& strcmp(appdata
, "")) {
65 strncpy(exedir
, appdata
, MAX_PATH
);
66 exedir
[MAX_PATH
-1] = '\0';
68 GetModuleFileNameA(NULL
, exedir
, MAX_PATH
);
70 for (i
=0; i
< strlen(exedir
); i
++)
74 sprintf(config_path
, "%s%s", exedir
, config_dir
);
76 if ((stat_res
= stat(config_path
, &statBuffer
)) < 0 ||
77 !(statBuffer
.st_mode
& S_IFDIR
)) {
78 GetModuleFileNameA(NULL
, exedir
, MAX_PATH
);
79 for (i
=0; i
< strlen(exedir
); i
++)
81 {exedir
[i
]='/'; imax
=i
;}
87 #elif defined(__OS2__)
92 // Get process info blocks
93 DosGetInfoBlocks(NULL
, &ppib
);
95 // Get full path of the executable
96 DosQueryModuleName(ppib
->pib_hmte
, sizeof( path
), path
);
98 // Truncate name part including last backslash
99 *strrchr(path
, '\\') = 0;
101 // Convert backslash to slash
109 len
= strlen(homedir
) + strlen(config_dir
) + 1;
110 if (filename
== NULL
) {
111 if ((buff
= malloc(len
)) == NULL
)
113 sprintf(buff
, "%s%s", homedir
, config_dir
);
115 len
+= strlen(filename
) + 1;
116 if ((buff
= malloc(len
)) == NULL
)
118 sprintf(buff
, "%s%s/%s", homedir
, config_dir
, filename
);
121 #ifdef CONFIG_MACOSX_BUNDLE
122 if (stat(buff
, &dummy
)) {
124 res_url_ref
=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
125 bdl_url_ref
=CFBundleCopyBundleURL(CFBundleGetMainBundle());
127 if (res_url_ref
&&bdl_url_ref
) {
129 res_url_path
=malloc(maxlen
);
130 bdl_url_path
=malloc(maxlen
);
132 while (!CFURLGetFileSystemRepresentation(res_url_ref
, true, res_url_path
, maxlen
)) {
134 res_url_path
=realloc(res_url_path
, maxlen
);
136 CFRelease(res_url_ref
);
138 while (!CFURLGetFileSystemRepresentation(bdl_url_ref
, true, bdl_url_path
, maxlen
)) {
140 bdl_url_path
=realloc(bdl_url_path
, maxlen
);
142 CFRelease(bdl_url_ref
);
144 if (strcmp(res_url_path
, bdl_url_path
) == 0)
148 if (res_url_path
&&filename
) {
149 if ((strlen(filename
)+strlen(res_url_path
)+2)>maxlen
) {
150 maxlen
=strlen(filename
)+strlen(res_url_path
)+2;
153 buff
= malloc(maxlen
);
154 strcpy(buff
, res_url_path
);
157 strcat(buff
, filename
);
161 mp_msg(MSGT_GLOBAL
,MSGL_V
,"get_path('%s') -> '%s'\n",filename
,buff
);
165 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
166 void set_path_env(void)
168 /*make our codec dirs available for LoadLibraryA()*/
169 char tmppath
[MAX_PATH
*2 + 1];
170 char win32path
[MAX_PATH
];
171 char realpath
[MAX_PATH
];
173 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
174 strcpy(tmppath
,win32path
);
175 #ifdef CONFIG_REALCODECS
176 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
177 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
178 #endif /*CONFIG_REALCODECS*/
180 /* Expand to absolute path unless it's already absolute */
181 if (!strstr(WIN32_PATH
,":") && WIN32_PATH
[0] != '\\'){
182 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
183 strcpy(strrchr(win32path
, '\\') + 1, WIN32_PATH
);
185 else strcpy(win32path
,WIN32_PATH
);
186 strcpy(tmppath
,win32path
);
187 #ifdef CONFIG_REALCODECS
188 /* Expand to absolute path unless it's already absolute */
189 if (!strstr(REALCODEC_PATH
,":") && REALCODEC_PATH
[0] != '\\'){
190 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
191 strcpy(strrchr(realpath
, '\\') + 1, REALCODEC_PATH
);
193 else strcpy(realpath
,REALCODEC_PATH
);
194 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
195 #endif /*CONFIG_REALCODECS*/
196 #endif /*__CYGWIN__*/
197 mp_msg(MSGT_WIN32
, MSGL_V
,"Setting PATH to %s\n",tmppath
);
198 if (!SetEnvironmentVariableA("PATH", tmppath
))
199 mp_msg(MSGT_WIN32
, MSGL_WARN
, "Cannot set PATH!");
201 #endif /* (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL) */