From 87312ab4f0915ffb989dc2c846180824eb98e3b2 Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 26 Jun 2016 19:41:33 +0200 Subject: [PATCH] Changed: Delete downloaded files in uninstaller --- .../client/ryzom_installer/src/operation.h | 2 + .../ryzom_installer/src/operationdialog.cpp | 43 +++++++++++++++++++ .../ryzom_installer/src/operationdialog.h | 2 +- .../ryzom_installer/src/uninstalldialog.cpp | 17 +++++++- .../ryzom_installer/src/uninstalldialog.h | 1 + 5 files changed, 63 insertions(+), 2 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/operation.h b/code/ryzom/tools/client/ryzom_installer/src/operation.h index 4e8b016be..5ea4326e1 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operation.h +++ b/code/ryzom/tools/client/ryzom_installer/src/operation.h @@ -38,12 +38,14 @@ struct SComponents SComponents() { installer = true; + downloadedFiles = true; } QStringList servers; QStringList profiles; bool installer; + bool downloadedFiles; }; enum OperationStep diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp index 617c5f613..c687a3df1 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp @@ -243,11 +243,13 @@ void COperationDialog::updateAddRemoveComponents() // update components to remove m_removeComponents.profiles << profilesToDelete; m_removeComponents.installer = false; + m_removeComponents.downloadedFiles = false; // update components to add m_addComponents.profiles << profilesToAdd; m_addComponents.servers << serversToUpdate; m_addComponents.installer = false; + m_addComponents.downloadedFiles = false; } void COperationDialog::processUpdateProfilesNextStep() @@ -351,6 +353,10 @@ void COperationDialog::processUninstallNextStep() { QtConcurrent::run(this, &COperationDialog::deleteComponentsProfiles); } + else if (m_removeComponents.downloadedFiles) + { + QtConcurrent::run(this, &COperationDialog::deleteComponentsDownloadedFiles); + } else if (m_removeComponents.installer) { QtConcurrent::run(this, &COperationDialog::deleteComponentsInstaller); @@ -1154,6 +1160,43 @@ void COperationDialog::deleteComponentsInstaller() // TODO: + // reset it once it's done + m_removeComponents.installer = false; + + emit onProgressSuccess(1); + emit done(); +} + +void COperationDialog::deleteComponentsDownloadedFiles() +{ + m_currentOperation = tr("Delete downloaded files"); + m_currentOperationProgressFormat = tr("Deleting %1..."); + + CConfigFile *config = CConfigFile::getInstance(); + + QString path = config->getInstallationDirectory(); + + QDir dir(path); + + QStringList filter; + filter << "*.7z"; + filter << "*.bnp"; + filter << "*.zip"; + filter << "*.part"; + + QStringList files = dir.entryList(filter, QDir::Files); + + foreach(const QString &file, files) + { + if (!QFile::remove(file)) + { + qDebug() << "Unable to delete" << file; + } + } + + // reset it once it's done + m_removeComponents.downloadedFiles = false; + emit onProgressSuccess(1); emit done(); } diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h index bae2a8b7f..091b77278 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h @@ -116,8 +116,8 @@ protected: void addComponentsProfiles(); void deleteComponentsProfiles(); - void addComponentsInstaller(); void deleteComponentsInstaller(); + void deleteComponentsDownloadedFiles(); void updateAddRemoveComponents(); diff --git a/code/ryzom/tools/client/ryzom_installer/src/uninstalldialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/uninstalldialog.cpp index 4c61da6d5..a527e680a 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/uninstalldialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/uninstalldialog.cpp @@ -79,7 +79,14 @@ CUninstallDialog::CUninstallDialog(QWidget *parent):QDialog(parent), m_installer // installer m_installerIndex = model->rowCount(); - item = new QStandardItem(tr("Ryzom Installer")); + item = new QStandardItem(tr("Installer")); + item->setCheckable(true); + model->appendRow(item); + + // downloaded files + m_downloadedFilesIndex = model->rowCount(); + + item = new QStandardItem(tr("Downloaded Files")); item->setCheckable(true); model->appendRow(item); @@ -148,6 +155,10 @@ void CUninstallDialog::setSelectedComponents(const SComponents &components) // installer item = model->item(m_installerIndex); if (item) item->setCheckState(components.installer ? Qt::Checked : Qt::Unchecked); + + // downloaded files + item = model->item(m_downloadedFilesIndex); + if (item) item->setCheckState(components.downloadedFiles ? Qt::Checked : Qt::Unchecked); } SComponents CUninstallDialog::getSelectedCompenents() const @@ -187,6 +198,10 @@ SComponents CUninstallDialog::getSelectedCompenents() const item = model->item(m_installerIndex); res.installer = item && item->checkState() == Qt::Checked; + // downloaded files + item = model->item(m_downloadedFilesIndex); + res.downloadedFiles = item && item->checkState() == Qt::Checked; + return res; } diff --git a/code/ryzom/tools/client/ryzom_installer/src/uninstalldialog.h b/code/ryzom/tools/client/ryzom_installer/src/uninstalldialog.h index f8bebace1..0c818ebc1 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/uninstalldialog.h +++ b/code/ryzom/tools/client/ryzom_installer/src/uninstalldialog.h @@ -61,6 +61,7 @@ private: IDIndicesMap m_profilesIndices; int m_installerIndex; + int m_downloadedFilesIndex; }; #endif