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
12 #include <CoreFoundation/CoreFoundation.h>
13 #include <sys/types.h>
21 char *get_path(char *filename
){
24 #if defined(__MINGW32__)
25 static char *config_dir
= "/mplayer";
27 static char *config_dir
= "/.mplayer";
33 CFURLRef res_url_ref
=NULL
;
34 CFURLRef bdl_url_ref
=NULL
;
35 char *res_url_path
= NULL
;
36 char *bdl_url_path
= NULL
;
39 if ((homedir
= getenv("HOME")) == NULL
)
40 #if defined(__MINGW32__)||defined(__CYGWIN__) /*hack to get fonts etc. loaded outside of cygwin environment*/
44 GetModuleFileNameA(NULL
, exedir
, 260);
45 for(i
=0; i
< strlen(exedir
);i
++)if(exedir
[i
] =='\\'){exedir
[i
]='/';imax
=i
;}
52 len
= strlen(homedir
) + strlen(config_dir
) + 1;
53 if (filename
== NULL
) {
54 if ((buff
= (char *) malloc(len
)) == NULL
)
56 sprintf(buff
, "%s%s", homedir
, config_dir
);
58 len
+= strlen(filename
) + 1;
59 if ((buff
= (char *) malloc(len
)) == NULL
)
61 sprintf(buff
, "%s%s/%s", homedir
, config_dir
, filename
);
65 if(stat(buff
, &dummy
)) {
67 res_url_ref
=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
68 bdl_url_ref
=CFBundleCopyBundleURL(CFBundleGetMainBundle());
70 if(res_url_ref
&&bdl_url_ref
) {
72 res_url_path
=malloc(maxlen
);
73 bdl_url_path
=malloc(maxlen
);
75 while(!CFURLGetFileSystemRepresentation(res_url_ref
, true, res_url_path
, maxlen
)) {
77 res_url_path
=realloc(res_url_path
, maxlen
);
79 CFRelease(res_url_ref
);
81 while(!CFURLGetFileSystemRepresentation(bdl_url_ref
, true, bdl_url_path
, maxlen
)) {
83 bdl_url_path
=realloc(bdl_url_path
, maxlen
);
85 CFRelease(bdl_url_ref
);
87 if( strcmp(res_url_path
, bdl_url_path
) == 0)
91 if(res_url_path
&&filename
) {
92 if((strlen(filename
)+strlen(res_url_path
)+2)>maxlen
) {
93 maxlen
=strlen(filename
)+strlen(res_url_path
)+2;
96 buff
= (char *) malloc(maxlen
);
97 strcpy(buff
, res_url_path
);
100 strcat(buff
, filename
);
104 mp_msg(MSGT_GLOBAL
,MSGL_V
,"get_path('%s') -> '%s'\n",filename
,buff
);
108 #if defined(WIN32) && defined(USE_WIN32DLL)
111 /*make our codec dirs available for LoadLibraryA()*/
112 char tmppath
[MAX_PATH
*2 + 1];
113 char win32path
[MAX_PATH
];
114 char realpath
[MAX_PATH
];
116 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
117 strcpy(tmppath
,win32path
);
118 #ifdef USE_REALCODECS
119 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
120 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
121 #endif /*USE_REALCODECS*/
123 /* Expand to absolute path unless it's already absolute */
124 if(!strstr(WIN32_PATH
,":") && WIN32_PATH
[0] != '\\'){
125 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
126 strcpy(strrchr(win32path
, '\\') + 1, WIN32_PATH
);
128 else strcpy(win32path
,WIN32_PATH
);
129 strcpy(tmppath
,win32path
);
130 #ifdef USE_REALCODECS
131 /* Expand to absolute path unless it's already absolute */
132 if(!strstr(REALCODEC_PATH
,":") && REALCODEC_PATH
[0] != '\\'){
133 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
134 strcpy(strrchr(realpath
, '\\') + 1, REALCODEC_PATH
);
136 else strcpy(realpath
,REALCODEC_PATH
);
137 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
138 #endif /*USE_REALCODECS*/
139 #endif /*__CYGWIN__*/
140 mp_msg(MSGT_WIN32
, MSGL_V
,"Setting PATH to %s\n",tmppath
);
141 if (!SetEnvironmentVariableA("PATH", tmppath
))
142 mp_msg(MSGT_WIN32
, MSGL_WARN
, "Cannot set PATH!");
144 #endif /*WIN32 && USE_WIN32DLL*/