summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/createinstancedialog.cpp10
-rw-r--r--src/instancemanager.cpp6
-rw-r--r--src/instancemanager.h5
-rw-r--r--src/instancemanagerdialog.cpp6
-rw-r--r--src/moapplication.cpp18
5 files changed, 37 insertions, 8 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)