]>
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 #include "wx/textfile.h"
39 #if defined( __LINUX__ ) || defined( __VMS )
43 // ============================================================================
44 // common VMS/Unix part of wxStandardPaths implementation
45 // ============================================================================
47 void wxStandardPaths::SetInstallPrefix(const wxString
& prefix
)
52 wxString
wxStandardPaths::GetUserConfigDir() const
54 return wxFileName::GetHomeDir();
58 // ============================================================================
59 // wxStandardPaths implementation for VMS
60 // ============================================================================
64 wxString
wxStandardPaths::GetInstallPrefix() const
66 if ( m_prefix
.empty() )
68 wx_const_cast(wxStandardPaths
*, this)->m_prefix
= wxT("/sys$system");
74 wxString
wxStandardPaths::GetConfigDir() const
76 return _T("/sys$manager");
79 wxString
wxStandardPaths::GetDataDir() const
81 return AppendAppInfo(GetInstallPrefix() + _T("/sys$share"));
84 wxString
wxStandardPaths::GetLocalDataDir() const
86 return AppendAppInfo(_T("/sys$manager"));
89 wxString
wxStandardPaths::GetUserDataDir() const
91 return wxFileName::GetHomeDir();
94 wxString
wxStandardPaths::GetPluginsDir() const
96 return wxString(); // TODO: this is wrong, it should return something
100 wxStandardPaths::GetLocalizedResourcesDir(const wxString
& lang
,
101 ResourceCat category
) const
103 return wxStandardPathsBase::GetLocalizedResourcesDir(lang
, category
);
106 wxString
wxStandardPaths::GetExecutablePath() const
108 return wxStandardPathsBase::GetExecutablePath();
113 // ============================================================================
114 // wxStandardPaths implementation for Unix
115 // ============================================================================
117 wxString
wxStandardPaths::GetExecutablePath() const
123 int result
= readlink("/proc/self/exe", buf
, WXSIZEOF(buf
) - sizeof(char));
126 buf
[result
] = '\0'; // readlink() doesn't NUL-terminate the buffer
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
);
135 if ( exeStr
.empty() )
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
);
146 if ( !exeStr
.empty() )
150 return wxStandardPathsBase::GetExecutablePath();
153 void wxStandardPaths::DetectPrefix()
155 // we can try to infer the prefix from the location of the executable
156 wxString exeStr
= GetExecutablePath();
157 if ( !exeStr
.empty() )
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
);
165 if ( m_prefix
.empty() )
167 m_prefix
= wxT("/usr/local");
171 wxString
wxStandardPaths::GetInstallPrefix() const
173 if ( m_prefix
.empty() )
175 wxStandardPaths
*pathPtr
= wx_const_cast(wxStandardPaths
*, this);
176 pathPtr
->DetectPrefix();
182 // ----------------------------------------------------------------------------
184 // ----------------------------------------------------------------------------
186 wxString
wxStandardPaths::GetConfigDir() const
191 wxString
wxStandardPaths::GetDataDir() const
193 return AppendAppInfo(GetInstallPrefix() + _T("/share"));
196 wxString
wxStandardPaths::GetLocalDataDir() const
198 return AppendAppInfo(_T("/etc"));
201 wxString
wxStandardPaths::GetUserDataDir() const
203 return AppendAppInfo(wxFileName::GetHomeDir() + _T("/."));
206 wxString
wxStandardPaths::GetPluginsDir() const
208 return AppendAppInfo(GetInstallPrefix() + _T("/lib"));
212 wxStandardPaths::GetLocalizedResourcesDir(const wxString
& lang
,
213 ResourceCat category
) const
215 if ( category
!= ResourceCat_Messages
)
216 return wxStandardPathsBase::GetLocalizedResourcesDir(lang
, category
);
218 return GetInstallPrefix() + _T("/share/locale/") + lang
+ _T("/LC_MESSAGES");
221 wxString
wxStandardPaths::GetDocumentsDir() const
225 wxString homeDir
= wxFileName::GetHomeDir();
227 if (wxGetenv(wxT("XDG_CONFIG_HOME")))
228 configPath
= wxGetenv(wxT("XDG_CONFIG_HOME"));
230 configPath
= homeDir
+ wxT("/.config");
231 wxString dirsFile
= configPath
+ wxT("/user-dirs.dirs");
232 if (wxFileExists(dirsFile
))
235 if (textFile
.Open(dirsFile
))
238 for (i
= 0; i
< textFile
.GetLineCount(); i
++)
240 wxString
line(textFile
[i
]);
241 int pos
= line
.Find(wxT("XDG_DOCUMENTS_DIR"));
242 if (pos
!= wxNOT_FOUND
)
244 wxString value
= line
.AfterFirst(wxT('='));
245 value
.Replace(wxT("$HOME"), homeDir
);
248 if (!value
.IsEmpty() && wxDirExists(value
))
258 return wxStandardPathsBase::GetDocumentsDir();
261 #endif // __VMS/!__VMS
263 #endif // wxUSE_STDPATHS