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
This commit is contained in:
Itay Grudev 2017-02-02 04:28:00 +00:00 committed by GitHub
parent 1c5164ed10
commit 4841681918
2 changed files with 19 additions and 1 deletions

View File

@ -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;

View File

@ -6,3 +6,8 @@ HEADERS += $$PWD/singleapplication.h \
SOURCES += $$PWD/singleapplication.cpp
INCLUDEPATH += $$PWD
win32 {
msvc:LIBS += Advapi32.lib
gcc:LIBS += -lAdvapi32
}