diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2020-07-23 01:16:47 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2020-11-03 11:39:03 -0500 |
| commit | 2c915429d84a9df0e9c512db248fb5c8ec6663f7 (patch) | |
| tree | 11ca6ba4a6ef5273d310a025493cfc07de69d1a8 /src | |
| parent | ae118153fbedc0240ea183488834a32abe202839 (diff) | |
refactored stuff into determineGameEdition() and handleCommandLine()
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 171 |
1 files changed, 100 insertions, 71 deletions
diff --git a/src/main.cpp b/src/main.cpp index 52011ef4..49f3c6c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -388,6 +388,94 @@ std::unique_ptr<QSplashScreen> createSplash( return splash; } +bool determineGameEdition(Settings& settings, IPluginGame* game) +{ + QString edition; + + if (auto v=settings.game().edition()) { + edition = *v; + } else { + QStringList editions = game->gameVariants(); + if (editions.size() < 2) { + edition = ""; + return true; + } + + SelectionDialog selection( + QObject::tr("Please select the game edition you have (MO can't " + "start the game correctly if this is set " + "incorrectly!)"), + nullptr); + + selection.setWindowFlag(Qt::WindowStaysOnTopHint, true); + + int index = 0; + for (const QString &edition : editions) { + selection.addChoice(edition, "", index++); + } + + if (selection.exec() == QDialog::Rejected) { + return false; + } + + edition = selection.getChoiceString(); + settings.game().setEdition(edition); + } + + game->setGameVariant(edition); + + return true; +} + +std::optional<int> handleCommandLine( + const cl::CommandLine& cl, OrganizerCore& organizer) +{ + // if we have a command line parameter, it is either a nxm link or + // a binary to start + if (cl.shortcut().isValid()) { + if (cl.shortcut().hasExecutable()) { + try { + organizer.processRunner() + .setFromShortcut(cl.shortcut()) + .setWaitForCompletion() + .run(); + + return 0; + } + catch (const std::exception &e) { + reportError( + QObject::tr("failed to start shortcut: %1").arg(e.what())); + return 1; + } + } + } else if (cl.nxmLink()) { + log::debug("starting download from command line: {}", *cl.nxmLink()); + organizer.externalMessage(*cl.nxmLink()); + } else if (cl.executable()) { + const QString exeName = *cl.executable(); + log::debug("starting {} from command line", exeName); + + try + { + // pass the remaining parameters to the binary + organizer.processRunner() + .setFromFileOrExecutable(exeName, cl.untouched()) + .setWaitForCompletion() + .run(); + + return 0; + } + catch (const std::exception &e) + { + reportError( + QObject::tr("failed to start application: %1").arg(e.what())); + return 1; + } + } + + return {}; +} + int runApplication( MOApplication &application, const cl::CommandLine& cl, SingleInstance &instance, const QString &dataPath) @@ -475,38 +563,16 @@ int runApplication( organizer.setManagedGame(game); organizer.createDefaultProfile(); - QString edition; - - if (auto v=settings.game().edition()) { - edition = *v; - } else { - QStringList editions = game->gameVariants(); - if (editions.size() > 1) { - SelectionDialog selection( - QObject::tr("Please select the game edition you have (MO can't " - "start the game correctly if this is set " - "incorrectly!)"), - nullptr); - selection.setWindowFlag(Qt::WindowStaysOnTopHint, true); - int index = 0; - for (const QString &edition : editions) { - selection.addChoice(edition, "", index++); - } - if (selection.exec() == QDialog::Rejected) { - return 1; - } else { - edition = selection.getChoiceString(); - settings.game().setEdition(edition); - } - } + if (!determineGameEdition(settings, game)) { + return 1; } - game->setGameVariant(edition); - log::info( - "using game plugin '{}' ('{}', steam id '{}') at {}", - game->gameName(), game->gameShortName(), game->steamAPPId(), - game->gameDirectory().absolutePath()); + "using game plugin '{}' ('{}', variant {}, steam id '{}') at {}", + game->gameName(), game->gameShortName(), + (settings.game().edition().value_or("").isEmpty() ? + "(none)" : *settings.game().edition()), + game->steamAPPId(), game->gameDirectory().absolutePath()); CategoryFactory::instance().loadCategories(); organizer.updateExecutablesList(); @@ -515,47 +581,8 @@ int runApplication( QString selectedProfileName = determineProfile(cl, settings); organizer.setCurrentProfile(selectedProfileName); - // if we have a command line parameter, it is either a nxm link or - // a binary to start - if (cl.shortcut().isValid()) { - if (cl.shortcut().hasExecutable()) { - try { - organizer.processRunner() - .setFromShortcut(cl.shortcut()) - .setWaitForCompletion() - .run(); - - return 0; - } - catch (const std::exception &e) { - reportError( - QObject::tr("failed to start shortcut: %1").arg(e.what())); - return 1; - } - } - } else if (cl.nxmLink()) { - log::debug("starting download from command line: {}", *cl.nxmLink()); - organizer.externalMessage(*cl.nxmLink()); - } else if (cl.executable()) { - const QString exeName = *cl.executable(); - log::debug("starting {} from command line", exeName); - - try - { - // pass the remaining parameters to the binary - organizer.processRunner() - .setFromFileOrExecutable(exeName, cl.untouched()) - .setWaitForCompletion() - .run(); - - return 0; - } - catch (const std::exception &e) - { - reportError( - QObject::tr("failed to start application: %1").arg(e.what())); - return 1; - } + if (auto r=handleCommandLine(cl, organizer)) { + return *r; } auto splash = createSplash(settings, dataPath, game); @@ -611,7 +638,9 @@ int runApplication( settings.geometry().resetIfNeeded(); return res; - } catch (const std::exception &e) { + } + catch (const std::exception &e) + { reportError(e.what()); } |
