diff options
author | Itay Grudev <itay-grudev@users.noreply.github.com> | 2017-02-02 04:28:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-02 04:28:00 +0000 |
commit | 48416819186ac02296b7cc6f02aeaa3d6778a75d (patch) | |
tree | 8930b99bf77185dc15312594eb711462ebee617c | |
parent | Fixed typo in README.md (diff) | |
download | singleapplication-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
-rw-r--r-- | singleapplication.cpp | 15 | ||||
-rw-r--r-- | singleapplication.pri | 5 |
2 files changed, 19 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; 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 +} |