From eaaa1b312dfd8ab0fed677dd9eb368c84c03a758 Mon Sep 17 00:00:00 2001 From: Tom Tanner Date: Sun, 2 Aug 2015 16:25:32 +0100 Subject: Extract multiple copies of file from archive Had to rewrite the archive handling a bit. First pass, some tidyups required. --- src/installationmanager.cpp | 60 ++++++++++++++++----------------------------- src/selfupdater.cpp | 6 ++--- 2 files changed, 24 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index c036a373..71b38139 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -124,23 +124,16 @@ void InstallationManager::mapToArchive(const DirectoryTree::Node *node, std::wst } for (DirectoryTree::const_leaf_iterator iter = node->leafsBegin(); iter != node->leafsEnd(); ++iter) { - if (! data[iter->getIndex()]->getSkip()) { - std::wstring newp((path + iter->getName().toStdWString())); - std::wstring oldp(data[iter->getIndex()]->getOutputFileName()); - qDebug() << "outputting to " << QString::fromStdWString(newp) << " but already outputting to " << QString::fromStdWString(oldp); - } - data[iter->getIndex()]->setSkip(false); std::wstring temp = path + iter->getName().toStdWString(); - data[iter->getIndex()]->setOutputFileName(temp.c_str()); + data[iter->getIndex()]->addOutputFileName(temp.c_str()); } for (DirectoryTree::const_node_iterator iter = node->nodesBegin(); iter != node->nodesEnd(); ++iter) { + std::wstring temp = path + (*iter)->getData().name.toStdWString(); if ((*iter)->getData().index != -1) { - data[(*iter)->getData().index]->setSkip(false); - std::wstring temp = path + (*iter)->getData().name.toStdWString(); - data[(*iter)->getData().index]->setOutputFileName(temp.c_str()); + data[(*iter)->getData().index]->addOutputFileName(temp.c_str()); } - mapToArchive(*iter, path + (*iter)->getData().name.toStdWString(), data); + mapToArchive(*iter, temp, data); } } @@ -151,11 +144,6 @@ void InstallationManager::mapToArchive(const DirectoryTree::Node *baseNode) size_t size; m_CurrentArchive->getFileList(data, size); - // first disable all files + folders, we will re-enable those present in baseNode - for (size_t i = 0; i < size; ++i) { - data[i]->setSkip(true); - } - std::wstring currentPath; mapToArchive(baseNode, currentPath, data); @@ -174,32 +162,29 @@ bool InstallationManager::unpackSingleFile(const QString &fileName) for (size_t i = 0; i < size; ++i) { if (_wcsicmp(data[i]->getFileName(), ToWString(fileName).c_str()) == 0) { available = true; - data[i]->setSkip(false); - data[i]->setOutputFileName(ToWString(baseName).c_str()); + data[i]->addOutputFileName(ToWString(baseName).c_str()); m_TempFilesToDelete.insert(baseName); - } else { - data[i]->setSkip(true); } } - if (available) { - m_InstallationProgress.setWindowTitle(tr("Extracting files")); - m_InstallationProgress.setLabelText(QString()); - m_InstallationProgress.setValue(0); - m_InstallationProgress.setWindowModality(Qt::WindowModal); - m_InstallationProgress.show(); + if (!available) { + return false; + } - bool res = m_CurrentArchive->extract(ToWString(QDir::toNativeSeparators(QDir::tempPath())).c_str(), - new MethodCallback(this, &InstallationManager::updateProgress), - new MethodCallback(this, &InstallationManager::dummyProgressFile), - new MethodCallback(this, &InstallationManager::report7ZipError)); + m_InstallationProgress.setWindowTitle(tr("Extracting files")); + m_InstallationProgress.setLabelText(QString()); + m_InstallationProgress.setValue(0); + m_InstallationProgress.setWindowModality(Qt::WindowModal); + m_InstallationProgress.show(); - m_InstallationProgress.hide(); + bool res = m_CurrentArchive->extract(ToWString(QDir::toNativeSeparators(QDir::tempPath())).c_str(), + new MethodCallback(this, &InstallationManager::updateProgress), + new MethodCallback(this, &InstallationManager::dummyProgressFile), + new MethodCallback(this, &InstallationManager::report7ZipError)); - return res; - } else { - return false; - } + m_InstallationProgress.hide(); + + return res; } @@ -256,14 +241,11 @@ QStringList InstallationManager::extractFiles(const QStringList &filesOrig, bool ++targetFile; } } - data[i]->setOutputFileName(targetFile); + data[i]->addOutputFileName(targetFile); result.append(QDir::tempPath().append("/").append(ToQString(targetFile))); - data[i]->setSkip(false); m_TempFilesToDelete.insert(ToQString(targetFile)); - } else { - data[i]->setSkip(true); } } diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index 071ee51c..9c151746 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -255,9 +255,9 @@ void SelfUpdater::installUpdate() QString outputName = ToQString(data[i]->getFileName()); if (outputName.startsWith("ModOrganizer\\", Qt::CaseInsensitive)) { outputName = outputName.mid(13); - data[i]->setOutputFileName(ToWString(outputName).c_str()); - } else if (outputName == "ModOrganizer") { - data[i]->setSkip(true); + data[i]->addOutputFileName(ToWString(outputName).c_str()); + } else if (outputName != "ModOrganizer") { + data[i]->addOutputFileName(ToWString(outputName).c_str()); } QFileInfo file(mopath.mid(0).append("/").append(outputName)); if (file.exists() && file.isFile()) { -- cgit v1.3.1 From b0982148609a8a6f0d73d801ec9fcd1a22930f98 Mon Sep 17 00:00:00 2001 From: Tom Tanner Date: Wed, 5 Aug 2015 22:40:49 +0100 Subject: More work on the executables list Apart from an off by one in the popup list which had crept back in, reworked the underlying code even more, which now seems to get the list behaving in a predictable way. --- src/editexecutablesdialog.cpp | 23 +++++----------- src/executableslist.cpp | 41 +++++++++++++++------------- src/executableslist.h | 63 ++++++++++++++++++++++++++++++++++--------- src/mainwindow.cpp | 9 +++---- src/organizercore.cpp | 20 +++++++------- 5 files changed, 94 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/editexecutablesdialog.cpp b/src/editexecutablesdialog.cpp index 47f9262d..998a4507 100644 --- a/src/editexecutablesdialog.cpp +++ b/src/editexecutablesdialog.cpp @@ -60,8 +60,7 @@ void EditExecutablesDialog::refreshExecutablesWidget() for(; current != end; ++current) { QListWidgetItem *newItem = new QListWidgetItem(current->m_Title); - newItem->setTextColor((current->m_Flags & Executable::CustomExecutable) ? QColor(Qt::black) - : QColor(Qt::darkGray)); + newItem->setTextColor(current->isCustom() ? QColor(Qt::black) : QColor(Qt::darkGray)); ui->executablesListBox->addItem(newItem); } @@ -92,17 +91,16 @@ void EditExecutablesDialog::resetInput() void EditExecutablesDialog::saveExecutable() { + Executable::SettableFlags flags; + if (ui->closeCheckBox->isChecked()) flags |= Executable::CloseOnExecution; + if (ui->useAppIconCheckBox->isChecked()) flags |= Executable::UseApplicationIcon; m_ExecutablesList.addExecutable(ui->titleEdit->text(), QDir::fromNativeSeparators(ui->binaryEdit->text()), ui->argumentsEdit->text(), QDir::fromNativeSeparators(ui->workingDirEdit->text()), - (ui->closeCheckBox->checkState() == Qt::Checked) ? - ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE - : ExecutableInfo::CloseMOStyle::DEFAULT_STAY, ui->overwriteAppIDBox->isChecked() ? ui->appIDOverwriteEdit->text() : "", - ui->useAppIconCheckBox->isChecked() ? - Executable::UseApplicationIcon : Executable::Flags()); + flags); } @@ -214,7 +212,7 @@ bool EditExecutablesDialog::executableChanged() || selectedExecutable.m_SteamAppID != ui->appIDOverwriteEdit->text() || selectedExecutable.m_WorkingDirectory != QDir::fromNativeSeparators(ui->workingDirEdit->text()) || selectedExecutable.m_BinaryInfo.absoluteFilePath() != QDir::fromNativeSeparators(ui->binaryEdit->text()) - || (selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE) != ui->closeCheckBox->isChecked() + || selectedExecutable.closeOnExecution() != ui->closeCheckBox->isChecked() || selectedExecutable.usesOwnIcon() != ui->useAppIconCheckBox->isChecked(); } else { return false; @@ -281,14 +279,7 @@ void EditExecutablesDialog::on_executablesListBox_clicked(const QModelIndex &cur ui->binaryEdit->setText(QDir::toNativeSeparators(selectedExecutable.m_BinaryInfo.absoluteFilePath())); ui->argumentsEdit->setText(selectedExecutable.m_Arguments); ui->workingDirEdit->setText(QDir::toNativeSeparators(selectedExecutable.m_WorkingDirectory)); - ui->closeCheckBox->setChecked(selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE); - if (selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::NEVER_CLOSE) { - ui->closeCheckBox->setEnabled(false); - ui->closeCheckBox->setToolTip(tr("MO must be kept running or this application will not work correctly.")); - } else { - ui->closeCheckBox->setEnabled(true); - ui->closeCheckBox->setToolTip(tr("If checked, MO will be closed once the specified executable is run.")); - } + ui->closeCheckBox->setChecked(selectedExecutable.closeOnExecution()); ui->removeButton->setEnabled(selectedExecutable.isCustom()); ui->overwriteAppIDBox->setChecked(!selectedExecutable.m_SteamAppID.isEmpty()); if (!selectedExecutable.m_SteamAppID.isEmpty()) { diff --git a/src/executableslist.cpp b/src/executableslist.cpp index 5a870009..ffb87703 100644 --- a/src/executableslist.cpp +++ b/src/executableslist.cpp @@ -48,7 +48,6 @@ void ExecutablesList::init(IPluginGame *game) info.binary().absoluteFilePath(), info.arguments().join(" "), info.workingDirectory().absolutePath(), - info.closeMO(), info.steamAppID()); } } @@ -133,19 +132,22 @@ void ExecutablesList::addExecutable(const QString &title, const QString &executableName, const QString &arguments, const QString &workingDirectory, - ExecutableInfo::CloseMOStyle closeMO, const QString &steamAppID, - Executable::Flags flags) + Executable::SettableFlags settable, + bool set_other, + Executable::OtherFlags other) { QFileInfo file(executableName); auto existingExe = findExe(title); if (existingExe != m_Executables.end()) { existingExe->m_Title = title; - existingExe->m_CloseMO = closeMO; - existingExe->m_Flags = flags; - if (flags & Executable::CustomExecutable) { - // for pre-configured executables don't overwrite settings we didn't store + existingExe->m_SettableFlags = settable; + if (set_other) { + existingExe->m_OtherFlags = other; + } + // for pre-configured executables don't overwrite settings we didn't store + if (existingExe->isCustom()) { existingExe->m_BinaryInfo = file; existingExe->m_Arguments = arguments; existingExe->m_WorkingDirectory = workingDirectory; @@ -154,12 +156,12 @@ void ExecutablesList::addExecutable(const QString &title, } else { Executable newExe; newExe.m_Title = title; - newExe.m_CloseMO = closeMO; newExe.m_BinaryInfo = file; newExe.m_Arguments = arguments; newExe.m_WorkingDirectory = workingDirectory; newExe.m_SteamAppID = steamAppID; - newExe.m_Flags = Executable::CustomExecutable | flags; + newExe.m_SettableFlags = settable; + newExe.m_OtherFlags = Executable::CustomExecutable | other; m_Executables.push_back(newExe); } } @@ -176,20 +178,22 @@ void ExecutablesList::remove(const QString &title) } -void ExecutablesList::addExecutableInternal(const QString &title, const QString &executableName, - const QString &arguments, const QString &workingDirectory, - ExecutableInfo::CloseMOStyle closeMO, const QString &steamAppID) +void ExecutablesList::addExecutableInternal(const QString &title, + const QString &executableName, + const QString &arguments, + const QString &workingDirectory, + const QString &steamAppID) { QFileInfo file(executableName); if (file.exists()) { Executable newExe; - newExe.m_CloseMO = closeMO; newExe.m_BinaryInfo = file; newExe.m_Title = title; newExe.m_Arguments = arguments; newExe.m_WorkingDirectory = workingDirectory; newExe.m_SteamAppID = steamAppID; - newExe.m_Flags = 0; + newExe.m_SettableFlags = 0; + newExe.m_OtherFlags = 0; m_Executables.push_back(newExe); } } @@ -197,8 +201,9 @@ void ExecutablesList::addExecutableInternal(const QString &title, const QString void Executable::showOnToolbar(bool state) { - if (state) - m_Flags |= ShowInToolbar; - else - m_Flags ^= ShowInToolbar; + if (state) { + m_OtherFlags |= ShowInToolbar; + } else { + m_OtherFlags &= ~ShowInToolbar; + } } diff --git a/src/executableslist.h b/src/executableslist.h index 907b37aa..4aba4ce2 100644 --- a/src/executableslist.h +++ b/src/executableslist.h @@ -35,27 +35,38 @@ struct Executable { QString m_Title; QFileInfo m_BinaryInfo; QString m_Arguments; - MOBase::ExecutableInfo::CloseMOStyle m_CloseMO; QString m_SteamAppID; QString m_WorkingDirectory; - enum Flag { + //These flags are set by other parts of the system and can't be + //changed when modifying from the custom executable window + enum OtherFlag__ { CustomExecutable = 0x01, - ShowInToolbar = 0x02, - UseApplicationIcon = 0x04 + ShowInToolbar = 0x02 }; + Q_DECLARE_FLAGS(OtherFlags, OtherFlag__) - Q_DECLARE_FLAGS(Flags, Flag) + OtherFlags m_OtherFlags; - Flags m_Flags; + //These flags can be changed from the Custom Executable window. + enum SettableFlag__ { + CloseOnExecution = 0x01, + UseApplicationIcon = 0x02 + }; + Q_DECLARE_FLAGS(SettableFlags, SettableFlag__) + + SettableFlags m_SettableFlags; - bool isCustom() const { return m_Flags.testFlag(CustomExecutable); } + bool isCustom() const { return m_OtherFlags.testFlag(CustomExecutable); } - bool shownOnToolbar() const { return m_Flags.testFlag(ShowInToolbar); } + bool shownOnToolbar() const { return m_OtherFlags.testFlag(ShowInToolbar); } void showOnToolbar(bool state); - bool usesOwnIcon() const { return m_Flags.testFlag(UseApplicationIcon); } + bool usesOwnIcon() const { return m_SettableFlags.testFlag(UseApplicationIcon); } + + bool closeOnExecution() const { return m_SettableFlags.testFlag(CloseOnExecution); } + }; @@ -138,9 +149,24 @@ public: const QString &executableName, const QString &arguments, const QString &workingDirectory, - MOBase::ExecutableInfo::CloseMOStyle closeMO, const QString &steamAppID, - Executable::Flags flags); + Executable::SettableFlags settable + ) + { + addExecutable(title, executableName, arguments, workingDirectory, steamAppID, settable, false, 0); + } + + void addExecutable(const QString &title, + const QString &executableName, + const QString &arguments, + const QString &workingDirectory, + const QString &steamAppID, + Executable::SettableFlags settable, + Executable::OtherFlags other + ) + { + addExecutable(title, executableName, arguments, workingDirectory, steamAppID, settable, true, other); + } /** * @brief remove the executable with the specified file name. This needs to be an absolute file path @@ -177,8 +203,18 @@ private: std::vector::iterator findExe(const QString &title); + void addExecutable(const QString &title, + const QString &executableName, + const QString &arguments, + const QString &workingDirectory, + const QString &steamAppID, + Executable::SettableFlags settable, + bool set_other, + Executable::OtherFlags other + ); + void addExecutableInternal(const QString &title, const QString &executableName, const QString &arguments, - const QString &workingDirectory, MOBase::ExecutableInfo::CloseMOStyle closeMO, + const QString &workingDirectory, const QString &steamAppID); private: @@ -187,6 +223,7 @@ private: }; -Q_DECLARE_OPERATORS_FOR_FLAGS(Executable::Flags) +Q_DECLARE_OPERATORS_FOR_FLAGS(Executable::OtherFlags) +Q_DECLARE_OPERATORS_FOR_FLAGS(Executable::SettableFlags) #endif // EXECUTABLESLIST_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index dda0470e..f0e576fe 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -959,7 +959,7 @@ void MainWindow::startExeAction() selectedExecutable.m_Arguments, selectedExecutable.m_WorkingDirectory.length() != 0 ? selectedExecutable.m_WorkingDirectory : selectedExecutable.m_BinaryInfo.absolutePath(), - selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE, + selectedExecutable.closeOnExecution(), selectedExecutable.m_SteamAppID); } else { qCritical("not an action?"); @@ -1619,7 +1619,7 @@ void MainWindow::on_startButton_clicked() selectedExecutable.m_Arguments, selectedExecutable.m_WorkingDirectory.length() != 0 ? selectedExecutable.m_WorkingDirectory : selectedExecutable.m_BinaryInfo.absolutePath(), - selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE, + selectedExecutable.closeOnExecution(), selectedExecutable.m_SteamAppID); } @@ -1731,7 +1731,7 @@ void MainWindow::on_executablesListBox_currentIndexChanged(int index) if (executablesList->isEnabled()) { //I think the 2nd test is impossible - if ((index == 0) || (index >= static_cast(m_OrganizerCore.executablesList()->size()))) { + if ((index == 0) || (index > static_cast(m_OrganizerCore.executablesList()->size()))) { if (modifyExecutablesDialog()) { setExecutableIndex(previousIndex); } @@ -3545,9 +3545,8 @@ void MainWindow::addAsExecutable() binaryInfo.absoluteFilePath(), arguments, targetInfo.absolutePath(), - ExecutableInfo::CloseMOStyle::DEFAULT_STAY, QString(), - Executable::CustomExecutable); + Executable::SettableFlags()); refreshExecutablesList(); } } break; diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 1a81d33b..a4746ddd 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -229,7 +229,7 @@ QSettings::Status OrganizerCore::storeSettings(const QString &fileName) settings.setValue("binary", item.m_BinaryInfo.absoluteFilePath()); settings.setValue("arguments", item.m_Arguments); settings.setValue("workingDirectory", item.m_WorkingDirectory); - settings.setValue("closeOnStart", item.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE); + settings.setValue("closeOnStart", item.closeOnExecution()); settings.setValue("steamAppID", item.m_SteamAppID); } } @@ -327,22 +327,22 @@ void OrganizerCore::updateExecutablesList(QSettings &settings) int numCustomExecutables = settings.beginReadArray("customExecutables"); for (int i = 0; i < numCustomExecutables; ++i) { settings.setArrayIndex(i); - ExecutableInfo::CloseMOStyle closeMO = - settings.value("closeOnStart").toBool() ? ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE - : ExecutableInfo::CloseMOStyle::DEFAULT_STAY; - Executable::Flags flags; - if (settings.value("custom", true).toBool()) flags |= Executable::CustomExecutable; - if (settings.value("toolbar", false).toBool()) flags |= Executable::ShowInToolbar; - if (settings.value("ownicon", false).toBool()) flags |= Executable::UseApplicationIcon; + Executable::OtherFlags other; + if (settings.value("custom", true).toBool()) other |= Executable::CustomExecutable; + if (settings.value("toolbar", false).toBool()) other |= Executable::ShowInToolbar; + + Executable::SettableFlags settable; + if (settings.value("closeOnStart", false).toBool()) settable |= Executable::CloseOnExecution; + if (settings.value("ownicon", false).toBool()) settable |= Executable::UseApplicationIcon; m_ExecutablesList.addExecutable(settings.value("title").toString(), settings.value("binary").toString(), settings.value("arguments").toString(), settings.value("workingDirectory", "").toString(), - closeMO, settings.value("steamAppID", "").toString(), - flags); + settable, + other); } settings.endArray(); -- cgit v1.3.1