]>
git.saurik.com Git - wxWidgets.git/blob - src/unix/stdpaths.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: unix/stdpaths.cpp
3 // Purpose: wxStandardPaths implementation for Unix & OpenVMS systems
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/stdpaths.h"
35 #include "wx/filename.h"
37 #if defined( __LINUX__ ) || defined( __VMS )
41 // ============================================================================
42 // common VMS/Unix part of wxStandardPaths implementation
43 // ============================================================================
45 void wxStandardPaths::SetInstallPrefix(const wxString
& prefix
)
50 wxString
wxStandardPaths::GetUserConfigDir() const
52 return wxFileName::GetHomeDir();
55 // ============================================================================
56 // wxStandardPaths implementation for VMS
57 // ============================================================================
61 wxString
wxStandardPaths::GetInstallPrefix() const
63 if ( m_prefix
.empty() )
65 wx_const_cast(wxStandardPaths
*, this)->m_prefix
= wxT("/sys$system");
71 wxString
wxStandardPaths::GetConfigDir() const
73 return _T("/sys$manager");
76 wxString
wxStandardPaths::GetDataDir() const
78 return AppendAppName(GetInstallPrefix() + _T("/sys$share"));
81 wxString
wxStandardPaths::GetLocalDataDir() const
83 return AppendAppName(_T("/sys$manager"));
86 wxString
wxStandardPaths::GetUserDataDir() const
88 return wxFileName::GetHomeDir();
91 wxString
wxStandardPaths::GetPluginsDir() const
93 return wxString(); // TODO: this is wrong, it should return something
97 wxStandardPaths::GetLocalizedResourcesDir(const wxString
& lang
,
98 ResourceCat category
) const
100 return wxStandardPathsBase::GetLocalizedResourcesDir(lang
, category
);
103 wxString
wxStandardPaths::GetExecutablePath() const
105 return wxStandardPathsBase::GetExecutablePath();
110 // ============================================================================
111 // wxStandardPaths implementation for Unix
112 // ============================================================================
114 wxString
wxStandardPaths::GetExecutablePath() const
120 int result
= readlink("/proc/self/exe", buf
, WXSIZEOF(buf
) - sizeof(char));
123 buf
[result
] = '\0'; // readlink() doesn't NUL-terminate the buffer
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
);
132 if ( exeStr
.empty() )
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
);
143 if ( !exeStr
.empty() )
147 return wxStandardPathsBase::GetExecutablePath();
150 void wxStandardPaths::DetectPrefix()
152 // we can try to infer the prefix from the location of the executable
153 wxString exeStr
= GetExecutablePath();
154 if ( !exeStr
.empty() )
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
);
162 if ( m_prefix
.empty() )
164 m_prefix
= wxT("/usr/local");
168 wxString
wxStandardPaths::GetInstallPrefix() const
170 if ( m_prefix
.empty() )
172 wxStandardPaths
*pathPtr
= wx_const_cast(wxStandardPaths
*, this);
173 pathPtr
->DetectPrefix();
179 // ----------------------------------------------------------------------------
181 // ----------------------------------------------------------------------------
183 wxString
wxStandardPaths::GetConfigDir() const
188 wxString
wxStandardPaths::GetDataDir() const
190 return AppendAppName(GetInstallPrefix() + _T("/share"));
193 wxString
wxStandardPaths::GetLocalDataDir() const
195 return AppendAppName(_T("/etc"));
198 wxString
wxStandardPaths::GetUserDataDir() const
200 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
203 wxString
wxStandardPaths::GetPluginsDir() const
205 return AppendAppName(GetInstallPrefix() + _T("/lib"));
209 wxStandardPaths::GetLocalizedResourcesDir(const wxString
& lang
,
210 ResourceCat category
) const
212 if ( category
!= ResourceCat_Messages
)
213 return wxStandardPathsBase::GetLocalizedResourcesDir(lang
, category
);
215 return GetInstallPrefix() + _T("/share/locale/") + lang
+ _T("/LC_MESSAGES");
218 #endif // __VMS/!__VMS
220 #endif // wxUSE_STDPATHS