Use ~/Application Support folder on Mac
[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 #if defined(__WXMAC__)
42 #include "wx/mac/private.h"
43 #endif
44
45 // ============================================================================
46 // wxStandardPaths implementation
47 // ============================================================================
48
49 // ----------------------------------------------------------------------------
50 // prefix management
51 // ----------------------------------------------------------------------------
52
53 void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
54 {
55 m_prefix = prefix;
56 }
57
58 wxString wxStandardPaths::GetInstallPrefix() const
59 {
60 if ( m_prefix.empty() )
61 {
62 wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this);
63
64 #ifdef __LINUX__
65 // under Linux, we can try to infer the prefix from the location of the
66 // executable
67 char buf[4096];
68 int result = readlink("/proc/self/exe", buf, WXSIZEOF(buf) - sizeof(char));
69 if ( result != -1 )
70 {
71 buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
72
73 wxString exeStr(buf, wxConvLibc);
74
75 // consider that we're in the last "bin" subdirectory of our prefix
76 wxString basename(wxString(wxTheApp->argv[0]).AfterLast(_T('/')));
77 size_t pos = exeStr.find(wxT("/bin/") + basename);
78 if ( pos != wxString::npos )
79 pathPtr->m_prefix.assign(exeStr, 0, pos);
80 }
81 #endif // __LINUX__
82
83 if ( m_prefix.empty() )
84 {
85 #ifdef __VMS
86 pathPtr->m_prefix = wxT("/sys$system");
87 #else
88 pathPtr->m_prefix = wxT("/usr/local");
89 #endif
90 }
91 }
92
93 return m_prefix;
94 }
95
96 // ----------------------------------------------------------------------------
97 // public functions
98 // ----------------------------------------------------------------------------
99
100 wxString wxStandardPaths::GetConfigDir() const
101 {
102 #ifdef __VMS
103 return _T("/sys$manager");
104 #else
105 return _T("/etc");
106 #endif
107 }
108
109 wxString wxStandardPaths::GetUserConfigDir() const
110 {
111 return wxFileName::GetHomeDir();
112 }
113
114 wxString wxStandardPaths::GetDataDir() const
115 {
116 #ifdef __VMS
117 return AppendAppName(GetInstallPrefix() + _T("/sys$share"));
118 #else
119 return AppendAppName(GetInstallPrefix() + _T("/share"));
120 #endif
121 }
122
123 wxString wxStandardPaths::GetLocalDataDir() const
124 {
125 #ifdef __VMS
126 return AppendAppName(_T("/sys$manager"));
127 #else
128 return AppendAppName(_T("/etc"));
129 #endif
130 }
131
132 wxString wxStandardPaths::GetUserDataDir() const
133 {
134 #ifdef __VMS
135 return wxFileName::GetHomeDir();
136 #elif defined(__WXMAC__)
137 return AppendAppName(wxMacFindFolder((short) kUserDomain, kApplicationSupportFolderType, kDontCreateFolder));
138 #else
139 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
140 #endif
141 }
142
143 wxString wxStandardPaths::GetPluginsDir() const
144 {
145 return wxString();
146 }
147
148 #endif // wxUSE_STDPATHS