2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
|
|
|
* Copyright (C) 2002-2009 PCSX2 Dev Team
|
|
|
|
*
|
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
2009-07-23 23:30:19 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
2009-07-23 23:30:19 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-07-23 23:30:19 +00:00
|
|
|
*/
|
|
|
|
|
2009-09-12 01:03:44 +00:00
|
|
|
#include <wx/filename.h>
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-22 12:08:05 +00:00
|
|
|
#define g_MaxPath 255 // 255 is safer with antiquated Win32 ASCII APIs.
|
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
class wxDirName : protected wxFileName
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit wxDirName( const wxFileName& src )
|
|
|
|
{
|
2009-09-12 01:03:44 +00:00
|
|
|
Assign( src.GetPath(), wxEmptyString );
|
2009-04-27 02:04:31 +00:00
|
|
|
}
|
2009-07-12 00:55:12 +00:00
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
wxDirName() : wxFileName() {}
|
|
|
|
wxDirName( const wxDirName& src ) : wxFileName( src ) { }
|
|
|
|
explicit wxDirName( const char* src ) { Assign( wxString::FromAscii(src) ); }
|
|
|
|
explicit wxDirName( const wxString& src ) { Assign( src ); }
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
void Assign( const wxString& volume, const wxString& path )
|
|
|
|
{
|
|
|
|
wxFileName::Assign( volume, path, wxEmptyString );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Assign( const wxString& path )
|
|
|
|
{
|
|
|
|
wxFileName::Assign( path, wxEmptyString );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Assign( const wxDirName& path )
|
|
|
|
{
|
|
|
|
wxFileName::Assign( path );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear() { wxFileName::Clear(); }
|
2009-07-12 00:55:12 +00:00
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
wxCharBuffer ToAscii() const { return GetPath().ToAscii(); }
|
|
|
|
wxString ToString() const { return GetPath(); }
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
bool IsWritable() const { return IsDirWritable(); }
|
|
|
|
bool IsReadable() const { return IsDirReadable(); }
|
|
|
|
bool Exists() const { return DirExists(); }
|
|
|
|
bool IsOk() const { return wxFileName::IsOk(); }
|
2009-09-12 01:03:44 +00:00
|
|
|
bool IsRelative() const { return wxFileName::IsRelative(); }
|
|
|
|
bool IsAbsolute() const { return wxFileName::IsAbsolute(); }
|
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
bool SameAs( const wxDirName& filepath ) const
|
|
|
|
{
|
|
|
|
return wxFileName::SameAs( filepath );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the number of sub folders in this directory path
|
|
|
|
size_t GetCount() const { return GetDirCount(); }
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
wxFileName Combine( const wxFileName& right ) const;
|
|
|
|
wxDirName Combine( const wxDirName& right ) const;
|
|
|
|
|
|
|
|
// removes the lastmost directory from the path
|
|
|
|
void RemoveLast() { wxFileName::RemoveDir(GetCount() - 1); }
|
|
|
|
|
2009-07-11 08:31:38 +00:00
|
|
|
wxDirName& Normalize( int flags = wxPATH_NORM_ALL, const wxString& cwd = wxEmptyString );
|
|
|
|
wxDirName& MakeRelativeTo( const wxString& pathBase = wxEmptyString );
|
|
|
|
wxDirName& MakeAbsolute( const wxString& cwd = wxEmptyString );
|
2009-04-27 02:04:31 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void AssignCwd( const wxString& volume = wxEmptyString ) { wxFileName::AssignCwd( volume ); }
|
2009-09-06 05:52:39 +00:00
|
|
|
bool SetCwd() { return wxFileName::SetCwd(); }
|
2009-04-27 02:04:31 +00:00
|
|
|
|
|
|
|
// wxWidgets is missing the const qualifier for this one! Shame!
|
|
|
|
void Rmdir();
|
|
|
|
bool Mkdir();
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
2009-07-12 00:55:12 +00:00
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
wxDirName& operator=(const wxDirName& dirname) { Assign( dirname ); return *this; }
|
|
|
|
wxDirName& operator=(const wxString& dirname) { Assign( dirname ); return *this; }
|
|
|
|
wxDirName& operator=(const char* dirname) { Assign( wxString::FromAscii(dirname) ); return *this; }
|
|
|
|
|
|
|
|
wxFileName operator+( const wxFileName& right ) const { return Combine( right ); }
|
|
|
|
wxDirName operator+( const wxDirName& right ) const { return Combine( right ); }
|
2009-07-12 00:55:12 +00:00
|
|
|
|
2009-04-27 02:04:31 +00:00
|
|
|
bool operator==(const wxDirName& filename) const { return SameAs(filename); }
|
|
|
|
bool operator!=(const wxDirName& filename) const { return !SameAs(filename); }
|
|
|
|
|
|
|
|
bool operator==(const wxFileName& filename) const { return SameAs(wxDirName(filename)); }
|
|
|
|
bool operator!=(const wxFileName& filename) const { return !SameAs(wxDirName(filename)); }
|
|
|
|
|
|
|
|
// compare with a filename string interpreted as a native file name
|
|
|
|
bool operator==(const wxString& filename) const { return SameAs(wxDirName(filename)); }
|
|
|
|
bool operator!=(const wxString& filename) const { return !SameAs(wxDirName(filename)); }
|
2009-07-12 00:55:12 +00:00
|
|
|
|
2009-07-07 20:53:32 +00:00
|
|
|
const wxFileName& GetFilename() const { return *this; }
|
|
|
|
wxFileName& GetFilename() { return *this; }
|
2009-04-27 02:04:31 +00:00
|
|
|
};
|
|
|
|
|
2009-09-13 17:11:35 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Path Namespace
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Cross-platform utilities for manipulation of paths and filenames. Mostly these fall
|
|
|
|
// back on wxWidgets APIs internally, but are still helpful because some of wx's file stuff
|
|
|
|
// has minor glitches, or requies sloppy wxFileName typecasting.
|
2009-04-27 02:04:31 +00:00
|
|
|
//
|
2009-02-09 21:15:56 +00:00
|
|
|
namespace Path
|
|
|
|
{
|
2009-09-12 01:03:44 +00:00
|
|
|
extern bool IsRelative( const wxString& path );
|
2009-09-13 17:11:35 +00:00
|
|
|
extern s64 GetFileSize( const wxString& path );
|
2009-09-12 01:03:44 +00:00
|
|
|
|
|
|
|
extern wxString Combine( const wxString& srcPath, const wxString& srcFile );
|
|
|
|
extern wxString Combine( const wxDirName& srcPath, const wxFileName& srcFile );
|
|
|
|
extern wxString Combine( const wxString& srcPath, const wxDirName& srcFile );
|
|
|
|
extern wxString ReplaceExtension( const wxString& src, const wxString& ext );
|
|
|
|
extern wxString ReplaceFilename( const wxString& src, const wxString& newfilename );
|
|
|
|
extern wxString GetFilename( const wxString& src );
|
|
|
|
extern wxString GetDirectory( const wxString& src );
|
|
|
|
extern wxString GetFilenameWithoutExt( const wxString& src );
|
|
|
|
extern wxString GetRootDirectory( const wxString& src );
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|