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(const 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("MPLAYER_HOME")) != NULL
)
41 else if ((homedir
= getenv("HOME")) == NULL
)
42 #if defined(__MINGW32__)||defined(__CYGWIN__) /*hack to get fonts etc. loaded outside of cygwin environment*/
46 GetModuleFileNameA(NULL
, exedir
, 260);
47 for(i
=0; i
< strlen(exedir
);i
++)if(exedir
[i
] =='\\'){exedir
[i
]='/';imax
=i
;}
54 len
= strlen(homedir
) + strlen(config_dir
) + 1;
55 if (filename
== NULL
) {
56 if ((buff
= (char *) malloc(len
)) == NULL
)
58 sprintf(buff
, "%s%s", homedir
, config_dir
);
60 len
+= strlen(filename
) + 1;
61 if ((buff
= (char *) malloc(len
)) == NULL
)
63 sprintf(buff
, "%s%s/%s", homedir
, config_dir
, filename
);
67 if(stat(buff
, &dummy
)) {
69 res_url_ref
=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
70 bdl_url_ref
=CFBundleCopyBundleURL(CFBundleGetMainBundle());
72 if(res_url_ref
&&bdl_url_ref
) {
74 res_url_path
=malloc(maxlen
);
75 bdl_url_path
=malloc(maxlen
);
77 while(!CFURLGetFileSystemRepresentation(res_url_ref
, true, res_url_path
, maxlen
)) {
79 res_url_path
=realloc(res_url_path
, maxlen
);
81 CFRelease(res_url_ref
);
83 while(!CFURLGetFileSystemRepresentation(bdl_url_ref
, true, bdl_url_path
, maxlen
)) {
85 bdl_url_path
=realloc(bdl_url_path
, maxlen
);
87 CFRelease(bdl_url_ref
);
89 if( strcmp(res_url_path
, bdl_url_path
) == 0)
93 if(res_url_path
&&filename
) {
94 if((strlen(filename
)+strlen(res_url_path
)+2)>maxlen
) {
95 maxlen
=strlen(filename
)+strlen(res_url_path
)+2;
98 buff
= (char *) malloc(maxlen
);
99 strcpy(buff
, res_url_path
);
102 strcat(buff
, filename
);
106 mp_msg(MSGT_GLOBAL
,MSGL_V
,"get_path('%s') -> '%s'\n",filename
,buff
);
110 #if defined(WIN32) && defined(USE_WIN32DLL)
113 /*make our codec dirs available for LoadLibraryA()*/
114 char tmppath
[MAX_PATH
*2 + 1];
115 char win32path
[MAX_PATH
];
116 char realpath
[MAX_PATH
];
118 cygwin_conv_to_full_win32_path(WIN32_PATH
,win32path
);
119 strcpy(tmppath
,win32path
);
120 #ifdef USE_REALCODECS
121 cygwin_conv_to_full_win32_path(REALCODEC_PATH
,realpath
);
122 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
123 #endif /*USE_REALCODECS*/
125 /* Expand to absolute path unless it's already absolute */
126 if(!strstr(WIN32_PATH
,":") && WIN32_PATH
[0] != '\\'){
127 GetModuleFileNameA(NULL
, win32path
, MAX_PATH
);
128 strcpy(strrchr(win32path
, '\\') + 1, WIN32_PATH
);
130 else strcpy(win32path
,WIN32_PATH
);
131 strcpy(tmppath
,win32path
);
132 #ifdef USE_REALCODECS
133 /* Expand to absolute path unless it's already absolute */
134 if(!strstr(REALCODEC_PATH
,":") && REALCODEC_PATH
[0] != '\\'){
135 GetModuleFileNameA(NULL
, realpath
, MAX_PATH
);
136 strcpy(strrchr(realpath
, '\\') + 1, REALCODEC_PATH
);
138 else strcpy(realpath
,REALCODEC_PATH
);
139 sprintf(tmppath
,"%s;%s",win32path
,realpath
);
140 #endif /*USE_REALCODECS*/
141 #endif /*__CYGWIN__*/
142 mp_msg(MSGT_WIN32
, MSGL_V
,"Setting PATH to %s\n",tmppath
);
143 if (!SetEnvironmentVariableA("PATH", tmppath
))
144 mp_msg(MSGT_WIN32
, MSGL_WARN
, "Cannot set PATH!");
146 #endif /*WIN32 && USE_WIN32DLL*/