Fix portable mode detection for native messaging files

* Fixes #10755
This commit is contained in:
Jonathan White 2024-05-26 10:19:10 -04:00
parent 2a62000b28
commit 1fd8923746
3 changed files with 28 additions and 16 deletions

View file

@ -512,20 +512,8 @@ void Config::init(const QString& configFileName, const QString& localConfigFileN
QPair<QString, QString> Config::defaultConfigFiles()
{
// Check if we are running in portable mode, if so store the config files local to the app
#ifdef Q_OS_WIN
// Enable QFileInfo::isWritable check on Windows
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
qt_ntfs_permission_lookup++;
#endif
auto portablePath = QCoreApplication::applicationDirPath().append("/%1");
auto portableFile = portablePath.arg(".portable");
bool isPortable = QFile::exists(portableFile) && QFileInfo(portableFile).isWritable();
#ifdef Q_OS_WIN
qt_ntfs_permission_lookup--;
#endif
if (isPortable) {
return {portablePath.arg("config/keepassxc.ini"), portablePath.arg("config/keepassxc_local.ini")};
if (isPortable()) {
return {portableConfigDir().append("/keepassxc.ini"), portableConfigDir().append("/keepassxc_local.ini")};
}
QString configPath;
@ -602,6 +590,27 @@ void Config::createTempFileInstance()
tmpFile->setParent(m_instance);
}
bool Config::isPortable()
{
#ifdef Q_OS_WIN
// Enable QFileInfo::isWritable check on Windows
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
qt_ntfs_permission_lookup++;
#endif
auto portablePath = QCoreApplication::applicationDirPath().append("/%1");
auto portableFile = portablePath.arg(".portable");
auto isPortable = QFile::exists(portableFile) && QFileInfo(portableFile).isWritable();
#ifdef Q_OS_WIN
qt_ntfs_permission_lookup--;
#endif
return isPortable;
}
QString Config::portableConfigDir()
{
return QCoreApplication::applicationDirPath().append("/config");
}
QList<Config::ShortcutEntry> Config::getShortcuts() const
{
m_settings->beginGroup("Shortcuts");