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>
22 #define _WIN32_IE 0x0400
25 #include <sys/types.h>
27 #if defined(__CYGWIN__)
28 #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
[4096], config_path
[4096], appdata
[4096];
62 if (SHGetSpecialFolderPathA(NULL
, appdata
, CSIDL_APPDATA
, 1)) {
63 strncpy(exedir
, appdata
, strlen(appdata
));
65 GetModuleFileNameA(NULL
, exedir
, 4096);
67 int len
= strlen(exedir
);
68 for (i
=0; i
< len
; i
++)
72 sprintf(config_path
, "%s%s", exedir
, config_dir
);
74 if ((stat_res
= stat(config_path
, &statBuffer
)) < 0 ||
75 !(statBuffer
.st_mode
& S_IFDIR
)) {
76 GetModuleFileNameA(NULL
, exedir
, 4096);
78 for (i
=0; i
< len
; i
++)
80 {exedir
[i
]='/'; imax
=i
;}
86 #elif defined(__OS2__)
91 // Get process info blocks
92 DosGetInfoBlocks(NULL
, &ppib
);
94 // Get full path of the executable
95 DosQueryModuleName(ppib
->pib_hmte
, sizeof( path
), path
);
97 // Truncate name part including last backslash
98 *strrchr(path
, '\\') = 0;
100 // Convert backslash to slash
108 len
= strlen(homedir
) + strlen(config_dir
) + 1;
109 if (filename
== NULL
) {
110 if ((buff
= malloc(len
)) == NULL
)
112 sprintf(buff
, "%s%s", homedir
, config_dir
);
114 len
+= strlen(filename
) + 1;
115 if ((buff
= malloc(len
)) == NULL
)
117 sprintf(buff
, "%s%s/%s", homedir
, config_dir
, filename
);
120 #ifdef CONFIG_MACOSX_BUNDLE
121 if (stat(buff
, &dummy
)) {
123 res_url_ref
=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
124 bdl_url_ref
=CFBundleCopyBundleURL(CFBundleGetMainBundle());
126 if (res_url_ref
&&bdl_url_ref
) {
128 res_url_path
=malloc(maxlen
);
129 bdl_url_path
=malloc(maxlen
);
131 while (!CFURLGetFileSystemRepresentation(res_url_ref
, true, res_url_path
, maxlen
)) {
133 res_url_path
=realloc(res_url_path
, maxlen
);
135 CFRelease(res_url_ref
);
137 while (!CFURLGetFileSystemRepresentation(bdl_url_ref
, true, bdl_url_path
, maxlen
)) {
139 bdl_url_path
=realloc(bdl_url_path
, maxlen
);
141 CFRelease(bdl_url_ref
);
143 if (strcmp(res_url_path
, bdl_url_path
) == 0)
147 if (res_url_path
&&filename
) {
148 if ((strlen(filename
)+strlen(res_url_path
)+2)>maxlen
) {
149 maxlen
=strlen(filename
)+strlen(res_url_path
)+2;
152 buff
= malloc(maxlen
);
153 strcpy(buff
, res_url_path
);
156 strcat(buff
, filename
);
160 mp_msg(MSGT_GLOBAL
,MSGL_V
,"get_path('%s') -> '%s'\n",filename
,buff
);
164 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
165 void set_path_env(void)
167 /*make our codec dirs available for LoadLibraryA()*/
168 char tmppath
[MAX_PATH
*2 + 1];
169 char win32path
[MAX_PATH
];
170 char realpath
[MAX_PATH
];
172 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
173 strcpy(tmppath
,win32path
);
174 #ifdef CONFIG_REALCODECS
175 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
176 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
177 #endif /*CONFIG_REALCODECS*/
179 /* Expand to absolute path unless it's already absolute */
180 if (!strstr(WIN32_PATH
,":") && WIN32_PATH
[0] != '\\'){
181 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
182 strcpy(strrchr(win32path
, '\\') + 1, WIN32_PATH
);
184 else strcpy(win32path
,WIN32_PATH
);
185 strcpy(tmppath
,win32path
);
186 #ifdef CONFIG_REALCODECS
187 /* Expand to absolute path unless it's already absolute */
188 if (!strstr(REALCODEC_PATH
,":") && REALCODEC_PATH
[0] != '\\'){
189 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
190 strcpy(strrchr(realpath
, '\\') + 1, REALCODEC_PATH
);
192 else strcpy(realpath
,REALCODEC_PATH
);
193 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
194 #endif /*CONFIG_REALCODECS*/
195 #endif /*__CYGWIN__*/
196 mp_msg(MSGT_WIN32
, MSGL_V
,"Setting PATH to %s\n",tmppath
);
197 if (!SetEnvironmentVariableA("PATH", tmppath
))
198 mp_msg(MSGT_WIN32
, MSGL_WARN
, "Cannot set PATH!");
200 #endif /* (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL) */