]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/unix/stdpaths.cpp
Removed GetAdjustedBestSize().
[wxWidgets.git] / src / unix / stdpaths.cpp
... / ...
CommitLineData
1///////////////////////////////////////////////////////////////////////////////
2// Name: unix/stdpaths.cpp
3// Purpose: wxStandardPaths implementation for Unix & OpenVMS systems
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
27#if wxUSE_STDPATHS
28
29#include "wx/stdpaths.h"
30
31#ifndef WX_PRECOMP
32 #include "wx/utils.h"
33#endif //WX_PRECOMP
34
35#include "wx/filename.h"
36
37#if defined( __LINUX__ ) || defined( __VMS )
38 #include <unistd.h>
39#endif
40
41// ============================================================================
42// common VMS/Unix part of wxStandardPaths implementation
43// ============================================================================
44
45void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
46{
47 m_prefix = prefix;
48}
49
50wxString wxStandardPaths::GetUserConfigDir() const
51{
52 return wxFileName::GetHomeDir();
53}
54
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 }
67
68 return m_prefix;
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
91wxString wxStandardPaths::GetPluginsDir() const
92{
93 return wxString(); // TODO: this is wrong, it should return something
94}
95
96wxString
97wxStandardPaths::GetLocalizedResourcesDir(const wxChar *lang,
98 ResourceCat category) const
99{
100 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
101}
102
103#else // !__VMS
104
105// ============================================================================
106// wxStandardPaths implementation for Unix
107// ============================================================================
108
109void wxStandardPaths::DetectPrefix()
110{
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 )
119 {
120 buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
121
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 }
147#endif // __LINUX__
148
149 if ( m_prefix.empty() )
150 {
151 m_prefix = wxT("/usr/local");
152 }
153}
154
155wxString wxStandardPaths::GetInstallPrefix() const
156{
157 if ( m_prefix.empty() )
158 {
159 wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this);
160 pathPtr->DetectPrefix();
161 }
162
163 return m_prefix;
164}
165
166// ----------------------------------------------------------------------------
167// public functions
168// ----------------------------------------------------------------------------
169
170wxString wxStandardPaths::GetConfigDir() const
171{
172 return _T("/etc");
173}
174
175wxString wxStandardPaths::GetDataDir() const
176{
177 return AppendAppName(GetInstallPrefix() + _T("/share"));
178}
179
180wxString wxStandardPaths::GetLocalDataDir() const
181{
182 return AppendAppName(_T("/etc"));
183}
184
185wxString wxStandardPaths::GetUserDataDir() const
186{
187 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
188}
189
190wxString wxStandardPaths::GetPluginsDir() const
191{
192 return AppendAppName(GetInstallPrefix() + _T("/lib"));
193}
194
195wxString
196wxStandardPaths::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
205#endif // __VMS/!__VMS
206
207#endif // wxUSE_STDPATHS