From c320b3e32d8da0d3d09983e26efe01eb322b1b53 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 20 Oct 2004 00:35:26 +0000 Subject: [PATCH] initial Unix implementation git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30028 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/unix/stdpaths.h | 3 + src/unix/stdpaths.cpp | 115 +++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 src/unix/stdpaths.cpp diff --git a/include/wx/unix/stdpaths.h b/include/wx/unix/stdpaths.h index b262750803..f809ac9547 100644 --- a/include/wx/unix/stdpaths.h +++ b/include/wx/unix/stdpaths.h @@ -41,6 +41,9 @@ public: virtual wxString GetLocalDataDir() const; virtual wxString GetUserDataDir() const; virtual wxString GetPluginsDir() const; + +private: + wxString m_prefix; }; #endif // _WX_UNIX_STDPATHS_H_ diff --git a/src/unix/stdpaths.cpp b/src/unix/stdpaths.cpp new file mode 100644 index 0000000000..2cbcb456d3 --- /dev/null +++ b/src/unix/stdpaths.cpp @@ -0,0 +1,115 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: unix/stdpaths.cpp +// Purpose: wxStandardPaths implementation for Unix systems +// Author: Vadim Zeitlin +// Modified by: +// Created: 2004-10-19 +// RCS-ID: $Id$ +// Copyright: (c) 2004 Vadim Zeitlin +// License: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/app.h" +#endif //WX_PRECOMP + +#include "wx/filename.h" + +#include "wx/stdpaths.h" + +#ifdef __LINUX__ + #include +#endif + +// ============================================================================ +// wxStandardPaths implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// prefix management +// ---------------------------------------------------------------------------- + +void wxStandardPaths::SetInstallPrefix(const wxString& prefix) +{ + m_prefix = prefix; +} + +wxString wxStandardPaths::GetInstallPrefix() const +{ + if ( m_prefix.empty() ) + { + wxStandardPaths *self = wx_const_cast(wxStandardPaths *, this); + +#ifdef __LINUX__ + // under Linux, we can get location of the executable + wxString exe; + if ( readlink("/proc/self/exe", wxStringBuffer(exe), 1024) != -1 ) + { + // consider that we're in the last "bin" subdirectory of our prefix + wxString basename(wxString(wxTheApp->argv[0]).AfterLast(_T('/'))); + size_t pos = exe.find(_T("/bin/") + basename); + if ( pos != wxString::npos ) + { + self->m_prefix.assign(exe, 0, pos); + } + } + + if ( m_prefix.empty() ) +#endif // __LINUX__ + { + self->m_prefix = _T("/usr/local"); + } + } + + return m_prefix; +} + +// ---------------------------------------------------------------------------- +// public functions +// ---------------------------------------------------------------------------- + +wxString wxStandardPaths::GetConfigDir() const +{ + return _T("/etc"); +} + +wxString wxStandardPaths::GetUserConfigDir() const +{ + return wxFileName::GetHomeDir(); +} + +wxString wxStandardPaths::GetDataDir() const +{ + return AppendAppName(GetInstallPrefix() + _T("/share")); +} + +wxString wxStandardPaths::GetLocalDataDir() const +{ + return AppendAppName(_T("/etc")); +} + +wxString wxStandardPaths::GetUserDataDir() const +{ + return AppendAppName(wxFileName::GetHomeDir() + _T("/.")); +} + +wxString wxStandardPaths::GetPluginsDir() const +{ + return wxString(); +} +