fix for bug 1371386, with some minor mods and cleanup
[wxWidgets.git] / src / unix / stdpaths.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: unix/stdpaths.cpp
3 // Purpose: wxStandardPaths implementation for Unix & OpenVMS 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 #if wxUSE_STDPATHS
28
29 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #endif //WX_PRECOMP
32
33 #include "wx/filename.h"
34
35 #include "wx/stdpaths.h"
36
37 #if defined( __LINUX__ ) || defined( __VMS )
38 #include <unistd.h>
39 #endif
40
41 // ============================================================================
42 // wxStandardPaths implementation
43 // ============================================================================
44
45 // ----------------------------------------------------------------------------
46 // prefix management
47 // ----------------------------------------------------------------------------
48
49 void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
50 {
51 m_prefix = prefix;
52 }
53
54 wxString wxStandardPaths::GetInstallPrefix() const
55 {
56 if ( m_prefix.empty() )
57 {
58 wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this);
59
60 #ifdef __LINUX__
61 // under Linux, we can get location of the executable
62 wxChar buf[4096];
63 int result;
64
65 result = readlink( wxT("/proc/self/exe"), buf, WXSIZEOF(buf) - sizeof(wxChar) );
66 if (result != -1)
67 {
68 buff[result] = wxChar(0);
69 wxString exeStr( buf, wxConvLibc );
70
71 // consider that we're in the last "bin" subdirectory of our prefix
72 wxString basename( wxString( wxTheApp->argv[0]).AfterLast(_T('/')) );
73 size_t pos = exeStr.find( wxT("/bin/") + basename );
74 if (pos != wxString::npos)
75 pathPtr->m_prefix.assign( exeStr, 0, pos );
76 }
77 #endif // __LINUX__
78
79 if (m_prefix.empty())
80 {
81 #ifdef __VMS
82 pathPtr->m_prefix = wxT("/sys$system");
83 #else
84 pathPtr->m_prefix = wxT("/usr/local");
85 #endif
86 }
87 }
88
89 return m_prefix;
90 }
91
92 // ----------------------------------------------------------------------------
93 // public functions
94 // ----------------------------------------------------------------------------
95
96 wxString wxStandardPaths::GetConfigDir() const
97 {
98 #ifdef __VMS
99 return _T("/sys$manager");
100 #else
101 return _T("/etc");
102 #endif
103 }
104
105 wxString wxStandardPaths::GetUserConfigDir() const
106 {
107 return wxFileName::GetHomeDir();
108 }
109
110 wxString wxStandardPaths::GetDataDir() const
111 {
112 #ifdef __VMS
113 return AppendAppName(GetInstallPrefix() + _T("/sys$share"));
114 #else
115 return AppendAppName(GetInstallPrefix() + _T("/share"));
116 #endif
117 }
118
119 wxString wxStandardPaths::GetLocalDataDir() const
120 {
121 #ifdef __VMS
122 return AppendAppName(_T("/sys$manager"));
123 #else
124 return AppendAppName(_T("/etc"));
125 #endif
126 }
127
128 wxString wxStandardPaths::GetUserDataDir() const
129 {
130 #ifdef __VMS
131 return wxFileName::GetHomeDir();
132 #else
133 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
134 #endif
135 }
136
137 wxString wxStandardPaths::GetPluginsDir() const
138 {
139 return wxString();
140 }
141
142 #endif // wxUSE_STDPATHS