mirror of
https://github.com/itay-grudev/SingleApplication.git
synced 2025-01-15 17:02:06 +08:00
Allow data exclusion for the server name hash and Windows fixes (#16)
* Allows the application path and version to be excluded from the server name hash. The following flags were added for this purpose: * `SingleApplication::Mode::ExcludeAppVersion` * `SingleApplication::Mode::ExcludeAppPath` * Allow a non elevated process to connect to a local server created by an elevated process run by the same user on Windows * Fixes a problem with upper case letters in paths on Windows
This commit is contained in:
parent
26943b1e69
commit
0f821d44f3
@ -59,11 +59,21 @@ void SingleApplicationPrivate::genBlockServerName( int timeout )
|
|||||||
QCryptographicHash appData( QCryptographicHash::Sha256 );
|
QCryptographicHash appData( QCryptographicHash::Sha256 );
|
||||||
appData.addData( "SingleApplication", 17 );
|
appData.addData( "SingleApplication", 17 );
|
||||||
appData.addData( SingleApplication::app_t::applicationName().toUtf8() );
|
appData.addData( SingleApplication::app_t::applicationName().toUtf8() );
|
||||||
appData.addData( SingleApplication::app_t::applicationVersion().toUtf8() );
|
|
||||||
appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() );
|
|
||||||
appData.addData( SingleApplication::app_t::organizationName().toUtf8() );
|
appData.addData( SingleApplication::app_t::organizationName().toUtf8() );
|
||||||
appData.addData( SingleApplication::app_t::organizationDomain().toUtf8() );
|
appData.addData( SingleApplication::app_t::organizationDomain().toUtf8() );
|
||||||
|
|
||||||
|
if( ! (options & SingleApplication::Mode::ExcludeAppVersion) ) {
|
||||||
|
appData.addData( SingleApplication::app_t::applicationVersion().toUtf8() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ! (options & SingleApplication::Mode::ExcludeAppPath) ) {
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
appData.addData( SingleApplication::app_t::applicationFilePath().toLower().toUtf8() );
|
||||||
|
#else
|
||||||
|
appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
@ -108,6 +118,15 @@ void SingleApplicationPrivate::startPrimary( bool resetMemory )
|
|||||||
// So we start a QLocalServer to listen for connections
|
// So we start a QLocalServer to listen for connections
|
||||||
QLocalServer::removeServer( blockServerName );
|
QLocalServer::removeServer( blockServerName );
|
||||||
server = new QLocalServer();
|
server = new QLocalServer();
|
||||||
|
|
||||||
|
// Restrict access to the socket according to the
|
||||||
|
// SingleApplication::Mode::User flag on User level or no restrictions
|
||||||
|
if( options & SingleApplication::Mode::User ) {
|
||||||
|
server->setSocketOptions( QLocalServer::UserAccessOption );
|
||||||
|
} else {
|
||||||
|
server->setSocketOptions( QLocalServer::WorldAccessOption );
|
||||||
|
}
|
||||||
|
|
||||||
server->listen( blockServerName );
|
server->listen( blockServerName );
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
server,
|
server,
|
||||||
|
@ -59,7 +59,9 @@ public:
|
|||||||
enum Mode {
|
enum Mode {
|
||||||
User = 1 << 0,
|
User = 1 << 0,
|
||||||
System = 1 << 1,
|
System = 1 << 1,
|
||||||
SecondaryNotification = 1 << 2
|
SecondaryNotification = 1 << 2,
|
||||||
|
ExcludeAppVersion = 1 << 3,
|
||||||
|
ExcludeAppPath = 1 << 4
|
||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(Options, Mode)
|
Q_DECLARE_FLAGS(Options, Mode)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user