]> git.saurik.com Git - wxWidgets.git/blame - src/unix/stdpaths.cpp
Check axis number in the received joystick messages.
[wxWidgets.git] / src / unix / stdpaths.cpp
CommitLineData
c320b3e3 1///////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/unix/stdpaths.cpp
a98ce49a 3// Purpose: wxStandardPaths implementation for Unix & OpenVMS systems
c320b3e3
VZ
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 2004-10-19
7// RCS-ID: $Id$
8// Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
526954c5 9// Licence: wxWindows licence
c320b3e3
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
07158944
VZ
27#if wxUSE_STDPATHS
28
ab9f9e71
PC
29#include "wx/stdpaths.h"
30
c320b3e3 31#ifndef WX_PRECOMP
f3d79306 32 #include "wx/app.h"
f95abb9d 33 #include "wx/wxcrt.h"
ab9f9e71 34 #include "wx/utils.h"
c320b3e3
VZ
35#endif //WX_PRECOMP
36
37#include "wx/filename.h"
0ce52f3d
JS
38#include "wx/log.h"
39#include "wx/textfile.h"
c320b3e3 40
a98ce49a 41#if defined( __LINUX__ ) || defined( __VMS )
c320b3e3
VZ
42 #include <unistd.h>
43#endif
44
45// ============================================================================
d3b9c627 46// common VMS/Unix part of wxStandardPaths implementation
c320b3e3
VZ
47// ============================================================================
48
c320b3e3
VZ
49void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
50{
51 m_prefix = prefix;
52}
53
d3b9c627
VZ
54wxString wxStandardPaths::GetUserConfigDir() const
55{
56 return wxFileName::GetHomeDir();
57}
58
0ce52f3d 59
d3b9c627
VZ
60// ============================================================================
61// wxStandardPaths implementation for VMS
62// ============================================================================
63
64#ifdef __VMS
65
66wxString wxStandardPaths::GetInstallPrefix() const
67{
68 if ( m_prefix.empty() )
69 {
5c33522f 70 const_cast<wxStandardPaths *>(this)->m_prefix = wxT("/sys$system");
d3b9c627 71 }
cc4d9903
VZ
72
73 return m_prefix;
d3b9c627
VZ
74}
75
76wxString wxStandardPaths::GetConfigDir() const
77{
9a83f860 78 return wxT("/sys$manager");
d3b9c627
VZ
79}
80
81wxString wxStandardPaths::GetDataDir() const
82{
9a83f860 83 return AppendAppInfo(GetInstallPrefix() + wxT("/sys$share"));
d3b9c627
VZ
84}
85
86wxString wxStandardPaths::GetLocalDataDir() const
87{
9a83f860 88 return AppendAppInfo(wxT("/sys$manager"));
d3b9c627
VZ
89}
90
91wxString wxStandardPaths::GetUserDataDir() const
92{
93 return wxFileName::GetHomeDir();
94}
95
cc4d9903
VZ
96wxString wxStandardPaths::GetPluginsDir() const
97{
98 return wxString(); // TODO: this is wrong, it should return something
99}
100
3af9f2de 101wxString
e0b3b9d0 102wxStandardPaths::GetLocalizedResourcesDir(const wxString& lang,
3af9f2de
VZ
103 ResourceCat category) const
104{
105 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
106}
107
b29aaf4a
JJ
108wxString wxStandardPaths::GetExecutablePath() const
109{
110 return wxStandardPathsBase::GetExecutablePath();
111}
112
d3b9c627
VZ
113#else // !__VMS
114
115// ============================================================================
116// wxStandardPaths implementation for Unix
117// ============================================================================
118
ac7ad70d 119wxString wxStandardPaths::GetExecutablePath() const
c320b3e3 120{
3abcfa9b 121#ifdef __LINUX__
3abcfa9b
VZ
122 wxString exeStr;
123
124 char buf[4096];
784d9056 125 int result = readlink("/proc/self/exe", buf, WXSIZEOF(buf) - 1);
3abcfa9b 126 if ( result != -1 )
c320b3e3 127 {
3abcfa9b 128 buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
c320b3e3 129
3abcfa9b
VZ
130 // if the /proc/self/exe symlink has been dropped by the kernel for
131 // some reason, then readlink() could also return success but
132 // "(deleted)" as link destination...
133 if ( strcmp(buf, "(deleted)") != 0 )
134 exeStr = wxString(buf, wxConvLibc);
135 }
136
137 if ( exeStr.empty() )
138 {
139 // UPX-specific hack: when using UPX on linux, the kernel will drop the
140 // /proc/self/exe link; in this case we try to look for a special
141 // environment variable called " " which is created by UPX to save
142 // /proc/self/exe contents. See
143 // http://sf.net/tracker/?func=detail&atid=309863&aid=1565357&group_id=9863
144 // for more information about this issue.
145 wxGetEnv(wxT(" "), &exeStr);
146 }
147
ac7ad70d
RR
148 if ( !exeStr.empty() )
149 return exeStr;
150#endif // __LINUX__
151
152 return wxStandardPathsBase::GetExecutablePath();
153}
154
155void wxStandardPaths::DetectPrefix()
156{
157 // we can try to infer the prefix from the location of the executable
158 wxString exeStr = GetExecutablePath();
3abcfa9b
VZ
159 if ( !exeStr.empty() )
160 {
161 // consider that we're in the last "bin" subdirectory of our prefix
162 size_t pos = exeStr.rfind(wxT("/bin/"));
163 if ( pos != wxString::npos )
164 m_prefix.assign(exeStr, 0, pos);
165 }
74ebd406 166
3abcfa9b
VZ
167 if ( m_prefix.empty() )
168 {
169 m_prefix = wxT("/usr/local");
170 }
171}
172
173wxString wxStandardPaths::GetInstallPrefix() const
174{
175 if ( m_prefix.empty() )
176 {
5c33522f 177 wxStandardPaths *pathPtr = const_cast<wxStandardPaths *>(this);
3abcfa9b 178 pathPtr->DetectPrefix();
c320b3e3
VZ
179 }
180
181 return m_prefix;
182}
183
184// ----------------------------------------------------------------------------
185// public functions
186// ----------------------------------------------------------------------------
187
188wxString wxStandardPaths::GetConfigDir() const
189{
9a83f860 190 return wxT("/etc");
c320b3e3
VZ
191}
192
193wxString wxStandardPaths::GetDataDir() const
194{
306a5d95
VZ
195 // allow to override the location of the data directory by setting
196 // WX_APPNAME_DATA_DIR environment variable: this is very useful in
197 // practice for running well-written (and so using wxStandardPaths to find
198 // their files) wx applications without installing them
199 static const wxString
3781248c
VZ
200 envOverride(
201 getenv(
202 ("WX_" + wxTheApp->GetAppName().Upper() + "_DATA_DIR").c_str()
203 )
204 );
306a5d95
VZ
205
206 if ( !envOverride.empty() )
207 return envOverride;
208
9a83f860 209 return AppendAppInfo(GetInstallPrefix() + wxT("/share"));
c320b3e3
VZ
210}
211
212wxString wxStandardPaths::GetLocalDataDir() const
213{
9a83f860 214 return AppendAppInfo(wxT("/etc"));
c320b3e3
VZ
215}
216
217wxString wxStandardPaths::GetUserDataDir() const
218{
9a83f860 219 return AppendAppInfo(wxFileName::GetHomeDir() + wxT("/."));
c320b3e3
VZ
220}
221
cc4d9903
VZ
222wxString wxStandardPaths::GetPluginsDir() const
223{
9a83f860 224 return AppendAppInfo(GetInstallPrefix() + wxT("/lib"));
cc4d9903
VZ
225}
226
3af9f2de 227wxString
e0b3b9d0 228wxStandardPaths::GetLocalizedResourcesDir(const wxString& lang,
3af9f2de
VZ
229 ResourceCat category) const
230{
231 if ( category != ResourceCat_Messages )
232 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
233
9a83f860 234 return GetInstallPrefix() + wxT("/share/locale/") + lang + wxT("/LC_MESSAGES");
3af9f2de
VZ
235}
236
0ce52f3d
JS
237wxString wxStandardPaths::GetDocumentsDir() const
238{
239 {
240 wxLogNull logNull;
241 wxString homeDir = wxFileName::GetHomeDir();
242 wxString configPath;
243 if (wxGetenv(wxT("XDG_CONFIG_HOME")))
244 configPath = wxGetenv(wxT("XDG_CONFIG_HOME"));
245 else
246 configPath = homeDir + wxT("/.config");
247 wxString dirsFile = configPath + wxT("/user-dirs.dirs");
248 if (wxFileExists(dirsFile))
249 {
250 wxTextFile textFile;
251 if (textFile.Open(dirsFile))
252 {
253 size_t i;
254 for (i = 0; i < textFile.GetLineCount(); i++)
255 {
256 wxString line(textFile[i]);
257 int pos = line.Find(wxT("XDG_DOCUMENTS_DIR"));
258 if (pos != wxNOT_FOUND)
259 {
260 wxString value = line.AfterFirst(wxT('='));
261 value.Replace(wxT("$HOME"), homeDir);
262 value.Trim(true);
263 value.Trim(false);
264 if (!value.IsEmpty() && wxDirExists(value))
265 return value;
266 else
267 break;
268 }
269 }
270 }
271 }
272 }
273
274 return wxStandardPathsBase::GetDocumentsDir();
275}
276
d3b9c627 277#endif // __VMS/!__VMS
c320b3e3 278
07158944 279#endif // wxUSE_STDPATHS