/[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 62 - (show annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (10 years, 1 month ago) by william
File MIME type: text/plain
File size: 5869 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug in ./trunk
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 ToAscii() const { return GetPath().ToAscii(); }
57 wxString ToString() const { return GetPath(); }
58
59 // ------------------------------------------------------------------------
60 bool IsWritable() const { return IsDirWritable(); }
61 bool IsReadable() const { return IsDirReadable(); }
62 bool Exists() const { return DirExists(); }
63 bool FileExists() const { return wxFileName::FileExists(); }
64 bool IsOk() const { return wxFileName::IsOk(); }
65 bool IsRelative() const { return wxFileName::IsRelative(); }
66 bool IsAbsolute() const { return wxFileName::IsAbsolute(); }
67
68 bool SameAs( const wxDirName& filepath ) const
69 {
70 return wxFileName::SameAs( filepath );
71 }
72
73 // Returns the number of sub folders in this directory path
74 size_t GetCount() const { return GetDirCount(); }
75
76 // ------------------------------------------------------------------------
77 wxFileName Combine( const wxFileName& right ) const;
78 wxDirName Combine( const wxDirName& right ) const;
79
80 // removes the lastmost directory from the path
81 void RemoveLast() { wxFileName::RemoveDir(GetCount() - 1); }
82
83 wxDirName& Normalize( int flags = wxPATH_NORM_ALL, const wxString& cwd = wxEmptyString );
84 wxDirName& MakeRelativeTo( const wxString& pathBase = wxEmptyString );
85 wxDirName& MakeAbsolute( const wxString& cwd = wxEmptyString );
86
87 // ------------------------------------------------------------------------
88
89 void AssignCwd( const wxString& volume = wxEmptyString ) { wxFileName::AssignCwd( volume ); }
90 bool SetCwd() { return wxFileName::SetCwd(); }
91
92 // wxWidgets is missing the const qualifier for this one! Shame!
93 void Rmdir();
94 bool Mkdir();
95
96 // ------------------------------------------------------------------------
97
98 wxDirName& operator=(const wxDirName& dirname) { Assign( dirname ); return *this; }
99 wxDirName& operator=(const wxString& dirname) { Assign( dirname ); return *this; }
100 wxDirName& operator=(const char* dirname) { Assign( fromUTF8(dirname) ); return *this; }
101
102 wxFileName operator+( const wxFileName& right ) const { return Combine( right ); }
103 wxDirName operator+( const wxDirName& right ) const { return Combine( right ); }
104
105 bool operator==(const wxDirName& filename) const { return SameAs(filename); }
106 bool operator!=(const wxDirName& filename) const { return !SameAs(filename); }
107
108 bool operator==(const wxFileName& filename) const { return SameAs(wxDirName(filename)); }
109 bool operator!=(const wxFileName& filename) const { return !SameAs(wxDirName(filename)); }
110
111 // compare with a filename string interpreted as a native file name
112 bool operator==(const wxString& filename) const { return SameAs(wxDirName(filename)); }
113 bool operator!=(const wxString& filename) const { return !SameAs(wxDirName(filename)); }
114
115 const wxFileName& GetFilename() const { return *this; }
116 wxFileName& GetFilename() { return *this; }
117 };
118
119 // --------------------------------------------------------------------------------------
120 // Path Namespace
121 // --------------------------------------------------------------------------------------
122 // Cross-platform utilities for manipulation of paths and filenames. Mostly these fall
123 // back on wxWidgets APIs internally, but are still helpful because some of wx's file stuff
124 // has minor glitches, or requies sloppy wxFileName typecasting.
125 //
126 namespace Path
127 {
128 extern bool IsRelative( const wxString& path );
129 extern s64 GetFileSize( const wxString& path );
130
131 extern wxString Normalize( const wxString& srcpath );
132 extern wxString Normalize( const wxDirName& srcpath );
133
134 extern wxString Combine( const wxString& srcPath, const wxString& srcFile );
135 extern wxString Combine( const wxDirName& srcPath, const wxFileName& srcFile );
136 extern wxString Combine( const wxString& srcPath, const wxDirName& srcFile );
137 extern wxString ReplaceExtension( const wxString& src, const wxString& ext );
138 extern wxString ReplaceFilename( const wxString& src, const wxString& newfilename );
139 extern wxString GetFilename( const wxString& src );
140 extern wxString GetDirectory( const wxString& src );
141 extern wxString GetFilenameWithoutExt( const wxString& src );
142 extern wxString GetRootDirectory( const wxString& src );
143 }

  ViewVC Help
Powered by ViewVC 1.1.22