diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-11-13 16:14:31 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-11-13 16:14:31 +0100 |
| commit | 1facda19438bf01e5b8e08b7ebeb7f3a1c21028f (patch) | |
| tree | bb5b9483c32b781b58ae275e4850fd85596573e0 /src | |
| parent | 4d94ba8dbba20da6d030a8a3adf73d2dbd6fc56f (diff) | |
| parent | 85f515da2d1713bc208d2f1bca4197b91950528a (diff) | |
Merge branch 'master' of github.com:ModOrganizer2/modorganizer into iplugin-isactive-refactoring
Diffstat (limited to 'src')
| -rw-r--r-- | src/createinstancedialog.cpp | 10 | ||||
| -rw-r--r-- | src/instancemanager.cpp | 6 | ||||
| -rw-r--r-- | src/instancemanager.h | 5 | ||||
| -rw-r--r-- | src/instancemanagerdialog.cpp | 6 | ||||
| -rw-r--r-- | src/moapplication.cpp | 18 | ||||
| -rw-r--r-- | src/modlist.cpp | 8 |
6 files changed, 42 insertions, 11 deletions
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<std::unique_ptr<DirectoryCreator>> 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<Instance> 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<Instance> 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<Instance> 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)
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); |
