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 #elif defined(__CYGWIN__)
25 #include <sys/cygwin.h>
26 #elif defined(__OS2__)
31 char *get_path(const char *filename
){
35 static char *config_dir
= "/mplayer";
37 static char *config_dir
= "/.mplayer";
40 #ifdef CONFIG_MACOSX_BUNDLE
43 CFURLRef res_url_ref
=NULL
;
44 CFURLRef bdl_url_ref
=NULL
;
45 char *res_url_path
= NULL
;
46 char *bdl_url_path
= NULL
;
49 if ((homedir
= getenv("MPLAYER_HOME")) != NULL
)
51 else if ((homedir
= getenv("HOME")) == NULL
)
52 #if defined(__MINGW32__) || defined(__CYGWIN__)
53 /* Hack to get fonts etc. loaded outside of Cygwin environment. */
57 GetModuleFileNameA(NULL
, exedir
, 260);
58 for (i
=0; i
< strlen(exedir
); i
++)
60 {exedir
[i
]='/'; imax
=i
;}
64 #elif defined(__OS2__)
69 // Get process info blocks
70 DosGetInfoBlocks(NULL
, &ppib
);
72 // Get full path of the executable
73 DosQueryModuleName(ppib
->pib_hmte
, sizeof( path
), path
);
75 // Truncate name part including last backslash
76 *strrchr(path
, '\\') = 0;
78 // Convert backslash to slash
86 len
= strlen(homedir
) + strlen(config_dir
) + 1;
87 if (filename
== NULL
) {
88 if ((buff
= malloc(len
)) == NULL
)
90 sprintf(buff
, "%s%s", homedir
, config_dir
);
92 len
+= strlen(filename
) + 1;
93 if ((buff
= malloc(len
)) == NULL
)
95 sprintf(buff
, "%s%s/%s", homedir
, config_dir
, filename
);
98 #ifdef CONFIG_MACOSX_BUNDLE
99 if (stat(buff
, &dummy
)) {
101 res_url_ref
=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
102 bdl_url_ref
=CFBundleCopyBundleURL(CFBundleGetMainBundle());
104 if (res_url_ref
&&bdl_url_ref
) {
106 res_url_path
=malloc(maxlen
);
107 bdl_url_path
=malloc(maxlen
);
109 while (!CFURLGetFileSystemRepresentation(res_url_ref
, true, res_url_path
, maxlen
)) {
111 res_url_path
=realloc(res_url_path
, maxlen
);
113 CFRelease(res_url_ref
);
115 while (!CFURLGetFileSystemRepresentation(bdl_url_ref
, true, bdl_url_path
, maxlen
)) {
117 bdl_url_path
=realloc(bdl_url_path
, maxlen
);
119 CFRelease(bdl_url_ref
);
121 if (strcmp(res_url_path
, bdl_url_path
) == 0)
125 if (res_url_path
&&filename
) {
126 if ((strlen(filename
)+strlen(res_url_path
)+2)>maxlen
) {
127 maxlen
=strlen(filename
)+strlen(res_url_path
)+2;
130 buff
= malloc(maxlen
);
131 strcpy(buff
, res_url_path
);
134 strcat(buff
, filename
);
138 mp_msg(MSGT_GLOBAL
,MSGL_V
,"get_path('%s') -> '%s'\n",filename
,buff
);
142 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
145 /*make our codec dirs available for LoadLibraryA()*/
146 char tmppath
[MAX_PATH
*2 + 1];
147 char win32path
[MAX_PATH
];
148 char realpath
[MAX_PATH
];
150 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
151 strcpy(tmppath
,win32path
);
152 #ifdef CONFIG_REALCODECS
153 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
154 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
155 #endif /*CONFIG_REALCODECS*/
157 /* Expand to absolute path unless it's already absolute */
158 if (!strstr(WIN32_PATH
,":") && WIN32_PATH
[0] != '\\'){
159 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
160 strcpy(strrchr(win32path
, '\\') + 1, WIN32_PATH
);
162 else strcpy(win32path
,WIN32_PATH
);
163 strcpy(tmppath
,win32path
);
164 #ifdef CONFIG_REALCODECS
165 /* Expand to absolute path unless it's already absolute */
166 if (!strstr(REALCODEC_PATH
,":") && REALCODEC_PATH
[0] != '\\'){
167 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
168 strcpy(strrchr(realpath
, '\\') + 1, REALCODEC_PATH
);
170 else strcpy(realpath
,REALCODEC_PATH
);
171 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
172 #endif /*CONFIG_REALCODECS*/
173 #endif /*__CYGWIN__*/
174 mp_msg(MSGT_WIN32
, MSGL_V
,"Setting PATH to %s\n",tmppath
);
175 if (!SetEnvironmentVariableA("PATH", tmppath
))
176 mp_msg(MSGT_WIN32
, MSGL_WARN
, "Cannot set PATH!");
178 #endif /* (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL) */