mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:36:09 +00:00
UI: Exit when can't open the driver device.
This commit is contained in:
parent
f591c0f80d
commit
7cf9847a21
@ -48,6 +48,11 @@ void DriverManager::setupWorker()
|
||||
m_workerThread->start();
|
||||
}
|
||||
|
||||
bool DriverManager::isDeviceOpened() const
|
||||
{
|
||||
return m_device->isOpened();
|
||||
}
|
||||
|
||||
bool DriverManager::openDevice()
|
||||
{
|
||||
if (!m_device->open(FortCommon::deviceName())) {
|
||||
|
@ -21,6 +21,8 @@ public:
|
||||
|
||||
QString errorMessage() const { return m_errorMessage; }
|
||||
|
||||
bool isDeviceOpened() const;
|
||||
|
||||
signals:
|
||||
void errorMessageChanged();
|
||||
|
||||
|
@ -22,12 +22,13 @@
|
||||
#include "util/netutil.h"
|
||||
#include "util/osutil.h"
|
||||
|
||||
FortManager::FortManager(QObject *parent) :
|
||||
FortManager::FortManager(FortSettings *fortSettings,
|
||||
QObject *parent) :
|
||||
QObject(parent),
|
||||
m_trayIcon(new QSystemTrayIcon(this)),
|
||||
m_engine(nullptr),
|
||||
m_appWindow(nullptr),
|
||||
m_fortSettings(new FortSettings(qApp->arguments(), this)),
|
||||
m_fortSettings(fortSettings),
|
||||
m_firewallConf(new FirewallConf(this)),
|
||||
m_firewallConfToEdit(nullConf()),
|
||||
m_driverManager(new DriverManager(this))
|
||||
@ -69,7 +70,7 @@ void FortManager::registerQmlTypes()
|
||||
bool FortManager::setupDriver()
|
||||
{
|
||||
if (!m_driverManager->openDevice()) {
|
||||
showErrorBox(m_driverManager->errorMessage());
|
||||
showErrorBox("Setup Driver: " + m_driverManager->errorMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -197,7 +198,7 @@ void FortManager::setFirewallConfToEdit(FirewallConf *conf)
|
||||
bool FortManager::loadSettings(FirewallConf *conf)
|
||||
{
|
||||
if (!m_fortSettings->readConf(*conf)) {
|
||||
showErrorBox(m_fortSettings->errorMessage());
|
||||
showErrorBox("Load Settings: " + m_fortSettings->errorMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -208,7 +209,7 @@ bool FortManager::saveSettings(FirewallConf *newConf, bool onlyFlags)
|
||||
{
|
||||
if (!(onlyFlags ? m_fortSettings->writeConfFlags(*newConf)
|
||||
: m_fortSettings->writeConf(*newConf))) {
|
||||
showErrorBox(m_fortSettings->errorMessage());
|
||||
showErrorBox("Save Settings: " + m_fortSettings->errorMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -223,9 +224,12 @@ bool FortManager::saveSettings(FirewallConf *newConf, bool onlyFlags)
|
||||
|
||||
bool FortManager::updateDriverConf(FirewallConf *conf)
|
||||
{
|
||||
if (!m_driverManager->isDeviceOpened())
|
||||
return false;
|
||||
|
||||
// Update driver
|
||||
if (!m_driverManager->writeConf(*conf)) {
|
||||
showErrorBox(m_driverManager->errorMessage());
|
||||
showErrorBox("Update Driver Conf: " + m_driverManager->errorMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -236,7 +240,7 @@ bool FortManager::updateDriverConfFlags(FirewallConf *conf)
|
||||
{
|
||||
// Update driver
|
||||
if (!m_driverManager->writeConfFlags(*conf)) {
|
||||
showErrorBox(m_driverManager->errorMessage());
|
||||
showErrorBox("Update Driver Conf Flags: " + m_driverManager->errorMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,8 @@ class FortManager : public QObject
|
||||
Q_PROPERTY(DriverManager *driverManager READ driverManager CONSTANT)
|
||||
|
||||
public:
|
||||
explicit FortManager(QObject *parent = nullptr);
|
||||
explicit FortManager(FortSettings *fortSettings,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
FortSettings *fortSettings() const { return m_fortSettings; }
|
||||
|
||||
|
@ -97,6 +97,10 @@ bool FortSettings::readConf(FirewallConf &conf)
|
||||
const QString filePath = confFilePath();
|
||||
const QString backupFilePath = confBackupFilePath();
|
||||
|
||||
if (!(FileUtil::fileExists(filePath)
|
||||
|| FileUtil::fileExists(backupFilePath)))
|
||||
return true;
|
||||
|
||||
return tryToReadConf(conf, filePath)
|
||||
|| tryToReadConf(conf, backupFilePath);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <QApplication>
|
||||
|
||||
#include "../common/version.h"
|
||||
#include "driver/drivermanager.h"
|
||||
#include "fortcommon.h"
|
||||
#include "fortmanager.h"
|
||||
#include "fortsettings.h"
|
||||
@ -14,14 +15,20 @@ int main(int argc, char *argv[])
|
||||
app.setApplicationVersion(APP_VERSION_STR);
|
||||
app.setApplicationDisplayName(APP_NAME " v" APP_VERSION_STR);
|
||||
|
||||
FortManager fortManager;
|
||||
FortSettings fortSettings(qApp->arguments());
|
||||
|
||||
// Register booted provider and exit
|
||||
if (fortManager.fortSettings()->boot()) {
|
||||
if (fortSettings.boot()) {
|
||||
FortCommon::provUnregister();
|
||||
return FortCommon::provRegister(true);
|
||||
}
|
||||
|
||||
FortManager fortManager(&fortSettings);
|
||||
|
||||
// Error: Cannot open the driver device
|
||||
if (!fortManager.driverManager()->isDeviceOpened())
|
||||
return 1;
|
||||
|
||||
fortManager.showTrayIcon();
|
||||
|
||||
return app.exec();
|
||||
|
@ -15,6 +15,11 @@ Device::~Device()
|
||||
close();
|
||||
}
|
||||
|
||||
bool Device::isOpened() const
|
||||
{
|
||||
return (m_handle != INVALID_HANDLE_VALUE);
|
||||
}
|
||||
|
||||
bool Device::open(const QString &filePath)
|
||||
{
|
||||
const DWORD access = GENERIC_READ | GENERIC_WRITE;
|
||||
|
@ -11,6 +11,8 @@ public:
|
||||
explicit Device(QObject *parent = nullptr);
|
||||
virtual ~Device();
|
||||
|
||||
bool isOpened() const;
|
||||
|
||||
static QString lastErrorMessage();
|
||||
|
||||
signals:
|
||||
|
Loading…
Reference in New Issue
Block a user