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"
32 #include "wx/apptrait.h"
34 #include "wx/filename.h"
35 #include "wx/stdpaths.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 static wxStandardPaths gs_stdPaths
;
43 // ============================================================================
45 // ============================================================================
48 wxStandardPathsBase
& wxStandardPathsBase::Get()
50 wxAppTraits
* const traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
51 wxCHECK_MSG( traits
, gs_stdPaths
, _T("create wxApp before calling this") );
53 return traits
->GetStandardPaths();
56 wxString
wxStandardPathsBase::GetExecutablePath() const
58 if ( !wxTheApp
|| !wxTheApp
->argv
)
61 wxString argv0
= wxTheApp
->argv
[0];
62 if (wxIsAbsolutePath(argv0
))
65 // Search PATH.environment variable...
67 pathlist
.AddEnvList(wxT("PATH"));
68 wxString path
= pathlist
.FindAbsoluteValidPath(argv0
);
70 return argv0
; // better than nothing
72 wxFileName
filename(path
);
74 return filename
.GetFullPath();
77 wxStandardPathsBase
& wxAppTraitsBase::GetStandardPaths()
82 wxStandardPathsBase::~wxStandardPathsBase()
87 wxString
wxStandardPathsBase::GetLocalDataDir() const
92 wxString
wxStandardPathsBase::GetUserLocalDataDir() const
94 return GetUserDataDir();
97 wxString
wxStandardPathsBase::GetDocumentsDir() const
99 return wxFileName::GetHomeDir();
102 // return the temporary directory for the current user
103 wxString
wxStandardPathsBase::GetTempDir() const
105 return wxFileName::GetTempDir();
109 wxString
wxStandardPathsBase::AppendAppName(const wxString
& dir
)
111 wxString
subdir(dir
);
113 // empty string indicates that an error has occurred, don't touch it then
114 if ( !subdir
.empty() )
116 const wxString appname
= wxTheApp
->GetAppName();
117 if ( !appname
.empty() )
119 const wxChar ch
= *(subdir
.end() - 1);
120 if ( !wxFileName::IsPathSeparator(ch
) && ch
!= _T('.') )
121 subdir
+= wxFileName::GetPathSeparator();
130 #endif // wxUSE_STDPATHS