From 3397d1dc38d91e478763769d7856422074c1a016 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 14 May 2016 18:50:27 +0200 Subject: [PATCH] Changed: Clean files --HG-- branch : feature-ryzom-installer --- .../client/ryzom_installer/src/archive.cpp | 28 +++++++++++++++ .../client/ryzom_installer/src/archive.h | 1 + .../client/ryzom_installer/src/configfile.cpp | 35 ++++++++++++++++++- .../client/ryzom_installer/src/configfile.h | 3 ++ .../client/ryzom_installer/src/mainwindow.cpp | 5 +++ 5 files changed, 71 insertions(+), 1 deletion(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/archive.cpp b/code/ryzom/tools/client/ryzom_installer/src/archive.cpp index 287f559dc..5d32a4c39 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/archive.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/archive.cpp @@ -355,6 +355,34 @@ bool CArchive::copyProfileFiles() return copyFiles(files); } +bool CArchive::cleanServerFiles(const QString &directory) +{ + QDir dir(directory); + + // directory doesn't exist + if (!dir.exists()) return false; + + if (!dir.cd("data") && dir.exists()) return false; + + // temporary files + QStringList files = dir.entryList(QStringList() << "*.string_cache" << "*.packed_sheets" << "*.packed" << "*.pem", QDir::Files); + + foreach(const QString &file, files) + { + dir.remove(file); + } + + // fonts directory is not needed anymore + if (dir.cd("fonts") && dir.exists()) + { + dir.removeRecursively(); + } + + emit done(); + + return true; +} + bool CArchive::copyServerFiles(const QString &src, const QString &dst) { if (src.isEmpty() || dst.isEmpty()) return false; diff --git a/code/ryzom/tools/client/ryzom_installer/src/archive.h b/code/ryzom/tools/client/ryzom_installer/src/archive.h index 0f8284b9e..202ad664f 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/archive.h +++ b/code/ryzom/tools/client/ryzom_installer/src/archive.h @@ -34,6 +34,7 @@ public: bool extract(const QString &filename, const QString &dest); bool copyServerFiles(const QString &src, const QString &dst); bool copyProfileFiles(const QString &src, const QString &dst); + bool cleanServerFiles(const QString &directory); void stop(); bool mustStop(); diff --git a/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp b/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp index b3b41cfde..ffc77a9d4 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp @@ -420,13 +420,41 @@ bool CConfigFile::isRyzomClientInstalledIn(const QString &directory) const // client_default.cfg doesn't exist if (!dir.exists("client_default.cfg")) return false; - if (!dir.exists(getServer().clientFilename)) return false; + QString clientFilename = getServer().clientFilename; + + // check if client is defined and exists + if (!clientFilename.isEmpty() && !dir.exists(clientFilename)) return false; // TODO: more checks return true; } +bool CConfigFile::foundTemporaryFiles(const QString &directory) const +{ + QDir dir(directory); + + // directory doesn't exist + if (!dir.exists()) return false; + + if (!dir.cd("data") && dir.exists()) return false; + + // temporary files + if (!dir.entryList(QStringList() << "*.string_cache" << "*.packed_sheets" << "*.packed" << "*.pem", QDir::Files).isEmpty()) return true; + + // fonts directory is not needed anymore + if (dir.cd("fonts") && dir.exists()) return true; + + return false; +} + +bool CConfigFile::shouldCreateDesktopShortcut() const +{ + const CProfile &profile = getProfile(); + + return profile.desktopShortcut && !QFile::exists(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/Ryzom.lnk"); +} + QString CConfigFile::getClientFullPath() const { QString path = getProfile().executable; @@ -527,6 +555,11 @@ CConfigFile::InstallationStep CConfigFile::getNextStep() const // client is not extracted from BNP if (!isRyzomClientInstalledIn(serverDirectory)) { + if (foundTemporaryFiles(serverDirectory)) + { + return CleanFiles; + } + if (QFile::exists(getSrcServerClientBNPFullPath())) { return ExtractBnpClient; diff --git a/code/ryzom/tools/client/ryzom_installer/src/configfile.h b/code/ryzom/tools/client/ryzom_installer/src/configfile.h index 32bfb99c6..ae01ee2af 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/configfile.h +++ b/code/ryzom/tools/client/ryzom_installer/src/configfile.h @@ -87,6 +87,7 @@ public: ExtractDownloadedClient, CopyServerFiles, CopyProfileFiles, + CleanFiles, ExtractBnpClient, CreateProfile, CreateShortcuts, @@ -144,6 +145,8 @@ public: bool isRyzomInstalledIn(const QString &directory) const; bool areRyzomDataInstalledIn(const QString &directory) const; bool isRyzomClientInstalledIn(const QString &directory) const; + bool foundTemporaryFiles(const QString &directory) const; + bool shouldCreateDesktopShortcut() const; // installation choices bool use64BitsClient() const; diff --git a/code/ryzom/tools/client/ryzom_installer/src/mainwindow.cpp b/code/ryzom/tools/client/ryzom_installer/src/mainwindow.cpp index d316bc6c9..b1e7952be 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/mainwindow.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/mainwindow.cpp @@ -135,6 +135,11 @@ void CMainWindow::processNextStep() m_archive->extract(config->getSrcServerClientBNPFullPath(), config->getInstallationDirectory() + "/" + server.id); break; + case CConfigFile::CleanFiles: + hideProgressBar(); + m_archive->cleanServerFiles(config->getInstallationDirectory() + "/" + server.id); + break; + case CConfigFile::CreateProfile: displayProgressBar(); break;