1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "filescleaner.h"
19 #include "operation.h"
25 CFilesCleaner::CFilesCleaner(IOperationProgressListener
*listener
):m_listener(listener
)
29 CFilesCleaner::~CFilesCleaner()
33 void CFilesCleaner::setDirectory(const QString
&src
)
38 bool CFilesCleaner::exec()
40 if (m_directory
.isEmpty()) return false;
42 if (m_listener
) m_listener
->operationPrepare();
44 QDir
dir(m_directory
);
46 // directory doesn't exist
47 if (!dir
.exists()) return false;
49 if (!dir
.cd("data")) return false;
52 filter
<< "*.string_cache";
54 // certificate should be in gamedev.bnp now
57 if (dir
.exists("packedsheets.bnp"))
59 filter
<< "*.packed_sheets";
63 // only .ref files should be there
64 filter
<< "exedll*.bnp";
67 QStringList files
= dir
.entryList(filter
, QDir::Files
);
69 // temporary directories
70 QStringList dirs
= dir
.entryList(QDir::Dirs
| QDir::NoDotAndDotDot
);
72 // fonts directory is not needed anymore if fonts.bnp exists
73 if (!dir
.exists("fonts.bnp")) dirs
.removeAll("fonts");
77 m_listener
->operationInit(0, files
.size() + dirs
.size());
78 m_listener
->operationStart();
83 foreach(const QString
&file
, files
)
87 if (m_listener
) m_listener
->operationProgress(filesCount
, file
);
92 foreach(const QString
&d
, dirs
)
96 dir
.removeRecursively();
100 if (m_listener
) m_listener
->operationProgress(filesCount
, d
);
105 if (m_listener
) m_listener
->operationSuccess(files
.size() + dirs
.size());