From 37156bd5f8234cb6f62d55475f1b11587beb5b87 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sun, 31 May 2020 09:28:33 -0400 Subject: [PATCH] Prevent overwriting of portable config on update * Move portable configuration files into a config subfolder from the executable. This prevents overwriting the stored config when the application is updated in-place. * Use .portable file to signal a portable app * Fix #4751 --- release-tool | 4 +++- share/keepassxc.ini | 10 ---------- src/core/Config.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 15 deletions(-) delete mode 100644 share/keepassxc.ini diff --git a/release-tool b/release-tool index 376d0d1217..0d176835aa 100755 --- a/release-tool +++ b/release-tool @@ -987,13 +987,15 @@ build() { cpack -G "${CPACK_GENERATORS};${build_generators}" # Inject the portable config into the zip build and rename + touch .portable for filename in ${APP_NAME}-*.zip; do logInfo "Creating portable zip file" local folder=$(echo ${filename} | sed -r 's/(.*)\.zip/\1/') python -c 'import zipfile,sys ; zipfile.ZipFile(sys.argv[1],"a").write(sys.argv[2],sys.argv[3])' \ - ${filename} ${SRC_DIR}/share/keepassxc.ini ${folder}/keepassxc.ini + ${filename} .portable ${folder}/.portable mv ${filename} ${folder}-portable.zip done + rm .portable mv "${APP_NAME}-"*.* ../ else diff --git a/share/keepassxc.ini b/share/keepassxc.ini deleted file mode 100644 index ab450d485e..0000000000 --- a/share/keepassxc.ini +++ /dev/null @@ -1,10 +0,0 @@ -[General] -UpdateCheckMessageShown=false -LastActiveDatabase=@Invalid() -LastOpenedDatabases=@Invalid() -HideWindowOnCopy=false -MinimizeOnCopy=true - -[GUI] -HideUsernames=false -HidePasswords=true diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 9f60cfef07..3c28af17dd 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -427,10 +427,10 @@ Config::Config(const QString& fileName, QObject* parent) Config::Config(QObject* parent) : QObject(parent) { - // Check if portable config is present (use it also to store local config) - QString portablePath = QDir::fromNativeSeparators(QCoreApplication::applicationDirPath()) + "/keepassxc.ini"; - if (QFile::exists(portablePath)) { - init(portablePath); + // Check if we are running in portable mode, if so store the config files local to the app + auto appDir = QCoreApplication::applicationDirPath(); + if (QFile::exists(appDir + QStringLiteral("/.portable"))) { + init(appDir + QStringLiteral("/config/keepassxc.ini"), appDir + QStringLiteral("/config/keepassxc_local.ini")); return; }