]>
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 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/stdpaths.h"
37 #include "wx/filename.h"
39 #include "wx/textfile.h"
41 #if defined( __LINUX__ ) || defined( __VMS )
45 // ============================================================================
46 // common VMS/Unix part of wxStandardPaths implementation
47 // ============================================================================
49 void wxStandardPaths::SetInstallPrefix(const wxString
& prefix
)
54 wxString
wxStandardPaths::GetUserConfigDir() const
56 return wxFileName::GetHomeDir();
60 // ============================================================================
61 // wxStandardPaths implementation for VMS
62 // ============================================================================
66 wxString
wxStandardPaths::GetInstallPrefix() const
68 if ( m_prefix
.empty() )
70 const_cast<wxStandardPaths
*>(this)->m_prefix
= wxT("/sys$system");
76 wxString
wxStandardPaths::GetConfigDir() const
78 return wxT("/sys$manager");
81 wxString
wxStandardPaths::GetDataDir() const
83 return AppendAppInfo(GetInstallPrefix() + wxT("/sys$share"));
86 wxString
wxStandardPaths::GetLocalDataDir() const
88 return AppendAppInfo(wxT("/sys$manager"));
91 wxString
wxStandardPaths::GetUserDataDir() const
93 return wxFileName::GetHomeDir();
96 wxString
wxStandardPaths::GetPluginsDir() const
98 return wxString(); // TODO: this is wrong, it should return something
102 wxStandardPaths::GetLocalizedResourcesDir(const wxString
& lang
,
103 ResourceCat category
) const
105 return wxStandardPathsBase::GetLocalizedResourcesDir(lang
, category
);
108 wxString
wxStandardPaths::GetExecutablePath() const
110 return wxStandardPathsBase::GetExecutablePath();
115 // ============================================================================
116 // wxStandardPaths implementation for Unix
117 // ============================================================================
119 wxString
wxStandardPaths::GetExecutablePath() const
125 int result
= readlink("/proc/self/exe", buf
, WXSIZEOF(buf
) - sizeof(char));
128 buf
[result
] = '\0'; // readlink() doesn't NUL-terminate the buffer
130 // if the /proc/self/exe symlink has been dropped by the kernel for
131 // some reason, then readlink() could also return success but
132 // "(deleted)" as link destination...
133 if ( strcmp(buf
, "(deleted)") != 0 )
134 exeStr
= wxString(buf
, wxConvLibc
);
137 if ( exeStr
.empty() )
139 // UPX-specific hack: when using UPX on linux, the kernel will drop the
140 // /proc/self/exe link; in this case we try to look for a special
141 // environment variable called " " which is created by UPX to save
142 // /proc/self/exe contents. See
143 // http://sf.net/tracker/?func=detail&atid=309863&aid=1565357&group_id=9863
144 // for more information about this issue.
145 wxGetEnv(wxT(" "), &exeStr
);
148 if ( !exeStr
.empty() )
152 return wxStandardPathsBase::GetExecutablePath();
155 void wxStandardPaths::DetectPrefix()
157 // we can try to infer the prefix from the location of the executable
158 wxString exeStr
= GetExecutablePath();
159 if ( !exeStr
.empty() )
161 // consider that we're in the last "bin" subdirectory of our prefix
162 size_t pos
= exeStr
.rfind(wxT("/bin/"));
163 if ( pos
!= wxString::npos
)
164 m_prefix
.assign(exeStr
, 0, pos
);
167 if ( m_prefix
.empty() )
169 m_prefix
= wxT("/usr/local");
173 wxString
wxStandardPaths::GetInstallPrefix() const
175 if ( m_prefix
.empty() )
177 wxStandardPaths
*pathPtr
= const_cast<wxStandardPaths
*>(this);
178 pathPtr
->DetectPrefix();
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
188 wxString
wxStandardPaths::GetConfigDir() const
193 wxString
wxStandardPaths::GetDataDir() const
195 // allow to override the location of the data directory by setting
196 // WX_APPNAME_DATA_DIR environment variable: this is very useful in
197 // practice for running well-written (and so using wxStandardPaths to find
198 // their files) wx applications without installing them
199 static const wxString
202 ("WX_" + wxTheApp
->GetAppName().Upper() + "_DATA_DIR").c_str()
206 if ( !envOverride
.empty() )
209 return AppendAppInfo(GetInstallPrefix() + wxT("/share"));
212 wxString
wxStandardPaths::GetLocalDataDir() const
214 return AppendAppInfo(wxT("/etc"));
217 wxString
wxStandardPaths::GetUserDataDir() const
219 return AppendAppInfo(wxFileName::GetHomeDir() + wxT("/."));
222 wxString
wxStandardPaths::GetPluginsDir() const
224 return AppendAppInfo(GetInstallPrefix() + wxT("/lib"));
228 wxStandardPaths::GetLocalizedResourcesDir(const wxString
& lang
,
229 ResourceCat category
) const
231 if ( category
!= ResourceCat_Messages
)
232 return wxStandardPathsBase::GetLocalizedResourcesDir(lang
, category
);
234 return GetInstallPrefix() + wxT("/share/locale/") + lang
+ wxT("/LC_MESSAGES");
237 wxString
wxStandardPaths::GetDocumentsDir() const
241 wxString homeDir
= wxFileName::GetHomeDir();
243 if (wxGetenv(wxT("XDG_CONFIG_HOME")))
244 configPath
= wxGetenv(wxT("XDG_CONFIG_HOME"));
246 configPath
= homeDir
+ wxT("/.config");
247 wxString dirsFile
= configPath
+ wxT("/user-dirs.dirs");
248 if (wxFileExists(dirsFile
))
251 if (textFile
.Open(dirsFile
))
254 for (i
= 0; i
< textFile
.GetLineCount(); i
++)
256 wxString
line(textFile
[i
]);
257 int pos
= line
.Find(wxT("XDG_DOCUMENTS_DIR"));
258 if (pos
!= wxNOT_FOUND
)
260 wxString value
= line
.AfterFirst(wxT('='));
261 value
.Replace(wxT("$HOME"), homeDir
);
264 if (!value
.IsEmpty() && wxDirExists(value
))
274 return wxStandardPathsBase::GetDocumentsDir();
277 #endif // __VMS/!__VMS
279 #endif // wxUSE_STDPATHS