| 1 | /////////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: unix/stdpaths.cpp |
| 3 | // Purpose: wxStandardPaths implementation for Unix 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 | #ifndef WX_PRECOMP |
| 28 | #include "wx/app.h" |
| 29 | #endif //WX_PRECOMP |
| 30 | |
| 31 | #include "wx/filename.h" |
| 32 | |
| 33 | #include "wx/stdpaths.h" |
| 34 | |
| 35 | #ifdef __LINUX__ |
| 36 | #include <unistd.h> |
| 37 | #endif |
| 38 | |
| 39 | // ============================================================================ |
| 40 | // wxStandardPaths implementation |
| 41 | // ============================================================================ |
| 42 | |
| 43 | // ---------------------------------------------------------------------------- |
| 44 | // prefix management |
| 45 | // ---------------------------------------------------------------------------- |
| 46 | |
| 47 | void wxStandardPaths::SetInstallPrefix(const wxString& prefix) |
| 48 | { |
| 49 | m_prefix = prefix; |
| 50 | } |
| 51 | |
| 52 | wxString wxStandardPaths::GetInstallPrefix() const |
| 53 | { |
| 54 | if ( m_prefix.empty() ) |
| 55 | { |
| 56 | wxStandardPaths *self = wx_const_cast(wxStandardPaths *, this); |
| 57 | |
| 58 | #ifdef __LINUX__ |
| 59 | // under Linux, we can get location of the executable |
| 60 | char buf[4096]; |
| 61 | if ( readlink("/proc/self/exe", buf, WXSIZEOF(buf)) != -1 ) |
| 62 | { |
| 63 | wxString exe(buf, wxConvLibc); |
| 64 | |
| 65 | // consider that we're in the last "bin" subdirectory of our prefix |
| 66 | wxString basename(wxString(wxTheApp->argv[0]).AfterLast(_T('/'))); |
| 67 | size_t pos = exe.find(_T("/bin/") + basename); |
| 68 | if ( pos != wxString::npos ) |
| 69 | { |
| 70 | self->m_prefix.assign(exe, 0, pos); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if ( m_prefix.empty() ) |
| 75 | #endif // __LINUX__ |
| 76 | { |
| 77 | self->m_prefix = _T("/usr/local"); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return m_prefix; |
| 82 | } |
| 83 | |
| 84 | // ---------------------------------------------------------------------------- |
| 85 | // public functions |
| 86 | // ---------------------------------------------------------------------------- |
| 87 | |
| 88 | wxString wxStandardPaths::GetConfigDir() const |
| 89 | { |
| 90 | return _T("/etc"); |
| 91 | } |
| 92 | |
| 93 | wxString wxStandardPaths::GetUserConfigDir() const |
| 94 | { |
| 95 | return wxFileName::GetHomeDir(); |
| 96 | } |
| 97 | |
| 98 | wxString wxStandardPaths::GetDataDir() const |
| 99 | { |
| 100 | return AppendAppName(GetInstallPrefix() + _T("/share")); |
| 101 | } |
| 102 | |
| 103 | wxString wxStandardPaths::GetLocalDataDir() const |
| 104 | { |
| 105 | return AppendAppName(_T("/etc")); |
| 106 | } |
| 107 | |
| 108 | wxString wxStandardPaths::GetUserDataDir() const |
| 109 | { |
| 110 | return AppendAppName(wxFileName::GetHomeDir() + _T("/.")); |
| 111 | } |
| 112 | |
| 113 | wxString wxStandardPaths::GetPluginsDir() const |
| 114 | { |
| 115 | return wxString(); |
| 116 | } |
| 117 | |