Skip to content

Commit

Permalink
Removed Windows specific code for getting username
Browse files Browse the repository at this point in the history
On the absolute path to the home directory is now explicitly used.
  • Loading branch information
itay-grudev committed Jan 24, 2017
1 parent 60d30db commit 6a4d892
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
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__
----------

Expand Down
23 changes: 7 additions & 16 deletions singleapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <cstdlib>

#include <QtCore/QDir>
#include <QtCore/QProcess>
#include <QtCore/QByteArray>
#include <QtCore/QSemaphore>
Expand All @@ -36,11 +37,6 @@
#include <unistd.h>
#endif

#ifdef Q_OS_WIN
#include <windows.h>
#include <lmcons.h>
#endif

#include "singleapplication.h"
#include "singleapplication_p.h"

Expand Down Expand Up @@ -77,25 +73,20 @@ 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
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
#ifdef Q_OS_UNIX
QString username;
QProcess process;
process.start( "whoami" );
if( process.waitForFinished( timeout ) &&
process.exitCode() == QProcess::NormalExit) {
appData.addData( process.readLine() );
} else {
appData.addData( QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).join("").toUtf8() );
appData.addData(
QDir(
QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).first()
).absolutePath().toUtf8()
);
}
#endif
}
Expand Down

0 comments on commit 6a4d892

Please sign in to comment.