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