summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAl12rs <gabriel.cortesi@outlook.com>2018-04-06 21:35:15 +0200
committerAl12rs <gabriel.cortesi@outlook.com>2018-04-07 14:10:16 +0200
commit5c39a762e68c3559438a622dbf747eb8bddec7ed (patch)
tree7d74dc78c8b8f6cb0dcb24556fe9dd0dc6f076fc
parenta905ce130d0f1f4894f135660d9cf515788bb2ad (diff)
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.
-rw-r--r--src/main.cpp66
-rw-r--r--src/moshortcut.cpp3
-rw-r--r--src/moshortcut.h3
-rw-r--r--src/organizercore.cpp5
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 <http://www.gnu.org/licenses/>.
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());