1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
/**
* File utilities to uninstall a D-Mod
* Copyright (C) 2005, 2006 Dan Walma
* Copyright (C) 2008 Sylvain Beucler
* This file is part of GNU FreeDink
* GNU FreeDink is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
* GNU FreeDink 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.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include "RecursiveDelete.hpp"
#include <wx/dir.h>
#include <wx/wx.h>
RecursiveDelete::RecursiveDelete(bool aRemoveSaveGames) :
mRemoveSaveGames(aRemoveSaveGames),
mError(false)
{
}
wxDirTraverseResult RecursiveDelete::OnFile(const wxString& aFilename)
{
bool lRemoveFile( true );
// See if it is a save game file
if (mRemoveSaveGames == false)
{
wxString lFilename = aFilename.Mid( aFilename.Find( '/', true ) + 1 );
if (lFilename.Mid(0, 4).MakeUpper() == _T("SAVE")
&& lFilename.Mid(lFilename.Len() - 3).MakeUpper() == _T("DAT"))
{
lRemoveFile = false;
}
}
// Remove the file
if (lRemoveFile == true)
{
if (::wxRemoveFile(aFilename) == false)
{
wxLogError(_("Could not remove %s"), aFilename.c_str());
mError = true;
}
}
return wxDIR_CONTINUE;
}
wxDirTraverseResult RecursiveDelete::OnDir( const wxString& aDirname )
{
RecursiveDelete lRecursiveDelete( false );
wxDir* lDir = new wxDir( aDirname );
lDir->Traverse( lRecursiveDelete );
delete lDir;
if ( lRecursiveDelete.getError() == false )
{
if ( ::wxRmdir( aDirname ) == false )
{
wxLogError(_("Could not remove %s"), aDirname.c_str());
mError = true;
}
}
else if ( mError == false )
{
mError = true;
}
return wxDIR_IGNORE;
}
bool RecursiveDelete::getError( void )
{
return mError;
}
|