mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:56:22 +00:00
UI: DriverManager: Refactor error handling.
This commit is contained in:
parent
3545fa1518
commit
8b4d06320a
@ -91,4 +91,7 @@ DEFINE_GUID(FORT_GUID_FILTER_REAUTH_OUT,
|
||||
#define NT_SUCCESS(status) ((LONG) (status) >= 0)
|
||||
#endif
|
||||
|
||||
#define FORT_STATUS_USER_ERROR STATUS_INVALID_PARAMETER
|
||||
#define FORT_ERROR_USER_ERROR ERROR_INVALID_PARAMETER
|
||||
|
||||
#endif COMMON_H
|
||||
|
@ -227,7 +227,7 @@ fort_conf_ref_exe_add_path_locked (PFORT_CONF_REF conf_ref,
|
||||
return TRUE;
|
||||
} else {
|
||||
if (flags.is_new)
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return FORT_STATUS_USER_ERROR;
|
||||
|
||||
// Replace flags
|
||||
{
|
||||
|
@ -991,7 +991,7 @@ fort_device_control (PDEVICE_OBJECT device, PIRP irp)
|
||||
PIO_STACK_LOCATION irp_stack;
|
||||
ULONG_PTR info = 0;
|
||||
ULONG control_code;
|
||||
NTSTATUS status = STATUS_INVALID_PARAMETER;
|
||||
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
||||
|
||||
irp_stack = IoGetCurrentIrpStackLocation(irp);
|
||||
control_code = irp_stack->Parameters.DeviceIoControl.IoControlCode;
|
||||
@ -1102,7 +1102,7 @@ fort_device_control (PDEVICE_OBJECT device, PIRP irp)
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(status)) {
|
||||
if (!NT_SUCCESS(status) && status != FORT_STATUS_USER_ERROR) {
|
||||
DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL,
|
||||
"FORT: Device Control: Error: %x\n", status);
|
||||
}
|
||||
|
@ -486,7 +486,7 @@ fort_defer_stream_add (PFORT_DEFER defer,
|
||||
if (dataOffset->streamDataOffset != 0
|
||||
&& (dataOffset->netBuffer != netBuf
|
||||
|| dataOffset->mdl != NET_BUFFER_CURRENT_MDL(netBuf)))
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return STATUS_FWP_CANNOT_PEND;
|
||||
}
|
||||
|
||||
KeAcquireInStackQueuedSpinLock(&defer->lock, &lock_queue);
|
||||
|
@ -23,24 +23,22 @@ DriverManager::~DriverManager()
|
||||
abortWorker();
|
||||
}
|
||||
|
||||
void DriverManager::setErrorMessage(const QString &errorMessage)
|
||||
QString DriverManager::errorMessage() const
|
||||
{
|
||||
if (m_errorMessage != errorMessage) {
|
||||
m_errorMessage = errorMessage;
|
||||
emit errorMessageChanged();
|
||||
}
|
||||
return (m_errorCode == 0) ? QString()
|
||||
: OsUtil::errorMessage(m_errorCode);
|
||||
}
|
||||
|
||||
void DriverManager::updateError(bool success)
|
||||
{
|
||||
m_errorCode = success ? 0 : OsUtil::lastErrorCode();
|
||||
setErrorMessage(success ? QString()
|
||||
: OsUtil::lastErrorMessage(m_errorCode));
|
||||
emit errorMessageChanged();
|
||||
}
|
||||
|
||||
bool DriverManager::isDeviceError() const
|
||||
{
|
||||
return m_errorCode == OsUtil::userErrorCode();
|
||||
return m_errorCode != 0
|
||||
&& m_errorCode != FortCommon::userErrorCode();
|
||||
}
|
||||
|
||||
void DriverManager::setupWorker()
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
|
||||
DriverWorker *driverWorker() const { return m_driverWorker; }
|
||||
|
||||
QString errorMessage() const { return m_errorMessage; }
|
||||
QString errorMessage() const;
|
||||
bool isDeviceError() const;
|
||||
|
||||
bool isDeviceOpened() const;
|
||||
@ -59,8 +59,6 @@ private:
|
||||
|
||||
Device *m_device = nullptr;
|
||||
DriverWorker *m_driverWorker = nullptr;
|
||||
|
||||
QString m_errorMessage;
|
||||
};
|
||||
|
||||
#endif // DRIVERMANAGER_H
|
||||
|
@ -109,7 +109,7 @@ void DriverWorker::readLog()
|
||||
if (success) {
|
||||
m_logBuffer->reset(nr);
|
||||
} else if (!m_cancelled) {
|
||||
errorMessage = OsUtil::lastErrorMessage();
|
||||
errorMessage = OsUtil::errorMessage();
|
||||
}
|
||||
|
||||
emitReadLogResult(success, errorMessage);
|
||||
|
@ -310,13 +310,12 @@ void OptionsPage::setupDriverIcon()
|
||||
: ":/images/plugin_disabled.png";
|
||||
|
||||
m_iconDriver->setPixmap(QPixmap(iconPath));
|
||||
|
||||
retranslateDriverMessage();
|
||||
};
|
||||
|
||||
refreshDriverIcon();
|
||||
|
||||
connect(driverManager(), &DriverManager::isDeviceOpenedChanged, this, refreshDriverIcon);
|
||||
connect(driverManager(), &DriverManager::errorMessageChanged, this, &OptionsPage::retranslateDriverMessage);
|
||||
}
|
||||
|
||||
void OptionsPage::setupNewVersionBox()
|
||||
|
@ -53,6 +53,11 @@ quint32 FortCommon::ioctlDelApp()
|
||||
return FORT_IOCTL_DELAPP;
|
||||
}
|
||||
|
||||
quint32 FortCommon::userErrorCode()
|
||||
{
|
||||
return FORT_ERROR_USER_ERROR;
|
||||
}
|
||||
|
||||
int FortCommon::bufferSize()
|
||||
{
|
||||
return FORT_BUFFER_SIZE;
|
||||
|
@ -20,6 +20,8 @@ public:
|
||||
static quint32 ioctlAddApp();
|
||||
static quint32 ioctlDelApp();
|
||||
|
||||
static quint32 userErrorCode();
|
||||
|
||||
static int bufferSize();
|
||||
|
||||
static quint32 confIoConfOff();
|
||||
|
@ -28,17 +28,12 @@ bool OsUtil::createGlobalMutex(const char *name)
|
||||
&& GetLastError() != ERROR_ALREADY_EXISTS;
|
||||
}
|
||||
|
||||
quint32 OsUtil::userErrorCode()
|
||||
{
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
quint32 OsUtil::lastErrorCode()
|
||||
{
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
QString OsUtil::lastErrorMessage(quint32 errorCode)
|
||||
QString OsUtil::errorMessage(quint32 errorCode)
|
||||
{
|
||||
LPWSTR buf = nullptr;
|
||||
|
||||
|
@ -14,9 +14,8 @@ public:
|
||||
|
||||
static bool createGlobalMutex(const char *name);
|
||||
|
||||
static quint32 userErrorCode();
|
||||
static quint32 lastErrorCode();
|
||||
static QString lastErrorMessage(quint32 errorCode = lastErrorCode());
|
||||
static QString errorMessage(quint32 errorCode = lastErrorCode());
|
||||
|
||||
static qint32 getTickCount();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user