diff --git a/pcsx2/Utilities/FileUtils.cpp b/pcsx2/Utilities/FileUtils.cpp index 5da4ecdf38..739635d6ab 100644 --- a/pcsx2/Utilities/FileUtils.cpp +++ b/pcsx2/Utilities/FileUtils.cpp @@ -16,6 +16,9 @@ #include "PrecompiledHeader.h" #include "AsciiFile.h" +#include +#include + void AsciiFile::Printf( const char* fmt, ... ) { va_list list; @@ -25,3 +28,70 @@ void AsciiFile::Printf( const char* fmt, ... ) va_end( list ); Write( ascii, strlen(ascii) ); } + +bool CopyDirectory( const wxString& from, const wxString& to ) { + wxDir src( from ); + if ( !src.IsOpened() ) { + return false; + } + + wxMkdir( to ); + wxDir dst( to ); + if ( !dst.IsOpened() ) { + return false; + } + + wxString filename; + + // copy directories + if ( src.GetFirst( &filename, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN ) ) { + do { + if ( !CopyDirectory( wxFileName( from, filename ).GetFullPath(), wxFileName( to, filename ).GetFullPath() ) ) { + return false; + } + } while ( src.GetNext( &filename ) ); + } + + // copy files + if ( src.GetFirst( &filename, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN ) ) { + do { + if ( !wxCopyFile( wxFileName( from, filename ).GetFullPath(), wxFileName( to, filename ).GetFullPath() ) ) { + return false; + } + } while ( src.GetNext( &filename ) ); + } + + return true; +} + +bool RemoveDirectory( const wxString& dirname ) { + { + wxDir dir( dirname ); + if ( !dir.IsOpened() ) { + return false; + } + + wxString filename; + + // delete subdirs recursively + if ( dir.GetFirst( &filename, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN ) ) { + do { + if ( !RemoveDirectory( wxFileName( dirname, filename ).GetFullPath() ) ) { + return false; + } + } while ( dir.GetNext( &filename ) ); + } + + // delete files + if ( dir.GetFirst( &filename, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN ) ) { + do { + if ( !wxRemoveFile( wxFileName( dirname, filename ).GetFullPath() ) ) { + return false; + } + } while ( dir.GetNext( &filename ) ); + } + } + + // oddly enough this has different results compared to the more sensible dirname.Rmdir(), don't change! + return wxFileName::Rmdir( dirname ); +} diff --git a/pcsx2/gui/Panels/MemoryCardListPanel.cpp b/pcsx2/gui/Panels/MemoryCardListPanel.cpp index d391088bce..75bd3f5aef 100644 --- a/pcsx2/gui/Panels/MemoryCardListPanel.cpp +++ b/pcsx2/gui/Panels/MemoryCardListPanel.cpp @@ -30,6 +30,9 @@ #include +bool CopyDirectory( const wxString& from, const wxString& to ); +bool RemoveDirectory( const wxString& dirname ); + using namespace pxSizerFlags; using namespace Panels; @@ -779,73 +782,6 @@ void Panels::MemoryCardListPanel_Simple::UiConvertCard( McdSlotItem& card ) { closed_core.AllowResume(); } -bool CopyDirectory( const wxString& from, const wxString& to ) { - wxDir src( from ); - if ( !src.IsOpened() ) { - return false; - } - - wxMkdir( to ); - wxDir dst( to ); - if ( !dst.IsOpened() ) { - return false; - } - - wxString filename; - - // copy directories - if ( src.GetFirst( &filename, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN ) ) { - do { - if ( !CopyDirectory( wxFileName( from, filename ).GetFullPath(), wxFileName( to, filename ).GetFullPath() ) ) { - return false; - } - } while ( src.GetNext( &filename ) ); - } - - // copy files - if ( src.GetFirst( &filename, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN ) ) { - do { - if ( !wxCopyFile( wxFileName( from, filename ).GetFullPath(), wxFileName( to, filename ).GetFullPath() ) ) { - return false; - } - } while ( src.GetNext( &filename ) ); - } - - return true; -} - -bool RemoveDirectory( const wxString& dirname ) { - { - wxDir dir( dirname ); - if ( !dir.IsOpened() ) { - return false; - } - - wxString filename; - - // delete subdirs recursively - if ( dir.GetFirst( &filename, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN ) ) { - do { - if ( !RemoveDirectory( wxFileName( dirname, filename ).GetFullPath() ) ) { - return false; - } - } while ( dir.GetNext( &filename ) ); - } - - // delete files - if ( dir.GetFirst( &filename, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN ) ) { - do { - if ( !wxRemoveFile( wxFileName( dirname, filename ).GetFullPath() ) ) { - return false; - } - } while ( dir.GetNext( &filename ) ); - } - } - - // oddly enough this has different results compared to the more sensible dirname.Rmdir(), don't change! - return wxFileName::Rmdir( dirname ); -} - void Panels::MemoryCardListPanel_Simple::UiDeleteCard( McdSlotItem& card ) { if( !card.IsPresent ){