/[pcsx2_0.9.7]/trunk/common/include/Utilities/Path.h
ViewVC logotype

Contents of /trunk/common/include/Utilities/Path.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 1 month ago) by william
File MIME type: text/plain
File size: 6083 byte(s)
re-commit (had local access denied errors when committing)
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #pragma once
17
18 #include <wx/filename.h>
19 #include "StringHelpers.h"
20
21 #define g_MaxPath 255 // 255 is safer with antiquated Win32 ASCII APIs.
22
23 //////////////////////////////////////////////////////////////////////////////////////////
24 //
25 class wxDirName : protected wxFileName
26 {
27 public:
28 explicit wxDirName( const wxFileName& src )
29 {
30 Assign( src.GetPath(), wxEmptyString );
31 }
32
33 wxDirName() : wxFileName() {}
34 wxDirName( const wxDirName& src ) : wxFileName( src ) { }
35 explicit wxDirName( const char* src ) { Assign( fromUTF8(src) ); }
36 explicit wxDirName( const wxString& src ) { Assign( src ); }
37
38 // ------------------------------------------------------------------------
39 void Assign( const wxString& volume, const wxString& path )
40 {
41 wxFileName::Assign( volume, path, wxEmptyString );
42 }
43
44 void Assign( const wxString& path )
45 {
46 wxFileName::Assign( path, wxEmptyString );
47 }
48
49 void Assign( const wxDirName& path )
50 {
51 wxFileName::Assign( path );
52 }
53
54 void Clear() { wxFileName::Clear(); }
55
56 wxCharBuffer ToUTF8() const { return GetPath().ToUTF8(); }
57 wxCharBuffer ToAscii() const { return GetPath().ToAscii(); }
58 wxString ToString() const { return GetPath(); }
59
60 // ------------------------------------------------------------------------
61 bool IsWritable() const { return IsDirWritable(); }
62 bool IsReadable() const { return IsDirReadable(); }
63 bool Exists() const { return DirExists(); }
64 bool FileExists() const { return wxFileName::FileExists(); }
65 bool IsOk() const { return wxFileName::IsOk(); }
66 bool IsRelative() const { return wxFileName::IsRelative(); }
67 bool IsAbsolute() const { return wxFileName::IsAbsolute(); }
68
69 bool SameAs( const wxDirName& filepath ) const
70 {
71 return wxFileName::SameAs( filepath );
72 }
73
74 // Returns the number of sub folders in this directory path
75 size_t GetCount() const { return GetDirCount(); }
76
77 // ------------------------------------------------------------------------
78 wxFileName Combine( const wxFileName& right ) const;
79 wxDirName Combine( const wxDirName& right ) const;
80
81 // removes the lastmost directory from the path
82 void RemoveLast() { wxFileName::RemoveDir(GetCount() - 1); }
83
84 wxDirName& Normalize( int flags = wxPATH_NORM_ALL, const wxString& cwd = wxEmptyString );
85 wxDirName& MakeRelativeTo( const wxString& pathBase = wxEmptyString );
86 wxDirName& MakeAbsolute( const wxString& cwd = wxEmptyString );
87
88 // ------------------------------------------------------------------------
89
90 void AssignCwd( const wxString& volume = wxEmptyString ) { wxFileName::AssignCwd( volume ); }
91 bool SetCwd() { return wxFileName::SetCwd(); }
92
93 // wxWidgets is missing the const qualifier for this one! Shame!
94 void Rmdir();
95 bool Mkdir();
96
97 // ------------------------------------------------------------------------
98
99 wxDirName& operator=(const wxDirName& dirname) { Assign( dirname ); return *this; }
100 wxDirName& operator=(const wxString& dirname) { Assign( dirname ); return *this; }
101 wxDirName& operator=(const char* dirname) { Assign( fromUTF8(dirname) ); return *this; }
102
103 wxFileName operator+( const wxFileName& right ) const { return Combine( right ); }
104 wxDirName operator+( const wxDirName& right ) const { return Combine( right ); }
105 wxFileName operator+( const wxString& right ) const { return Combine( wxFileName(right) ); }
106
107 bool operator==(const wxDirName& filename) const { return SameAs(filename); }
108 bool operator!=(const wxDirName& filename) const { return !SameAs(filename); }
109
110 bool operator==(const wxFileName& filename) const { return SameAs(wxDirName(filename)); }
111 bool operator!=(const wxFileName& filename) const { return !SameAs(wxDirName(filename)); }
112
113 // compare with a filename string interpreted as a native file name
114 bool operator==(const wxString& filename) const { return SameAs(wxDirName(filename)); }
115 bool operator!=(const wxString& filename) const { return !SameAs(wxDirName(filename)); }
116
117 const wxFileName& GetFilename() const { return *this; }
118 wxFileName& GetFilename() { return *this; }
119 };
120
121 // --------------------------------------------------------------------------------------
122 // Path Namespace
123 // --------------------------------------------------------------------------------------
124 // Cross-platform utilities for manipulation of paths and filenames. Mostly these fall
125 // back on wxWidgets APIs internally, but are still helpful because some of wx's file stuff
126 // has minor glitches, or requires sloppy wxFileName typecasting.
127 //
128 namespace Path
129 {
130 extern bool IsRelative( const wxString& path );
131 extern s64 GetFileSize( const wxString& path );
132
133 extern wxString Normalize( const wxString& srcpath );
134 extern wxString Normalize( const wxDirName& srcpath );
135 extern wxString MakeAbsolute( const wxString& srcpath );
136
137 extern wxString Combine( const wxString& srcPath, const wxString& srcFile );
138 extern wxString Combine( const wxDirName& srcPath, const wxFileName& srcFile );
139 extern wxString Combine( const wxString& srcPath, const wxDirName& srcFile );
140 extern wxString ReplaceExtension( const wxString& src, const wxString& ext );
141 extern wxString ReplaceFilename( const wxString& src, const wxString& newfilename );
142 extern wxString GetFilename( const wxString& src );
143 extern wxString GetDirectory( const wxString& src );
144 extern wxString GetFilenameWithoutExt( const wxString& src );
145 extern wxString GetRootDirectory( const wxString& src );
146 }

  ViewVC Help
Powered by ViewVC 1.1.22