From 667b0de250149fcb19d03ba065a1dc077dde828e Mon Sep 17 00:00:00 2001 From: pvdk Date: Mon, 17 Mar 2014 23:39:21 +0100 Subject: [PATCH] Fixed problems with cd content autodetection --- apps/wizard/unshield/unshieldworker.cpp | 111 ++++++++++++++---------- apps/wizard/unshield/unshieldworker.hpp | 4 +- 2 files changed, 70 insertions(+), 45 deletions(-) diff --git a/apps/wizard/unshield/unshieldworker.cpp b/apps/wizard/unshield/unshieldworker.cpp index aceac69b8..679730715 100644 --- a/apps/wizard/unshield/unshieldworker.cpp +++ b/apps/wizard/unshield/unshieldworker.cpp @@ -386,7 +386,7 @@ void Wizard::UnshieldWorker::extract() writeSettings(); // Remove the temporary directory - //removeDirectory(getPath() + QDir::separator() + QLatin1String("extract-temp")); + removeDirectory(getPath() + QDir::separator() + QLatin1String("extract-temp")); // Fill the progress bar int total = 0; @@ -445,26 +445,39 @@ bool Wizard::UnshieldWorker::setupComponent(Component component) foreach (const QString &file, list) { + qDebug() << "current archive: " << file; + + // Try to open the archive + Unshield *unshield = NULL; + unshield = openCab(file); + + if (!unshield) + return false; + if (component == Wizard::Component_Morrowind) { - bool morrowindFound = findInCab(file, QLatin1String("Morrowind.bsa")); - bool tribunalFound = findInCab(file, QLatin1String("Tribunal.bsa")); - bool bloodmoonFound = findInCab(file, QLatin1String("Bloodmoon.bsa")); + bool morrowindFound = findInCab(QLatin1String("Morrowind.bsa"), unshield); + bool tribunalFound = findInCab(QLatin1String("Tribunal.bsa"), unshield); + bool bloodmoonFound = findInCab(QLatin1String("Bloodmoon.bsa"), unshield); if (morrowindFound) { // Check if we have correct archive, other archives have Morrowind.bsa too if ((tribunalFound && bloodmoonFound) || (!tribunalFound && !bloodmoonFound)) { cabFile = file; - found = true; // We have a GoTY disk + found = true; // We have a GoTY disk or a Morrowind-only disk } } } else { - if (findInCab(file, name + QLatin1String(".bsa"))) { + + if (findInCab(name + QLatin1String(".bsa"), unshield)) { cabFile = file; found = true; } } + + // Close the current archive + unshield_close(unshield); } if (!found) { @@ -746,6 +759,39 @@ bool Wizard::UnshieldWorker::extractFile(Unshield *unshield, const QString &dest return success; } +bool Wizard::UnshieldWorker::extractCab(const QString &cabFile, const QString &destination) +{ + bool success = false; + + QByteArray array(cabFile.toUtf8()); + + Unshield *unshield; + unshield = unshield_open(array.constData()); + + if (!unshield) { + emit error(tr("Failed to open InstallShield Cabinet File."), tr("Opening %1 failed.").arg(cabFile)); + return false; + } + + int counter = 0; + + for (int i=0; ifirst_file; j<=group->last_file; ++j) + { + if (unshield_file_is_valid(unshield, j)) { + success = extractFile(unshield, destination, group->name, j, counter); + ++counter; + } + } + } + + unshield_close(unshield); + return success; +} + QString Wizard::UnshieldWorker::findFile(const QString &fileName, const QString &path) { return findFiles(fileName, path).first(); @@ -764,14 +810,16 @@ QStringList Wizard::UnshieldWorker::findFiles(const QString &fileName, const QSt QStringList result; QDir dir(path); + // Prevent parsing over the complete filesystem + if (dir == QDir::rootPath()) + return QStringList(); + if (!dir.exists()) return QStringList(); QFileInfoList list(dir.entryInfoList(QDir::NoDotAndDotDot | - QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)); foreach(QFileInfo info, list) { - if (info.isSymLink()) continue; @@ -813,7 +861,7 @@ QStringList Wizard::UnshieldWorker::findDirectories(const QString &dirName, cons return findFiles(dirName, path, 0, true, true); } -bool Wizard::UnshieldWorker::findInCab(const QString &cabFile, const QString &fileName) +Unshield* Wizard::UnshieldWorker::openCab(const QString &cabFile) { QByteArray array(cabFile.toUtf8()); @@ -822,43 +870,17 @@ bool Wizard::UnshieldWorker::findInCab(const QString &cabFile, const QString &fi if (!unshield) { emit error(tr("Failed to open InstallShield Cabinet File."), tr("Opening %1 failed.").arg(cabFile)); - return false; + unshield_close(unshield); + return NULL; } - for (int i=0; ifirst_file; j<=group->last_file; ++j) - { - - if (unshield_file_is_valid(unshield, j)) { - QString current(QString::fromUtf8(unshield_file_name(unshield, j))); - if (current.toLower() == fileName.toLower()) - return true; // File is found! - } - } - } - - unshield_close(unshield); - return false; + return unshield; } -bool Wizard::UnshieldWorker::extractCab(const QString &cabFile, const QString &destination) +bool Wizard::UnshieldWorker::findInCab(const QString &fileName, Unshield *unshield) { - bool success = false; - - QByteArray array(cabFile.toUtf8()); - - Unshield *unshield; - unshield = unshield_open(array.constData()); - - if (!unshield) { - emit error(tr("Failed to open InstallShield Cabinet File."), tr("Opening %1 failed.").arg(cabFile)); + if (!unshield) return false; - } - - int counter = 0; for (int i=0; ifirst_file; j<=group->last_file; ++j) { + if (unshield_file_is_valid(unshield, j)) { - success = extractFile(unshield, destination, group->name, j, counter); - ++counter; + QString current(QString::fromUtf8(unshield_file_name(unshield, j))); + if (current.toLower() == fileName.toLower()) + return true; // File is found! } } } - unshield_close(unshield); - return success; + return false; } diff --git a/apps/wizard/unshield/unshieldworker.hpp b/apps/wizard/unshield/unshieldworker.hpp index f23dc1aa7..36215bf5d 100644 --- a/apps/wizard/unshield/unshieldworker.hpp +++ b/apps/wizard/unshield/unshieldworker.hpp @@ -62,7 +62,9 @@ namespace Wizard bool extractCab(const QString &cabFile, const QString &destination); bool extractFile(Unshield *unshield, const QString &destination, const QString &prefix, int index, int counter); - bool findInCab(const QString &cabFile, const QString &fileName); + + Unshield* openCab(const QString &cabFile); + bool findInCab(const QString &fileName, Unshield *unshield); QString findFile(const QString &fileName, const QString &path);