diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index c3afcf06f..21c367b8f 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -155,11 +155,12 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath, const QString& password, const QString& keyfile) { - QFileInfo fileInfo(filePath); + QString cleanFilePath = QDir::toNativeSeparators(filePath); + QFileInfo fileInfo(cleanFilePath); QString canonicalFilePath = fileInfo.canonicalFilePath(); if (canonicalFilePath.isEmpty()) { - emit messageGlobal(tr("Failed to open %1. It either does not exist or is not accessible.").arg(filePath), + emit messageGlobal(tr("Failed to open %1. It either does not exist or is not accessible.").arg(cleanFilePath), MessageWidget::Error); return; } @@ -178,10 +179,10 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath, } } - auto* dbWidget = new DatabaseWidget(QSharedPointer::create(filePath), this); + auto* dbWidget = new DatabaseWidget(QSharedPointer::create(cleanFilePath), this); addDatabaseTab(dbWidget, inBackground); dbWidget->performUnlockDatabase(password, keyfile); - updateLastDatabases(filePath); + updateLastDatabases(cleanFilePath); } /** @@ -782,7 +783,7 @@ void DatabaseTabWidget::updateLastDatabases(const QString& filename) config()->remove(Config::LastDatabases); } else { QStringList lastDatabases = config()->get(Config::LastDatabases).toStringList(); - lastDatabases.prepend(filename); + lastDatabases.prepend(QDir::toNativeSeparators(filename)); lastDatabases.removeDuplicates(); while (lastDatabases.count() > config()->get(Config::NumberOfRememberedLastDatabases).toInt()) { diff --git a/src/main.cpp b/src/main.cpp index 9fabf89ed..047e44740 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,6 +44,10 @@ Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) #endif #endif +#ifdef Q_OS_WIN +#include +#endif + int main(int argc, char** argv) { QT_REQUIRE_VERSION(argc, argv, QT_VERSION_STR) @@ -110,9 +114,29 @@ int main(int argc, char** argv) Config::createConfigFromFile(parser.value(configOption), parser.value(localConfigOption)); } + // Extract file names provided on the command line for opening + QStringList fileNames; +#ifdef Q_OS_WIN + // Get correct case for Windows filenames (fixes #7139) + for (const auto& file : parser.positionalArguments()) { + const auto fileInfo = QFileInfo(file); + WIN32_FIND_DATA findFileData; + HANDLE hFind; + hFind = FindFirstFile(fileInfo.absoluteFilePath().toUtf8(), &findFileData); + if (hFind != INVALID_HANDLE_VALUE) { + fileNames << QString("%1/%2").arg(fileInfo.absolutePath(), QString::fromUtf8(findFileData.cFileName)); + FindClose(hFind); + } + } +#else + for (const auto& file : parser.positionalArguments()) { + if (QFile::exists(file)) { + fileNames << QDir::toNativeSeparators(file); + } + } +#endif + // Process single instance and early exit if already running - // FIXME: this is a *mess* and it is entirely my fault. --wundrweapon - const QStringList fileNames = parser.positionalArguments(); if (app.isAlreadyRunning()) { if (parser.isSet(lockOption)) { if (app.sendLockToInstance()) { @@ -179,10 +203,7 @@ int main(int argc, char** argv) out << QObject::tr("Database password: ") << flush; password = Utils::getPassword(); } - - if (!filename.isEmpty() && QFile::exists(filename) && !filename.endsWith(".json", Qt::CaseInsensitive)) { - mainWindow.openDatabase(QDir::toNativeSeparators(filename), password, parser.value(keyfileOption)); - } + mainWindow.openDatabase(filename, password, parser.value(keyfileOption)); } int exitCode = Application::exec();