]>
Commit | Line | Data |
---|---|---|
6cb5e50b | 1 | /////////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: src/common/stdpbase.cpp |
6cb5e50b VZ |
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> | |
526954c5 | 9 | // Licence: wxWindows licence |
6cb5e50b VZ |
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 | ||
38aae140 VZ |
39 | namespace |
40 | { | |
41 | ||
42 | // Derive a class just to be able to create it: wxStandardPaths ctor is | |
43 | // protected to prevent its misuse, but it also means we can't create an object | |
44 | // of this class directly. | |
45 | class wxStandardPathsDefault : public wxStandardPaths | |
46 | { | |
47 | public: | |
48 | wxStandardPathsDefault() { } | |
49 | }; | |
50 | ||
51 | static wxStandardPathsDefault gs_stdPaths; | |
52 | ||
53 | } // anonymous namespace | |
6cb5e50b VZ |
54 | |
55 | // ============================================================================ | |
56 | // implementation | |
57 | // ============================================================================ | |
58 | ||
59 | /* static */ | |
25f49256 | 60 | wxStandardPaths& wxStandardPathsBase::Get() |
fc480dc1 | 61 | { |
81f9c575 | 62 | wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL; |
9a83f860 | 63 | wxCHECK_MSG( traits, gs_stdPaths, wxT("create wxApp before calling this") ); |
81f9c575 VZ |
64 | |
65 | return traits->GetStandardPaths(); | |
fc480dc1 DE |
66 | } |
67 | ||
ac7ad70d RR |
68 | wxString wxStandardPathsBase::GetExecutablePath() const |
69 | { | |
d154ab3d | 70 | if ( !wxTheApp || !wxTheApp->argv ) |
ac7ad70d RR |
71 | return wxEmptyString; |
72 | ||
73 | wxString argv0 = wxTheApp->argv[0]; | |
74 | if (wxIsAbsolutePath(argv0)) | |
75 | return argv0; | |
76 | ||
77 | // Search PATH.environment variable... | |
78 | wxPathList pathlist; | |
79 | pathlist.AddEnvList(wxT("PATH")); | |
80 | wxString path = pathlist.FindAbsoluteValidPath(argv0); | |
81 | if ( path.empty() ) | |
82 | return argv0; // better than nothing | |
83 | ||
84 | wxFileName filename(path); | |
85 | filename.Normalize(); | |
86 | return filename.GetFullPath(); | |
87 | } | |
88 | ||
25f49256 | 89 | wxStandardPaths& wxAppTraitsBase::GetStandardPaths() |
6cb5e50b VZ |
90 | { |
91 | return gs_stdPaths; | |
92 | } | |
93 | ||
2b147f2e VZ |
94 | wxStandardPathsBase::wxStandardPathsBase() |
95 | { | |
96 | // Set the default information that is used when | |
97 | // forming some paths (by AppendAppInfo). | |
98 | // Derived classes can call this in their constructors | |
99 | // to set the platform-specific settings | |
100 | UseAppInfo(AppInfo_AppName); | |
101 | } | |
102 | ||
6cb5e50b VZ |
103 | wxStandardPathsBase::~wxStandardPathsBase() |
104 | { | |
105 | // nothing to do here | |
106 | } | |
107 | ||
108 | wxString wxStandardPathsBase::GetLocalDataDir() const | |
109 | { | |
110 | return GetDataDir(); | |
111 | } | |
112 | ||
113 | wxString wxStandardPathsBase::GetUserLocalDataDir() const | |
114 | { | |
115 | return GetUserDataDir(); | |
116 | } | |
117 | ||
17af82fb VZ |
118 | wxString wxStandardPathsBase::GetDocumentsDir() const |
119 | { | |
120 | return wxFileName::GetHomeDir(); | |
121 | } | |
122 | ||
d8efd219 VZ |
123 | wxString wxStandardPathsBase::GetAppDocumentsDir() const |
124 | { | |
125 | const wxString docsDir = GetDocumentsDir(); | |
126 | wxString appDocsDir = AppendAppInfo(docsDir); | |
127 | ||
128 | return wxDirExists(appDocsDir) ? appDocsDir : docsDir; | |
129 | } | |
130 | ||
ecf9559d JS |
131 | // return the temporary directory for the current user |
132 | wxString wxStandardPathsBase::GetTempDir() const | |
133 | { | |
134 | return wxFileName::GetTempDir(); | |
135 | } | |
136 | ||
ce336c6d | 137 | /* static */ |
d8efd219 VZ |
138 | wxString |
139 | wxStandardPathsBase::AppendPathComponent(const wxString& dir, | |
140 | const wxString& component) | |
ce336c6d VZ |
141 | { |
142 | wxString subdir(dir); | |
143 | ||
3103e8a9 | 144 | // empty string indicates that an error has occurred, don't touch it then |
ce336c6d VZ |
145 | if ( !subdir.empty() ) |
146 | { | |
2b147f2e | 147 | if ( !component.empty() ) |
ce336c6d VZ |
148 | { |
149 | const wxChar ch = *(subdir.end() - 1); | |
9a83f860 | 150 | if ( !wxFileName::IsPathSeparator(ch) && ch != wxT('.') ) |
ce336c6d VZ |
151 | subdir += wxFileName::GetPathSeparator(); |
152 | ||
2b147f2e | 153 | subdir += component; |
ce336c6d VZ |
154 | } |
155 | } | |
156 | ||
157 | return subdir; | |
158 | } | |
2b147f2e VZ |
159 | |
160 | ||
161 | wxString wxStandardPathsBase::AppendAppInfo(const wxString& dir) const | |
162 | { | |
163 | wxString subdir(dir); | |
164 | ||
165 | if ( UsesAppInfo(AppInfo_VendorName) ) | |
166 | { | |
167 | subdir = AppendPathComponent(subdir, wxTheApp->GetVendorName()); | |
168 | } | |
169 | ||
170 | if ( UsesAppInfo(AppInfo_AppName) ) | |
171 | { | |
172 | subdir = AppendPathComponent(subdir, wxTheApp->GetAppName()); | |
173 | } | |
174 | ||
175 | return subdir; | |
176 | } | |
177 |