1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/stdpbase.cpp
3 // Purpose: wxStandardPathsBase methods common to all ports
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/apptrait.h"
32 #include "wx/filename.h"
33 #include "wx/stdpaths.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 static wxStandardPaths gs_stdPaths
;
41 // ============================================================================
43 // ============================================================================
46 wxStandardPathsBase
& wxStandardPathsBase::Get()
48 wxAppTraits
* const traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
49 wxCHECK_MSG( traits
, gs_stdPaths
, _T("create wxApp before calling this") );
51 return traits
->GetStandardPaths();
54 wxString
wxStandardPathsBase::GetExecutablePath() const
56 if ( !wxTheApp
|| !wxTheApp
->argv
)
59 wxString argv0
= wxTheApp
->argv
[0];
60 if (wxIsAbsolutePath(argv0
))
63 // Search PATH.environment variable...
65 pathlist
.AddEnvList(wxT("PATH"));
66 wxString path
= pathlist
.FindAbsoluteValidPath(argv0
);
68 return argv0
; // better than nothing
70 wxFileName
filename(path
);
72 return filename
.GetFullPath();
75 wxStandardPathsBase
& wxAppTraitsBase::GetStandardPaths()
80 wxStandardPathsBase::~wxStandardPathsBase()
85 wxString
wxStandardPathsBase::GetLocalDataDir() const
90 wxString
wxStandardPathsBase::GetUserLocalDataDir() const
92 return GetUserDataDir();
95 wxString
wxStandardPathsBase::GetDocumentsDir() const
97 return wxFileName::GetHomeDir();
100 // return the temporary directory for the current user
101 wxString
wxStandardPathsBase::GetTempDir() const
103 return wxFileName::GetTempDir();
107 wxString
wxStandardPathsBase::AppendAppName(const wxString
& dir
)
109 wxString
subdir(dir
);
111 // empty string indicates that an error has occurred, don't touch it then
112 if ( !subdir
.empty() )
114 const wxString appname
= wxTheApp
->GetAppName();
115 if ( !appname
.empty() )
117 const wxChar ch
= *(subdir
.end() - 1);
118 if ( !wxFileName::IsPathSeparator(ch
) && ch
!= _T('.') )
119 subdir
+= wxFileName::GetPathSeparator();