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 // ----------------------------------------------------------------------------
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
48 wxStandardPathsDefault() { }
51 static wxStandardPathsDefault gs_stdPaths
;
53 } // anonymous namespace
55 // ============================================================================
57 // ============================================================================
60 wxStandardPaths
& wxStandardPathsBase::Get()
62 wxAppTraits
* const traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
63 wxCHECK_MSG( traits
, gs_stdPaths
, wxT("create wxApp before calling this") );
65 return traits
->GetStandardPaths();
68 wxString
wxStandardPathsBase::GetExecutablePath() const
70 if ( !wxTheApp
|| !wxTheApp
->argv
)
73 wxString argv0
= wxTheApp
->argv
[0];
74 if (wxIsAbsolutePath(argv0
))
77 // Search PATH.environment variable...
79 pathlist
.AddEnvList(wxT("PATH"));
80 wxString path
= pathlist
.FindAbsoluteValidPath(argv0
);
82 return argv0
; // better than nothing
84 wxFileName
filename(path
);
86 return filename
.GetFullPath();
89 wxStandardPaths
& wxAppTraitsBase::GetStandardPaths()
94 wxStandardPathsBase::wxStandardPathsBase()
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
);
103 wxStandardPathsBase::~wxStandardPathsBase()
105 // nothing to do here
108 wxString
wxStandardPathsBase::GetLocalDataDir() const
113 wxString
wxStandardPathsBase::GetUserLocalDataDir() const
115 return GetUserDataDir();
118 wxString
wxStandardPathsBase::GetDocumentsDir() const
120 return wxFileName::GetHomeDir();
123 wxString
wxStandardPathsBase::GetAppDocumentsDir() const
125 const wxString docsDir
= GetDocumentsDir();
126 wxString appDocsDir
= AppendAppInfo(docsDir
);
128 return wxDirExists(appDocsDir
) ? appDocsDir
: docsDir
;
131 // return the temporary directory for the current user
132 wxString
wxStandardPathsBase::GetTempDir() const
134 return wxFileName::GetTempDir();
139 wxStandardPathsBase::AppendPathComponent(const wxString
& dir
,
140 const wxString
& component
)
142 wxString
subdir(dir
);
144 // empty string indicates that an error has occurred, don't touch it then
145 if ( !subdir
.empty() )
147 if ( !component
.empty() )
149 const wxChar ch
= *(subdir
.end() - 1);
150 if ( !wxFileName::IsPathSeparator(ch
) && ch
!= wxT('.') )
151 subdir
+= wxFileName::GetPathSeparator();
161 wxString
wxStandardPathsBase::AppendAppInfo(const wxString
& dir
) const
163 wxString
subdir(dir
);
165 if ( UsesAppInfo(AppInfo_VendorName
) )
167 subdir
= AppendPathComponent(subdir
, wxTheApp
->GetVendorName());
170 if ( UsesAppInfo(AppInfo_AppName
) )
172 subdir
= AppendPathComponent(subdir
, wxTheApp
->GetAppName());