]>
Commit | Line | Data |
---|---|---|
c320b3e3 VZ |
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 | wxString exe; | |
61 | if ( readlink("/proc/self/exe", wxStringBuffer(exe), 1024) != -1 ) | |
62 | { | |
63 | // consider that we're in the last "bin" subdirectory of our prefix | |
64 | wxString basename(wxString(wxTheApp->argv[0]).AfterLast(_T('/'))); | |
65 | size_t pos = exe.find(_T("/bin/") + basename); | |
66 | if ( pos != wxString::npos ) | |
67 | { | |
68 | self->m_prefix.assign(exe, 0, pos); | |
69 | } | |
70 | } | |
71 | ||
72 | if ( m_prefix.empty() ) | |
73 | #endif // __LINUX__ | |
74 | { | |
75 | self->m_prefix = _T("/usr/local"); | |
76 | } | |
77 | } | |
78 | ||
79 | return m_prefix; | |
80 | } | |
81 | ||
82 | // ---------------------------------------------------------------------------- | |
83 | // public functions | |
84 | // ---------------------------------------------------------------------------- | |
85 | ||
86 | wxString wxStandardPaths::GetConfigDir() const | |
87 | { | |
88 | return _T("/etc"); | |
89 | } | |
90 | ||
91 | wxString wxStandardPaths::GetUserConfigDir() const | |
92 | { | |
93 | return wxFileName::GetHomeDir(); | |
94 | } | |
95 | ||
96 | wxString wxStandardPaths::GetDataDir() const | |
97 | { | |
98 | return AppendAppName(GetInstallPrefix() + _T("/share")); | |
99 | } | |
100 | ||
101 | wxString wxStandardPaths::GetLocalDataDir() const | |
102 | { | |
103 | return AppendAppName(_T("/etc")); | |
104 | } | |
105 | ||
106 | wxString wxStandardPaths::GetUserDataDir() const | |
107 | { | |
108 | return AppendAppName(wxFileName::GetHomeDir() + _T("/.")); | |
109 | } | |
110 | ||
111 | wxString wxStandardPaths::GetPluginsDir() const | |
112 | { | |
113 | return wxString(); | |
114 | } | |
115 |