From 2077b5ef61256dbfcc76e273dd4bcaf297f7a365 Mon Sep 17 00:00:00 2001 From: Eddoursul Date: Fri, 20 Oct 2023 19:04:37 +0200 Subject: [PATCH 1/4] Added modl support --- src/handlerstorage.cpp | 22 ++++++++++++++++------ src/main.cpp | 24 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/handlerstorage.cpp b/src/handlerstorage.cpp index 0dbf4cf..07464a8 100644 --- a/src/handlerstorage.cpp +++ b/src/handlerstorage.cpp @@ -26,12 +26,22 @@ void HandlerStorage::clear() void HandlerStorage::registerProxy(const QString &proxyPath) { - QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\nxm\\", QSettings::NativeFormat); - QString myExe = QString("\"%1\" ").arg(QDir::toNativeSeparators(proxyPath)).append("\"%1\""); - settings.setValue("Default", "URL:NXM Protocol"); - settings.setValue("URL Protocol", ""); - settings.setValue("shell/open/command/Default", myExe); - settings.sync(); + { + QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\nxm\\", QSettings::NativeFormat); + QString myExe = QString("\"%1\" ").arg(QDir::toNativeSeparators(proxyPath)).append("\"%1\""); + settings.setValue("Default", "URL:NXM Protocol"); + settings.setValue("URL Protocol", ""); + settings.setValue("shell/open/command/Default", myExe); + settings.sync(); + } + { + QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\modl\\", QSettings::NativeFormat); + QString myExe = QString("\"%1\" ").arg(QDir::toNativeSeparators(proxyPath)).append("\"%1\""); + settings.setValue("Default", "URL:MODL Protocol"); + settings.setValue("URL Protocol", ""); + settings.setValue("shell/open/command/Default", myExe); + settings.sync(); + } } void HandlerStorage::registerHandler(const QString &executable, const QString &arguments, bool prepend) diff --git a/src/main.cpp b/src/main.cpp index a491bed..b42fad3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include "logger.h" @@ -183,7 +185,7 @@ static void applyChromeFix() // toObject returns empty object if the key doesn't exist. Therefore if excluded_schemes exists, protocol_handler existed as well if (handlers.contains("excluded_schemes")) { QJsonObject schemes = handlers["excluded_schemes"].toObject(); - if (schemes["nxm"].toBool(true)) { + if (schemes["nxm"].toBool(true) || schemes["modl"].toBool(true)) { if (QMessageBox::question(nullptr, "Apply Chrome fix", "Chrome may not support nexus links even though the association is set up correctly. " "Do you want to apply a fix for that (You have to close chrome before pressing yes or " @@ -192,6 +194,7 @@ static void applyChromeFix() return; } schemes["nxm"] = false; + schemes["modl"] = false; handlers["excluded_schemes"] = schemes; docMap["protocol_handler"] = handlers; QByteArray result = QJsonDocument(docMap).toJson(); @@ -243,6 +246,7 @@ int main(int argc, char *argv[]) if ((args.at(1) == "reg") || (args.at(1) == "forcereg")) { if (args.count() == 4) { storage->registerHandler(args.at(2).split(",", Qt::SkipEmptyParts), QDir::toNativeSeparators(args.at(3)), "", true, forceReg); + storage->registerProxy(QCoreApplication::applicationFilePath()); if (forceReg) { applyChromeFix(); } @@ -268,6 +272,24 @@ int main(int argc, char *argv[]) "the links that MO doesn't.").arg(url.game())); return 1; } + } else if (args.at(1).startsWith("modl://")) { + QUrl url(args.at(1)); + QUrlQuery query(url.query()); + QStringList handlerVals = storage->getHandler(url.host()); + QString executable = handlerVals.front(); + handlerVals.pop_front(); + QString arguments = handlerVals.join(" "); + if (!executable.isEmpty()) { + handleLink(executable, "download", query.queryItemValue("url")); + return 0; + } + else { + QMessageBox::warning(nullptr, QObject::tr("No handler found"), + QObject::tr("No application registered to handle this game (%1).\n" + "If you expected Mod Organizer to handle the link, " + "you have to go to Settings->Nexus and click the \"Associate with ... links\"-button.").arg(url.host())); + return 1; + } } else { QMessageBox::warning(nullptr, QObject::tr("Invalid Arguments"), QObject::tr("Invalid number of parameters")); return 1; From 62c07c9b4355f3a64ea90c06d432d89792db16b0 Mon Sep 17 00:00:00 2001 From: Eddoursul Date: Fri, 20 Oct 2023 19:24:45 +0200 Subject: [PATCH 2/4] Supplied URL must be urlencoded --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b42fad3..8f9b3e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -280,7 +280,7 @@ int main(int argc, char *argv[]) handlerVals.pop_front(); QString arguments = handlerVals.join(" "); if (!executable.isEmpty()) { - handleLink(executable, "download", query.queryItemValue("url")); + handleLink(executable, "download", QUrl::fromPercentEncoding(query.queryItemValue("url").toUtf8())); return 0; } else { From 0e62a4c28c54e629929fd8a18a01af06e9354191 Mon Sep 17 00:00:00 2001 From: Eddoursul Date: Fri, 20 Oct 2023 19:31:41 +0200 Subject: [PATCH 3/4] Cleaned up unused variables --- src/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8f9b3e5..25256d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -277,8 +277,6 @@ int main(int argc, char *argv[]) QUrlQuery query(url.query()); QStringList handlerVals = storage->getHandler(url.host()); QString executable = handlerVals.front(); - handlerVals.pop_front(); - QString arguments = handlerVals.join(" "); if (!executable.isEmpty()) { handleLink(executable, "download", QUrl::fromPercentEncoding(query.queryItemValue("url").toUtf8())); return 0; From 42b4659197b1eb2041ea2e33303a1ec20521d8fd Mon Sep 17 00:00:00 2001 From: Eddoursul Date: Sun, 22 Oct 2023 21:50:16 +0200 Subject: [PATCH 4/4] Auto-register only modl handler, keeping nxm behavior intact --- src/handlerstorage.cpp | 34 ++++++++++++++++++---------------- src/handlerstorage.h | 1 + src/main.cpp | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/handlerstorage.cpp b/src/handlerstorage.cpp index 07464a8..c64c388 100644 --- a/src/handlerstorage.cpp +++ b/src/handlerstorage.cpp @@ -26,22 +26,24 @@ void HandlerStorage::clear() void HandlerStorage::registerProxy(const QString &proxyPath) { - { - QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\nxm\\", QSettings::NativeFormat); - QString myExe = QString("\"%1\" ").arg(QDir::toNativeSeparators(proxyPath)).append("\"%1\""); - settings.setValue("Default", "URL:NXM Protocol"); - settings.setValue("URL Protocol", ""); - settings.setValue("shell/open/command/Default", myExe); - settings.sync(); - } - { - QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\modl\\", QSettings::NativeFormat); - QString myExe = QString("\"%1\" ").arg(QDir::toNativeSeparators(proxyPath)).append("\"%1\""); - settings.setValue("Default", "URL:MODL Protocol"); - settings.setValue("URL Protocol", ""); - settings.setValue("shell/open/command/Default", myExe); - settings.sync(); - } + QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\nxm\\", QSettings::NativeFormat); + QString myExe = QString("\"%1\" ").arg(QDir::toNativeSeparators(proxyPath)).append("\"%1\""); + settings.setValue("Default", "URL:NXM Protocol"); + settings.setValue("URL Protocol", ""); + settings.setValue("shell/open/command/Default", myExe); + settings.sync(); + + registerModlProxy(proxyPath); +} + +void HandlerStorage::registerModlProxy(const QString& proxyPath) +{ + QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\modl\\", QSettings::NativeFormat); + QString myExe = QString("\"%1\" ").arg(QDir::toNativeSeparators(proxyPath)).append("\"%1\""); + settings.setValue("Default", "URL:MODL Protocol"); + settings.setValue("URL Protocol", ""); + settings.setValue("shell/open/command/Default", myExe); + settings.sync(); } void HandlerStorage::registerHandler(const QString &executable, const QString &arguments, bool prepend) diff --git a/src/handlerstorage.h b/src/handlerstorage.h index f0b40f1..61f39a3 100644 --- a/src/handlerstorage.h +++ b/src/handlerstorage.h @@ -25,6 +25,7 @@ class HandlerStorage : public QObject void clear(); /// register the primary proxy handler void registerProxy(const QString &proxyPath); + void registerModlProxy(const QString& proxyPath); /// register handler (for all games) void registerHandler(const QString &executable, const QString &arguments, bool prepend); /// register handler for specified games diff --git a/src/main.cpp b/src/main.cpp index 25256d6..483cc1c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -246,7 +246,7 @@ int main(int argc, char *argv[]) if ((args.at(1) == "reg") || (args.at(1) == "forcereg")) { if (args.count() == 4) { storage->registerHandler(args.at(2).split(",", Qt::SkipEmptyParts), QDir::toNativeSeparators(args.at(3)), "", true, forceReg); - storage->registerProxy(QCoreApplication::applicationFilePath()); + storage->registerModlProxy(QCoreApplication::applicationFilePath()); if (forceReg) { applyChromeFix(); }