UI: Improve startup checks.

This commit is contained in:
Nodir Temirkhodjaev 2018-04-15 11:19:31 +05:00
parent aaa2dd7e83
commit e7e576ad29
2 changed files with 16 additions and 4 deletions

View File

@ -1,4 +1,5 @@
#include <QApplication>
#include <QMessageBox>
#include "../common/version.h"
#include "driver/drivermanager.h"
@ -7,6 +8,9 @@
#include "fortsettings.h"
#include "util/osutil.h"
#define FORT_ERROR_INSTANCE 1
#define FORT_ERROR_DEVICE 2
int main(int argc, char *argv[])
{
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
@ -28,13 +32,20 @@ int main(int argc, char *argv[])
}
// To check running instance
OsUtil::createGlobalMutex(APP_NAME);
if (!OsUtil::createGlobalMutex(APP_NAME)) {
QMessageBox::critical(nullptr, QString(),
"Application is already running!");
return FORT_ERROR_INSTANCE;
}
FortManager fortManager(&fortSettings);
// Error: Cannot open the driver device
if (!fortManager.driverManager()->isDeviceOpened())
return 1;
if (!fortManager.driverManager()->isDeviceOpened()) {
QMessageBox::critical(nullptr, QString(),
"Cannot open the driver device!");
return FORT_ERROR_DEVICE;
}
fortManager.showTrayIcon();

View File

@ -18,7 +18,8 @@ QString OsUtil::pidToPath(quint32 pid, bool isKernelPath)
bool OsUtil::createGlobalMutex(const char *name)
{
return !CreateMutexA(nullptr, FALSE, name);
return CreateMutexA(nullptr, FALSE, name)
&& GetLastError() != ERROR_ALREADY_EXISTS;
}
quint32 OsUtil::lastErrorCode()