From a0c26517028a25ccd39dc92f9da8539f25db85fc Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 12 Nov 2020 00:17:36 -0500 Subject: highlighting plugins from the data directory would crash the mod name is "data" and getByName() crashes with a mod name that doesn't exist --- src/modlist.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/modlist.cpp b/src/modlist.cpp index 04abfb01..d7324e7f 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -860,9 +860,11 @@ void ModList::highlightMods(const QItemSelectionModel *selection, const MOShared if (fileEntry.get() != nullptr) { QString originName = QString::fromStdWString(directoryEntry.getOriginByID(fileEntry->getOrigin()).getName()); - - auto modInfo = ModInfo::getByName(originName); - modInfo->setPluginSelected(true); + const auto index = ModInfo::getIndex(originName); + if (index != UINT_MAX) { + auto modInfo = ModInfo::getByIndex(index); + modInfo->setPluginSelected(true); + } } } notifyChange(0, rowCount() - 1); -- cgit v1.3.1 From 6ae27224b0dcc860b882bebff3149828d874c832 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 12 Nov 2020 03:15:14 -0500 Subject: fixed a bunch of instance and command line stuff - clear instance manager overrides when restarting, or switching instances after starting MO with moshortcut://instance: won't do anything - clear overrides when the last selected instance can't be opened; MO would keep trying to open shortcuts even after selecting a different instance - command line was cleared too early, before the first run, so shortcuts were broken - the instance manager dialog can be opened without an instance loaded if the last selected instance doesn't exist, createNew() would throw because it tried to access the global Settings - fixed some problems with parts of MO wanting to restart and others expecting flow to continue - fixed create instance dialog using settings pointer to decide whether to restart; it restarts when it's the first created instance, which is not always the case even if the settings are null, so just check whether there are instances --- src/createinstancedialog.cpp | 10 ++++++---- src/instancemanager.cpp | 6 ++++++ src/instancemanager.h | 5 +++++ src/instancemanagerdialog.cpp | 6 +++++- src/moapplication.cpp | 18 +++++++++++++++--- 5 files changed, 37 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/createinstancedialog.cpp b/src/createinstancedialog.cpp index 47cb9d5c..a4e3c336 100644 --- a/src/createinstancedialog.cpp +++ b/src/createinstancedialog.cpp @@ -131,7 +131,7 @@ CreateInstanceDialog::CreateInstanceDialog( ui->pages->setCurrentIndex(0); ui->launch->setChecked(true); - if (!m_settings) + if (!InstanceManager::singleton().hasAnyInstances()) { // first run of MO, there are no instances yet, force launch ui->launch->setEnabled(false); @@ -314,6 +314,10 @@ void CreateInstanceDialog::finish() }; + // don't restart if this is the first instance, it'll be selected and opened + const bool mustRestart = InstanceManager::singleton().hasAnyInstances(); + + try { std::vector> dirs; @@ -396,9 +400,7 @@ void CreateInstanceDialog::finish() if (ui->launch->isChecked()) { InstanceManager::singleton().setCurrentInstance(ci.instanceName); - if (m_settings) { - // don't restart without settings, it happens on startup when there are - // no instances + if (mustRestart) { ExitModOrganizer(Exit::Restart); m_switching = true; } diff --git a/src/instancemanager.cpp b/src/instancemanager.cpp index 4191f850..2753fc4c 100644 --- a/src/instancemanager.cpp +++ b/src/instancemanager.cpp @@ -538,6 +538,12 @@ void InstanceManager::overrideProfile(const QString& profileName) m_overrideProfileName = profileName; } +void InstanceManager::clearOverrides() +{ + m_overrideInstanceName = {}; + m_overrideProfileName = {}; +} + std::optional InstanceManager::currentInstance() const { const QString profile = m_overrideProfileName ? diff --git a/src/instancemanager.h b/src/instancemanager.h index 4f8b01c7..981aed43 100644 --- a/src/instancemanager.h +++ b/src/instancemanager.h @@ -232,6 +232,11 @@ public: // void overrideProfile(const QString& profileName); + // clears instance and profile overrides, used when restarting MO to select + // another instance + // + void clearOverrides(); + // returns a game plugin that considers the given directory valid // // this will check for an INI file in the directory and use its game name diff --git a/src/instancemanagerdialog.cpp b/src/instancemanagerdialog.cpp index ff76e121..2497d8d8 100644 --- a/src/instancemanagerdialog.cpp +++ b/src/instancemanagerdialog.cpp @@ -580,13 +580,17 @@ void InstanceManagerDialog::onSelection() void InstanceManagerDialog::createNew() { - CreateInstanceDialog dlg(m_pc, &Settings::instance(), this); + // there might not be settings available; the dialog can be shown when the + // last selected instance doesn't exist anymore + CreateInstanceDialog dlg(m_pc, Settings::maybeInstance(), this); + if (dlg.exec() != QDialog::Accepted) { return; } if (dlg.switching()) { // restarting MO + accept(); return; } diff --git a/src/moapplication.cpp b/src/moapplication.cpp index 9139acbb..e7ac3926 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -170,12 +170,13 @@ int MOApplication::run(MOMultiProcess& multiProcess) { try { - // resets things when MO is "restarted" - resetForRestart(); - tt.stop(); + const auto r = doOneRun(multiProcess); + if (r == RestartExitCode) { + // resets things when MO is "restarted" + resetForRestart(); continue; } @@ -396,6 +397,10 @@ std::optional MOApplication::getCurrentInstance() if (!currentInstance) { + // clear any overrides that might have been given on the command line + m.clearOverrides(); + m_cl.clear(); + currentInstance = selectInstance(); } else @@ -403,6 +408,10 @@ std::optional MOApplication::getCurrentInstance() if (!QDir(currentInstance->directory()).exists()) { // the previously used instance doesn't exist anymore + // clear any overrides that might have been given on the command line + m.clearOverrides(); + m_cl.clear(); + if (m.hasAnyInstances()) { MOShared::criticalOnTop(QObject::tr( "Instance at '%1' not found. Select another instance.") @@ -466,6 +475,9 @@ void MOApplication::resetForRestart() // don't reprocess command line m_cl.clear(); + + // clear instance and profile overrides + InstanceManager::singleton().clearOverrides(); } bool MOApplication::setStyleFile(const QString& styleName) -- cgit v1.3.1