Skip to content

Commit

Permalink
Added modl support
Browse files Browse the repository at this point in the history
  • Loading branch information
eddoursul committed Oct 20, 2023
1 parent 9876f57 commit 2077b5e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/handlerstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 23 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <QRegularExpression>
#include <QDateTime>
#include <QStandardPaths>
#include <QUrl>
#include <QUrlQuery>
#include "logger.h"


Expand Down Expand Up @@ -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 "
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
Expand Down

0 comments on commit 2077b5e

Please sign in to comment.