3 * Get path to config dir/file.
6 * Returns the pointer to the ALLOCATED buffer containing the
7 * zero terminated path string. This buffer has to be FREED
18 #include <CoreFoundation/CoreFoundation.h>
19 #include <sys/types.h>
24 char *get_path(const char *filename
){
27 #if defined(__MINGW32__)
28 static char *config_dir
= "/mplayer";
30 static char *config_dir
= "/.mplayer";
36 CFURLRef res_url_ref
=NULL
;
37 CFURLRef bdl_url_ref
=NULL
;
38 char *res_url_path
= NULL
;
39 char *bdl_url_path
= NULL
;
42 if ((homedir
= getenv("MPLAYER_HOME")) != NULL
)
44 else if ((homedir
= getenv("HOME")) == NULL
)
45 #if defined(__MINGW32__)||defined(__CYGWIN__) /*hack to get fonts etc. loaded outside of cygwin environment*/
49 GetModuleFileNameA(NULL
, exedir
, 260);
50 for(i
=0; i
< strlen(exedir
);i
++)if(exedir
[i
] =='\\'){exedir
[i
]='/';imax
=i
;}
57 len
= strlen(homedir
) + strlen(config_dir
) + 1;
58 if (filename
== NULL
) {
59 if ((buff
= malloc(len
)) == NULL
)
61 sprintf(buff
, "%s%s", homedir
, config_dir
);
63 len
+= strlen(filename
) + 1;
64 if ((buff
= malloc(len
)) == NULL
)
66 sprintf(buff
, "%s%s/%s", homedir
, config_dir
, filename
);
70 if(stat(buff
, &dummy
)) {
72 res_url_ref
=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
73 bdl_url_ref
=CFBundleCopyBundleURL(CFBundleGetMainBundle());
75 if(res_url_ref
&&bdl_url_ref
) {
77 res_url_path
=malloc(maxlen
);
78 bdl_url_path
=malloc(maxlen
);
80 while(!CFURLGetFileSystemRepresentation(res_url_ref
, true, res_url_path
, maxlen
)) {
82 res_url_path
=realloc(res_url_path
, maxlen
);
84 CFRelease(res_url_ref
);
86 while(!CFURLGetFileSystemRepresentation(bdl_url_ref
, true, bdl_url_path
, maxlen
)) {
88 bdl_url_path
=realloc(bdl_url_path
, maxlen
);
90 CFRelease(bdl_url_ref
);
92 if( strcmp(res_url_path
, bdl_url_path
) == 0)
96 if(res_url_path
&&filename
) {
97 if((strlen(filename
)+strlen(res_url_path
)+2)>maxlen
) {
98 maxlen
=strlen(filename
)+strlen(res_url_path
)+2;
101 buff
= malloc(maxlen
);
102 strcpy(buff
, res_url_path
);
105 strcat(buff
, filename
);
109 mp_msg(MSGT_GLOBAL
,MSGL_V
,"get_path('%s') -> '%s'\n",filename
,buff
);
113 #if defined(WIN32) && defined(USE_WIN32DLL)
116 /*make our codec dirs available for LoadLibraryA()*/
117 char tmppath
[MAX_PATH
*2 + 1];
118 char win32path
[MAX_PATH
];
119 char realpath
[MAX_PATH
];
121 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
122 strcpy(tmppath
,win32path
);
123 #ifdef USE_REALCODECS
124 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
125 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
126 #endif /*USE_REALCODECS*/
128 /* Expand to absolute path unless it's already absolute */
129 if(!strstr(WIN32_PATH
,":") && WIN32_PATH
[0] != '\\'){
130 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
131 strcpy(strrchr(win32path
, '\\') + 1, WIN32_PATH
);
133 else strcpy(win32path
,WIN32_PATH
);
134 strcpy(tmppath
,win32path
);
135 #ifdef USE_REALCODECS
136 /* Expand to absolute path unless it's already absolute */
137 if(!strstr(REALCODEC_PATH
,":") && REALCODEC_PATH
[0] != '\\'){
138 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
139 strcpy(strrchr(realpath
, '\\') + 1, REALCODEC_PATH
);
141 else strcpy(realpath
,REALCODEC_PATH
);
142 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
143 #endif /*USE_REALCODECS*/
144 #endif /*__CYGWIN__*/
145 mp_msg(MSGT_WIN32
, MSGL_V
,"Setting PATH to %s\n",tmppath
);
146 if (!SetEnvironmentVariableA("PATH", tmppath
))
147 mp_msg(MSGT_WIN32
, MSGL_WARN
, "Cannot set PATH!");
149 #endif /*WIN32 && USE_WIN32DLL*/