|
@@ -7,6 +7,7 @@
|
|
|
#include "array.h"
|
|
|
#include "fileutil.h"
|
|
|
#include "iniutil.h"
|
|
|
+#include "toolkit.h"
|
|
|
|
|
|
#if defined(RVC_OS_LINUX)
|
|
|
#include "SogouVersion.h"
|
|
@@ -128,6 +129,19 @@ void ResourceWatcherServiceSession::Handle_GetNetworkInfo(SpReqAnsContext<Resour
|
|
|
m_pEntity->GetNetworkInfo(ctx);
|
|
|
}
|
|
|
|
|
|
+void ResourceWatcherServiceSession::Handle_GetThirdPartyInstallState(SpReqAnsContext<ResourceWatcherService_GetThirdPartyInstallState_Req, ResourceWatcherService_GetThirdPartyInstallState_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->GetThirdPartyInstallState(ctx);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void ResourceWatcherServiceSession::Handle_InstallThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_InstallThirdPartyProgram_Req, ResourceWatcherService_InstallThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->InstallThirdPartyProgram(ctx);
|
|
|
+}
|
|
|
+
|
|
|
void ResourceWatcherEntity::UpdateDNS(SpReqAnsContext<ResourceWatcherService_UpdateDNS_Req, ResourceWatcherService_UpdateDNS_Ans>::Pointer ctx)
|
|
|
{
|
|
|
ctx->Answer(Error_NotImpl);
|
|
@@ -223,6 +237,202 @@ void ResourceWatcherEntity::GetNetworkInfo(SpReqAnsContext<ResourceWatcherServic
|
|
|
ctx->Answer(Error_Succeed);
|
|
|
}
|
|
|
|
|
|
+void ResourceWatcherEntity::GetThirdPartyInstallState(SpReqAnsContext<ResourceWatcherService_GetThirdPartyInstallState_Req, ResourceWatcherService_GetThirdPartyInstallState_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+
|
|
|
+ if (ctx->Req.mode == 1) {//查看搜狗输入法安装状态
|
|
|
+ SogouInstallInfo info;
|
|
|
+ info.state.dwInstalledStatus = Sogou_GetInstallStatus();
|
|
|
+ info.state.strInstallDate = Sogou_GetInstallTime();
|
|
|
+ info.program.strInstallDir = Sogou_GetInstallPath();
|
|
|
+ info.program.strVersion = Sogou_GetVersion();
|
|
|
+ Dbg("%d, %s, %s, %s"
|
|
|
+ , info.state.dwInstalledStatus, info.state.strInstallDate.GetData()
|
|
|
+ , info.program.strInstallDir.GetData(), info.program.strVersion.GetData());
|
|
|
+ Dbg("InstallTime: %s", info.state.GetInstallTime().ToTimeString().GetData());
|
|
|
+
|
|
|
+ ctx->Ans.status = info.IsInstalledSuccess() ? 1 : 0;
|
|
|
+ ctx->Ans.reserverd1 = info.state.GetInstallTime().ToTimeString();
|
|
|
+ ctx->Ans.path = info.program.strInstallDir;
|
|
|
+ ctx->Ans.version = info.program.strVersion;
|
|
|
+ } else {
|
|
|
+ result = Error_NotSupport;
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Answer(result);
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_InstallThirdPartyProgram_Req, ResourceWatcherService_InstallThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+ ErrorCodeEnum tmpResult(Error_Succeed);
|
|
|
+ CSimpleStringA tmpMsg(true);
|
|
|
+
|
|
|
+ if (ctx->Req.type == 1) {//安装搜狗输入法
|
|
|
+
|
|
|
+ Dbg("to install sogou input...");
|
|
|
+
|
|
|
+ CSimpleStringA strInstallPkgPath;
|
|
|
+ CSimpleStringA strAdDataDirPath(true);
|
|
|
+ tmpResult = GetFunction()->GetPath("Ad", strAdDataDirPath);
|
|
|
+ if (strAdDataDirPath.IsNullOrEmpty()) {
|
|
|
+ tmpResult = Error_Unexpect;
|
|
|
+ tmpMsg = "获取安装包路径失败";
|
|
|
+ } else {
|
|
|
+ array_header_t* subs;
|
|
|
+ subs = fileutil_get_sub_dirs_a(strAdDataDirPath);
|
|
|
+ if (subs) {
|
|
|
+ for (int i = 0; i < subs->nelts; ++i) {
|
|
|
+ char* dir = ARRAY_IDX(subs, i, char*);
|
|
|
+ const char* dirname = &dir[strAdDataDirPath.GetLength() + 1];
|
|
|
+ if (CSimpleStringA(dirname).IsStartWith("sogou", true)) {
|
|
|
+ Dbg("found it: %s", dir);
|
|
|
+ strInstallPkgPath = dir;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ toolkit_array_free2(subs);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (strInstallPkgPath.IsNullOrEmpty()) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 路径下找不到输入法安装包文件夹", strAdDataDirPath.GetData());
|
|
|
+ tmpResult = Error_NotExist;
|
|
|
+ } else {
|
|
|
+ CSimpleStringA strRunIniFilePath = strInstallPkgPath + SPLIT_SLASH_STR + "Run.ini";
|
|
|
+ if (ExistsFileA(strRunIniFilePath)) {
|
|
|
+ char* p = inifile_read_str(strRunIniFilePath, "Action", "ToRun", "");
|
|
|
+ CSimpleStringA strInstallScriptFile(strInstallPkgPath + SPLIT_SLASH_STR + p);
|
|
|
+ toolkit_free(p);
|
|
|
+ Dbg("RunScript file: %s", strInstallScriptFile.GetData());
|
|
|
+ if (ExistsFileA(strInstallScriptFile)) {
|
|
|
+ do {
|
|
|
+ char app[MAX_PATH] = { '\0' };
|
|
|
+ tk_process_t* process = NULL;
|
|
|
+ tk_process_option_t option;
|
|
|
+ option.exit_cb = NULL;
|
|
|
+ option.file = NULL;
|
|
|
+ option.flags = 0;
|
|
|
+
|
|
|
+ sprintf(app, "bash %s", strInstallScriptFile.GetData());
|
|
|
+ option.params = app;
|
|
|
+ const int res = process_spawn(&option, &process);
|
|
|
+ if (0 == res) {
|
|
|
+ FREE(process);
|
|
|
+ Dbg("execute {%s} suc", strInstallScriptFile.GetData());
|
|
|
+ } else {
|
|
|
+ tmpMsg = CSimpleStringA::Format("执行 %s 失败:%s", strInstallScriptFile.GetData(), toolkit_strerror(res));
|
|
|
+ tmpResult = Error_Process;
|
|
|
+ }
|
|
|
+
|
|
|
+ } while (false);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 执行文件不存在", strInstallScriptFile.GetData());
|
|
|
+ tmpResult = Error_NotExist;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 文件不存在", strRunIniFilePath.GetData());
|
|
|
+ tmpResult = Error_NotExist;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tmpResult == Error_Succeed) {
|
|
|
+ Sleep(500);
|
|
|
+ SogouInstallInfo info;
|
|
|
+ info.state.dwInstalledStatus = Sogou_GetInstallStatus();
|
|
|
+ info.state.strInstallDate = Sogou_GetInstallTime();
|
|
|
+ info.program.strInstallDir = Sogou_GetInstallPath();
|
|
|
+ info.program.strVersion = Sogou_GetVersion();
|
|
|
+ Dbg("%d, %s, %s, %s"
|
|
|
+ , info.state.dwInstalledStatus, info.state.strInstallDate.GetData()
|
|
|
+ , info.program.strInstallDir.GetData(), info.program.strVersion.GetData());
|
|
|
+ Dbg("InstallTime: %s", info.state.GetInstallTime().ToTimeString().GetData());
|
|
|
+
|
|
|
+ if (!info.IsInstalledSuccess()) {
|
|
|
+ tmpResult = Error_FailVerify;
|
|
|
+ tmpMsg = CSimpleStringA::Format("安装成功,但检测版本信息失败!");
|
|
|
+ } else {
|
|
|
+ ctx->Ans.path = info.program.strInstallDir;
|
|
|
+ ctx->Ans.reserverd1 = info.program.strVersion;
|
|
|
+ ctx->Ans.reserverd2 = info.state.GetInstallTime().ToTimeString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (ctx->Req.type == 2) {//安装花了钱的字体
|
|
|
+
|
|
|
+ Dbg("to install sogou input...");
|
|
|
+
|
|
|
+
|
|
|
+ CSimpleStringA strAdDataDirPath(true);
|
|
|
+ tmpResult = GetFunction()->GetPath("Ad", strAdDataDirPath);
|
|
|
+ if (strAdDataDirPath.IsNullOrEmpty()) {
|
|
|
+ tmpResult = Error_Unexpect;
|
|
|
+ tmpMsg = "获取安装包路径失败";
|
|
|
+ } else {
|
|
|
+
|
|
|
+ CSimpleStringA strInstallPkgPath = strAdDataDirPath + SPLIT_SLASH_STR "HYQiHei";
|
|
|
+ if (!ExistsDirA(strInstallPkgPath)) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 文件夹不存在", strInstallPkgPath.GetData());
|
|
|
+ tmpResult = Error_NotExist;
|
|
|
+ } else {
|
|
|
+ CSimpleStringA strRunIniFilePath = strInstallPkgPath + SPLIT_SLASH_STR + "Run.ini";
|
|
|
+ if (ExistsFileA(strRunIniFilePath)) {
|
|
|
+ char* p = inifile_read_str(strRunIniFilePath, "Action", "ToRun", "");
|
|
|
+ CSimpleStringA strInstallScriptFile(strInstallPkgPath + SPLIT_SLASH_STR + p);
|
|
|
+ toolkit_free(p);
|
|
|
+ Dbg("RunScript file: %s", strInstallScriptFile.GetData());
|
|
|
+ if (ExistsFileA(strInstallScriptFile)) {
|
|
|
+ do {
|
|
|
+ char app[MAX_PATH] = { '\0' };
|
|
|
+ tk_process_t* process = NULL;
|
|
|
+ tk_process_option_t option;
|
|
|
+ option.exit_cb = NULL;
|
|
|
+ option.file = NULL;
|
|
|
+ option.flags = 0;
|
|
|
+
|
|
|
+ sprintf(app, "bash %s", strInstallScriptFile.GetData());
|
|
|
+ option.params = app;
|
|
|
+ const int res = process_spawn(&option, &process);
|
|
|
+ if (0 == res) {
|
|
|
+ FREE(process);
|
|
|
+ Dbg("execute {%s} suc", strInstallScriptFile.GetData());
|
|
|
+ } else {
|
|
|
+ tmpMsg = CSimpleStringA::Format("执行 %s 失败:%s", strInstallScriptFile.GetData(), toolkit_strerror(res));
|
|
|
+ tmpResult = Error_Process;
|
|
|
+ }
|
|
|
+
|
|
|
+ } while (false);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 执行文件不存在", strInstallScriptFile.GetData());
|
|
|
+ tmpResult = Error_NotExist;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 文件不存在", strRunIniFilePath.GetData());
|
|
|
+ tmpResult = Error_NotExist;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tmpResult == Error_Succeed) {
|
|
|
+ ///**TODO(Gifur@10/21/2021): 二次校验 */
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result = Error_NotSupport;
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Ans.result = tmpResult;
|
|
|
+ ctx->Ans.msg = tmpMsg;
|
|
|
+ ctx->Answer(result);
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
#if defined(RVC_OS_WIN)
|
|
|
//1: 32bit process running at 64bit platform
|
|
|
//0:
|