From e4dcdb01ac2e3f99fea76b21e1acfd21d0de89c7 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 20 Jul 2019 10:45:59 -0400 Subject: split workarounds tab --- src/settingsdialogworkarounds.cpp | 108 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/settingsdialogworkarounds.cpp (limited to 'src/settingsdialogworkarounds.cpp') diff --git a/src/settingsdialogworkarounds.cpp b/src/settingsdialogworkarounds.cpp new file mode 100644 index 00000000..4cca5fd4 --- /dev/null +++ b/src/settingsdialogworkarounds.cpp @@ -0,0 +1,108 @@ +#include "settingsdialogworkarounds.h" +#include "ui_settingsdialog.h" +#include "helper.h" +#include + +WorkaroundsSettingsTab::WorkaroundsSettingsTab(Settings *m_parent, SettingsDialog &m_dialog) + : SettingsTab(m_parent, m_dialog) +{ + ui->appIDEdit->setText(m_parent->getSteamAppID()); + + LoadMechanism::EMechanism mechanismID = m_parent->getLoadMechanism(); + int index = 0; + + if (m_parent->loadMechanism().isDirectLoadingSupported()) { + ui->mechanismBox->addItem(QObject::tr("Mod Organizer"), LoadMechanism::LOAD_MODORGANIZER); + if (mechanismID == LoadMechanism::LOAD_MODORGANIZER) { + index = ui->mechanismBox->count() - 1; + } + } + + if (m_parent->loadMechanism().isScriptExtenderSupported()) { + ui->mechanismBox->addItem(QObject::tr("Script Extender"), LoadMechanism::LOAD_SCRIPTEXTENDER); + if (mechanismID == LoadMechanism::LOAD_SCRIPTEXTENDER) { + index = ui->mechanismBox->count() - 1; + } + } + + if (m_parent->loadMechanism().isProxyDLLSupported()) { + ui->mechanismBox->addItem(QObject::tr("Proxy DLL"), LoadMechanism::LOAD_PROXYDLL); + if (mechanismID == LoadMechanism::LOAD_PROXYDLL) { + index = ui->mechanismBox->count() - 1; + } + } + + ui->mechanismBox->setCurrentIndex(index); + + ui->hideUncheckedBox->setChecked(m_parent->hideUncheckedPlugins()); + ui->forceEnableBox->setChecked(m_parent->forceEnableCoreFiles()); + ui->displayForeignBox->setChecked(m_parent->displayForeign()); + ui->lockGUIBox->setChecked(m_parent->lockGUI()); + ui->enableArchiveParsingBox->setChecked(m_parent->archiveParsing()); + + ui->resetGeometryBtn->setChecked(m_parent->directInterface().value("reset_geometry", false).toBool()); + + setExecutableBlacklist(m_parent->executablesBlacklist()); + + QObject::connect(ui->bsaDateBtn, &QPushButton::clicked, [&]{ on_bsaDateBtn_clicked(); }); + QObject::connect(ui->execBlacklistBtn, &QPushButton::clicked, [&]{ on_execBlacklistBtn_clicked(); }); + QObject::connect(ui->resetGeometryBtn, &QPushButton::clicked, [&]{ on_resetGeometryBtn_clicked(); }); +} + +void WorkaroundsSettingsTab::update() +{ + if (ui->appIDEdit->text() != m_parent->gamePlugin()->steamAPPId()) { + m_Settings.setValue("Settings/app_id", ui->appIDEdit->text()); + } else { + m_Settings.remove("Settings/app_id"); + } + m_Settings.setValue("Settings/load_mechanism", ui->mechanismBox->itemData(ui->mechanismBox->currentIndex()).toInt()); + m_Settings.setValue("Settings/hide_unchecked_plugins", ui->hideUncheckedBox->isChecked()); + m_Settings.setValue("Settings/force_enable_core_files", ui->forceEnableBox->isChecked()); + m_Settings.setValue("Settings/display_foreign", ui->displayForeignBox->isChecked()); + m_Settings.setValue("Settings/lock_gui", ui->lockGUIBox->isChecked()); + m_Settings.setValue("Settings/archive_parsing_experimental", ui->enableArchiveParsingBox->isChecked()); + + m_Settings.setValue("Settings/executable_blacklist", getExecutableBlacklist()); +} + +void WorkaroundsSettingsTab::on_execBlacklistBtn_clicked() +{ + bool ok = false; + QString result = QInputDialog::getMultiLineText( + parentWidget(), + QObject::tr("Executables Blacklist"), + QObject::tr("Enter one executable per line to be blacklisted from the virtual file system.\n" + "Mods and other virtualized files will not be visible to these executables and\n" + "any executables launched by them.\n\n" + "Example:\n" + " Chrome.exe\n" + " Firefox.exe"), + m_ExecutableBlacklist.split(";").join("\n"), + &ok + ); + if (ok) { + QStringList blacklist; + for (auto exec : result.split("\n")) { + if (exec.trimmed().endsWith(".exe", Qt::CaseInsensitive)) { + blacklist << exec.trimmed(); + } + } + m_ExecutableBlacklist = blacklist.join(";"); + } +} + +void WorkaroundsSettingsTab::on_bsaDateBtn_clicked() +{ + const auto* game = qApp->property("managed_game").value(); + QDir dir = game->dataDirectory(); + + Helper::backdateBSAs(qApp->applicationDirPath().toStdWString(), + dir.absolutePath().toStdWString()); +} + +void WorkaroundsSettingsTab::on_resetGeometryBtn_clicked() +{ + m_dialog.m_GeometriesReset = true; + ui->resetGeometryBtn->setChecked(true); +} -- cgit v1.3.1 From ee43c405987d646fd15ad17cf1f1ffe2db45bc51 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 20 Jul 2019 12:03:05 -0400 Subject: removed obsolete load mechanisms --- src/loadmechanism.cpp | 272 +------------------------------------- src/loadmechanism.h | 63 +-------- src/settings.cpp | 19 ++- src/settings.h | 8 +- src/settingsdialog.cpp | 2 +- src/settingsdialogworkarounds.cpp | 14 -- 6 files changed, 23 insertions(+), 355 deletions(-) (limited to 'src/settingsdialogworkarounds.cpp') diff --git a/src/loadmechanism.cpp b/src/loadmechanism.cpp index 2d01562d..06e9f201 100644 --- a/src/loadmechanism.cpp +++ b/src/loadmechanism.cpp @@ -32,286 +32,20 @@ along with Mod Organizer. If not, see . #include #include - using namespace MOBase; using namespace MOShared; - LoadMechanism::LoadMechanism() : m_SelectedMechanism(LOAD_MODORGANIZER) { } -void LoadMechanism::writeHintFile(const QDir &targetDirectory) -{ - QString hintFilePath = targetDirectory.absoluteFilePath("mo_path.txt"); - QFile hintFile(hintFilePath); - if (hintFile.exists()) { - hintFile.remove(); - } - if (!hintFile.open(QIODevice::WriteOnly)) { - throw MyException(QObject::tr("failed to open %1: %2").arg(hintFilePath).arg(hintFile.errorString())); - } - hintFile.write(qApp->applicationDirPath().toUtf8().constData()); - hintFile.close(); -} - - -void LoadMechanism::removeHintFile(QDir targetDirectory) -{ - targetDirectory.remove("mo_path.txt"); -} - - bool LoadMechanism::isDirectLoadingSupported() const { - //FIXME: Seriously? isn't there a 'do i need steam' thing? - IPluginGame const *game = qApp->property("managed_game").value(); - if (game->gameName().compare("oblivion", Qt::CaseInsensitive) == 0) { - // oblivion can be loaded directly if it's not the steam variant - return !game->gameDirectory().exists("steam_api.dll"); - } else { - // all other games work afaik - return true; - } -} - -bool LoadMechanism::isScriptExtenderSupported() const -{ - IPluginGame const *game = qApp->property("managed_game").value(); - ScriptExtender *extender = game->feature(); - - // test if there even is an extender for the managed game and if so whether it's installed - return extender != nullptr && extender->isInstalled(); -} - -bool LoadMechanism::isProxyDLLSupported() const -{ - // using steam_api.dll as the proxy is way too game specific as many games will have different - // versions of that dll. - // plus: the proxy dll hasn't been working for at least the whole 1.12.x versions of MO and - // noone reported it so why maintain an unused feature? - return false; -/* IPluginGame const *game = qApp->property("managed_game").value(); - return game->gameDirectory().exists(QString::fromStdWString(AppConfig::proxyDLLTarget()));*/ -} - - -bool LoadMechanism::hashIdentical(const QString &fileNameLHS, const QString &fileNameRHS) -{ - QFile fileLHS(fileNameLHS); - if (!fileLHS.open(QIODevice::ReadOnly)) { - throw MyException(QObject::tr("file not found: %1").arg(qUtf8Printable(fileNameLHS))); - } - QByteArray dataLHS = fileLHS.readAll(); - QByteArray hashLHS = QCryptographicHash::hash(dataLHS, QCryptographicHash::Md5); - - fileLHS.close(); - - QFile fileRHS(fileNameRHS); - if (!fileRHS.open(QIODevice::ReadOnly)) { - throw MyException(QObject::tr("file not found: %1").arg(qUtf8Printable(fileNameRHS))); - } - QByteArray dataRHS = fileRHS.readAll(); - QByteArray hashRHS = QCryptographicHash::hash(dataRHS, QCryptographicHash::Md5); - - fileRHS.close(); - - return hashLHS == hashRHS; + return true; } - -void LoadMechanism::deactivateScriptExtender() +void LoadMechanism::activate(EMechanism) { - try { - IPluginGame const *game = qApp->property("managed_game").value(); - ScriptExtender *extender = game->feature(); - if (extender == nullptr) { - return; - } - - QDir pluginsDir(game->gameDirectory().absolutePath() + "/data/" + extender->PluginPath()); - -#pragma message("implement this for usvfs") - - QString vfsDLLName = ""; - if (extender->getArch() == IMAGE_FILE_MACHINE_I386) { - vfsDLLName = ToQString(AppConfig::vfs32DLLName()); - } - else if (extender->getArch() == IMAGE_FILE_MACHINE_AMD64) - { - vfsDLLName = ToQString(AppConfig::vfs64DLLName()); - } - log::debug("USVFS DLL Name: {}", vfsDLLName); - if (vfsDLLName != "") { - if (QFile(pluginsDir.absoluteFilePath(vfsDLLName)).exists()) { - // remove dll from SE plugins directory - if (!pluginsDir.remove(vfsDLLName)) { - throw MyException(QObject::tr("Failed to delete %1").arg(pluginsDir.absoluteFilePath(vfsDLLName))); - } - } - } - - removeHintFile(pluginsDir); - } catch (const std::exception &e) { - QMessageBox::critical(nullptr, QObject::tr("Failed to deactivate script extender loading"), e.what()); - } + // no-op } - - -void LoadMechanism::deactivateProxyDLL() -{ - try { - IPluginGame const *game = qApp->property("managed_game").value(); - - QString targetPath = game->gameDirectory().absoluteFilePath(QString::fromStdWString(AppConfig::proxyDLLTarget())); - - QFile targetDLL(targetPath); - if (targetDLL.exists()) { - QString origFile = game->gameDirectory().absoluteFilePath(QString::fromStdWString(AppConfig::proxyDLLOrig())); - // determine if a proxy-dll is installed - // this is a very crude way of making this decision but it should be good enough - if ((targetDLL.size() < 24576) && (QFile(origFile).exists())) { - // remove proxy-dll - if (!targetDLL.remove()) { - throw MyException(QObject::tr("Failed to remove %1: %2").arg(targetPath).arg(targetDLL.errorString())); - } else if (!QFile::rename(origFile, targetPath)) { - throw MyException(QObject::tr("Failed to rename %1 to %2").arg(origFile, targetPath)); - } - } - } - - removeHintFile(game->gameDirectory()); - } catch (const std::exception &e) { - QMessageBox::critical(nullptr, QObject::tr("Failed to deactivate proxy-dll loading"), e.what()); - } -} - - -void LoadMechanism::activateScriptExtender() -{ - try { - IPluginGame const *game = qApp->property("managed_game").value(); - ScriptExtender *extender = game->feature(); - if (extender == nullptr) { - return; - } - - QDir pluginsDir(game->gameDirectory().absolutePath() + "/data/" + extender->PluginPath()); - - if (!pluginsDir.exists()) { - pluginsDir.mkpath("."); - } - -#pragma message("implement this for usvfs") - std::wstring vfsDLL = L""; - if (extender->getArch() == IMAGE_FILE_MACHINE_I386) { - vfsDLL = AppConfig::vfs32DLLName(); - } - else if (extender->getArch() == IMAGE_FILE_MACHINE_AMD64) - { - vfsDLL = AppConfig::vfs64DLLName(); - } - if (vfsDLL != L"") { - QString targetPath = pluginsDir.absoluteFilePath(ToQString(vfsDLL)); - QString vfsDLLPath = qApp->applicationDirPath() + "/" + QString::fromStdWString(vfsDLL); - - log::debug("DLL USVFS Target Path: {}", targetPath); - log::debug("DLL USVFS VFS DLL Path: {}", vfsDLLPath); - - QFile dllFile(targetPath); - - if (dllFile.exists()) { - // may be outdated - if (!hashIdentical(targetPath, vfsDLLPath)) { - dllFile.remove(); - } - } - - if (!dllFile.exists()) { - // install dll to SE plugins - if (!QFile::copy(vfsDLLPath, targetPath)) { - throw MyException(QObject::tr("Failed to copy %1 to %2").arg(vfsDLLPath, targetPath)); - } - } - } - writeHintFile(pluginsDir); - } catch (const std::exception &e) { - QMessageBox::critical(nullptr, QObject::tr("Failed to set up script extender loading"), e.what()); - } -} - - -void LoadMechanism::activateProxyDLL() -{ - try { - IPluginGame const *game = qApp->property("managed_game").value(); - - QString targetPath = game->gameDirectory().absoluteFilePath(QString::fromStdWString(AppConfig::proxyDLLTarget())); - - QFile targetDLL(targetPath); - if (!targetDLL.exists()) { - return; - } - - QString sourcePath = qApp->applicationDirPath() + "/" + ToQString(AppConfig::proxyDLLSource()); - - // this is a very crude way of making this decision but it should be good enough - if (targetDLL.size() < 24576) { - // determine if a proxy-dll is already installed and if so, if it's the right one - if (!hashIdentical(targetPath, sourcePath)) { - // wrong proxy dll, probably outdated. delete and install the new one - if (!QFile::remove(targetPath)) { - throw MyException(QObject::tr("Failed to delete old proxy-dll %1").arg(targetPath)); - } - if (!QFile::copy(sourcePath, targetPath)) { - throw MyException(QObject::tr("Failed to copy %1 to %2").arg(sourcePath).arg(targetPath)); - } - } // otherwise the proxy-dll is already the right one - } else { - // no proxy dll installed yet. move the original and insert proxy-dll - - QString origFile = game->gameDirectory().absoluteFilePath(QString::fromStdWString(AppConfig::proxyDLLOrig())); - - if (QFile(origFile).exists()) { - // orig-file exists. this may happen if the steam-api was updated or the user messed with the - // dlls. - if (!QFile::remove(origFile)) { - throw MyException(QObject::tr("Failed to overwrite %1").arg(origFile)); - } - } - if (!QFile::rename(targetPath, origFile)) { - throw MyException(QObject::tr("Failed to rename %1 to %2").arg(targetPath).arg(origFile)); - } - if (!QFile::copy(sourcePath, targetPath)) { - throw MyException(QObject::tr("Failed to copy %1 to %2").arg(sourcePath).arg(targetPath)); - } - } - writeHintFile(game->gameDirectory()); - } catch (const std::exception &e) { - QMessageBox::critical(nullptr, QObject::tr("Failed to set up proxy-dll loading"), e.what()); - } -} - - -void LoadMechanism::activate(EMechanism mechanism) -{ - switch (mechanism) { - case LOAD_MODORGANIZER: { - log::debug("Load Mechanism: Mod Organizer"); - deactivateProxyDLL(); - deactivateScriptExtender(); - } break; - case LOAD_SCRIPTEXTENDER: { - log::debug("Load Mechanism: ScriptExtender"); - deactivateProxyDLL(); - activateScriptExtender(); - } break; - case LOAD_PROXYDLL: { - log::debug("Load Mechanism: Proxy DLL"); - deactivateScriptExtender(); - activateProxyDLL(); - } break; - } -} - diff --git a/src/loadmechanism.h b/src/loadmechanism.h index 51fefaf9..49eb0c52 100644 --- a/src/loadmechanism.h +++ b/src/loadmechanism.h @@ -27,33 +27,14 @@ along with Mod Organizer. If not, see . /** * @brief manages the various load mechanisms supported by Mod Organizer - * the load mechanisms is the means by which the mo-dll is injected into the target - * process. The default mode "mod organizer" requires the target process to be started - * from inside mod organizer. In certain cases (oblivion steam edition) this is not - * possible since the game can then only be started from steam. - * "Script Extender" is an alternative load mechanism that uses a script extender (obse, - * fose, nvse or skse) to load MO. This is reliable but prevents se plugins installed - * through MO from working. - * "Proxy DLL" replaces a dll belonging to the game by a proxy that will load MO and then - * chain-load the original dll. This currently only works with steam-versions of games and - * is intended as a last resort solution. **/ class LoadMechanism { public: - enum EMechanism { LOAD_MODORGANIZER = 0, - LOAD_SCRIPTEXTENDER, - LOAD_PROXYDLL }; -public: - - /** - * @brief constructor - * - **/ LoadMechanism(); /** @@ -66,54 +47,12 @@ public: /** * @brief test whether the "Mod Organizer" load mechanism is supported for the current game * - * @return true if the load mechanism is supported + * @return true **/ bool isDirectLoadingSupported() const; - /** - * @brief test whether the "Script Extender" load mechanism is supported for the current game - * - * @return true if the load mechanism is supported - **/ - bool isScriptExtenderSupported() const; - - /** - * @brief test whether the "Proxy DLL" load mechanism is supported for the current game - * - * @return true if the load mechanism is supported - **/ - bool isProxyDLLSupported() const; - -private: - - // write a hint file that is required for certain loading mechanisms for the dll to find - // the mod organizer installation - void writeHintFile(const QDir &targetDirectory); - - // remove the hint file if it exists. does nothing if the file doesn't exist - void removeHintFile(QDir targetDirectory); - - // compare the two files by md5-hash, returns true if they are identical - bool hashIdentical(const QString &fileNameLHS, const QString &fileNameRHS); - - // deactivate loading through script extender. does nothing if se-loading wasn't active - void deactivateScriptExtender(); - - // deactivate loading through proxy-dll. does nothing if se-loading wasn't active - void deactivateProxyDLL(); - - // activate loading through script extender. does nothing if already active. updates - // the dll if necessary - void activateScriptExtender(); - - // activate loading through proxy-dll. does nothing if already active. updates - // the dll if necessary - void activateProxyDLL(); - private: - EMechanism m_SelectedMechanism; - }; diff --git a/src/settings.cpp b/src/settings.cpp index e7a853a2..77db6918 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -429,12 +429,21 @@ void Settings::setSteamLogin(QString username, QString password) LoadMechanism::EMechanism Settings::getLoadMechanism() const { - switch (m_Settings.value("Settings/load_mechanism").toInt()) { - case LoadMechanism::LOAD_MODORGANIZER: return LoadMechanism::LOAD_MODORGANIZER; - case LoadMechanism::LOAD_SCRIPTEXTENDER: return LoadMechanism::LOAD_SCRIPTEXTENDER; - case LoadMechanism::LOAD_PROXYDLL: return LoadMechanism::LOAD_PROXYDLL; + const auto i = m_Settings.value("Settings/load_mechanism").toInt(); + + switch (i) + { + case LoadMechanism::LOAD_MODORGANIZER: + return LoadMechanism::LOAD_MODORGANIZER; + + default: + qCritical().nospace().noquote() + << "invalid load mechanism " << i << ", reverting to modorganizer"; + + m_Settings.setValue("Settings/load_mechanism", LoadMechanism::LOAD_MODORGANIZER); + + return LoadMechanism::LOAD_MODORGANIZER; } - throw std::runtime_error("invalid load mechanism"); } diff --git a/src/settings.h b/src/settings.h index b20e78d0..63718089 100644 --- a/src/settings.h +++ b/src/settings.h @@ -367,14 +367,14 @@ public: static QColor getIdealTextColor(const QColor& rBackgroundColor); - // temp - QSettings& settingsRef() { return m_Settings; } MOBase::IPluginGame const *gamePlugin() { return m_GamePlugin; } + const LoadMechanism& loadMechanism() const { return m_LoadMechanism; } + + // temp QMap m_PluginSettings; QMap m_PluginDescriptions; QSet m_PluginBlacklist; void writePluginBlacklist(); - const LoadMechanism& loadMechanism() const { return m_LoadMechanism; } public slots: void managedGameChanged(MOBase::IPluginGame const *gamePlugin); @@ -386,7 +386,7 @@ signals: private: static Settings *s_Instance; MOBase::IPluginGame const *m_GamePlugin; - QSettings m_Settings; + mutable QSettings m_Settings; LoadMechanism m_LoadMechanism; std::vector m_Plugins; diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index e008086a..d870c192 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -169,7 +169,7 @@ bool SettingsDialog::getApiKeyChanged() SettingsTab::SettingsTab(Settings *m_parent, SettingsDialog &m_dialog) : m_parent(m_parent) - , m_Settings(m_parent->settingsRef()) + , m_Settings(m_parent->directInterface()) , m_dialog(m_dialog) , ui(m_dialog.ui) { diff --git a/src/settingsdialogworkarounds.cpp b/src/settingsdialogworkarounds.cpp index 4cca5fd4..9ac46ac1 100644 --- a/src/settingsdialogworkarounds.cpp +++ b/src/settingsdialogworkarounds.cpp @@ -18,20 +18,6 @@ WorkaroundsSettingsTab::WorkaroundsSettingsTab(Settings *m_parent, SettingsDialo } } - if (m_parent->loadMechanism().isScriptExtenderSupported()) { - ui->mechanismBox->addItem(QObject::tr("Script Extender"), LoadMechanism::LOAD_SCRIPTEXTENDER); - if (mechanismID == LoadMechanism::LOAD_SCRIPTEXTENDER) { - index = ui->mechanismBox->count() - 1; - } - } - - if (m_parent->loadMechanism().isProxyDLLSupported()) { - ui->mechanismBox->addItem(QObject::tr("Proxy DLL"), LoadMechanism::LOAD_PROXYDLL); - if (mechanismID == LoadMechanism::LOAD_PROXYDLL) { - index = ui->mechanismBox->count() - 1; - } - } - ui->mechanismBox->setCurrentIndex(index); ui->hideUncheckedBox->setChecked(m_parent->hideUncheckedPlugins()); -- cgit v1.3.1