Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormckeema <mckeema@umich.edu>2022-09-10 19:23:30 +0300
committerJonathan White <support@dmapps.us>2022-09-11 15:31:29 +0300
commit3098bb1f188cb527c57a540418a3cc57f9752db6 (patch)
tree08685f721bc40d32b44792758f69f794c2ba3a43
parent3309dc2b5cd6ccb723ce3654d41e15c93656ea3b (diff)
Set correct case for database file path on Windows
* Fix #7139 - when opening database files from the command line, ensure the correct case is fed to the program to prevent case changes during saves. * Cleanup old code (checking for .json extension) from when KeePassXC app could act as a proxy.
-rw-r--r--src/gui/DatabaseTabWidget.cpp11
-rw-r--r--src/main.cpp33
2 files changed, 33 insertions, 11 deletions
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<Database>::create(filePath), this);
+ auto* dbWidget = new DatabaseWidget(QSharedPointer<Database>::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 <windows.h>
+#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();