]> git.saurik.com Git - wxWidgets.git/blob - src/common/stdpbase.cpp
no changes, just reformat/indent consistently
[wxWidgets.git] / src / common / stdpbase.cpp
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
27 #ifndef WX_PRECOMP
28 #include "wx/app.h"
29 #endif //WX_PRECOMP
30 #include "wx/apptrait.h"
31
32 #include "wx/filename.h"
33 #include "wx/stdpaths.h"
34
35 // ----------------------------------------------------------------------------
36 // module globals
37 // ----------------------------------------------------------------------------
38
39 static wxStandardPaths gs_stdPaths;
40
41 // ============================================================================
42 // implementation
43 // ============================================================================
44
45 /* static */
46 wxStandardPathsBase& wxStandardPathsBase::Get()
47 {
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();
52 }
53
54 wxString wxStandardPathsBase::GetExecutablePath() const
55 {
56 if ( !wxTheApp || !wxTheApp->argv )
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
75 wxStandardPathsBase& wxAppTraitsBase::GetStandardPaths()
76 {
77 return gs_stdPaths;
78 }
79
80 wxStandardPathsBase::wxStandardPathsBase()
81 {
82 // Set the default information that is used when
83 // forming some paths (by AppendAppInfo).
84 // Derived classes can call this in their constructors
85 // to set the platform-specific settings
86 UseAppInfo(AppInfo_AppName);
87 }
88
89 wxStandardPathsBase::~wxStandardPathsBase()
90 {
91 // nothing to do here
92 }
93
94 wxString wxStandardPathsBase::GetLocalDataDir() const
95 {
96 return GetDataDir();
97 }
98
99 wxString wxStandardPathsBase::GetUserLocalDataDir() const
100 {
101 return GetUserDataDir();
102 }
103
104 wxString wxStandardPathsBase::GetDocumentsDir() const
105 {
106 return wxFileName::GetHomeDir();
107 }
108
109 // return the temporary directory for the current user
110 wxString wxStandardPathsBase::GetTempDir() const
111 {
112 return wxFileName::GetTempDir();
113 }
114
115 /* static */
116 wxString wxStandardPathsBase::AppendPathComponent(const wxString& dir, const wxString& component)
117 {
118 wxString subdir(dir);
119
120 // empty string indicates that an error has occurred, don't touch it then
121 if ( !subdir.empty() )
122 {
123 if ( !component.empty() )
124 {
125 const wxChar ch = *(subdir.end() - 1);
126 if ( !wxFileName::IsPathSeparator(ch) && ch != _T('.') )
127 subdir += wxFileName::GetPathSeparator();
128
129 subdir += component;
130 }
131 }
132
133 return subdir;
134 }
135
136
137 wxString wxStandardPathsBase::AppendAppInfo(const wxString& dir) const
138 {
139 wxString subdir(dir);
140
141 if ( UsesAppInfo(AppInfo_VendorName) )
142 {
143 subdir = AppendPathComponent(subdir, wxTheApp->GetVendorName());
144 }
145
146 if ( UsesAppInfo(AppInfo_AppName) )
147 {
148 subdir = AppendPathComponent(subdir, wxTheApp->GetAppName());
149 }
150
151 return subdir;
152 }
153