diff --git a/src/ui/control/controlworker.cpp b/src/ui/control/controlworker.cpp index 7fce01db..81b1bd84 100644 --- a/src/ui/control/controlworker.cpp +++ b/src/ui/control/controlworker.cpp @@ -78,6 +78,11 @@ int ControlWorker::id() const return int(socket()->socketDescriptor()); } +bool ControlWorker::isConnected() const +{ + return socket()->state() == QLocalSocket::ConnectedState; +} + QString ControlWorker::errorString() const { return socket()->errorString(); @@ -124,7 +129,11 @@ bool ControlWorker::sendCommandData(const QByteArray &commandData) const int bytesSent = socket()->write(commandData); if (bytesSent != commandData.size()) { - qWarning() << "Sent partial:" << id() << bytesSent << commandData.size(); + if (bytesSent < 0) { + qWarning() << "Send error:" << id() << errorString(); + } else { + qWarning() << "Sent partial:" << id() << bytesSent << commandData.size(); + } return false; } diff --git a/src/ui/control/controlworker.h b/src/ui/control/controlworker.h index 9bf5c883..3acdd3e8 100644 --- a/src/ui/control/controlworker.h +++ b/src/ui/control/controlworker.h @@ -24,7 +24,7 @@ public: QLocalSocket *socket() const { return m_socket; } int id() const; - + bool isConnected() const; QString errorString() const; void setupForAsync(); diff --git a/src/ui/driver/drivermanager.cpp b/src/ui/driver/drivermanager.cpp index 0c6f170b..1d40037b 100644 --- a/src/ui/driver/drivermanager.cpp +++ b/src/ui/driver/drivermanager.cpp @@ -116,22 +116,22 @@ bool DriverManager::writeData(quint32 code, QByteArray &buf, int size) return res; } -void DriverManager::reinstallDriver() +bool DriverManager::reinstallDriver() { - executeCommand("reinstall.lnk"); + return executeCommand("reinstall.lnk"); } -void DriverManager::uninstallDriver() +bool DriverManager::uninstallDriver() { - executeCommand("uninstall.lnk"); + return executeCommand("uninstall.lnk"); } -void DriverManager::executeCommand(const QString &fileName) +bool DriverManager::executeCommand(const QString &fileName) { const QString binPath = FileUtil::toNativeSeparators(FileUtil::appBinLocation()); const QString cmdPath = qEnvironmentVariable("COMSPEC"); const QString scriptPath = binPath + R"(\driver\scripts\execute-cmd.bat)"; - QProcess::execute(cmdPath, QStringList() << "/C" << scriptPath << fileName); + return QProcess::execute(cmdPath, QStringList() << "/C" << scriptPath << fileName) == 0; } diff --git a/src/ui/driver/drivermanager.h b/src/ui/driver/drivermanager.h index 474cda21..6d839e04 100644 --- a/src/ui/driver/drivermanager.h +++ b/src/ui/driver/drivermanager.h @@ -31,8 +31,8 @@ public: virtual void initialize(); - virtual void reinstallDriver(); - virtual void uninstallDriver(); + virtual bool reinstallDriver(); + virtual bool uninstallDriver(); signals: void errorCodeChanged(); @@ -58,7 +58,7 @@ private: bool writeData(quint32 code, QByteArray &buf, int size); - static void executeCommand(const QString &fileName); + static bool executeCommand(const QString &fileName); private: quint32 m_errorCode = 0; diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index 20165f70..c24e5165 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -161,7 +161,7 @@ void FortManager::setupRpcManager() } } -void FortManager::installDriver() +bool FortManager::installDriver() { closeDriver(); @@ -170,13 +170,17 @@ void FortManager::installDriver() if (setupDriver()) { updateDriverConf(); } + + return true; } -void FortManager::removeDriver() +bool FortManager::removeDriver() { closeDriver(); driverManager()->uninstallDriver(); + + return true; } bool FortManager::setupDriver() diff --git a/src/ui/fortmanager.h b/src/ui/fortmanager.h index a9a44912..44862111 100644 --- a/src/ui/fortmanager.h +++ b/src/ui/fortmanager.h @@ -86,8 +86,8 @@ signals: void graphWindowChanged(bool visible); public slots: - void installDriver(); - void removeDriver(); + bool installDriver(); + bool removeDriver(); void show(); diff --git a/src/ui/rpc/drivermanagerrpc.cpp b/src/ui/rpc/drivermanagerrpc.cpp index 10c67df0..ce2eba92 100644 --- a/src/ui/rpc/drivermanagerrpc.cpp +++ b/src/ui/rpc/drivermanagerrpc.cpp @@ -21,14 +21,14 @@ RpcManager *DriverManagerRpc::rpcManager() const return fortManager()->rpcManager(); } -void DriverManagerRpc::reinstallDriver() +bool DriverManagerRpc::reinstallDriver() { - rpcManager()->invokeOnServer(Control::Rpc_DriverManager_reinstallDriver); + return rpcManager()->doOnServer(Control::Rpc_DriverManager_reinstallDriver); } -void DriverManagerRpc::uninstallDriver() +bool DriverManagerRpc::uninstallDriver() { - rpcManager()->invokeOnServer(Control::Rpc_DriverManager_uninstallDriver); + return rpcManager()->doOnServer(Control::Rpc_DriverManager_uninstallDriver); } void DriverManagerRpc::updateState(quint32 errorCode, bool isDeviceOpened) diff --git a/src/ui/rpc/drivermanagerrpc.h b/src/ui/rpc/drivermanagerrpc.h index ad993632..befc4d18 100644 --- a/src/ui/rpc/drivermanagerrpc.h +++ b/src/ui/rpc/drivermanagerrpc.h @@ -21,8 +21,8 @@ public: void initialize() override { } - void reinstallDriver() override; - void uninstallDriver() override; + bool reinstallDriver() override; + bool uninstallDriver() override; void updateState(quint32 errorCode, bool isDeviceOpened); diff --git a/src/ui/rpc/rpcmanager.cpp b/src/ui/rpc/rpcmanager.cpp index efd20e53..31199c2a 100644 --- a/src/ui/rpc/rpcmanager.cpp +++ b/src/ui/rpc/rpcmanager.cpp @@ -184,14 +184,20 @@ void RpcManager::sendResult(ControlWorker *w, bool ok, const QVariantList &args) w->sendCommand(ok ? Control::Rpc_Result_Ok : Control::Rpc_Result_Error, args); } -void RpcManager::invokeOnServer(Control::Command cmd, const QVariantList &args) +bool RpcManager::invokeOnServer(Control::Command cmd, const QVariantList &args) { - client()->sendCommand(cmd, args); + return client()->sendCommand(cmd, args); } bool RpcManager::doOnServer(Control::Command cmd, const QVariantList &args) { - invokeOnServer(cmd, args); + if (!client()->isConnected()) { + fortManager()->showErrorBox("Service isn't available."); + return false; + } + + if (!invokeOnServer(cmd, args)) + return false; if (!waitResult()) { fortManager()->showErrorBox("Service isn't responding."); @@ -280,7 +286,7 @@ bool RpcManager::processManagerRpc( return processConfManagerRpc(w, cmd, args); case Control::Rpc_DriverManager: - return processDriverManagerRpc(cmd, args); + return processDriverManagerRpc(w, cmd, args); case Control::Rpc_QuotaManager: return processQuotaManagerRpc(cmd, args); @@ -398,14 +404,15 @@ bool RpcManager::processConfManagerRpc( } } -bool RpcManager::processDriverManagerRpc(Control::Command cmd, const QVariantList &args) +bool RpcManager::processDriverManagerRpc( + ControlWorker *w, Control::Command cmd, const QVariantList &args) { switch (cmd) { case Control::Rpc_DriverManager_reinstallDriver: - fortManager()->installDriver(); + sendResult(w, fortManager()->installDriver()); return true; case Control::Rpc_DriverManager_uninstallDriver: - fortManager()->removeDriver(); + sendResult(w, fortManager()->removeDriver()); return true; case Control::Rpc_DriverManager_updateState: if (auto dm = qobject_cast(driverManager())) { diff --git a/src/ui/rpc/rpcmanager.h b/src/ui/rpc/rpcmanager.h index 4d5af753..674e5946 100644 --- a/src/ui/rpc/rpcmanager.h +++ b/src/ui/rpc/rpcmanager.h @@ -43,7 +43,7 @@ public: bool waitResult(); void sendResult(ControlWorker *w, bool ok, const QVariantList &args = {}); - void invokeOnServer(Control::Command cmd, const QVariantList &args = {}); + bool invokeOnServer(Control::Command cmd, const QVariantList &args = {}); bool doOnServer(Control::Command cmd, const QVariantList &args = {}); bool processCommandRpc(ControlWorker *w, Control::Command cmd, const QVariantList &args, @@ -72,7 +72,7 @@ private: bool processAppInfoManagerRpc(Control::Command cmd, const QVariantList &args); bool processConfManagerRpc(ControlWorker *w, Control::Command cmd, const QVariantList &args); - bool processDriverManagerRpc(Control::Command cmd, const QVariantList &args); + bool processDriverManagerRpc(ControlWorker *w, Control::Command cmd, const QVariantList &args); bool processQuotaManagerRpc(Control::Command cmd, const QVariantList &args); bool processStatManagerRpc(ControlWorker *w, Control::Command cmd, const QVariantList &args); bool processTaskManagerRpc(Control::Command cmd, const QVariantList &args);