Skip to content
Merged
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: 11 additions & 1 deletion src/addbinarydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
#include <QFileDialog>

AddBinaryDialog::AddBinaryDialog(
const std::vector<std::tuple<QString, QString, QString>>& games, QWidget* parent)
const std::vector<std::tuple<QString, QString, QString>>& games,
const QStringList schemas, QWidget* parent)
: QDialog(parent), ui(new Ui::AddBinaryDialog)
{
ui->setupUi(this);

for (auto iter = games.begin(); iter != games.end(); ++iter) {
addGame(std::get<0>(*iter), std::get<1>(*iter));
}

for (auto schema : schemas) {
this->ui->schemaSelector->addItem(schema);
}
}

AddBinaryDialog::~AddBinaryDialog()
Expand Down Expand Up @@ -45,6 +50,11 @@ QString AddBinaryDialog::arguments()
return ui->argumentsEdit->text();
}

QString AddBinaryDialog::schema()
{
return ui->schemaSelector->currentText();
}

void AddBinaryDialog::on_browseButton_clicked()
{
ui->binaryEdit->setText(QFileDialog::getOpenFileName(
Expand Down
3 changes: 2 additions & 1 deletion src/addbinarydialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ class AddBinaryDialog : public QDialog
public:
explicit AddBinaryDialog(
const std::vector<std::tuple<QString, QString, QString>>& handlers,
QWidget* parent = 0);
const QStringList schemas, QWidget* parent = 0);
~AddBinaryDialog();
QStringList gameIDs();
QString executable();
QString arguments();
QString schema();
private slots:
void on_browseButton_clicked();

Expand Down
24 changes: 17 additions & 7 deletions src/addbinarydialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>575</width>
<height>160</height>
<height>219</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -28,7 +28,7 @@
<item>
<widget class="QListWidget" name="gamesList">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
<enum>QAbstractItemView::SelectionMode::ExtendedSelection</enum>
</property>
</widget>
</item>
Expand All @@ -37,7 +37,7 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="binaryLabel">
<property name="text">
<string>Select Handler Binary (i.e. ModOrganizer.exe)</string>
</property>
Expand All @@ -64,7 +64,17 @@
</layout>
</item>
<item>
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="schemaLabel">
<property name="text">
<string>Assigned Schema</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="schemaSelector"/>
</item>
<item>
<widget class="QLabel" name="argumentsLabel">
<property name="text">
<string>Set Arguments (optional)</string>
</property>
Expand All @@ -76,7 +86,7 @@
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -93,10 +103,10 @@
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>
Expand Down
60 changes: 40 additions & 20 deletions src/handlerstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,30 @@ void HandlerStorage::clear()
m_Handlers.clear();
}

void HandlerStorage::registerProxy(const QString& proxyPath)
void HandlerStorage::registerSchemaProxy(const QString& proxyPath,
const QString& schema)
{
QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\nxm\\",
QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\" + schema + "\\",
QSettings::NativeFormat);
QString myExe =
QString("\"%1\" ").arg(QDir::toNativeSeparators(proxyPath)).append("\"%1\"");
settings.setValue("Default", "URL:NXM Protocol");
settings.setValue("Default", "URL:" + schema.toUpper() + " Protocol");
settings.setValue("URL Protocol", "");
settings.setValue("shell/open/command/Default", myExe);
settings.sync();
}

void HandlerStorage::registerHandler(const QString& executable,
void HandlerStorage::registerHandler(const QString& schema, const QString& executable,
const QString& arguments, bool prepend)
{
QStringList games;
for (const auto& game : this->knownGames()) {
games.append(std::get<1>(game));
}
registerHandler(games, executable, arguments, prepend, false);
registerHandler(games, schema, executable, arguments, prepend, false);
}

void HandlerStorage::registerHandler(const QStringList& games,
void HandlerStorage::registerHandler(const QStringList& games, const QString& schema,
const QString& executable,
const QString& arguments, bool prepend, bool rereg)
{
Expand All @@ -54,12 +55,14 @@ void HandlerStorage::registerHandler(const QStringList& games,
gamesLower.append(game.toLower());
}
for (auto iter = m_Handlers.begin(); iter != m_Handlers.end(); ++iter) {
if (iter->executable.compare(executable, Qt::CaseInsensitive) == 0) {
// executable already registered, update supported games and move it to top if
// requested
if (iter->executable.compare(executable, Qt::CaseInsensitive) == 0 &&
iter->schema.compare(schema, Qt::CaseInsensitive) == 0) {
// executable already registered, update supported games and move it to
// top if requested
if (rereg) {
HandlerInfo info = *iter;
info.games = gamesLower;
info.arguments = arguments;
m_Handlers.erase(iter);
if (prepend) {
m_Handlers.push_front(info);
Expand All @@ -69,6 +72,7 @@ void HandlerStorage::registerHandler(const QStringList& games,
} else {
iter->games.append(gamesLower);
iter->games.removeDuplicates();
iter->arguments = arguments;
}
return; // important: in the rereg-case we changed the list thus screwing up the
// iterator
Expand All @@ -79,6 +83,7 @@ void HandlerStorage::registerHandler(const QStringList& games,
HandlerInfo info;
info.ID = static_cast<int>(m_Handlers.size());
info.games = gamesLower;
info.schema = schema;
info.executable = executable;
info.arguments = arguments;
if (prepend) {
Expand All @@ -88,7 +93,7 @@ void HandlerStorage::registerHandler(const QStringList& games,
}
}

QStringList HandlerStorage::getHandler(const QString& game) const
QStringList HandlerStorage::getHandler(const QString& game, const QString& schema) const
{
QString gameKey;
QStringList results;
Expand All @@ -102,23 +107,27 @@ QStringList HandlerStorage::getHandler(const QString& game) const
}
// look for an explictly registered handler
for (const HandlerInfo& info : m_Handlers) {
for (auto handler : info.games) {
if (game.compare(handler, Qt::CaseInsensitive) == 0 ||
gameKey.compare(handler, Qt::CaseInsensitive) == 0) {
results << info.executable;
results << info.arguments;
return results;
if (info.schema == schema) {
for (auto handler : info.games) {
if (game.compare(handler, Qt::CaseInsensitive) == 0 ||
gameKey.compare(handler, Qt::CaseInsensitive) == 0) {
results << info.executable;
results << info.arguments;
return results;
}
}
}
}

// if no registered handler, look for the first "other" entry
if (results.length() == 0) {
for (const HandlerInfo& info : m_Handlers) {
if (info.games.contains("other", Qt::CaseInsensitive)) {
results << info.executable;
results << info.arguments;
return results;
if (info.schema == schema) {
if (info.games.contains("other", Qt::CaseInsensitive)) {
results << info.executable;
results << info.arguments;
return results;
}
}
}
}
Expand All @@ -136,18 +145,26 @@ std::vector<std::tuple<QString, QString, QString>> HandlerStorage::knownGames()
return {
std::make_tuple<QString, QString, QString>("Morrowind", "morrowind", "morrowind"),
std::make_tuple<QString, QString, QString>("Oblivion", "oblivion", "oblivion"),
std::make_tuple<QString, QString, QString>(
"Oblivion Remastered", "oblivionremastered", "oblivionremastered"),
std::make_tuple<QString, QString, QString>("Fallout 3", "fallout3", "fallout3"),
std::make_tuple<QString, QString, QString>("Fallout 4", "fallout4", "fallout4"),
std::make_tuple<QString, QString, QString>("Fallout NV", "falloutnv", "newvegas"),
std::make_tuple<QString, QString, QString>("Skyrim", "skyrim", "skyrim"),
std::make_tuple<QString, QString, QString>("SkyrimSE", "skyrimse",
"skyrimspecialedition"),
std::make_tuple<QString, QString, QString>("Starfield", "starfield", "starfield"),
std::make_tuple<QString, QString, QString>("Enderal", "enderal", "enderal"),
std::make_tuple<QString, QString, QString>("EnderalSE", "enderalse",
"enderalspecialedition"),
std::make_tuple<QString, QString, QString>("Other", "other", "other")};
}

QStringList HandlerStorage::availableSchemas() const
{
return {"nxm", "modl"};
}

QStringList HandlerStorage::stripCall(const QString& call)
{
// results[0] is binary, results[1..n] are optional arguments
Expand Down Expand Up @@ -213,6 +230,7 @@ void HandlerStorage::loadStore()
if (!gameList.isEmpty()) {
info.games = gameList.split(",");
}
info.schema = settings.value("schema", "nxm").toString();
info.executable = settings.value("executable").toString();
info.arguments = settings.value("arguments").toString();
if (QFile::exists(info.executable)) {
Expand All @@ -234,6 +252,7 @@ void HandlerStorage::loadStore()
ids.append(std::get<1>(*iter));
}
info.games = QStringList() << ids;
info.schema = "nxm";
info.executable = handlerValues.front();
handlerValues.pop_front();
info.arguments = handlerValues.join(" ");
Expand Down Expand Up @@ -261,6 +280,7 @@ void HandlerStorage::saveStore()
for (auto iter = m_Handlers.begin(); iter != m_Handlers.end(); ++iter) {
settings.setArrayIndex(i++);
settings.setValue("games", iter->games.join(","));
settings.setValue("schema", iter->schema);
settings.setValue("executable", iter->executable);
settings.setValue("arguments", iter->arguments);
}
Expand Down
17 changes: 10 additions & 7 deletions src/handlerstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct HandlerInfo
{
int ID;
QStringList games;
QString schema;
QString executable;
QString arguments;
};
Expand All @@ -22,16 +23,18 @@ class HandlerStorage : public QObject
~HandlerStorage();

void clear();
/// register the primary proxy handler
void registerProxy(const QString& proxyPath);
/// register a proxy handler
void registerSchemaProxy(const QString& proxyPath, const QString& schema);
/// register handler (for all games)
void registerHandler(const QString& executable, const QString& arguments,
bool prepend);
void registerHandler(const QString& schema, const QString& executable,
const QString& arguments, bool prepend);
/// register handler for specified games
void registerHandler(const QStringList& games, const QString& executable,
const QString& arguments, bool prepend, bool rereg);
QStringList getHandler(const QString& game) const;
void registerHandler(const QStringList& games, const QString& schema,
const QString& executable, const QString& arguments,
bool prepend, bool rereg);
QStringList getHandler(const QString& game, const QString& schema) const;
std::vector<std::tuple<QString, QString, QString>> knownGames() const;
QStringList availableSchemas() const;
std::list<HandlerInfo> handlers() const { return m_Handlers; }

static QStringList stripCall(const QString& call);
Expand Down
Loading
Loading