diff options
| author | Itay Grudev <itay@grudev.com> | 2017-01-24 17:24:38 +0000 | 
|---|---|---|
| committer | Itay Grudev <itay@grudev.com> | 2017-01-24 17:25:00 +0000 | 
| commit | 6a4d89297b356c130d88a1718111f96e4b42705a (patch) | |
| tree | bd31a4cc55a901b35c460e0f2463fe7c50788435 | |
| parent | Refactored slotConnectionEstablished() (diff) | |
| download | singleapplication-6a4d89297b356c130d88a1718111f96e4b42705a.tar.xz | |
Removed Windows specific code for getting usernamev3.0.3a
On the absolute path to the home directory is now explicitly used.
| -rw-r--r-- | CHANGELOG.md | 11 | ||||
| -rw-r--r-- | singleapplication.cpp | 23 | 
2 files changed, 18 insertions, 16 deletions
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 <cstdlib> +#include <QtCore/QDir>  #include <QtCore/QProcess>  #include <QtCore/QByteArray>  #include <QtCore/QSemaphore> @@ -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" @@ -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      }  | 
