aboutsummaryrefslogtreecommitdiff
path: root/singleapplication.cpp
diff options
context:
space:
mode:
authorItay Grudev <itay-grudev@users.noreply.github.com>2017-02-02 04:28:00 +0000
committerGitHub <noreply@github.com>2017-02-02 04:28:00 +0000
commit48416819186ac02296b7cc6f02aeaa3d6778a75d (patch)
tree8930b99bf77185dc15312594eb711462ebee617c /singleapplication.cpp
parentFixed typo in README.md (diff)
downloadsingleapplication-48416819186ac02296b7cc6f02aeaa3d6778a75d.tar.xz
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
Diffstat (limited to 'singleapplication.cpp')
-rw-r--r--singleapplication.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/singleapplication.cpp b/singleapplication.cpp
index 34d9b1d..d178d98 100644
--- a/singleapplication.cpp
+++ b/singleapplication.cpp
@@ -37,6 +37,11 @@
#include <unistd.h>
#endif
+#ifdef Q_OS_WIN
+ #include <windows.h>
+ #include <lmcons.h>
+#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;