summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/moapplication.cpp54
-rw-r--r--src/moapplication.h5
2 files changed, 35 insertions, 24 deletions
diff --git a/src/moapplication.cpp b/src/moapplication.cpp
index b4ba7da6..24cafd05 100644
--- a/src/moapplication.cpp
+++ b/src/moapplication.cpp
@@ -160,8 +160,13 @@ int MOApplication::run(SingleInstance& singleInstance)
// IOrganizer::getPluginDataPath()
MOBase::details::setPluginDataPath(OrganizerCore::pluginDataPath());
+ // MO runs in a loop because it can be restarted in several ways, such as
+ // when switching instances or changing some settings
for (;;)
{
+ // resets things when MO is "restarted"
+ resetForRestart();
+
const auto r = doOneRun(singleInstance);
if (r == RestartExitCode) {
continue;
@@ -175,18 +180,37 @@ int MOApplication::doOneRun(SingleInstance& singleInstance)
{
TimeThis tt("doOneRun() to runApplication()");
- // resets things when MO is "restarted"
- resetForRestart();
+ auto currentInstance = getCurrentInstance();
+ if (!currentInstance) {
+ return 1;
+ }
+
+ const QString dataPath = currentInstance->directory();
+ setProperty("dataPath", dataPath);
+
+ setExceptionHandlers();
+
+ if (!setLogDirectory(dataPath)) {
+ reportError("Failed to create log folder");
+ InstanceManager::singleton().clearCurrentInstance();
+ return 1;
+ }
+
+ log::debug("command line: '{}'", QString::fromWCharArray(GetCommandLineW()));
+
+ tt.stop();
+
+ return runApplication(singleInstance, dataPath, *currentInstance);
+}
+std::optional<Instance> MOApplication::getCurrentInstance()
+{
auto& m = InstanceManager::singleton();
auto currentInstance = m.currentInstance();
if (!currentInstance)
{
currentInstance = selectInstance();
- if (!currentInstance) {
- return 1;
- }
}
else
{
@@ -204,28 +228,10 @@ int MOApplication::doOneRun(SingleInstance& singleInstance)
}
currentInstance = selectInstance();
- if (!currentInstance) {
- return 1;
- }
}
}
- const QString dataPath = currentInstance->directory();
- setProperty("dataPath", dataPath);
-
- setExceptionHandlers();
-
- if (!setLogDirectory(dataPath)) {
- reportError("Failed to create log folder");
- InstanceManager::singleton().clearCurrentInstance();
- return 1;
- }
-
- log::debug("command line: '{}'", QString::fromWCharArray(GetCommandLineW()));
-
- tt.stop();
-
- return runApplication(singleInstance, dataPath, *currentInstance);
+ return currentInstance;
}
int MOApplication::runApplication(
diff --git a/src/moapplication.h b/src/moapplication.h
index c1512d9b..8cbb5f28 100644
--- a/src/moapplication.h
+++ b/src/moapplication.h
@@ -37,7 +37,10 @@ class MOApplication : public QApplication
public:
MOApplication(cl::CommandLine& cl, int& argc, char** argv);
+ // sets up everything, creates the main window and runs it
+ //
int run(SingleInstance& si);
+
virtual bool notify(QObject* receiver, QEvent* event);
public slots:
@@ -53,6 +56,8 @@ private:
int doOneRun(SingleInstance& singleInstance);
+ std::optional<Instance> getCurrentInstance();
+
int runApplication(
SingleInstance& singleInstance,
const QString &dataPath, Instance& currentInstance);