Move the CopyDirectory() and RemoveDirectory() functions into FileUtils.cpp.

This commit is contained in:
Admiral H. Curtiss committed 2015-07-12 14:38:16 +02:00
1 parent 40e6a5c515
commit 65058df3da
2 files changed
+73 -67

No files matched your search

+70
View File
@@ -16,6 +16,9 @@
#include "PrecompiledHeader.h"
#include "AsciiFile.h"
#include <wx/dir.h>
#include <wx/string.h>
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 );
}
+3 -67
View File
@@ -30,6 +30,9 @@
#include <wx/dir.h>
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 ){