fix: improve single instance detection for non-standard USER env var on Windows

This commit is contained in:
sshekhar563 2025-10-27 18:04:37 +05:30 committed by Jonathan White
parent 8cfbe48f78
commit 8289793f95
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01

View file

@ -75,8 +75,27 @@ Application::Application(int& argc, char** argv)
}
#endif
userName.replace('/', '_');
userName.replace('\\', '_');
static const QRegularExpression invalidFileChars(R"([<>:\"/\\|?*])");
userName.replace(invalidFileChars, "_");
// Remove leading/trailing whitespace and trailing dots/spaces
userName = userName.trimmed();
while (!userName.isEmpty() && (userName.endsWith('.') || userName.endsWith(' '))) {
userName.chop(1);
}
// Build identifier for lock/socket file naming
QString identifier = QStringLiteral("keepassxc");
if (!userName.isEmpty()) {
identifier += QChar('-') + userName;
}
#ifdef QT_DEBUG
identifier += QStringLiteral("-DEBUG");
#endif
QString lockName = identifier + QStringLiteral(".lock");
m_socketName = identifier + QStringLiteral(".socket");
QString identifier = "keepassxc";
if (!userName.isEmpty()) {
identifier += "-" + userName;