]>
git.saurik.com Git - wxWidgets.git/blob - src/unix/stdpaths.cpp
c127fc3d665611b43b1fd5b83b959b467a14dec4
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"
36 #include "wx/filename.h"
38 #include "wx/textfile.h"
40 #if defined( __LINUX__ ) || defined( __VMS )
44 // ============================================================================
45 // common VMS/Unix part of wxStandardPaths implementation
46 // ============================================================================
48 void wxStandardPaths::SetInstallPrefix(const wxString
& prefix
)
53 wxString
wxStandardPaths::GetUserConfigDir() const
55 return wxFileName::GetHomeDir();
59 // ============================================================================
60 // wxStandardPaths implementation for VMS
61 // ============================================================================
65 wxString
wxStandardPaths::GetInstallPrefix() const
67 if ( m_prefix
.empty() )
69 const_cast<wxStandardPaths
*>(this)->m_prefix
= wxT("/sys$system");
75 wxString
wxStandardPaths::GetConfigDir() const
77 return wxT("/sys$manager");
80 wxString
wxStandardPaths::GetDataDir() const
82 return AppendAppInfo(GetInstallPrefix() + wxT("/sys$share"));
85 wxString
wxStandardPaths::GetLocalDataDir() const
87 return AppendAppInfo(wxT("/sys$manager"));
90 wxString
wxStandardPaths::GetUserDataDir() const
92 return wxFileName::GetHomeDir();
95 wxString
wxStandardPaths::GetPluginsDir() const
97 return wxString(); // TODO: this is wrong, it should return something
101 wxStandardPaths::GetLocalizedResourcesDir(const wxString
& lang
,
102 ResourceCat category
) const
104 return wxStandardPathsBase::GetLocalizedResourcesDir(lang
, category
);
107 wxString
wxStandardPaths::GetExecutablePath() const
109 return wxStandardPathsBase::GetExecutablePath();
114 // ============================================================================
115 // wxStandardPaths implementation for Unix
116 // ============================================================================
118 wxString
wxStandardPaths::GetExecutablePath() const
124 int result
= readlink("/proc/self/exe", buf
, WXSIZEOF(buf
) - sizeof(char));
127 buf
[result
] = '\0'; // readlink() doesn't NUL-terminate the buffer
129 // if the /proc/self/exe symlink has been dropped by the kernel for
130 // some reason, then readlink() could also return success but
131 // "(deleted)" as link destination...
132 if ( strcmp(buf
, "(deleted)") != 0 )
133 exeStr
= wxString(buf
, wxConvLibc
);
136 if ( exeStr
.empty() )
138 // UPX-specific hack: when using UPX on linux, the kernel will drop the
139 // /proc/self/exe link; in this case we try to look for a special
140 // environment variable called " " which is created by UPX to save
141 // /proc/self/exe contents. See
142 // http://sf.net/tracker/?func=detail&atid=309863&aid=1565357&group_id=9863
143 // for more information about this issue.
144 wxGetEnv(wxT(" "), &exeStr
);
147 if ( !exeStr
.empty() )
151 return wxStandardPathsBase::GetExecutablePath();
154 void wxStandardPaths::DetectPrefix()
156 // we can try to infer the prefix from the location of the executable
157 wxString exeStr
= GetExecutablePath();
158 if ( !exeStr
.empty() )
160 // consider that we're in the last "bin" subdirectory of our prefix
161 size_t pos
= exeStr
.rfind(wxT("/bin/"));
162 if ( pos
!= wxString::npos
)
163 m_prefix
.assign(exeStr
, 0, pos
);
166 if ( m_prefix
.empty() )
168 m_prefix
= wxT("/usr/local");
172 wxString
wxStandardPaths::GetInstallPrefix() const
174 if ( m_prefix
.empty() )
176 wxStandardPaths
*pathPtr
= const_cast<wxStandardPaths
*>(this);
177 pathPtr
->DetectPrefix();
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
187 wxString
wxStandardPaths::GetConfigDir() const
192 wxString
wxStandardPaths::GetDataDir() const
194 // allow to override the location of the data directory by setting
195 // WX_APPNAME_DATA_DIR environment variable: this is very useful in
196 // practice for running well-written (and so using wxStandardPaths to find
197 // their files) wx applications without installing them
198 static const wxString
199 envOverride(getenv("WX_" + wxTheApp
->GetAppName().Upper() + "_DATA_DIR"));
201 if ( !envOverride
.empty() )
204 return AppendAppInfo(GetInstallPrefix() + wxT("/share"));
207 wxString
wxStandardPaths::GetLocalDataDir() const
209 return AppendAppInfo(wxT("/etc"));
212 wxString
wxStandardPaths::GetUserDataDir() const
214 return AppendAppInfo(wxFileName::GetHomeDir() + wxT("/."));
217 wxString
wxStandardPaths::GetPluginsDir() const
219 return AppendAppInfo(GetInstallPrefix() + wxT("/lib"));
223 wxStandardPaths::GetLocalizedResourcesDir(const wxString
& lang
,
224 ResourceCat category
) const
226 if ( category
!= ResourceCat_Messages
)
227 return wxStandardPathsBase::GetLocalizedResourcesDir(lang
, category
);
229 return GetInstallPrefix() + wxT("/share/locale/") + lang
+ wxT("/LC_MESSAGES");
232 wxString
wxStandardPaths::GetDocumentsDir() const
236 wxString homeDir
= wxFileName::GetHomeDir();
238 if (wxGetenv(wxT("XDG_CONFIG_HOME")))
239 configPath
= wxGetenv(wxT("XDG_CONFIG_HOME"));
241 configPath
= homeDir
+ wxT("/.config");
242 wxString dirsFile
= configPath
+ wxT("/user-dirs.dirs");
243 if (wxFileExists(dirsFile
))
246 if (textFile
.Open(dirsFile
))
249 for (i
= 0; i
< textFile
.GetLineCount(); i
++)
251 wxString
line(textFile
[i
]);
252 int pos
= line
.Find(wxT("XDG_DOCUMENTS_DIR"));
253 if (pos
!= wxNOT_FOUND
)
255 wxString value
= line
.AfterFirst(wxT('='));
256 value
.Replace(wxT("$HOME"), homeDir
);
259 if (!value
.IsEmpty() && wxDirExists(value
))
269 return wxStandardPathsBase::GetDocumentsDir();
272 #endif // __VMS/!__VMS
274 #endif // wxUSE_STDPATHS