/[pcsx2_0.9.7]/trunk/3rdparty/wxWidgets/src/common/stdpbase.cpp
ViewVC logotype

Contents of /trunk/3rdparty/wxWidgets/src/common/stdpbase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (10 years, 2 months ago) by william
File size: 4906 byte(s)
committing r3113 initial commit again...
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/stdpbase.cpp
3 // Purpose: wxStandardPathsBase methods common to all ports
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 2004-10-19
7 // RCS-ID: $Id: stdpbase.cpp 53093 2008-04-08 13:51:17Z JS $
8 // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_STDPATHS
28
29 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #endif //WX_PRECOMP
32 #include "wx/apptrait.h"
33
34 #include "wx/filename.h"
35 #include "wx/stdpaths.h"
36
37 #if defined(__UNIX__) && !defined(__WXMAC__)
38 #include "wx/log.h"
39 #include "wx/textfile.h"
40 #endif
41
42 // ----------------------------------------------------------------------------
43 // module globals
44 // ----------------------------------------------------------------------------
45
46 static wxStandardPaths gs_stdPaths;
47
48 // ============================================================================
49 // implementation
50 // ============================================================================
51
52 /* static */
53 wxStandardPathsBase& wxStandardPathsBase::Get()
54 {
55 wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
56 wxCHECK_MSG( traits, gs_stdPaths, _T("create wxApp before calling this") );
57
58 return traits->GetStandardPaths();
59 }
60
61 wxString wxStandardPathsBase::GetExecutablePath() const
62 {
63 if ( !wxTheApp || !wxTheApp->argv )
64 return wxEmptyString;
65
66 wxString argv0 = wxTheApp->argv[0];
67 if (wxIsAbsolutePath(argv0))
68 return argv0;
69
70 // Search PATH.environment variable...
71 wxPathList pathlist;
72 pathlist.AddEnvList(wxT("PATH"));
73 wxString path = pathlist.FindAbsoluteValidPath(argv0);
74 if ( path.empty() )
75 return argv0; // better than nothing
76
77 wxFileName filename(path);
78 filename.Normalize();
79 return filename.GetFullPath();
80 }
81
82 wxStandardPathsBase& wxAppTraitsBase::GetStandardPaths()
83 {
84 return gs_stdPaths;
85 }
86
87 wxStandardPathsBase::~wxStandardPathsBase()
88 {
89 // nothing to do here
90 }
91
92 wxString wxStandardPathsBase::GetLocalDataDir() const
93 {
94 return GetDataDir();
95 }
96
97 wxString wxStandardPathsBase::GetUserLocalDataDir() const
98 {
99 return GetUserDataDir();
100 }
101
102 wxString wxStandardPathsBase::GetDocumentsDir() const
103 {
104 #if defined(__UNIX__) && !defined(__WXMAC__)
105 {
106 wxLogNull logNull;
107 wxString homeDir = wxFileName::GetHomeDir();
108 wxString configPath;
109 if (wxGetenv(wxT("XDG_CONFIG_HOME")))
110 configPath = wxGetenv(wxT("XDG_CONFIG_HOME"));
111 else
112 configPath = homeDir + wxT("/.config");
113 wxString dirsFile = configPath + wxT("/user-dirs.dirs");
114 if (wxFileExists(dirsFile))
115 {
116 wxTextFile textFile;
117 if (textFile.Open(dirsFile))
118 {
119 size_t i;
120 for (i = 0; i < textFile.GetLineCount(); i++)
121 {
122 wxString line(textFile[i]);
123 int pos = line.Find(wxT("XDG_DOCUMENTS_DIR"));
124 if (pos != wxNOT_FOUND)
125 {
126 wxString value = line.AfterFirst(wxT('='));
127 value.Replace(wxT("$HOME"), homeDir);
128 value.Trim(true);
129 value.Trim(false);
130 if (!value.IsEmpty() && wxDirExists(value))
131 return value;
132 else
133 break;
134 }
135 }
136 }
137 }
138 }
139 #endif
140
141 return wxFileName::GetHomeDir();
142 }
143
144 // return the temporary directory for the current user
145 wxString wxStandardPathsBase::GetTempDir() const
146 {
147 return wxFileName::GetTempDir();
148 }
149
150 /* static */
151 wxString wxStandardPathsBase::AppendAppName(const wxString& dir)
152 {
153 wxString subdir(dir);
154
155 // empty string indicates that an error has occurred, don't touch it then
156 if ( !subdir.empty() )
157 {
158 const wxString appname = wxTheApp->GetAppName();
159 if ( !appname.empty() )
160 {
161 const wxChar ch = *(subdir.end() - 1);
162 if ( !wxFileName::IsPathSeparator(ch) && ch != _T('.') )
163 subdir += wxFileName::GetPathSeparator();
164
165 subdir += appname;
166 }
167 }
168
169 return subdir;
170 }
171
172 #endif // wxUSE_STDPATHS

  ViewVC Help
Powered by ViewVC 1.1.22