Removed Windows specific code for getting username

On the absolute path to the home directory is now explicitly used.
This commit is contained in:
Itay Grudev 2017-01-24 17:24:38 +00:00
parent 60d30db837
commit 6a4d89297b
No known key found for this signature in database
GPG Key ID: 8BA92A8D5F1660F3
2 changed files with 18 additions and 16 deletions

View File

@ -1,6 +1,17 @@
Changelog Changelog
========= =========
__3.0.3a__
----------
* Removed Microsoft Windows specific code for getting username due to
multiple problems and compiler differences on Windows platforms. On
Windows the shaered memory block in User mode now includes the user's
home path (which contains the user's username).
* Explicitly getting absolute path of the user's home directory as on Unix
a relative path (`~`) may be returned.
__3.0.2a__ __3.0.2a__
---------- ----------

View File

@ -22,6 +22,7 @@
#include <cstdlib> #include <cstdlib>
#include <QtCore/QDir>
#include <QtCore/QProcess> #include <QtCore/QProcess>
#include <QtCore/QByteArray> #include <QtCore/QByteArray>
#include <QtCore/QSemaphore> #include <QtCore/QSemaphore>
@ -36,11 +37,6 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifdef Q_OS_WIN
#include <windows.h>
#include <lmcons.h>
#endif
#include "singleapplication.h" #include "singleapplication.h"
#include "singleapplication_p.h" #include "singleapplication_p.h"
@ -77,25 +73,20 @@ void SingleApplicationPrivate::genBlockServerName( int timeout )
// User level block requires a user specific data in the hash // User level block requires a user specific data in the hash
if( options & SingleApplication::Mode::User ) { if( options & SingleApplication::Mode::User ) {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
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() ); appData.addData( QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).join("").toUtf8() );
}
#endif #endif
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
QString username;
QProcess process; QProcess process;
process.start( "whoami" ); process.start( "whoami" );
if( process.waitForFinished( timeout ) && if( process.waitForFinished( timeout ) &&
process.exitCode() == QProcess::NormalExit) { process.exitCode() == QProcess::NormalExit) {
appData.addData( process.readLine() ); appData.addData( process.readLine() );
} else { } else {
appData.addData( QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).join("").toUtf8() ); appData.addData(
QDir(
QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).first()
).absolutePath().toUtf8()
);
} }
#endif #endif
} }