]> git.saurik.com Git - wxWidgets.git/blame - src/unix/stdpaths.cpp
Applied [ 1708971 ] Make a virtual function to enable/disable docking
[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"
36
a98ce49a 37#if defined( __LINUX__ ) || defined( __VMS )
c320b3e3
VZ
38 #include <unistd.h>
39#endif
40
41// ============================================================================
d3b9c627 42// common VMS/Unix part of wxStandardPaths implementation
c320b3e3
VZ
43// ============================================================================
44
c320b3e3
VZ
45void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
46{
47 m_prefix = prefix;
48}
49
d3b9c627
VZ
50wxString wxStandardPaths::GetUserConfigDir() const
51{
52 return wxFileName::GetHomeDir();
53}
54
d3b9c627
VZ
55// ============================================================================
56// wxStandardPaths implementation for VMS
57// ============================================================================
58
59#ifdef __VMS
60
61wxString wxStandardPaths::GetInstallPrefix() const
62{
63 if ( m_prefix.empty() )
64 {
65 wx_const_cast(wxStandardPaths *, this)->m_prefix = wxT("/sys$system");
66 }
cc4d9903
VZ
67
68 return m_prefix;
d3b9c627
VZ
69}
70
71wxString wxStandardPaths::GetConfigDir() const
72{
73 return _T("/sys$manager");
74}
75
76wxString wxStandardPaths::GetDataDir() const
77{
78 return AppendAppName(GetInstallPrefix() + _T("/sys$share"));
79}
80
81wxString wxStandardPaths::GetLocalDataDir() const
82{
83 return AppendAppName(_T("/sys$manager"));
84}
85
86wxString wxStandardPaths::GetUserDataDir() const
87{
88 return wxFileName::GetHomeDir();
89}
90
cc4d9903
VZ
91wxString wxStandardPaths::GetPluginsDir() const
92{
93 return wxString(); // TODO: this is wrong, it should return something
94}
95
3af9f2de 96wxString
e0b3b9d0 97wxStandardPaths::GetLocalizedResourcesDir(const wxString& lang,
3af9f2de
VZ
98 ResourceCat category) const
99{
100 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
101}
102
b29aaf4a
JJ
103wxString wxStandardPaths::GetExecutablePath() const
104{
105 return wxStandardPathsBase::GetExecutablePath();
106}
107
d3b9c627
VZ
108#else // !__VMS
109
110// ============================================================================
111// wxStandardPaths implementation for Unix
112// ============================================================================
113
ac7ad70d 114wxString wxStandardPaths::GetExecutablePath() const
c320b3e3 115{
3abcfa9b 116#ifdef __LINUX__
3abcfa9b
VZ
117 wxString exeStr;
118
119 char buf[4096];
120 int result = readlink("/proc/self/exe", buf, WXSIZEOF(buf) - sizeof(char));
121 if ( result != -1 )
c320b3e3 122 {
3abcfa9b 123 buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
c320b3e3 124
3abcfa9b
VZ
125 // if the /proc/self/exe symlink has been dropped by the kernel for
126 // some reason, then readlink() could also return success but
127 // "(deleted)" as link destination...
128 if ( strcmp(buf, "(deleted)") != 0 )
129 exeStr = wxString(buf, wxConvLibc);
130 }
131
132 if ( exeStr.empty() )
133 {
134 // UPX-specific hack: when using UPX on linux, the kernel will drop the
135 // /proc/self/exe link; in this case we try to look for a special
136 // environment variable called " " which is created by UPX to save
137 // /proc/self/exe contents. See
138 // http://sf.net/tracker/?func=detail&atid=309863&aid=1565357&group_id=9863
139 // for more information about this issue.
140 wxGetEnv(wxT(" "), &exeStr);
141 }
142
ac7ad70d
RR
143 if ( !exeStr.empty() )
144 return exeStr;
145#endif // __LINUX__
146
147 return wxStandardPathsBase::GetExecutablePath();
148}
149
150void wxStandardPaths::DetectPrefix()
151{
152 // we can try to infer the prefix from the location of the executable
153 wxString exeStr = GetExecutablePath();
3abcfa9b
VZ
154 if ( !exeStr.empty() )
155 {
156 // consider that we're in the last "bin" subdirectory of our prefix
157 size_t pos = exeStr.rfind(wxT("/bin/"));
158 if ( pos != wxString::npos )
159 m_prefix.assign(exeStr, 0, pos);
160 }
74ebd406 161
3abcfa9b
VZ
162 if ( m_prefix.empty() )
163 {
164 m_prefix = wxT("/usr/local");
165 }
166}
167
168wxString wxStandardPaths::GetInstallPrefix() const
169{
170 if ( m_prefix.empty() )
171 {
172 wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this);
173 pathPtr->DetectPrefix();
c320b3e3
VZ
174 }
175
176 return m_prefix;
177}
178
179// ----------------------------------------------------------------------------
180// public functions
181// ----------------------------------------------------------------------------
182
183wxString wxStandardPaths::GetConfigDir() const
184{
a98ce49a 185 return _T("/etc");
c320b3e3
VZ
186}
187
188wxString wxStandardPaths::GetDataDir() const
189{
a98ce49a 190 return AppendAppName(GetInstallPrefix() + _T("/share"));
c320b3e3
VZ
191}
192
193wxString wxStandardPaths::GetLocalDataDir() const
194{
a98ce49a 195 return AppendAppName(_T("/etc"));
c320b3e3
VZ
196}
197
198wxString wxStandardPaths::GetUserDataDir() const
199{
a98ce49a 200 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
c320b3e3
VZ
201}
202
cc4d9903
VZ
203wxString wxStandardPaths::GetPluginsDir() const
204{
205 return AppendAppName(GetInstallPrefix() + _T("/lib"));
206}
207
3af9f2de 208wxString
e0b3b9d0 209wxStandardPaths::GetLocalizedResourcesDir(const wxString& lang,
3af9f2de
VZ
210 ResourceCat category) const
211{
212 if ( category != ResourceCat_Messages )
213 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
214
215 return GetInstallPrefix() + _T("/share/locale/") + lang + _T("/LC_MESSAGES");
216}
217
d3b9c627 218#endif // __VMS/!__VMS
c320b3e3 219
07158944 220#endif // wxUSE_STDPATHS