From c603681115b6071f241f6931685d36a92b6403f8 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 19 Sep 2019 10:07:52 -0400 Subject: moved helper stuff to spawn so it can reuse error handling removed unused helper::init() removed logging when deleting a credential that doesn't exist, happens all the time --- src/settingsdialogworkarounds.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/settingsdialogworkarounds.cpp') diff --git a/src/settingsdialogworkarounds.cpp b/src/settingsdialogworkarounds.cpp index 4d811e40..f89b021c 100644 --- a/src/settingsdialogworkarounds.cpp +++ b/src/settingsdialogworkarounds.cpp @@ -83,7 +83,7 @@ void WorkaroundsSettingsTab::on_bsaDateBtn_clicked() const auto* game = qApp->property("managed_game").value(); QDir dir = game->dataDirectory(); - Helper::backdateBSAs(qApp->applicationDirPath().toStdWString(), + helper::backdateBSAs(qApp->applicationDirPath().toStdWString(), dir.absolutePath().toStdWString()); } -- cgit v1.3.1 From c50722100c485d2945082d573158a7083efe2f23 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 19 Sep 2019 10:11:56 -0400 Subject: removed helper.h and helper.cpp, merged into spawn --- src/CMakeLists.txt | 3 --- src/helper.cpp | 20 -------------------- src/helper.h | 26 -------------------------- src/main.cpp | 1 - src/organizercore.cpp | 1 - src/settingsdialogworkarounds.cpp | 2 +- src/spawn.cpp | 1 - 7 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 src/helper.cpp delete mode 100644 src/helper.h (limited to 'src/settingsdialogworkarounds.cpp') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 60822834..7c29ff48 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -87,7 +87,6 @@ SET(organizer_SRCS waitingonclosedialog.cpp loadmechanism.cpp installationmanager.cpp - helper.cpp filedialogmemory.cpp executableslist.cpp editexecutablesdialog.cpp @@ -208,7 +207,6 @@ SET(organizer_HDRS waitingonclosedialog.h loadmechanism.h installationmanager.h - helper.h filedialogmemory.h executableslist.h editexecutablesdialog.h @@ -464,7 +462,6 @@ set(utilities csvbuilder shared/error_report eventfilter - helper shared/leaktrace persistentcookiejar serverinfo diff --git a/src/helper.cpp b/src/helper.cpp deleted file mode 100644 index 24446cb8..00000000 --- a/src/helper.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright (C) 2012 Sebastian Herbord. All rights reserved. - -This file is part of Mod Organizer. - -Mod Organizer is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Mod Organizer is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Mod Organizer. If not, see . -*/ - -// moved to spawn.cpp diff --git a/src/helper.h b/src/helper.h deleted file mode 100644 index 335b8647..00000000 --- a/src/helper.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright (C) 2012 Sebastian Herbord. All rights reserved. - -This file is part of Mod Organizer. - -Mod Organizer is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Mod Organizer is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Mod Organizer. If not, see . -*/ - -#ifndef HELPER_H -#define HELPER_H - -// all helper code moved to spawn.h and spawn.cpp -#include "spawn.h" - -#endif // HELPER_H diff --git a/src/main.cpp b/src/main.cpp index 74b04970..ba988ae3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,7 +38,6 @@ along with Mod Organizer. If not, see . #include "executableslist.h" #include "singleinstance.h" #include "utility.h" -#include "helper.h" #include "loglist.h" #include "selectiondialog.h" #include "moapplication.h" diff --git a/src/organizercore.cpp b/src/organizercore.cpp index fbc9083b..0da5b604 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -33,7 +33,6 @@ #include "lockeddialog.h" #include "instancemanager.h" #include -#include "helper.h" #include "previewdialog.h" #include diff --git a/src/settingsdialogworkarounds.cpp b/src/settingsdialogworkarounds.cpp index f89b021c..ccbfcbfe 100644 --- a/src/settingsdialogworkarounds.cpp +++ b/src/settingsdialogworkarounds.cpp @@ -1,6 +1,6 @@ #include "settingsdialogworkarounds.h" #include "ui_settingsdialog.h" -#include "helper.h" +#include "spawn.h" #include WorkaroundsSettingsTab::WorkaroundsSettingsTab(Settings& s, SettingsDialog& d) diff --git a/src/spawn.cpp b/src/spawn.cpp index 6c524681..64766adf 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -33,7 +33,6 @@ along with Mod Organizer. If not, see . #include #include #include -#include "helper.h" #include #include #include -- cgit v1.3.1 From f92e2c376d36132a9676b30f0b08543f27a13064 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 19 Sep 2019 16:27:41 -0400 Subject: TaskDialog for restarting as admin for steam added a parent widget parameter to a bunch of places fixed paths still getting changed even if folders can't be created made private the member variables that were temporarily public during rework --- src/settingsdialog.cpp | 44 ++++++++++------ src/settingsdialog.h | 20 +++---- src/settingsdialoggeneral.cpp | 7 ++- src/settingsdialognexus.cpp | 14 ++--- src/settingsdialogpaths.cpp | 6 ++- src/settingsdialogworkarounds.cpp | 6 ++- src/spawn.cpp | 106 ++++++++++++++++++++------------------ src/spawn.h | 7 ++- 8 files changed, 121 insertions(+), 89 deletions(-) (limited to 'src/settingsdialogworkarounds.cpp') diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 1d3d4a39..8fb25b1c 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -33,8 +33,8 @@ SettingsDialog::SettingsDialog(PluginContainer *pluginContainer, Settings& setti : TutorableDialog("SettingsDialog", parent) , ui(new Ui::SettingsDialog) , m_settings(settings) - , m_PluginContainer(pluginContainer) - , m_keyChanged(false) + , m_pluginContainer(pluginContainer) + , m_restartNeeded(false) { ui->setupUi(this); @@ -47,6 +47,25 @@ SettingsDialog::SettingsDialog(PluginContainer *pluginContainer, Settings& setti m_tabs.push_back(std::unique_ptr(new WorkaroundsSettingsTab(settings, *this))); } +PluginContainer* SettingsDialog::pluginContainer() +{ + return m_pluginContainer; +} + +QWidget* SettingsDialog::parentWidgetForDialogs() +{ + if (isVisible()) { + return this; + } else { + return parentWidget(); + } +} + +void SettingsDialog::setRestartNeeded() +{ + m_restartNeeded = true; +} + int SettingsDialog::exec() { GeometrySaver gs(m_settings, this); @@ -68,13 +87,8 @@ int SettingsDialog::exec() } } - bool restartNeeded = false; - if (getApiKeyChanged()) { - restartNeeded = true; - } - - if (restartNeeded) { - if (QMessageBox::question(nullptr, + if (m_restartNeeded) { + if (QMessageBox::question(parentWidgetForDialogs(), tr("Restart Mod Organizer?"), tr("In order to finish configuration changes, MO must be restarted.\n" "Restart it now?"), @@ -111,7 +125,7 @@ void SettingsDialog::accept() QDir::fromNativeSeparators( Settings::instance().paths().mods(true))) && (QMessageBox::question( - nullptr, tr("Confirm"), + parentWidgetForDialogs(), tr("Confirm"), tr("Changing the mod directory affects all your profiles! " "Mods not present (or named differently) in the new location " "will be disabled in all profiles. " @@ -124,11 +138,6 @@ void SettingsDialog::accept() TutorableDialog::accept(); } -bool SettingsDialog::getApiKeyChanged() -{ - return m_keyChanged; -} - SettingsTab::SettingsTab(Settings& s, SettingsDialog& d) : ui(d.ui), m_settings(s), m_dialog(d) @@ -146,3 +155,8 @@ SettingsDialog& SettingsTab::dialog() { return m_dialog; } + +QWidget* SettingsTab::parentWidget() +{ + return m_dialog.parentWidgetForDialogs(); +} diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 6a99cb8d..e89da665 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -42,6 +42,7 @@ protected: Settings& settings(); SettingsDialog& dialog(); + QWidget* parentWidget(); private: Settings& m_settings; @@ -56,11 +57,12 @@ private: **/ class SettingsDialog : public MOBase::TutorableDialog { - Q_OBJECT + Q_OBJECT; + friend class SettingsTab; public: explicit SettingsDialog( - PluginContainer *pluginContainer, Settings& settings, QWidget *parent = 0); + PluginContainer* pluginContainer, Settings& settings, QWidget* parent = 0); ~SettingsDialog(); @@ -70,23 +72,21 @@ public: */ QString getColoredButtonStyleSheet() const; - // temp - Ui::SettingsDialog *ui; - bool m_keyChanged; - PluginContainer *m_PluginContainer; + PluginContainer* pluginContainer(); + QWidget* parentWidgetForDialogs(); + void setRestartNeeded(); int exec() override; public slots: virtual void accept(); -public: - bool getApiKeyChanged(); - private: Settings& m_settings; std::vector> m_tabs; - + Ui::SettingsDialog* ui; + bool m_restartNeeded; + PluginContainer* m_pluginContainer; }; #endif // SETTINGSDIALOG_H diff --git a/src/settingsdialoggeneral.cpp b/src/settingsdialoggeneral.cpp index 3f7ece38..8ecdcbb9 100644 --- a/src/settingsdialoggeneral.cpp +++ b/src/settingsdialoggeneral.cpp @@ -238,8 +238,11 @@ void GeneralSettingsTab::on_resetColorsBtn_clicked() void GeneralSettingsTab::on_resetDialogsButton_clicked() { - if (QMessageBox::question(&dialog(), QObject::tr("Confirm?"), - QObject::tr("This will make all dialogs show up again where you checked the \"Remember selection\"-box. Continue?"), + if (QMessageBox::question( + parentWidget(), QObject::tr("Confirm?"), + QObject::tr( + "This will reset all the choices you made to dialogs and make them all " + "visible again. Continue?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { resetDialogs(); } diff --git a/src/settingsdialognexus.cpp b/src/settingsdialognexus.cpp index 0b08f13f..826075c0 100644 --- a/src/settingsdialognexus.cpp +++ b/src/settingsdialognexus.cpp @@ -226,7 +226,7 @@ void NexusSettingsTab::on_nexusDisconnect_clicked() void NexusSettingsTab::on_clearCacheButton_clicked() { QDir(Settings::instance().paths().cache()).removeRecursively(); - NexusInterface::instance(dialog().m_PluginContainer)->clearCache(); + NexusInterface::instance(dialog().pluginContainer())->clearCache(); } void NexusSettingsTab::on_associateButton_clicked() @@ -238,7 +238,7 @@ void NexusSettingsTab::validateKey(const QString& key) { if (!m_nexusValidator) { m_nexusValidator.reset(new NexusKeyValidator( - *NexusInterface::instance(dialog().m_PluginContainer)->getAccessManager())); + *NexusInterface::instance(dialog().pluginContainer())->getAccessManager())); m_nexusValidator->stateChanged = [&](auto&& s, auto&& e){ onValidatorStateChanged(s, e); @@ -294,7 +294,7 @@ void NexusSettingsTab::onValidatorStateChanged( void NexusSettingsTab::onValidatorFinished(const APIUserAccount& user) { - NexusInterface::instance(dialog().m_PluginContainer)->setUserAccount(user); + NexusInterface::instance(dialog().pluginContainer())->setUserAccount(user); if (!user.apiKey().isEmpty()) { if (setKey(user.apiKey())) { @@ -311,7 +311,7 @@ void NexusSettingsTab::addNexusLog(const QString& s) bool NexusSettingsTab::setKey(const QString& key) { - dialog().m_keyChanged = true; + dialog().setRestartNeeded(); const bool ret = settings().nexus().setApiKey(key); updateNexusState(); return ret; @@ -319,10 +319,10 @@ bool NexusSettingsTab::setKey(const QString& key) bool NexusSettingsTab::clearKey() { - dialog().m_keyChanged = true; + dialog().setRestartNeeded(); const auto ret = settings().nexus().clearApiKey(); - NexusInterface::instance(dialog().m_PluginContainer)->getAccessManager()->clearApiKey(); + NexusInterface::instance(dialog().pluginContainer())->getAccessManager()->clearApiKey(); updateNexusState(); return ret; @@ -371,7 +371,7 @@ void NexusSettingsTab::updateNexusButtons() void NexusSettingsTab::updateNexusData() { - const auto user = NexusInterface::instance(dialog().m_PluginContainer) + const auto user = NexusInterface::instance(dialog().pluginContainer()) ->getAPIUserAccount(); if (user.isValid()) { diff --git a/src/settingsdialogpaths.cpp b/src/settingsdialogpaths.cpp index aeb4dd5d..c6fd40a7 100644 --- a/src/settingsdialogpaths.cpp +++ b/src/settingsdialogpaths.cpp @@ -68,10 +68,12 @@ void PathsSettingsTab::update() if (!QDir(realPath).exists()) { if (!QDir().mkpath(realPath)) { - QMessageBox::warning(qApp->activeWindow(), QObject::tr("Error"), + QMessageBox::warning(parentWidget(), QObject::tr("Error"), QObject::tr("Failed to create \"%1\", you may not have the " - "necessary permission. path remains unchanged.") + "necessary permissions. Path remains unchanged.") .arg(realPath)); + + continue; } } diff --git a/src/settingsdialogworkarounds.cpp b/src/settingsdialogworkarounds.cpp index ccbfcbfe..5e70e5a6 100644 --- a/src/settingsdialogworkarounds.cpp +++ b/src/settingsdialogworkarounds.cpp @@ -83,7 +83,9 @@ void WorkaroundsSettingsTab::on_bsaDateBtn_clicked() const auto* game = qApp->property("managed_game").value(); QDir dir = game->dataDirectory(); - helper::backdateBSAs(qApp->applicationDirPath().toStdWString(), + helper::backdateBSAs( + parentWidget(), + qApp->applicationDirPath().toStdWString(), dir.absolutePath().toStdWString()); } @@ -95,7 +97,7 @@ void WorkaroundsSettingsTab::on_resetGeometryBtn_clicked() "Restart now?"); const auto res = QMessageBox::question( - nullptr, caption, text, QMessageBox::Yes | QMessageBox::Cancel); + parentWidget(), caption, text, QMessageBox::Yes | QMessageBox::Cancel); if (res == QMessageBox::Yes) { settings().geometry().requestReset(); diff --git a/src/spawn.cpp b/src/spawn.cpp index e18e6bb3..a0cf9fb6 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -215,7 +215,7 @@ QMessageBox::StandardButton startSteamFailed( .exec(); } -void spawnFailed(const SpawnParameters& sp, DWORD code) +void spawnFailed(QWidget* parent, const SpawnParameters& sp, DWORD code) { const auto details = makeDetails(sp, code); log::error("{}", details); @@ -225,12 +225,7 @@ void spawnFailed(const SpawnParameters& sp, DWORD code) const auto mainText = QObject::tr("Cannot start %1") .arg(sp.binary.fileName()); - QWidget *window = qApp->activeWindow(); - if ((window != nullptr) && (!window->isVisible())) { - window = nullptr; - } - - MOBase::TaskDialog(window, title) + MOBase::TaskDialog(parent, title) .main(mainText) .content(makeContent(sp, code)) .details(details) @@ -239,7 +234,7 @@ void spawnFailed(const SpawnParameters& sp, DWORD code) } void helperFailed( - DWORD code, const QString& why, const std::wstring& binary, + QWidget* parent, DWORD code, const QString& why, const std::wstring& binary, const std::wstring& cwd, const std::wstring& args) { SpawnParameters sp; @@ -255,12 +250,7 @@ void helperFailed( const auto mainText = QObject::tr("Cannot start %1") .arg(sp.binary.fileName()); - QWidget *window = qApp->activeWindow(); - if ((window != nullptr) && (!window->isVisible())) { - window = nullptr; - } - - MOBase::TaskDialog(window, title) + MOBase::TaskDialog(parent, title) .main(mainText) .content(makeContent(sp, code)) .details(details) @@ -268,7 +258,7 @@ void helperFailed( .exec(); } -bool confirmRestartAsAdmin(const SpawnParameters& sp) +bool confirmRestartAsAdmin(QWidget* parent, const SpawnParameters& sp) { const auto details = makeDetails(sp, ERROR_ELEVATION_REQUIRED); @@ -287,15 +277,9 @@ bool confirmRestartAsAdmin(const SpawnParameters& sp) "You can restart Mod Organizer as administrator and try launching the " "program again."); - - QWidget *window = qApp->activeWindow(); - if ((window != nullptr) && (!window->isVisible())) { - window = nullptr; - } - log::debug("asking user to restart MO as administrator"); - const auto r = MOBase::TaskDialog(window, title) + const auto r = MOBase::TaskDialog(parent, title) .main(mainText) .content(content) .details(details) @@ -313,7 +297,7 @@ bool confirmRestartAsAdmin(const SpawnParameters& sp) } QMessageBox::StandardButton confirmStartSteam( - QWidget* window, const SpawnParameters& sp, const QString& details) + QWidget* parent, const SpawnParameters& sp, const QString& details) { const auto title = QObject::tr("Launch Steam"); const auto mainText = QObject::tr("This program requires Steam"); @@ -321,7 +305,7 @@ QMessageBox::StandardButton confirmStartSteam( "Mod Organizer has detected that this program likely requires Steam to be " "running to function properly."); - return MOBase::TaskDialog(window, title) + return MOBase::TaskDialog(parent, title) .main(mainText) .content(content) .details(details) @@ -340,17 +324,35 @@ QMessageBox::StandardButton confirmStartSteam( .exec(); } -QuestionBoxMemory::Button confirmRestartAsAdminForSteam(QWidget* parent, const SpawnParameters& sp) +QMessageBox::StandardButton confirmRestartAsAdminForSteam( + QWidget* parent, const SpawnParameters& sp) { - return QuestionBoxMemory::query( - parent, "steamAdminQuery", sp.binary.fileName(), - QObject::tr("Steam: Access Denied"), - QObject::tr("MO was denied access to the Steam process. This normally indicates that " - "Steam is being run as administrator while MO is not. This can cause issues " - "launching the game. It is recommended to not run Steam as administrator unless " - "absolutely necessary.\n\n" - "Restart MO as administrator?"), - QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel); + const auto title = QObject::tr("Elevation required"); + const auto mainText = QObject::tr("Steam is running as administrator"); + const auto content = QObject::tr( + "Running Steam as administrator is typically unnecessary and can cause " + "problems when Mod Organizer is not running as administrato\r\n\r\n" + "You can restart Mod Organizer as administrator and try launching the " + "program again."); + + return MOBase::TaskDialog(parent, title) + .main(mainText) + .content(content) + .details("") + .icon(QMessageBox::Question) + .button({ + QObject::tr("Restart Mod Organizer as administrator"), + QObject::tr("You must allow \"helper.exe\" to make changes to the system."), + QMessageBox::Yes}) + .button({ + QObject::tr("Continue"), + QObject::tr("The program might fail to run."), + QMessageBox::No}) + .button({ + QObject::tr("Cancel"), + QMessageBox::Cancel}) + .remember("steamAdminQuery", sp.binary.fileName()) + .exec(); } bool eventLogNotRunning( @@ -447,7 +449,7 @@ DWORD spawn(const SpawnParameters& sp, HANDLE& processHandle, HANDLE& threadHand return ERROR_SUCCESS; } -bool restartAsAdmin() +bool restartAsAdmin(QWidget* parent) { WCHAR cwd[MAX_PATH] = {}; if (!GetCurrentDirectory(MAX_PATH, cwd)) { @@ -455,6 +457,7 @@ bool restartAsAdmin() } if (!helper::adminLaunch( + parent, qApp->applicationDirPath().toStdWString(), qApp->applicationFilePath().toStdWString(), std::wstring(cwd))) @@ -469,21 +472,21 @@ bool restartAsAdmin() return true; } -void startBinaryAdmin(const SpawnParameters& sp) +void startBinaryAdmin(QWidget* parent, const SpawnParameters& sp) { - if (!dialogs::confirmRestartAsAdmin(sp)) { + if (!dialogs::confirmRestartAsAdmin(parent, sp)) { log::debug("user declined"); return; } log::info("restarting MO as administrator"); - restartAsAdmin(); + restartAsAdmin(parent); } bool checkBinary(QWidget* parent, const SpawnParameters& sp) { if (!sp.binary.exists()) { - dialogs::spawnFailed(sp, ERROR_FILE_NOT_FOUND); + dialogs::spawnFailed(parent, sp, ERROR_FILE_NOT_FOUND); return false; } @@ -660,7 +663,7 @@ bool checkSteam( const auto c = dialogs::confirmRestartAsAdminForSteam(parent, sp); if (c == QDialogButtonBox::Yes) { - restartAsAdmin(); + restartAsAdmin(parent); return false; } else if (c == QDialogButtonBox::No) { log::debug("user declined to restart MO, continuing"); @@ -720,13 +723,13 @@ HANDLE startBinary(QWidget* parent, const SpawnParameters& sp) case ERROR_ELEVATION_REQUIRED: { - startBinaryAdmin(sp); + startBinaryAdmin(parent, sp); return INVALID_HANDLE_VALUE; } default: { - dialogs::spawnFailed(sp, e); + dialogs::spawnFailed(parent, sp, e); return INVALID_HANDLE_VALUE; } } @@ -740,6 +743,7 @@ namespace helper { bool helperExec( + QWidget* parent, const std::wstring& moDirectory, const std::wstring& commandLine, BOOL async) { const std::wstring fileName = moDirectory + L"\\helper.exe"; @@ -766,7 +770,7 @@ bool helperExec( const auto e = GetLastError(); spawn::dialogs::helperFailed( - e, "ShellExecuteExW()", fileName, moDirectory, commandLine); + parent, e, "ShellExecuteExW()", fileName, moDirectory, commandLine); return false; } @@ -788,7 +792,8 @@ bool helperExec( ERROR_ABANDONED_WAIT_0 : GetLastError()); spawn::dialogs::helperFailed( - code, "WaitForSingleObject()", fileName, moDirectory, commandLine); + parent, code, "WaitForSingleObject()", + fileName, moDirectory, commandLine); return false; } @@ -798,7 +803,7 @@ bool helperExec( const auto e = GetLastError(); spawn::dialogs::helperFailed( - e, "GetExitCodeProcess()", fileName, moDirectory, commandLine); + parent, e, "GetExitCodeProcess()", fileName, moDirectory, commandLine); return false; } @@ -806,21 +811,24 @@ bool helperExec( return (exitCode == 0); } -bool backdateBSAs(const std::wstring &moPath, const std::wstring &dataPath) +bool backdateBSAs( + QWidget* parent, const std::wstring &moPath, const std::wstring &dataPath) { const std::wstring commandLine = fmt::format( L"backdateBSA \"{}\"", dataPath); - return helperExec(moPath, commandLine, FALSE); + return helperExec(parent, moPath, commandLine, FALSE); } -bool adminLaunch(const std::wstring &moPath, const std::wstring &moFile, const std::wstring &workingDir) +bool adminLaunch( + QWidget* parent, const std::wstring &moPath, + const std::wstring &moFile, const std::wstring &workingDir) { const std::wstring commandLine = fmt::format( L"adminLaunch {} \"{}\" \"{}\"", ::GetCurrentProcessId(), moFile, workingDir); - return helperExec(moPath, commandLine, true); + return helperExec(parent, moPath, commandLine, true); } } // namespace diff --git a/src/spawn.h b/src/spawn.h index da626329..9e1e2539 100644 --- a/src/spawn.h +++ b/src/spawn.h @@ -84,7 +84,8 @@ namespace helper * @param moPath absolute path to the modOrganizer base directory * @param dataPath the path taht contains the .bsa-files, usually the data directory of the game **/ -bool backdateBSAs(const std::wstring &moPath, const std::wstring &dataPath); +bool backdateBSAs( + QWidget* parent, const std::wstring &moPath, const std::wstring &dataPath); /** * @brief waits for the current process to exit and restarts it as an administrator @@ -92,7 +93,9 @@ bool backdateBSAs(const std::wstring &moPath, const std::wstring &dataPath); * @param moFile file name of modOrganizer * @param workingDir current working directory **/ -bool adminLaunch(const std::wstring &moPath, const std::wstring &moFile, const std::wstring &workingDir); +bool adminLaunch( + QWidget* parent, const std::wstring &moPath, + const std::wstring &moFile, const std::wstring &workingDir); } // namespace -- cgit v1.3.1 From 94b0c4634290b41398915c6635982dc7b3928f60 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 19 Sep 2019 17:10:30 -0400 Subject: TaskDialog for blacklisted, with button to change the blacklist --- src/settingsdialogworkarounds.cpp | 51 +++++++++++++++++++++++-------- src/settingsdialogworkarounds.h | 15 ++++++++-- src/spawn.cpp | 63 +++++++++++++++++++++++++++++---------- 3 files changed, 98 insertions(+), 31 deletions(-) (limited to 'src/settingsdialogworkarounds.cpp') diff --git a/src/settingsdialogworkarounds.cpp b/src/settingsdialogworkarounds.cpp index 5e70e5a6..0e31fc4b 100644 --- a/src/settingsdialogworkarounds.cpp +++ b/src/settingsdialogworkarounds.cpp @@ -1,6 +1,7 @@ #include "settingsdialogworkarounds.h" #include "ui_settingsdialog.h" #include "spawn.h" +#include "settings.h" #include WorkaroundsSettingsTab::WorkaroundsSettingsTab(Settings& s, SettingsDialog& d) @@ -26,7 +27,7 @@ WorkaroundsSettingsTab::WorkaroundsSettingsTab(Settings& s, SettingsDialog& d) ui->lockGUIBox->setChecked(settings().interface().lockGUI()); ui->enableArchiveParsingBox->setChecked(settings().archiveParsing()); - setExecutableBlacklist(settings().executablesBlacklist()); + m_ExecutableBlacklist = settings().executablesBlacklist(); QObject::connect(ui->bsaDateBtn, &QPushButton::clicked, [&]{ on_bsaDateBtn_clicked(); }); QObject::connect(ui->execBlacklistBtn, &QPushButton::clicked, [&]{ on_execBlacklistBtn_clicked(); }); @@ -49,14 +50,29 @@ void WorkaroundsSettingsTab::update() settings().interface().setDisplayForeign(ui->displayForeignBox->isChecked()); settings().interface().setLockGUI(ui->lockGUIBox->isChecked()); settings().setArchiveParsing(ui->enableArchiveParsingBox->isChecked()); - settings().setExecutablesBlacklist(getExecutableBlacklist()); + settings().setExecutablesBlacklist(m_ExecutableBlacklist); } -void WorkaroundsSettingsTab::on_execBlacklistBtn_clicked() +bool WorkaroundsSettingsTab::changeBlacklistNow( + QWidget* parent, Settings& settings) +{ + const auto current = settings.executablesBlacklist(); + + if (auto s=changeBlacklistLater(parent, current)) { + settings.setExecutablesBlacklist(*s); + return true; + } + + return false; +} + +std::optional WorkaroundsSettingsTab::changeBlacklistLater( + QWidget* parent, const QString& current) { bool ok = false; + QString result = QInputDialog::getMultiLineText( - &dialog(), + parent, 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" @@ -64,17 +80,28 @@ void WorkaroundsSettingsTab::on_execBlacklistBtn_clicked() "Example:\n" " Chrome.exe\n" " Firefox.exe"), - m_ExecutableBlacklist.split(";").join("\n"), + current.split(";").join("\n"), &ok ); - if (ok) { - QStringList blacklist; - for (auto exec : result.split("\n")) { - if (exec.trimmed().endsWith(".exe", Qt::CaseInsensitive)) { - blacklist << exec.trimmed(); - } + + if (!ok) { + return {}; + } + + QStringList blacklist; + for (auto exec : result.split("\n")) { + if (exec.trimmed().endsWith(".exe", Qt::CaseInsensitive)) { + blacklist << exec.trimmed(); } - m_ExecutableBlacklist = blacklist.join(";"); + } + + return blacklist.join(";"); +} + +void WorkaroundsSettingsTab::on_execBlacklistBtn_clicked() +{ + if (auto s=changeBlacklistLater(parentWidget(), m_ExecutableBlacklist)) { + m_ExecutableBlacklist = *s; } } diff --git a/src/settingsdialogworkarounds.h b/src/settingsdialogworkarounds.h index d5d6815f..cffc54a0 100644 --- a/src/settingsdialogworkarounds.h +++ b/src/settingsdialogworkarounds.h @@ -8,6 +8,18 @@ class WorkaroundsSettingsTab : public SettingsTab { public: WorkaroundsSettingsTab(Settings& settings, SettingsDialog& dialog); + + // shows the blacklist dialog from the given settings, and changes the + // settings when the user accepts it + // + static bool changeBlacklistNow(QWidget* parent, Settings& settings); + + // shows the blacklist dialog from the given string and returns the new + // blacklist if the user accepted it + // + static std::optional changeBlacklistLater( + QWidget* parent, const QString& current); + void update(); private: @@ -16,9 +28,6 @@ private: void on_bsaDateBtn_clicked(); void on_execBlacklistBtn_clicked(); void on_resetGeometryBtn_clicked(); - - QString getExecutableBlacklist() { return m_ExecutableBlacklist; } - void setExecutableBlacklist(QString blacklist) { m_ExecutableBlacklist = blacklist; } }; #endif // SETTINGSDIALOGWORKAROUNDS_H diff --git a/src/spawn.cpp b/src/spawn.cpp index b7aa90c0..ab9d90a0 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -26,6 +26,7 @@ along with Mod Organizer. If not, see . #include "envsecurity.h" #include "envmodule.h" #include "settings.h" +#include "settingsdialogworkarounds.h" #include #include #include @@ -379,21 +380,45 @@ bool eventLogNotRunning( QMessageBox::Cancel}) .exec(); - return (r == QDialogButtonBox::Yes); + return (r == QMessageBox::Yes); } -bool confirmBlacklisted(QWidget* parent, const SpawnParameters& sp) +QMessageBox::StandardButton confirmBlacklisted( + QWidget* parent, const SpawnParameters& sp) { - const auto r = QuestionBoxMemory::query( - parent, QString("blacklistedExecutable"), sp.binary.fileName(), - QObject::tr("Blacklisted Executable"), - QObject::tr("The executable you are attempted to launch is blacklisted in the virtual file" - " system. This will likely prevent the executable, and any executables that are" - " launched by this one, from seeing any mods. This could extend to INI files, save" - " games and any other virtualized files.\n\nContinue launching %1?").arg(sp.binary.fileName()), - QDialogButtonBox::Yes | QDialogButtonBox::No); - - return (r != QDialogButtonBox::No); + const auto title = QObject::tr("Blacklisted program"); + const auto mainText = QObject::tr("The program %1 is blacklisted") + .arg(sp.binary.fileName()); + const auto content = QObject::tr( + "The program you are attempting to launch is blacklisted in the virtual " + "filesystem. This will likely prevent it from seeing any mods, INI files " + "or any other virtualized files."); + + auto r = MOBase::TaskDialog(parent, title) + .main(mainText) + .content(content) + .details("") + .icon(QMessageBox::Question) + .remember("blacklistedExecutable", sp.binary.fileName()) + .button({ + QObject::tr("Continue"), + QObject::tr("Your mods might not work"), + QMessageBox::Yes}) + .button({ + QObject::tr("Change the blacklist"), + QMessageBox::Retry}) + .button({ + QObject::tr("Cancel"), + QMessageBox::Cancel}) + .exec(); + + if (r == QMessageBox::Retry) { + if (!WorkaroundsSettingsTab::changeBlacklistNow(parent, Settings::instance())) { + r = QMessageBox::Cancel; + } + } + + return r; } } // namespace @@ -716,11 +741,17 @@ bool checkEnvironment(QWidget* parent, const SpawnParameters& sp) bool checkBlacklist(QWidget* parent, const SpawnParameters& sp, const Settings& settings) { - if (settings.isExecutableBlacklisted(sp.binary.fileName())) { - return dialogs::confirmBlacklisted(parent, sp); - } + for (;;) { + if (!settings.isExecutableBlacklisted(sp.binary.fileName())) { + return true; + } - return true; + const auto r = dialogs::confirmBlacklisted(parent, sp); + + if (r != QMessageBox::Retry) { + return (r == QMessageBox::Yes); + } + } } -- cgit v1.3.1