1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/stdpbase.cpp
3 // Purpose: wxStandardPathsBase methods common to all ports
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
29 #include "wx/apptrait.h"
31 #include "wx/filename.h"
32 #include "wx/stdpaths.h"
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
41 // Derive a class just to be able to create it: wxStandardPaths ctor is
42 // protected to prevent its misuse, but it also means we can't create an object
43 // of this class directly.
44 class wxStandardPathsDefault
: public wxStandardPaths
47 wxStandardPathsDefault() { }
50 static wxStandardPathsDefault gs_stdPaths
;
52 } // anonymous namespace
54 // ============================================================================
56 // ============================================================================
59 wxStandardPaths
& wxStandardPathsBase::Get()
61 wxAppTraits
* const traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
62 wxCHECK_MSG( traits
, gs_stdPaths
, wxT("create wxApp before calling this") );
64 return traits
->GetStandardPaths();
67 wxString
wxStandardPathsBase::GetExecutablePath() const
69 if ( !wxTheApp
|| !wxTheApp
->argv
)
72 wxString argv0
= wxTheApp
->argv
[0];
73 if (wxIsAbsolutePath(argv0
))
76 // Search PATH.environment variable...
78 pathlist
.AddEnvList(wxT("PATH"));
79 wxString path
= pathlist
.FindAbsoluteValidPath(argv0
);
81 return argv0
; // better than nothing
83 wxFileName
filename(path
);
85 return filename
.GetFullPath();
88 wxStandardPaths
& wxAppTraitsBase::GetStandardPaths()
93 wxStandardPathsBase::wxStandardPathsBase()
95 // Set the default information that is used when
96 // forming some paths (by AppendAppInfo).
97 // Derived classes can call this in their constructors
98 // to set the platform-specific settings
99 UseAppInfo(AppInfo_AppName
);
102 wxStandardPathsBase::~wxStandardPathsBase()
104 // nothing to do here
107 wxString
wxStandardPathsBase::GetLocalDataDir() const
112 wxString
wxStandardPathsBase::GetUserLocalDataDir() const
114 return GetUserDataDir();
117 wxString
wxStandardPathsBase::GetDocumentsDir() const
119 return wxFileName::GetHomeDir();
122 wxString
wxStandardPathsBase::GetAppDocumentsDir() const
124 const wxString docsDir
= GetDocumentsDir();
125 wxString appDocsDir
= AppendAppInfo(docsDir
);
127 return wxDirExists(appDocsDir
) ? appDocsDir
: docsDir
;
130 // return the temporary directory for the current user
131 wxString
wxStandardPathsBase::GetTempDir() const
133 return wxFileName::GetTempDir();
138 wxStandardPathsBase::AppendPathComponent(const wxString
& dir
,
139 const wxString
& component
)
141 wxString
subdir(dir
);
143 // empty string indicates that an error has occurred, don't touch it then
144 if ( !subdir
.empty() )
146 if ( !component
.empty() )
148 const wxChar ch
= *(subdir
.end() - 1);
149 if ( !wxFileName::IsPathSeparator(ch
) && ch
!= wxT('.') )
150 subdir
+= wxFileName::GetPathSeparator();
160 wxString
wxStandardPathsBase::AppendAppInfo(const wxString
& dir
) const
162 wxString
subdir(dir
);
164 if ( UsesAppInfo(AppInfo_VendorName
) )
166 subdir
= AppendPathComponent(subdir
, wxTheApp
->GetVendorName());
169 if ( UsesAppInfo(AppInfo_AppName
) )
171 subdir
= AppendPathComponent(subdir
, wxTheApp
->GetAppName());