]> git.saurik.com Git - wxWidgets.git/blame - src/common/stdpbase.cpp
rename old wxAppConsole to wxAppConsoleBase and wxAppConsoleUnix to wxAppConsole...
[wxWidgets.git] / src / common / stdpbase.cpp
CommitLineData
6cb5e50b
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: common/stdpbase.cpp
3// Purpose: wxStandardPathsBase methods common to all ports
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
ce336c6d
VZ
29#ifndef WX_PRECOMP
30 #include "wx/app.h"
31#endif //WX_PRECOMP
fc480dc1 32#include "wx/apptrait.h"
ce336c6d
VZ
33
34#include "wx/filename.h"
6cb5e50b
VZ
35#include "wx/stdpaths.h"
36
37// ----------------------------------------------------------------------------
38// module globals
39// ----------------------------------------------------------------------------
40
41static wxStandardPaths gs_stdPaths;
42
43// ============================================================================
44// implementation
45// ============================================================================
46
47/* static */
fc480dc1
DE
48wxStandardPathsBase& wxStandardPathsBase::Get()
49{
81f9c575
VZ
50 wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
51 wxCHECK_MSG( traits, gs_stdPaths, _T("create wxApp before calling this") );
52
53 return traits->GetStandardPaths();
fc480dc1
DE
54}
55
ac7ad70d
RR
56wxString wxStandardPathsBase::GetExecutablePath() const
57{
58 if ( !wxTheApp || !wxTheApp->argv )
59 return wxEmptyString;
60
61 wxString argv0 = wxTheApp->argv[0];
62 if (wxIsAbsolutePath(argv0))
63 return argv0;
64
65 // Search PATH.environment variable...
66 wxPathList pathlist;
67 pathlist.AddEnvList(wxT("PATH"));
68 wxString path = pathlist.FindAbsoluteValidPath(argv0);
69 if ( path.empty() )
70 return argv0; // better than nothing
71
72 wxFileName filename(path);
73 filename.Normalize();
74 return filename.GetFullPath();
75}
76
fc480dc1 77wxStandardPathsBase& wxAppTraitsBase::GetStandardPaths()
6cb5e50b
VZ
78{
79 return gs_stdPaths;
80}
81
82wxStandardPathsBase::~wxStandardPathsBase()
83{
84 // nothing to do here
85}
86
87wxString wxStandardPathsBase::GetLocalDataDir() const
88{
89 return GetDataDir();
90}
91
92wxString wxStandardPathsBase::GetUserLocalDataDir() const
93{
94 return GetUserDataDir();
95}
96
17af82fb
VZ
97wxString wxStandardPathsBase::GetDocumentsDir() const
98{
99 return wxFileName::GetHomeDir();
100}
101
ecf9559d
JS
102// return the temporary directory for the current user
103wxString wxStandardPathsBase::GetTempDir() const
104{
105 return wxFileName::GetTempDir();
106}
107
ce336c6d
VZ
108/* static */
109wxString wxStandardPathsBase::AppendAppName(const wxString& dir)
110{
111 wxString subdir(dir);
112
3103e8a9 113 // empty string indicates that an error has occurred, don't touch it then
ce336c6d
VZ
114 if ( !subdir.empty() )
115 {
116 const wxString appname = wxTheApp->GetAppName();
117 if ( !appname.empty() )
118 {
119 const wxChar ch = *(subdir.end() - 1);
120 if ( !wxFileName::IsPathSeparator(ch) && ch != _T('.') )
121 subdir += wxFileName::GetPathSeparator();
122
123 subdir += appname;
124 }
125 }
126
127 return subdir;
128}
129
07158944 130#endif // wxUSE_STDPATHS