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