From 5c39a762e68c3559438a622dbf747eb8bddec7ed Mon Sep 17 00:00:00 2001 From: Al12rs Date: Fri, 6 Apr 2018 21:35:15 +0200 Subject: Allow MO2 shortcuts that open the indicated MO2 instance in the argument if the executable name is omitted. This should be added after the MO2 exe path: ' "moshortcut://myInstanceName:" '. If there are caracters after the ":" then MO2 will assume that is an execuatble and will try to run it. --- src/main.cpp | 66 ++++++++++++++++++++++++++++----------------------- src/moshortcut.cpp | 3 +++ src/moshortcut.h | 3 +++ src/organizercore.cpp | 5 ++-- 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0464ca9a..fc332fe7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -561,36 +561,42 @@ int runApplication(MOApplication &application, SingleInstance &instance, // if we have a command line parameter, it is either a nxm link or // a binary to start - if (arguments.size() > 1) { - if (MOShortcut shortcut{ arguments.at(1) }) { - try { - organizer.runShortcut(shortcut); - return 0; - } catch (const std::exception &e) { - reportError( - QObject::tr("failed to start shortcut: %1").arg(e.what())); - return 1; - } - } else if (OrganizerCore::isNxmLink(arguments.at(1))) { - qDebug("starting download from command line: %s", - qPrintable(arguments.at(1))); - organizer.externalMessage(arguments.at(1)); - } else { - QString exeName = arguments.at(1); - qDebug("starting %s from command line", qPrintable(exeName)); - arguments.removeFirst(); // remove application name (ModOrganizer.exe) - arguments.removeFirst(); // remove binary name - // pass the remaining parameters to the binary - try { - organizer.startApplication(exeName, arguments, QString(), QString()); - return 0; - } catch (const std::exception &e) { - reportError( - QObject::tr("failed to start application: %1").arg(e.what())); - return 1; - } - } - } + if (arguments.size() > 1) { + if (MOShortcut shortcut{ arguments.at(1) }) { + if (shortcut.hasExecutable()) { + try { + organizer.runShortcut(shortcut); + return 0; + } + catch (const std::exception &e) { + reportError( + QObject::tr("failed to start shortcut: %1").arg(e.what())); + return 1; + } + } + } + else if (OrganizerCore::isNxmLink(arguments.at(1))) { + qDebug("starting download from command line: %s", + qPrintable(arguments.at(1))); + organizer.externalMessage(arguments.at(1)); + } + else { + QString exeName = arguments.at(1); + qDebug("starting %s from command line", qPrintable(exeName)); + arguments.removeFirst(); // remove application name (ModOrganizer.exe) + arguments.removeFirst(); // remove binary name + // pass the remaining parameters to the binary + try { + organizer.startApplication(exeName, arguments, QString(), QString()); + return 0; + } + catch (const std::exception &e) { + reportError( + QObject::tr("failed to start application: %1").arg(e.what())); + return 1; + } + } + } QPixmap pixmap(splashPath); QSplashScreen splash(pixmap); diff --git a/src/moshortcut.cpp b/src/moshortcut.cpp index c8c2ef6f..aad7380e 100644 --- a/src/moshortcut.cpp +++ b/src/moshortcut.cpp @@ -24,6 +24,7 @@ along with Mod Organizer. If not, see . MOShortcut::MOShortcut(const QString& link) : m_valid(link.startsWith("moshortcut://")) , m_hasInstance(false) + , m_hasExecutable(false) { if (m_valid) { int start = (int)strlen("moshortcut://"); @@ -35,5 +36,7 @@ MOShortcut::MOShortcut(const QString& link) } else m_executable = link.mid(start); + if(!(m_executable=="")) + m_hasExecutable=true; } } diff --git a/src/moshortcut.h b/src/moshortcut.h index 7b7574b9..2ce54910 100644 --- a/src/moshortcut.h +++ b/src/moshortcut.h @@ -33,6 +33,8 @@ public: operator bool() const { return m_valid; } bool hasInstance() const { return m_hasInstance; } + + bool hasExecutable() const { return m_hasExecutable; } const QString& instance() const { return m_instance; } @@ -43,4 +45,5 @@ private: QString m_executable; bool m_valid; bool m_hasInstance; + bool m_hasExecutable; }; diff --git a/src/organizercore.cpp b/src/organizercore.cpp index b84488da..0398e9ac 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -602,8 +602,9 @@ void OrganizerCore::downloadRequestedNXM(const QString &url) void OrganizerCore::externalMessage(const QString &message) { - if (MOShortcut moshortcut{ message }) { - runShortcut(moshortcut); + if (MOShortcut moshortcut{ message } ) { + if(moshortcut.hasExecutable()) + runShortcut(moshortcut); } else if (isNxmLink(message)) { MessageDialog::showMessage(tr("Download started"), qApp->activeWindow()); -- cgit v1.3.1