Skip to content

Commit 71d5572

Browse files
authored
Migrate to new settings file to avoid compat issues (#26)
1 parent 374eead commit 71d5572

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/handlerstorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
static const QRegularExpression invalid_arguments("\"?%[0-9]+\"?");
99

1010
HandlerStorage::HandlerStorage(const QString& storagePath, QObject* parent)
11-
: QObject(parent), m_SettingsPath(storagePath + "/nxmhandler.ini")
11+
: QObject(parent), m_SettingsPath(storagePath + "/downloadhandler.ini")
1212
{
1313
loadStore();
1414
}

src/main.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ HandlerStorage* registerSchemaExecutable(const QDir& storagePath,
103103
return storage;
104104
}
105105

106+
QSettings resolveSettings(QDir baseDir)
107+
{
108+
if (!baseDir.exists("downloadhandler.ini") && baseDir.exists("nxmhandler.ini")) {
109+
QFile oldSettings(baseDir.absoluteFilePath("nxmhandler.ini"));
110+
oldSettings.copy(baseDir.absoluteFilePath("downloadhandler.ini"));
111+
}
112+
return QSettings(baseDir.absoluteFilePath("downloadhandler.ini"),
113+
QSettings::IniFormat);
114+
}
115+
106116
HandlerStorage* registerHandler(HandlerStorage* storage, const QString& schema,
107117
bool forceReg)
108118
{
@@ -125,21 +135,21 @@ HandlerStorage* registerHandler(HandlerStorage* storage, const QString& schema,
125135

126136
QDir handlerBaseDir = QFileInfo(handlerPath).absoluteDir();
127137

128-
QSettings settings(baseDir.absoluteFilePath("nxmhandler.ini"), QSettings::IniFormat);
129-
bool noRegister = settings.value("noregister", false).toBool();
130-
if (globalStorage.exists("nxmhandler.ini") &&
138+
QSettings settings = resolveSettings(baseDir);
139+
bool noRegister = settings.value("noregister", false).toBool();
140+
if (globalStorage.exists("downloadhandler.ini") &&
131141
handlerPath.endsWith("nxmhandler.exe", Qt::CaseInsensitive) &&
132142
QFile::exists(handlerPath)) {
133-
// global configuration avaible - use it
143+
// global configuration available - use it
134144
if (storage == nullptr)
135145
storage = new HandlerStorage(globalStorage.path());
136-
} else if (handlerBaseDir.exists("nxmhandler.ini") &&
146+
} else if (handlerBaseDir.exists("downloadhandler.ini") &&
137147
handlerPath.endsWith("nxmhandler.exe", Qt::CaseInsensitive) &&
138148
QFile::exists(handlerPath)) {
139149
// a portable installation is registered to handle links, use its
140150
// configuration
141151
if (storage == nullptr)
142-
storage = new HandlerStorage(globalStorage.path());
152+
storage = new HandlerStorage(handlerBaseDir.path());
143153
if (forceReg && (QString::compare(QDir::toNativeSeparators(
144154
QCoreApplication::applicationFilePath()),
145155
handlerPath, Qt::CaseInsensitive))) {

0 commit comments

Comments
 (0)