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