mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:38:16 +00:00
UI: Improve startup checks.
This commit is contained in:
parent
aaa2dd7e83
commit
e7e576ad29
@ -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();
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user