]> git.saurik.com Git - wxWidgets.git/blame - src/unix/stdpaths.cpp
removing outdated files for mac
[wxWidgets.git] / src / unix / stdpaths.cpp
CommitLineData
c320b3e3
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: 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>
9// License: wxWindows license
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
ab9f9e71 32 #include "wx/utils.h"
c320b3e3
VZ
33#endif //WX_PRECOMP
34
35#include "wx/filename.h"
0ce52f3d
JS
36#include "wx/log.h"
37#include "wx/textfile.h"
c320b3e3 38
a98ce49a 39#if defined( __LINUX__ ) || defined( __VMS )
c320b3e3
VZ
40 #include <unistd.h>
41#endif
42
43// ============================================================================
d3b9c627 44// common VMS/Unix part of wxStandardPaths implementation
c320b3e3
VZ
45// ============================================================================
46
c320b3e3
VZ
47void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
48{
49 m_prefix = prefix;
50}
51
d3b9c627
VZ
52wxString wxStandardPaths::GetUserConfigDir() const
53{
54 return wxFileName::GetHomeDir();
55}
56
0ce52f3d 57
d3b9c627
VZ
58// ============================================================================
59// wxStandardPaths implementation for VMS
60// ============================================================================
61
62#ifdef __VMS
63
64wxString wxStandardPaths::GetInstallPrefix() const
65{
66 if ( m_prefix.empty() )
67 {
68 wx_const_cast(wxStandardPaths *, this)->m_prefix = wxT("/sys$system");
69 }
cc4d9903
VZ
70
71 return m_prefix;
d3b9c627
VZ
72}
73
74wxString wxStandardPaths::GetConfigDir() const
75{
76 return _T("/sys$manager");
77}
78
79wxString wxStandardPaths::GetDataDir() const
80{
2b147f2e 81 return AppendAppInfo(GetInstallPrefix() + _T("/sys$share"));
d3b9c627
VZ
82}
83
84wxString wxStandardPaths::GetLocalDataDir() const
85{
2b147f2e 86 return AppendAppInfo(_T("/sys$manager"));
d3b9c627
VZ
87}
88
89wxString wxStandardPaths::GetUserDataDir() const
90{
91 return wxFileName::GetHomeDir();
92}
93
cc4d9903
VZ
94wxString wxStandardPaths::GetPluginsDir() const
95{
96 return wxString(); // TODO: this is wrong, it should return something
97}
98
3af9f2de 99wxString
e0b3b9d0 100wxStandardPaths::GetLocalizedResourcesDir(const wxString& lang,
3af9f2de
VZ
101 ResourceCat category) const
102{
103 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
104}
105
b29aaf4a
JJ
106wxString wxStandardPaths::GetExecutablePath() const
107{
108 return wxStandardPathsBase::GetExecutablePath();
109}
110
d3b9c627
VZ
111#else // !__VMS
112
113// ============================================================================
114// wxStandardPaths implementation for Unix
115// ============================================================================
116
ac7ad70d 117wxString wxStandardPaths::GetExecutablePath() const
c320b3e3 118{
3abcfa9b 119#ifdef __LINUX__
3abcfa9b
VZ
120 wxString exeStr;
121
122 char buf[4096];
123 int result = readlink("/proc/self/exe", buf, WXSIZEOF(buf) - sizeof(char));
124 if ( result != -1 )
c320b3e3 125 {
3abcfa9b 126 buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
c320b3e3 127
3abcfa9b
VZ
128 // if the /proc/self/exe symlink has been dropped by the kernel for
129 // some reason, then readlink() could also return success but
130 // "(deleted)" as link destination...
131 if ( strcmp(buf, "(deleted)") != 0 )
132 exeStr = wxString(buf, wxConvLibc);
133 }
134
135 if ( exeStr.empty() )
136 {
137 // UPX-specific hack: when using UPX on linux, the kernel will drop the
138 // /proc/self/exe link; in this case we try to look for a special
139 // environment variable called " " which is created by UPX to save
140 // /proc/self/exe contents. See
141 // http://sf.net/tracker/?func=detail&atid=309863&aid=1565357&group_id=9863
142 // for more information about this issue.
143 wxGetEnv(wxT(" "), &exeStr);
144 }
145
ac7ad70d
RR
146 if ( !exeStr.empty() )
147 return exeStr;
148#endif // __LINUX__
149
150 return wxStandardPathsBase::GetExecutablePath();
151}
152
153void wxStandardPaths::DetectPrefix()
154{
155 // we can try to infer the prefix from the location of the executable
156 wxString exeStr = GetExecutablePath();
3abcfa9b
VZ
157 if ( !exeStr.empty() )
158 {
159 // consider that we're in the last "bin" subdirectory of our prefix
160 size_t pos = exeStr.rfind(wxT("/bin/"));
161 if ( pos != wxString::npos )
162 m_prefix.assign(exeStr, 0, pos);
163 }
74ebd406 164
3abcfa9b
VZ
165 if ( m_prefix.empty() )
166 {
167 m_prefix = wxT("/usr/local");
168 }
169}
170
171wxString wxStandardPaths::GetInstallPrefix() const
172{
173 if ( m_prefix.empty() )
174 {
175 wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this);
176 pathPtr->DetectPrefix();
c320b3e3
VZ
177 }
178
179 return m_prefix;
180}
181
182// ----------------------------------------------------------------------------
183// public functions
184// ----------------------------------------------------------------------------
185
186wxString wxStandardPaths::GetConfigDir() const
187{
a98ce49a 188 return _T("/etc");
c320b3e3
VZ
189}
190
191wxString wxStandardPaths::GetDataDir() const
192{
2b147f2e 193 return AppendAppInfo(GetInstallPrefix() + _T("/share"));
c320b3e3
VZ
194}
195
196wxString wxStandardPaths::GetLocalDataDir() const
197{
2b147f2e 198 return AppendAppInfo(_T("/etc"));
c320b3e3
VZ
199}
200
201wxString wxStandardPaths::GetUserDataDir() const
202{
2b147f2e 203 return AppendAppInfo(wxFileName::GetHomeDir() + _T("/."));
c320b3e3
VZ
204}
205
cc4d9903
VZ
206wxString wxStandardPaths::GetPluginsDir() const
207{
2b147f2e 208 return AppendAppInfo(GetInstallPrefix() + _T("/lib"));
cc4d9903
VZ
209}
210
3af9f2de 211wxString
e0b3b9d0 212wxStandardPaths::GetLocalizedResourcesDir(const wxString& lang,
3af9f2de
VZ
213 ResourceCat category) const
214{
215 if ( category != ResourceCat_Messages )
216 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
217
218 return GetInstallPrefix() + _T("/share/locale/") + lang + _T("/LC_MESSAGES");
219}
220
0ce52f3d
JS
221wxString wxStandardPaths::GetDocumentsDir() const
222{
223 {
224 wxLogNull logNull;
225 wxString homeDir = wxFileName::GetHomeDir();
226 wxString configPath;
227 if (wxGetenv(wxT("XDG_CONFIG_HOME")))
228 configPath = wxGetenv(wxT("XDG_CONFIG_HOME"));
229 else
230 configPath = homeDir + wxT("/.config");
231 wxString dirsFile = configPath + wxT("/user-dirs.dirs");
232 if (wxFileExists(dirsFile))
233 {
234 wxTextFile textFile;
235 if (textFile.Open(dirsFile))
236 {
237 size_t i;
238 for (i = 0; i < textFile.GetLineCount(); i++)
239 {
240 wxString line(textFile[i]);
241 int pos = line.Find(wxT("XDG_DOCUMENTS_DIR"));
242 if (pos != wxNOT_FOUND)
243 {
244 wxString value = line.AfterFirst(wxT('='));
245 value.Replace(wxT("$HOME"), homeDir);
246 value.Trim(true);
247 value.Trim(false);
248 if (!value.IsEmpty() && wxDirExists(value))
249 return value;
250 else
251 break;
252 }
253 }
254 }
255 }
256 }
257
258 return wxStandardPathsBase::GetDocumentsDir();
259}
260
d3b9c627 261#endif // __VMS/!__VMS
c320b3e3 262
07158944 263#endif // wxUSE_STDPATHS