1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // Licence: wxWindows licence
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 wxStandardPaths
& wxStandardPathsBase::Get()
48 wxAppTraits
* const traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
49 wxCHECK_MSG( traits
, gs_stdPaths
, wxT("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 wxStandardPaths
& wxAppTraitsBase::GetStandardPaths()
80 wxStandardPathsBase::wxStandardPathsBase()
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
);
89 wxStandardPathsBase::~wxStandardPathsBase()
94 wxString
wxStandardPathsBase::GetLocalDataDir() const
99 wxString
wxStandardPathsBase::GetUserLocalDataDir() const
101 return GetUserDataDir();
104 wxString
wxStandardPathsBase::GetDocumentsDir() const
106 return wxFileName::GetHomeDir();
109 wxString
wxStandardPathsBase::GetAppDocumentsDir() const
111 const wxString docsDir
= GetDocumentsDir();
112 wxString appDocsDir
= AppendAppInfo(docsDir
);
114 return wxDirExists(appDocsDir
) ? appDocsDir
: docsDir
;
117 // return the temporary directory for the current user
118 wxString
wxStandardPathsBase::GetTempDir() const
120 return wxFileName::GetTempDir();
125 wxStandardPathsBase::AppendPathComponent(const wxString
& dir
,
126 const wxString
& component
)
128 wxString
subdir(dir
);
130 // empty string indicates that an error has occurred, don't touch it then
131 if ( !subdir
.empty() )
133 if ( !component
.empty() )
135 const wxChar ch
= *(subdir
.end() - 1);
136 if ( !wxFileName::IsPathSeparator(ch
) && ch
!= wxT('.') )
137 subdir
+= wxFileName::GetPathSeparator();
147 wxString
wxStandardPathsBase::AppendAppInfo(const wxString
& dir
) const
149 wxString
subdir(dir
);
151 if ( UsesAppInfo(AppInfo_VendorName
) )
153 subdir
= AppendPathComponent(subdir
, wxTheApp
->GetVendorName());
156 if ( UsesAppInfo(AppInfo_AppName
) )
158 subdir
= AppendPathComponent(subdir
, wxTheApp
->GetAppName());