2016-05-16 09:10:01 +00:00
|
|
|
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
|
|
|
// Copyright (C) 2010 Winch Gate Property Limited
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program 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 Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include "stdpch.h"
|
|
|
|
#include "filescleaner.h"
|
|
|
|
#include "operation.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG_NEW
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CFilesCleaner::CFilesCleaner(IOperationProgressListener *listener):m_listener(listener)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CFilesCleaner::~CFilesCleaner()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFilesCleaner::setDirectory(const QString &src)
|
|
|
|
{
|
|
|
|
m_directory = src;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CFilesCleaner::exec()
|
|
|
|
{
|
2016-06-12 12:18:36 +00:00
|
|
|
if (m_directory.isEmpty()) return false;
|
|
|
|
|
2016-05-16 12:58:50 +00:00
|
|
|
if (m_listener) m_listener->operationPrepare();
|
|
|
|
|
2016-05-16 09:10:01 +00:00
|
|
|
QDir dir(m_directory);
|
|
|
|
|
|
|
|
// directory doesn't exist
|
|
|
|
if (!dir.exists()) return false;
|
|
|
|
|
2016-09-03 08:14:06 +00:00
|
|
|
if (!dir.cd("data")) return false;
|
2016-05-16 09:10:01 +00:00
|
|
|
|
2016-06-19 19:04:31 +00:00
|
|
|
QStringList filter;
|
|
|
|
filter << "*.string_cache";
|
|
|
|
|
2016-09-22 09:39:33 +00:00
|
|
|
// certificate should be in gamedev.bnp now
|
|
|
|
filter << "*.pem";
|
|
|
|
|
2016-08-14 10:48:33 +00:00
|
|
|
if (dir.exists("packedsheets.bnp"))
|
2016-06-19 19:04:31 +00:00
|
|
|
{
|
|
|
|
filter << "*.packed_sheets";
|
|
|
|
filter << "*.packed";
|
|
|
|
}
|
|
|
|
|
2016-05-16 09:10:01 +00:00
|
|
|
// temporary files
|
2016-06-19 19:04:31 +00:00
|
|
|
QStringList files = dir.entryList(filter, QDir::Files);
|
2016-05-16 09:10:01 +00:00
|
|
|
|
2016-05-16 12:58:50 +00:00
|
|
|
if (m_listener)
|
|
|
|
{
|
|
|
|
m_listener->operationInit(0, files.size());
|
|
|
|
m_listener->operationStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
int filesCount = 0;
|
|
|
|
|
2016-05-16 09:10:01 +00:00
|
|
|
foreach(const QString &file, files)
|
|
|
|
{
|
|
|
|
dir.remove(file);
|
2016-05-16 12:58:50 +00:00
|
|
|
|
|
|
|
if (m_listener) m_listener->operationProgress(filesCount, file);
|
|
|
|
|
|
|
|
++filesCount;
|
2016-05-16 09:10:01 +00:00
|
|
|
}
|
|
|
|
|
2016-06-19 19:04:31 +00:00
|
|
|
// fonts directory is not needed anymore if fonts.bnp exists
|
2016-09-03 08:14:06 +00:00
|
|
|
if (dir.exists("fonts.bnp") && dir.cd("fonts"))
|
2016-05-16 09:10:01 +00:00
|
|
|
{
|
|
|
|
dir.removeRecursively();
|
|
|
|
}
|
|
|
|
|
2016-05-16 12:48:01 +00:00
|
|
|
if (m_listener) m_listener->operationSuccess(files.size());
|
2016-05-16 09:10:01 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|