summaryrefslogtreecommitdiff
path: root/src/installationmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/installationmanager.cpp')
-rw-r--r--src/installationmanager.cpp299
1 files changed, 41 insertions, 258 deletions
diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp
index d92cae15..96d3743f 100644
--- a/src/installationmanager.cpp
+++ b/src/installationmanager.cpp
@@ -20,10 +20,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "installationmanager.h"
#include "utility.h"
-#include "installdialog.h"
-#include "simpleinstalldialog.h"
-#include "baincomplexinstallerdialog.h"
-#include "fomodinstallerdialog.h"
+
#include "report.h"
#include "categories.h"
#include "questionboxmemory.h"
@@ -268,11 +265,11 @@ QStringList InstallationManager::extractFiles(const QStringList &filesOrig)
return result;
}
-IPluginInstaller::EInstallResult InstallationManager::installArchive(const QString &modName, const QString &archiveName)
+IPluginInstaller::EInstallResult InstallationManager::installArchive(GuessedValue<QString> &modName, const QString &archiveName)
{
- QString temp = modName;
+ GuessedValue<QString> temp(modName);
bool iniTweaks;
- if (install(archiveName, "", "modsdir", false, true, temp, iniTweaks)) {
+ if (install(archiveName, "modsdir", temp, iniTweaks)) {
return IPluginInstaller::RESULT_SUCCESS;
} else {
return IPluginInstaller::RESULT_FAILED;
@@ -484,7 +481,7 @@ QString InstallationManager::generateBackupName(const QString &directoryName)
}
-bool InstallationManager::testOverwrite(const QString &modsDirectory, QString &modName)
+bool InstallationManager::testOverwrite(const QString &modsDirectory, GuessedValue<QString> &modName)
{
QString targetDirectory = QDir::fromNativeSeparators(modsDirectory.mid(0).append("\\").append(modName));
@@ -503,7 +500,7 @@ bool InstallationManager::testOverwrite(const QString &modsDirectory, QString &m
QString name = QInputDialog::getText(m_ParentWidget, tr("Mod Name"), tr("Name"),
QLineEdit::Normal, modName, &ok);
if (ok && !name.isEmpty()) {
- modName = name;
+ modName.update(name, GUESS_USER);
if (!ensureValidModName(modName)) {
return false;
}
@@ -547,45 +544,48 @@ bool InstallationManager::testOverwrite(const QString &modsDirectory, QString &m
return true;
}
-
-void InstallationManager::fixModName(QString &name)
+/*
+bool InstallationManager::fixModName(QString &name)
{
-// name = name.remove("^[ ]*").trimmed();
- name = name.simplified();
- while (name.endsWith('.')) name.chop(1);
-
- name.replace(QRegExp("[<>:\"/\\|?*]"), "");
+ QString temp = name.simplified();
+ while (temp.endsWith('.')) temp.chop(1);
+ temp.replace(QRegExp("[<>:\"/\\|?*]"), "");
static QString invalidNames[] = { "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" };
for (int i = 0; i < sizeof(invalidNames) / sizeof(QString); ++i) {
- if (name == invalidNames[i]) {
- name = "";
+ if (temp == invalidNames[i]) {
+ temp = "";
break;
}
}
-}
+ if (temp.length() > 1) {
+ name = temp;
+ return true;
+ } else {
+ return false;
+ }
+}
+*/
-bool InstallationManager::ensureValidModName(QString &name)
+bool InstallationManager::ensureValidModName(GuessedValue<QString> &name)
{
- fixModName(name);
-
- while (name.isEmpty()) {
+ while (name->isEmpty()) {
bool ok;
- name = QInputDialog::getText(m_ParentWidget, tr("Invalid name"),
- tr("The name you entered is invalid, please enter a different one."),
- QLineEdit::Normal, "", &ok);
+ name.update(QInputDialog::getText(m_ParentWidget, tr("Invalid name"),
+ tr("The name you entered is invalid, please enter a different one."),
+ QLineEdit::Normal, "", &ok),
+ GUESS_USER);
if (!ok) {
return false;
}
- fixModName(name);
}
return true;
}
-bool InstallationManager::doInstall(const QString &modsDirectory, QString &modName, int modID,
+bool InstallationManager::doInstall(const QString &modsDirectory, GuessedValue<QString> &modName, int modID,
const QString &version, const QString &newestVersion, int categoryID)
{
if (!ensureValidModName(modName)) {
@@ -906,7 +906,7 @@ bool InstallationManager::installFomodExternal(const QString &fileName, const QS
errorOccured = true;
}
} // if it's a directory and the target exists that isn't really a problem
- // TODO: use shellRename?
+
if (!QFile::rename(fileInfo.absoluteFilePath(), newName)) {
// moving doesn't work when merging
if (!copyDir(fileInfo.absoluteFilePath(), newName, true)) {
@@ -924,7 +924,7 @@ bool InstallationManager::installFomodExternal(const QString &fileName, const QS
}
QString dataDir = modDirectory.mid(0).append("/Data");
- if (!shellDelete(QStringList(dataDir), NULL)) {
+ if (!removeDir(dataDir)) {
qCritical("failed to remove data directory from %s", dataDir.toUtf8().constData());
errorOccured = true;
}
@@ -953,8 +953,8 @@ bool InstallationManager::wasCancelled()
}
-bool InstallationManager::install(const QString &fileName, const QString &pluginsFileName, const QString &modsDirectory,
- bool preferIntegrated, bool enableQuickInstall, QString &modName, bool &hasIniTweaks)
+bool InstallationManager::install(const QString &fileName, const QString &modsDirectory,
+ GuessedValue<QString> &modName, bool &hasIniTweaks)
{
QFileInfo fileInfo(fileName);
bool success = false;
@@ -963,6 +963,8 @@ bool InstallationManager::install(const QString &fileName, const QString &plugin
return false;
}
+ modName.setFilter(&fixDirectoryName);
+
// read out meta information from the download if available
int modID = 0;
QString version = "";
@@ -974,14 +976,9 @@ bool InstallationManager::install(const QString &fileName, const QString &plugin
if (QFile(metaName).exists()) {
QSettings metaFile(metaName, QSettings::IniFormat);
modID = metaFile.value("modID", 0).toInt();
- if (modName.isEmpty()) {
- modName = metaFile.value("modName", "").toString();
- // it is possible we have a file-name but not the correct mod name. in this case,
- // the stored mod name may be "\0"
- if (modName.isEmpty() || (modName.length() < 2)) {
- modName = metaFile.value("name", "").toString();
- }
- }
+ modName.update(metaFile.value("name", "").toString(), GUESS_FALLBACK);
+ modName.update(metaFile.value("modName", "").toString(), GUESS_META);
+
version = metaFile.value("version", "").toString();
newestVersion = metaFile.value("newestVersion", "").toString();
unsigned int categoryIndex = CategoryFactory::instance().resolveNexusID(metaFile.value("category", 0).toInt());
@@ -997,15 +994,10 @@ bool InstallationManager::install(const QString &fileName, const QString &plugin
} else if (modID != guessedModID) {
qDebug("passed mod id: %d, guessed id: %d", modID, guessedModID);
}
-
- if (modName.isEmpty()) {
- modName = guessedModName;
- nameGuessed = true;
- }
+ modName.update(guessedModName, GUESS_GOOD);
}
- fixModName(modName);
- qDebug("using mod name \"%s\" (id %d)", modName.toUtf8().constData(), modID);
+ qDebug("using mod name \"%s\" (id %d)", modName->toUtf8().constData(), modID);
m_CurrentFile = fileInfo.fileName();
// open the archive and construct the directory tree the installers work on
@@ -1014,7 +1006,7 @@ bool InstallationManager::install(const QString &fileName, const QString &plugin
DirectoryTree *filesTree = archiveOpen ? createFilesTree() : NULL;
-/* IPluginInstaller::EInstallResult installResult = IPluginInstaller::RESULT_NOTATTEMPTED;
+ IPluginInstaller::EInstallResult installResult = IPluginInstaller::RESULT_NOTATTEMPTED;
std::sort(m_Installers.begin(), m_Installers.end(), [] (IPluginInstaller *LHS, IPluginInstaller *RHS) {
return LHS->priority() > RHS->priority();
@@ -1080,216 +1072,7 @@ bool InstallationManager::install(const QString &fileName, const QString &plugin
}
reportError(tr("None of the available installer plugins were able to handle that archive"));
- return false;*/
-
-
-
- hasIniTweaks = false;
-
-
- DirectoryTree::Node *baseNode = NULL;
- bool manualRequest = false;
-
- if (!archiveOpen) {
- reportError(tr("Failed to open \"%1\": %2").arg(QDir::toNativeSeparators(fileName)).arg(getErrorString(m_CurrentArchive->getLastError())));
- return false;
- }
-
- // bundled fomod?
- if ((baseNode == NULL) && !manualRequest) {
- QStringList bundledFomods;
- for (DirectoryTree::const_leaf_iterator fileIter = filesTree->leafsBegin(); fileIter != filesTree->leafsEnd(); ++fileIter) {
- if (fileIter->getName().endsWith(".fomod", Qt::CaseInsensitive)) {
- bundledFomods.append(fileIter->getName());
- }
- }
- QString bundledFomodInst;
- if (bundledFomods.count() > 1) {
- SelectionDialog selection(tr("This seems like a bundle of fomods, which one do you want to install?"), m_ParentWidget);
- foreach (const QString &fomod, bundledFomods) {
- selection.addChoice(fomod, fomod, QVariant());
- }
- if (selection.exec() == QDialog::Accepted) {
- bundledFomodInst = selection.getChoiceString();
- } else {
- return false;
- }
- } else if (bundledFomods.count() == 1) {
- bundledFomodInst = bundledFomods.at(0);
- qDebug("archive contains fomod: %s", qPrintable(bundledFomodInst));
- }
- if (!bundledFomodInst.isEmpty()) {
- unpackSingleFile(bundledFomodInst);
- m_CurrentArchive->close();
- return install(QDir::tempPath().append("/").append(bundledFomodInst), pluginsFileName, modsDirectory, preferIntegrated,
- enableQuickInstall, modName, hasIniTweaks);
- }
- }
-
- // fomod installer?
- if ((baseNode == NULL) && !manualRequest) {
- QString fomodPath;
- bool xmlInstaller = false;
- if (checkFomodPackage(filesTree, fomodPath, xmlInstaller)) {
- baseNode = filesTree;
- bool nmmInstaller = checkNMMInstaller();
-
- if (xmlInstaller || nmmInstaller) {
- if (!xmlInstaller || (nmmInstaller && !preferIntegrated)) {
- if (!ensureValidModName(modName) ||
- !testOverwrite(modsDirectory, modName)) {
- return false;
- }
-
- QString targetDirectory = QDir::fromNativeSeparators(modsDirectory.mid(0).append("\\").append(modName));
-
- if (installFomodExternal(fileName, pluginsFileName, targetDirectory)) {
- QSettings settingsFile(targetDirectory.mid(0).append("/meta.ini"), QSettings::IniFormat);
-
- // overwrite settings only if they are actually are available or haven't been set before
- if ((modID != 0) || !settingsFile.contains("modid")) {
- settingsFile.setValue("modid", modID);
- }
- if (!settingsFile.contains("version") ||
- (!version.isEmpty() &&
- (VersionInfo(version) >= VersionInfo(settingsFile.value("version").toString())))) {
- settingsFile.setValue("version", version);
- }
- if (!newestVersion.isEmpty() || !settingsFile.contains("newestVersion")) {
- settingsFile.setValue("newestVersion", newestVersion);
- }
- if (!settingsFile.contains("category")) {
- settingsFile.setValue("category", QString::number(categoryID));
- }
- settingsFile.setValue("installationFile", m_CurrentFile);
-
- success = true;
- }
- } else {
- if (installFomodInternal(baseNode, fomodPath, modsDirectory,
- modID, version, newestVersion, categoryID,
- modName, nameGuessed, manualRequest)) {
- success = true;
- }
- }
- if (success) {
- DirectoryTree::node_iterator iniTweakNode = baseNode->nodeFind(DirectoryTreeInformation("INI Tweaks"));
- hasIniTweaks = (iniTweakNode != baseNode->nodesEnd()) &&
- ((*iniTweakNode)->numLeafs() != 0);
- }
- if (baseNode != filesTree) {
- delete baseNode;
- }
- } else {
- if (QuestionBoxMemory::query(m_ParentWidget, Settings::instance().directInterface(), "missingNCC",
- tr("Installer missing"),
- tr("This package contains a scripted installer. To use this installer "
- "you need the optional \"NCC\"-package and the .net runtime. "
- "Do you want to continue, treating this as a manual installer?"),
- QDialogButtonBox::Yes | QDialogButtonBox::Cancel) == QMessageBox::Yes) {
- manualRequest = true;
- } else {
- MessageDialog::showMessage(tr("Please install NCC"), m_ParentWidget);
- }
- }
- }
- }
-
- // simple installer?
- if ((baseNode == NULL) && enableQuickInstall && !manualRequest) {
- baseNode = getSimpleArchiveBase(filesTree);
- if (baseNode != NULL) {
- qDebug("treating as simple archive (%d)", baseNode->numLeafs());
- SimpleInstallDialog dialog(modName, m_ParentWidget);
- if (dialog.exec() == QDialog::Accepted) {
- mapToArchive(baseNode);
- modName = dialog.getName();
- if (doInstall(modsDirectory, modName, modID, version, newestVersion, categoryID)) {
- success = true;
-
- DirectoryTree::node_iterator iniTweakNode = baseNode->nodeFind(DirectoryTreeInformation("INI Tweaks"));
- hasIniTweaks = (iniTweakNode != baseNode->nodesEnd()) &&
- ((*iniTweakNode)->numLeafs() != 0);
- }
- } else {
- if (dialog.manualRequested()) {
- manualRequest = true;
- modName = dialog.getName();
- }
- }
- }
- }
-
- // bain complex package?
- if ((baseNode == NULL) && !manualRequest) {
- if (checkBainPackage(filesTree)) {
- bool hasPackageTXT = unpackPackageTXT();
-
- baseNode = filesTree;
- qDebug("treating as complex archive (%d)", filesTree->numNodes());
- BainComplexInstallerDialog dialog(filesTree, modName, hasPackageTXT, m_ParentWidget);
- if (dialog.exec() == QDialog::Accepted) {
- modName = dialog.getName();
- // create a new tree with the selected directories mapped to the
- // base directory. This is destructive on the original tree
- baseNode = dialog.updateTree(baseNode);
- mapToArchive(baseNode);
-
- if (doInstall(modsDirectory, modName, modID, version, newestVersion, categoryID)) {
- success = true;
-
- DirectoryTree::node_iterator iniTweakNode = baseNode->nodeFind(DirectoryTreeInformation("INI Tweaks"));
- hasIniTweaks = (iniTweakNode != baseNode->nodesEnd()) &&
- ((*iniTweakNode)->numLeafs() != 0);
- }
- delete baseNode;
- } else {
- if (dialog.manualRequested()) {
- manualRequest = true;
- modName = dialog.getName();
- }
- }
- QFile::remove(QDir::tempPath().append("/package.txt"));
- }
- }
-
- // final option: manual installer
- if ((baseNode == NULL) || manualRequest) {
- qDebug("offering installation dialog");
- InstallDialog dialog(filesTree, modName, m_ParentWidget);
- connect(&dialog, SIGNAL(openFile(QString)), this, SLOT(openFile(QString)));
- if (dialog.exec() == QDialog::Accepted) {
- modName = dialog.getModName();
- baseNode = dialog.getDataTree();
- mapToArchive(baseNode);
- if (doInstall(modsDirectory, modName, modID, version, newestVersion, categoryID)) {
- success = true;
-
- DirectoryTree::node_iterator iniTweakNode = baseNode->nodeFind(DirectoryTreeInformation("INI Tweaks"));
- hasIniTweaks = (iniTweakNode != baseNode->nodesEnd()) &&
- ((*iniTweakNode)->numLeafs() != 0);
- }
- delete baseNode; // baseNode is a new tree, independent of filesTree
- }
- }
-
- delete filesTree;
- m_CurrentArchive->close();
-
- for (std::set<QString>::iterator iter = m_FilesToDelete.begin();
- iter != m_FilesToDelete.end(); ++iter) {
- QFile(*iter).remove();
- }
- m_FilesToDelete.clear();
-
- for (std::set<QString>::iterator iter = m_TempFilesToDelete.begin();
- iter != m_TempFilesToDelete.end(); ++iter) {
- QFile(QDir::tempPath().append("/").append(*iter)).remove();
- }
-
- m_TempFilesToDelete.clear();
-
- return success;
+ return false;
}