diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2021-01-10 22:06:38 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2021-01-18 08:20:07 -0500 |
| commit | 3bca0e761597f590fa3b1c6a57ee325e774e3f49 (patch) | |
| tree | 34a49c4754a26073a59f658b905b5cdae72e2235 /src/main.cpp | |
| parent | 59f055ba93381b965cdc04557ac1dce2df36bd07 (diff) | |
split run() into setup() and run()
this is so command line processing can happen outside of MOApplication
many important objects were local to run(), so they're not members of MOApplication instead
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index 877236e1..362caaad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,8 +4,10 @@ #include "organizercore.h" #include "commandline.h" #include "env.h" +#include "instancemanager.h" #include "thread_utils.h" #include "shared/util.h" +#include <report.h> #include <log.h> using namespace MOBase; @@ -31,7 +33,7 @@ int main(int argc, char *argv[]) TimeThis tt("main()"); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - MOApplication app(cl, argc, argv); + MOApplication app(argc, argv); MOMultiProcess multiProcess(cl.multiple()); if (multiProcess.ephemeral()) { @@ -40,7 +42,61 @@ int main(int argc, char *argv[]) tt.stop(); - return app.run(multiProcess); + + // MO runs in a loop because it can be restarted in several ways, such as + // when switching instances or changing some settings + for (;;) + { + try + { + auto& m = InstanceManager::singleton(); + + if (cl.instance()) { + m.overrideInstance(*cl.instance()); + } + + if (cl.profile()) { + m.overrideProfile(*cl.profile()); + } + + { + const auto r = app.setup(multiProcess); + + if (r == RestartExitCode) { + // resets things when MO is "restarted" + app.resetForRestart(); + + // don't reprocess command line + cl.clear(); + + continue; + } + } + + if (auto r=cl.setupCore(app.core())) { + return *r; + } + + const auto r = app.run(multiProcess); + + if (r == RestartExitCode) { + // resets things when MO is "restarted" + app.resetForRestart(); + + // don't reprocess command line + cl.clear(); + + continue; + } + + return r; + } + catch (const std::exception &e) + { + reportError(e.what()); + return 1; + } + } } int forwardToPrimary(MOMultiProcess& multiProcess, const cl::CommandLine& cl) |
