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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 401 - (hide annotations) (download)
Fri Feb 25 17:31:09 2011 UTC (9 years, 5 months ago) by william
File MIME type: text/plain
File size: 6285 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4358 local: v0.9.7.313-latest) in ./trunk
1 william 31 /* 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 william 401 // --------------------------------------------------------------------------------------
24     // wxDirName
25     // --------------------------------------------------------------------------------------
26 william 31 class wxDirName : protected wxFileName
27     {
28     public:
29     explicit wxDirName( const wxFileName& src )
30     {
31     Assign( src.GetPath(), wxEmptyString );
32     }
33    
34     wxDirName() : wxFileName() {}
35     wxDirName( const wxDirName& src ) : wxFileName( src ) { }
36     explicit wxDirName( const char* src ) { Assign( fromUTF8(src) ); }
37     explicit wxDirName( const wxString& src ) { Assign( src ); }
38    
39     // ------------------------------------------------------------------------
40     void Assign( const wxString& volume, const wxString& path )
41     {
42     wxFileName::Assign( volume, path, wxEmptyString );
43     }
44    
45     void Assign( const wxString& path )
46     {
47     wxFileName::Assign( path, wxEmptyString );
48     }
49    
50     void Assign( const wxDirName& path )
51     {
52     wxFileName::Assign( path );
53     }
54    
55     void Clear() { wxFileName::Clear(); }
56    
57 william 273 wxCharBuffer ToUTF8() const { return GetPath().ToUTF8(); }
58 william 31 wxCharBuffer ToAscii() const { return GetPath().ToAscii(); }
59     wxString ToString() const { return GetPath(); }
60    
61     // ------------------------------------------------------------------------
62     bool IsWritable() const { return IsDirWritable(); }
63     bool IsReadable() const { return IsDirReadable(); }
64     bool Exists() const { return DirExists(); }
65     bool FileExists() const { return wxFileName::FileExists(); }
66     bool IsOk() const { return wxFileName::IsOk(); }
67     bool IsRelative() const { return wxFileName::IsRelative(); }
68     bool IsAbsolute() const { return wxFileName::IsAbsolute(); }
69    
70     bool SameAs( const wxDirName& filepath ) const
71     {
72     return wxFileName::SameAs( filepath );
73     }
74    
75     // Returns the number of sub folders in this directory path
76     size_t GetCount() const { return GetDirCount(); }
77    
78     // ------------------------------------------------------------------------
79     wxFileName Combine( const wxFileName& right ) const;
80     wxDirName Combine( const wxDirName& right ) const;
81    
82     // removes the lastmost directory from the path
83     void RemoveLast() { wxFileName::RemoveDir(GetCount() - 1); }
84    
85     wxDirName& Normalize( int flags = wxPATH_NORM_ALL, const wxString& cwd = wxEmptyString );
86     wxDirName& MakeRelativeTo( const wxString& pathBase = wxEmptyString );
87     wxDirName& MakeAbsolute( const wxString& cwd = wxEmptyString );
88    
89     // ------------------------------------------------------------------------
90    
91     void AssignCwd( const wxString& volume = wxEmptyString ) { wxFileName::AssignCwd( volume ); }
92     bool SetCwd() { return wxFileName::SetCwd(); }
93    
94     // wxWidgets is missing the const qualifier for this one! Shame!
95     void Rmdir();
96     bool Mkdir();
97    
98     // ------------------------------------------------------------------------
99    
100     wxDirName& operator=(const wxDirName& dirname) { Assign( dirname ); return *this; }
101     wxDirName& operator=(const wxString& dirname) { Assign( dirname ); return *this; }
102     wxDirName& operator=(const char* dirname) { Assign( fromUTF8(dirname) ); return *this; }
103    
104     wxFileName operator+( const wxFileName& right ) const { return Combine( right ); }
105     wxDirName operator+( const wxDirName& right ) const { return Combine( right ); }
106 william 280 wxFileName operator+( const wxString& right ) const { return Combine( wxFileName(right) ); }
107 william 401 wxFileName operator+( const char* right ) const { return Combine( wxFileName(fromUTF8(right)) ); }
108 william 31
109     bool operator==(const wxDirName& filename) const { return SameAs(filename); }
110     bool operator!=(const wxDirName& filename) const { return !SameAs(filename); }
111    
112     bool operator==(const wxFileName& filename) const { return SameAs(wxDirName(filename)); }
113     bool operator!=(const wxFileName& filename) const { return !SameAs(wxDirName(filename)); }
114    
115     // compare with a filename string interpreted as a native file name
116     bool operator==(const wxString& filename) const { return SameAs(wxDirName(filename)); }
117     bool operator!=(const wxString& filename) const { return !SameAs(wxDirName(filename)); }
118    
119     const wxFileName& GetFilename() const { return *this; }
120     wxFileName& GetFilename() { return *this; }
121     };
122    
123     // --------------------------------------------------------------------------------------
124     // Path Namespace
125     // --------------------------------------------------------------------------------------
126     // Cross-platform utilities for manipulation of paths and filenames. Mostly these fall
127     // back on wxWidgets APIs internally, but are still helpful because some of wx's file stuff
128 william 280 // has minor glitches, or requires sloppy wxFileName typecasting.
129 william 31 //
130     namespace Path
131     {
132     extern bool IsRelative( const wxString& path );
133     extern s64 GetFileSize( const wxString& path );
134    
135     extern wxString Normalize( const wxString& srcpath );
136 william 62 extern wxString Normalize( const wxDirName& srcpath );
137 william 273 extern wxString MakeAbsolute( const wxString& srcpath );
138 william 31
139     extern wxString Combine( const wxString& srcPath, const wxString& srcFile );
140     extern wxString Combine( const wxDirName& srcPath, const wxFileName& srcFile );
141     extern wxString Combine( const wxString& srcPath, const wxDirName& srcFile );
142     extern wxString ReplaceExtension( const wxString& src, const wxString& ext );
143     extern wxString ReplaceFilename( const wxString& src, const wxString& newfilename );
144     extern wxString GetFilename( const wxString& src );
145     extern wxString GetDirectory( const wxString& src );
146     extern wxString GetFilenameWithoutExt( const wxString& src );
147     extern wxString GetRootDirectory( const wxString& src );
148     }

  ViewVC Help
Powered by ViewVC 1.1.22