Delete things related to old translation system
[mplayer/kovensky.git] / get_path.c
blob4a04f9ebb717a5e28b5c274794b14aa9a39a0d1c
1 /*
2 * Get path to config dir/file.
4 * Return Values:
5 * Returns the pointer to the ALLOCATED buffer containing the
6 * zero terminated path string. This buffer has to be FREED
7 * by the caller.
9 * This file is part of MPlayer.
11 * MPlayer is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * MPlayer is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include "config.h"
30 #include "mp_msg.h"
31 #include "get_path.h"
33 #ifdef CONFIG_MACOSX_BUNDLE
34 #include <CoreFoundation/CoreFoundation.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <unistd.h>
38 #elif defined(__MINGW32__)
39 #include <windows.h>
40 #elif defined(__CYGWIN__)
41 #include <windows.h>
42 #include <sys/cygwin.h>
43 #elif defined(__OS2__)
44 #define INCL_DOS
45 #include <os2.h>
46 #endif
48 char *get_path(const char *filename){
49 char *homedir;
50 char *buff;
51 #ifdef __MINGW32__
52 static char *config_dir = "/mplayer";
53 #else
54 static char *config_dir = "/.mplayer";
55 #endif
56 int len;
57 #ifdef CONFIG_MACOSX_BUNDLE
58 struct stat dummy;
59 CFIndex maxlen=256;
60 CFURLRef res_url_ref=NULL;
61 CFURLRef bdl_url_ref=NULL;
62 char *res_url_path = NULL;
63 char *bdl_url_path = NULL;
64 #endif
66 if ((homedir = getenv("MPLAYER_HOME")) != NULL)
67 config_dir = "";
68 else if ((homedir = getenv("HOME")) == NULL)
69 #if defined(__MINGW32__) || defined(__CYGWIN__)
70 /* Hack to get fonts etc. loaded outside of Cygwin environment. */
72 int i,imax=0;
73 char exedir[260];
74 GetModuleFileNameA(NULL, exedir, 260);
75 for (i=0; i< strlen(exedir); i++)
76 if (exedir[i] =='\\')
77 {exedir[i]='/'; imax=i;}
78 exedir[imax]='\0';
79 homedir = exedir;
81 #elif defined(__OS2__)
83 PPIB ppib;
84 char path[260];
86 // Get process info blocks
87 DosGetInfoBlocks(NULL, &ppib);
89 // Get full path of the executable
90 DosQueryModuleName(ppib->pib_hmte, sizeof( path ), path);
92 // Truncate name part including last backslash
93 *strrchr(path, '\\') = 0;
95 // Convert backslash to slash
96 _fnslashify(path);
98 homedir = path;
100 #else
101 return NULL;
102 #endif
103 len = strlen(homedir) + strlen(config_dir) + 1;
104 if (filename == NULL) {
105 if ((buff = malloc(len)) == NULL)
106 return NULL;
107 sprintf(buff, "%s%s", homedir, config_dir);
108 } else {
109 len += strlen(filename) + 1;
110 if ((buff = malloc(len)) == NULL)
111 return NULL;
112 sprintf(buff, "%s%s/%s", homedir, config_dir, filename);
115 #ifdef CONFIG_MACOSX_BUNDLE
116 if (stat(buff, &dummy)) {
118 res_url_ref=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
119 bdl_url_ref=CFBundleCopyBundleURL(CFBundleGetMainBundle());
121 if (res_url_ref&&bdl_url_ref) {
123 res_url_path=malloc(maxlen);
124 bdl_url_path=malloc(maxlen);
126 while (!CFURLGetFileSystemRepresentation(res_url_ref, true, res_url_path, maxlen)) {
127 maxlen*=2;
128 res_url_path=realloc(res_url_path, maxlen);
130 CFRelease(res_url_ref);
132 while (!CFURLGetFileSystemRepresentation(bdl_url_ref, true, bdl_url_path, maxlen)) {
133 maxlen*=2;
134 bdl_url_path=realloc(bdl_url_path, maxlen);
136 CFRelease(bdl_url_ref);
138 if (strcmp(res_url_path, bdl_url_path) == 0)
139 res_url_path = NULL;
142 if (res_url_path&&filename) {
143 if ((strlen(filename)+strlen(res_url_path)+2)>maxlen) {
144 maxlen=strlen(filename)+strlen(res_url_path)+2;
146 free(buff);
147 buff = malloc(maxlen);
148 strcpy(buff, res_url_path);
150 strcat(buff,"/");
151 strcat(buff, filename);
154 #endif
155 mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff);
156 return buff;
159 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
160 void set_path_env(void)
162 /*make our codec dirs available for LoadLibraryA()*/
163 char tmppath[MAX_PATH*2 + 1];
164 char win32path[MAX_PATH];
165 char realpath[MAX_PATH];
166 #ifdef __CYGWIN__
167 cygwin_conv_to_full_win32_path(WIN32_PATH,win32path);
168 strcpy(tmppath,win32path);
169 #ifdef CONFIG_REALCODECS
170 cygwin_conv_to_full_win32_path(REALCODEC_PATH,realpath);
171 sprintf(tmppath,"%s;%s",win32path,realpath);
172 #endif /*CONFIG_REALCODECS*/
173 #else /*__CYGWIN__*/
174 /* Expand to absolute path unless it's already absolute */
175 if (!strstr(WIN32_PATH,":") && WIN32_PATH[0] != '\\'){
176 GetModuleFileNameA(NULL, win32path, MAX_PATH);
177 strcpy(strrchr(win32path, '\\') + 1, WIN32_PATH);
179 else strcpy(win32path,WIN32_PATH);
180 strcpy(tmppath,win32path);
181 #ifdef CONFIG_REALCODECS
182 /* Expand to absolute path unless it's already absolute */
183 if (!strstr(REALCODEC_PATH,":") && REALCODEC_PATH[0] != '\\'){
184 GetModuleFileNameA(NULL, realpath, MAX_PATH);
185 strcpy(strrchr(realpath, '\\') + 1, REALCODEC_PATH);
187 else strcpy(realpath,REALCODEC_PATH);
188 sprintf(tmppath,"%s;%s",win32path,realpath);
189 #endif /*CONFIG_REALCODECS*/
190 #endif /*__CYGWIN__*/
191 mp_msg(MSGT_WIN32, MSGL_V,"Setting PATH to %s\n",tmppath);
192 if (!SetEnvironmentVariableA("PATH", tmppath))
193 mp_msg(MSGT_WIN32, MSGL_WARN, "Cannot set PATH!");
195 #endif /* (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL) */