Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modl:// support #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/handlerstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ void HandlerStorage::registerProxy(const QString &proxyPath)
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)
Expand Down
1 change: 1 addition & 0 deletions src/handlerstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 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->registerModlProxy(QCoreApplication::applicationFilePath());
if (forceReg) {
applyChromeFix();
}
Expand All @@ -268,6 +272,22 @@ 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();
if (!executable.isEmpty()) {
handleLink(executable, "download", QUrl::fromPercentEncoding(query.queryItemValue("url").toUtf8()));
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