diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f417b0..e391ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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__ ---------- diff --git a/singleapplication.cpp b/singleapplication.cpp index 7d77292..4e1c6ac 100644 --- a/singleapplication.cpp +++ b/singleapplication.cpp @@ -22,6 +22,7 @@ #include +#include #include #include #include @@ -36,11 +37,6 @@ #include #endif -#ifdef Q_OS_WIN - #include - #include -#endif - #include "singleapplication.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 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 }