From 48416819186ac02296b7cc6f02aeaa3d6778a75d Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Thu, 2 Feb 2017 04:28:00 +0000 Subject: Reverted GetUserName API usage on Windows (#25) * Added back support for getting username on Windows * Fixed typo in singleapplication.pri * Compiler specific Advapi32.lib links * Removed username debug statement --- singleapplication.cpp | 15 ++++++++++++++- singleapplication.pri | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/singleapplication.cpp b/singleapplication.cpp index 34d9b1d..d178d98 100644 --- a/singleapplication.cpp +++ b/singleapplication.cpp @@ -37,6 +37,11 @@ #include #endif +#ifdef Q_OS_WIN + #include + #include +#endif + #include "singleapplication.h" #include "singleapplication_p.h" @@ -85,7 +90,15 @@ void SingleApplicationPrivate::genBlockServerName( int timeout ) // User level block requires a user specific data in the hash if( options & SingleApplication::Mode::User ) { #ifdef Q_OS_WIN - appData.addData( QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).join("").toUtf8() ); + Q_UNUSED(timeout); + wchar_t username [ UNLEN + 1 ]; + // Specifies size of the buffer on input + DWORD usernameLength = UNLEN + 1; + if( GetUserName( username, &usernameLength ) ) { + appData.addData( QString::fromWCharArray(username).toUtf8() ); + } else { + appData.addData( QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).join("").toUtf8() ); + } #endif #ifdef Q_OS_UNIX QProcess process; diff --git a/singleapplication.pri b/singleapplication.pri index 388e59f..cd3dd35 100644 --- a/singleapplication.pri +++ b/singleapplication.pri @@ -6,3 +6,8 @@ HEADERS += $$PWD/singleapplication.h \ SOURCES += $$PWD/singleapplication.cpp INCLUDEPATH += $$PWD + +win32 { + msvc:LIBS += Advapi32.lib + gcc:LIBS += -lAdvapi32 +} -- cgit v1.2.1