|
@@ -176,6 +176,12 @@ void ResourceWatcherServiceSession::Handle_ManipulateVersion(SpReqAnsContext<Res
|
|
|
m_pEntity->ManipulateVersion(ctx);
|
|
|
}
|
|
|
|
|
|
+void ResourceWatcherServiceSession::Handle_UninstallThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_UninstallThirdPartyProgram_Req, ResourceWatcherService_UninstallThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->UninstallThirdPartyProgram(ctx);
|
|
|
+}
|
|
|
+
|
|
|
void ResourceWatcherEntity::UpdateDNS(SpReqAnsContext<ResourceWatcherService_UpdateDNS_Req, ResourceWatcherService_UpdateDNS_Ans>::Pointer ctx)
|
|
|
{
|
|
|
ctx->Answer(Error_NotImpl);
|
|
@@ -284,8 +290,8 @@ void ResourceWatcherEntity::GetThirdPartyInstallState(SpReqAnsContext<ResourceWa
|
|
|
info.program.strVersion = Sogou_GetVersion();
|
|
|
const int maxTimes = 5;
|
|
|
int curTimes = 0;
|
|
|
- while (info.program.strVersion.IsNullOrEmpty() && curTimes < maxTimes) {
|
|
|
- Sleep(2000);
|
|
|
+ while (info.state.dwInstalledStatus == 0 && info.program.strVersion.IsNullOrEmpty() && curTimes < maxTimes) {
|
|
|
+ Sleep(1200);
|
|
|
info.program.strVersion = Sogou_GetVersion();
|
|
|
curTimes++;
|
|
|
}
|
|
@@ -406,130 +412,79 @@ void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWat
|
|
|
if (ctx->Req.type == 1) {//安装搜狗输入法
|
|
|
|
|
|
Dbg("to install sogou input...");
|
|
|
- const bool doNotStartup(true);
|
|
|
-
|
|
|
+ const bool doNotStartup(true); //安装后是否启动搜狗输入法服务,据搜狗反馈,不能通过root权限启动Sogou输入法
|
|
|
CSimpleStringA strInstallPkgPath;
|
|
|
- CSimpleStringA strAdDataDirPath(true);
|
|
|
- tmpResult = GetFunction()->GetPath("Ad", strAdDataDirPath);
|
|
|
- if (strAdDataDirPath.IsNullOrEmpty() && m_bInitMode) {
|
|
|
- strAdDataDirPath = "/opt/rvc/adData";
|
|
|
- }
|
|
|
-
|
|
|
- if (strAdDataDirPath.IsNullOrEmpty()) {
|
|
|
- tmpResult = Error_Unexpect;
|
|
|
- tmpMsg = "获取安装包路径Ad失败";
|
|
|
+ tmpResult = GetSogouPkgDirPath(strInstallPkgPath);
|
|
|
+ if (tmpResult != 0) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("指定位置找不到输入法安装包");
|
|
|
} 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)) {
|
|
|
- if (strInstallPkgPath.IsNullOrEmpty()) {
|
|
|
- Dbg("found it: %s", dir);
|
|
|
- strInstallPkgPath = dir;
|
|
|
- } else if(strInstallPkgPath.Compare(dir) < 0) {
|
|
|
- Dbg("replace %s with %s", (LPCTSTR)strInstallPkgPath, dir);
|
|
|
- strInstallPkgPath = dir;
|
|
|
- }
|
|
|
- //break;
|
|
|
- }
|
|
|
- }
|
|
|
- toolkit_array_free2(subs);
|
|
|
- }
|
|
|
-
|
|
|
- if (strInstallPkgPath.IsNullOrEmpty()) {
|
|
|
- tmpMsg = CSimpleStringA::Format("%s 路径下找不到输入法安装包文件夹", strAdDataDirPath.GetData());
|
|
|
+ tmpResult = SetFileExecutePriviledge(strInstallPkgPath);
|
|
|
+ if (tmpResult != Error_Succeed) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 修改文件夹权限失败", strInstallPkgPath.GetData());
|
|
|
tmpResult = Error_NotExist;
|
|
|
} else {
|
|
|
-
|
|
|
- tmpResult = SetFileExecutePriviledge(strInstallPkgPath);
|
|
|
- if (tmpResult != Error_Succeed) {
|
|
|
- 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("install script 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", app, toolkit_strerror(res));
|
|
|
- tmpResult = Error_Process;
|
|
|
- }
|
|
|
-
|
|
|
- } while (false);
|
|
|
-
|
|
|
- if (!doNotStartup) {
|
|
|
- CSimpleStringA strStartupScriptFile(strInstallPkgPath + SPLIT_SLASH_STR + "startup_service.sh");
|
|
|
- Dbg("startup script file: %s", strStartupScriptFile.GetData());
|
|
|
- if (!ExistsFileA(strStartupScriptFile)) {
|
|
|
- tmpMsg = CSimpleStringA::Format("%s 启动脚本文件不存在,请重启设备再次验证", strStartupScriptFile.GetData());
|
|
|
- tmpResult = Error_NotExist;
|
|
|
- } else {
|
|
|
- Sleep(1000);
|
|
|
- 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;
|
|
|
+ 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("install script file: %s", strInstallScriptFile.GetData());
|
|
|
+ if (ExistsFileA(strInstallScriptFile)) {
|
|
|
+ char app[MAX_PATH] = { '\0' };
|
|
|
+ sprintf(app, "bash %s", strInstallScriptFile.GetData());
|
|
|
+ tmpResult = RunShellScript(app);
|
|
|
+ if (tmpResult != 0) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("执行 '%s' 失败", app);
|
|
|
+ } else if(!doNotStartup) {
|
|
|
+ CSimpleStringA strStartupScriptFile(strInstallPkgPath + SPLIT_SLASH_STR + "startup_service.sh");
|
|
|
+ Dbg("startup script file: %s", strStartupScriptFile.GetData());
|
|
|
+ if (!ExistsFileA(strStartupScriptFile)) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 启动脚本文件不存在,请重启设备再次验证", strStartupScriptFile.GetData());
|
|
|
+ tmpResult = Error_NotExist;
|
|
|
+ } else {
|
|
|
+ Sleep(1000);
|
|
|
+ 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;
|
|
|
#if 0
|
|
|
- auto users = GetUserNameList(true);
|
|
|
- if (users.size() == 1) {
|
|
|
- sprintf(app, "su -m -p -c \"bash %s\" %s", strStartupScriptFile.GetData(), users[0].c_str());
|
|
|
- } else {
|
|
|
- for (auto it = users.cbegin(); it != users.cend(); ++it) {
|
|
|
- Dbg("user:%s", it->c_str());
|
|
|
- }
|
|
|
- sprintf(app, "bash %s", strStartupScriptFile.GetData());
|
|
|
+ auto users = GetUserNameList(true);
|
|
|
+ if (users.size() == 1) {
|
|
|
+ sprintf(app, "su -m -p -c \"bash %s\" %s", strStartupScriptFile.GetData(), users[0].c_str());
|
|
|
+ } else {
|
|
|
+ for (auto it = users.cbegin(); it != users.cend(); ++it) {
|
|
|
+ Dbg("user:%s", it->c_str());
|
|
|
}
|
|
|
-#else
|
|
|
sprintf(app, "bash %s", strStartupScriptFile.GetData());
|
|
|
+ }
|
|
|
+#else
|
|
|
+ sprintf(app, "bash %s", strStartupScriptFile.GetData());
|
|
|
#endif
|
|
|
- option.params = app;
|
|
|
- const int res = process_spawn(&option, &process);
|
|
|
- if (0 == res) {
|
|
|
- FREE(process);
|
|
|
- Dbg("execute {%s} suc", app);
|
|
|
- } else {
|
|
|
- tmpMsg = CSimpleStringA::Format("执行 '%s' 失败:%s", app, toolkit_strerror(res));
|
|
|
- tmpResult = Error_Process;
|
|
|
- }
|
|
|
- } while (false);
|
|
|
- }
|
|
|
+ option.params = app;
|
|
|
+ const int res = process_spawn(&option, &process);
|
|
|
+ if (0 == res) {
|
|
|
+ FREE(process);
|
|
|
+ Dbg("execute {%s} suc", app);
|
|
|
+ } else {
|
|
|
+ tmpMsg = CSimpleStringA::Format("执行 '%s' 失败:%s", app, 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());
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 执行文件不存在", strInstallScriptFile.GetData());
|
|
|
tmpResult = Error_NotExist;
|
|
|
}
|
|
|
+ } else {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 文件不存在,请检查安装包完整性", strRunIniFilePath.GetData());
|
|
|
+ tmpResult = Error_NotExist;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
if (tmpResult == Error_Succeed) {
|
|
|
Sleep(1500);
|
|
|
const CSimpleStringA strResultLogFilePath = strInstallPkgPath + SPLIT_SLASH_STR + "result.log";
|
|
@@ -564,21 +519,21 @@ void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWat
|
|
|
tmpMsg = CSimpleStringA::Format("%s", szTmp);
|
|
|
} else {
|
|
|
SogouInstallInfo info;
|
|
|
+ info.state.dwInstalledStatus = Sogou_GetInstallStatus();
|
|
|
+ info.state.strInstallDate = Sogou_GetInstallTime();
|
|
|
+ info.program.strInstallDir = Sogou_GetInstallPath();
|
|
|
info.program.strVersion = Sogou_GetVersion();
|
|
|
const int maxTimes = 5;
|
|
|
int curTimes = 0;
|
|
|
- while (!doNotStartup && info.program.strVersion.IsNullOrEmpty() && curTimes < maxTimes) {
|
|
|
- Sleep(2000);
|
|
|
+ while (!doNotStartup && info.state.dwInstalledStatus == 0 && info.program.strVersion.IsNullOrEmpty() && curTimes < maxTimes) {
|
|
|
+ Sleep(1200);
|
|
|
info.program.strVersion = Sogou_GetVersion();
|
|
|
curTimes++;
|
|
|
}
|
|
|
- info.state.dwInstalledStatus = Sogou_GetInstallStatus();
|
|
|
- info.state.strInstallDate = Sogou_GetInstallTime();
|
|
|
- info.program.strInstallDir = Sogou_GetInstallPath();
|
|
|
+ Dbg("InstallTime: %s", info.state.GetInstallTime().ToTimeString().GetData());
|
|
|
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;
|
|
@@ -825,6 +780,63 @@ void ResourceWatcherEntity::ManipulateVersion(SpReqAnsContext<ResourceWatcherSer
|
|
|
ctx->Answer(result);
|
|
|
}
|
|
|
|
|
|
+void ResourceWatcherEntity::UninstallThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_UninstallThirdPartyProgram_Req, ResourceWatcherService_UninstallThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+ ErrorCodeEnum tmpResult(Error_Succeed);
|
|
|
+ CSimpleStringA tmpMsg(true);
|
|
|
+
|
|
|
+ if (ctx->Req.type == 1) {
|
|
|
+ Dbg("to uninstall sogou input...");
|
|
|
+ CSimpleStringA strInstallPkgPath;
|
|
|
+ tmpResult = GetSogouPkgDirPath(strInstallPkgPath);
|
|
|
+ if (tmpResult == Error_Succeed) {
|
|
|
+ do
|
|
|
+ {
|
|
|
+ tmpResult = SetFileExecutePriviledge(strInstallPkgPath);
|
|
|
+ if (tmpResult != Error_Succeed) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 修改文件夹权限失败", strInstallPkgPath.GetData());
|
|
|
+ tmpResult = Error_NoPrivilege;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ const CSimpleStringA strShutdownScriptFile = strInstallPkgPath + SPLIT_SLASH_STR + "shutdown_service.sh";
|
|
|
+ const CSimpleStringA strUninstallScriptFile = strInstallPkgPath + SPLIT_SLASH_STR + "uninstall_sogouime.sh";
|
|
|
+ if (!ExistsFileA(strShutdownScriptFile)) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 文件不存在!", strShutdownScriptFile.GetData());
|
|
|
+ tmpResult = Error_InvalidState;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (!ExistsFileA(strUninstallScriptFile)) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s 文件不存在!", strUninstallScriptFile.GetData());
|
|
|
+ tmpResult = Error_InvalidState;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ char app[MAX_PATH] = { '\0' };
|
|
|
+ sprintf(app, "bash %s", strShutdownScriptFile.GetData());
|
|
|
+ tmpResult = RunShellScript(app);
|
|
|
+ if (tmpResult != 0) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("执行 '%s' 失败", app);
|
|
|
+ } else {
|
|
|
+ Sleep(300);
|
|
|
+ sprintf(app, "bash %s", strUninstallScriptFile.GetData());
|
|
|
+ tmpResult = RunShellScript(app);
|
|
|
+ if (tmpResult != 0) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("执行 '%s' 失败", app);
|
|
|
+ } else {
|
|
|
+ Sleep(100);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } while (false);
|
|
|
+ }
|
|
|
+ } 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:
|
|
@@ -970,10 +982,10 @@ ErrorCodeEnum ResourceWatcherEntity::DoCheckInstallStateJob()
|
|
|
info.program.strInstallDir = Sogou_GetInstallPath();
|
|
|
info.program.strVersion = Sogou_GetVersion();
|
|
|
/** 重试获取版本号 [Gifur@2022224]*/
|
|
|
- const int maxTimes = 8;
|
|
|
+ const int maxTimes = 3;
|
|
|
int curTimes = 0;
|
|
|
- while (info.program.strVersion.IsNullOrEmpty() && curTimes < maxTimes) {
|
|
|
- Sleep(1000);
|
|
|
+ while (info.state.dwInstalledStatus == 0 && info.program.strVersion.IsNullOrEmpty() && curTimes < maxTimes) {
|
|
|
+ Sleep(1500);
|
|
|
info.program.strVersion = Sogou_GetVersion();
|
|
|
curTimes++;
|
|
|
}
|
|
@@ -1206,6 +1218,63 @@ std::vector<std::string> ResourceWatcherEntity::GetUserNameList(bool bExcludeRoo
|
|
|
}
|
|
|
|
|
|
|
|
|
+ErrorCodeEnum ResourceWatcherEntity::GetSogouPkgDirPath(CSimpleStringA& strPkgPath)
|
|
|
+{
|
|
|
+ CSimpleStringA strAdDataDirPath(true);
|
|
|
+ CSimpleStringA strInstallPkgPath(true);
|
|
|
+ ErrorCodeEnum result = GetFunction()->GetPath("Ad", strAdDataDirPath);
|
|
|
+ if (strAdDataDirPath.IsNullOrEmpty() && m_bInitMode) {
|
|
|
+ strAdDataDirPath = "/opt/rvc/adData";
|
|
|
+ }
|
|
|
+ if (strAdDataDirPath.IsNullOrEmpty()) {
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+ 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)) {
|
|
|
+ if (strInstallPkgPath.IsNullOrEmpty()) {
|
|
|
+ Dbg("found it: %s", dir);
|
|
|
+ strInstallPkgPath = dir;
|
|
|
+ } else if (strInstallPkgPath.Compare(dir) < 0) {
|
|
|
+ Dbg("replace %s with %s", (LPCTSTR)strInstallPkgPath, dir);
|
|
|
+ strInstallPkgPath = dir;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ toolkit_array_free2(subs);
|
|
|
+ }
|
|
|
+ if (strInstallPkgPath.IsNullOrEmpty()) {
|
|
|
+ return Error_NotExist;
|
|
|
+ }
|
|
|
+
|
|
|
+ strPkgPath = strInstallPkgPath;
|
|
|
+ return Error_Succeed;
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum ResourceWatcherEntity::RunShellScript(LPCTSTR cmdline)
|
|
|
+{
|
|
|
+ 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;
|
|
|
+ option.params = (char*)cmdline;
|
|
|
+ const int res = process_spawn(&option, &process);
|
|
|
+ if (0 == res) {
|
|
|
+ Dbg("execute {%s}, pid: %d", cmdline, process->pid);
|
|
|
+ FREE(process);
|
|
|
+ return Error_Succeed;
|
|
|
+ } else {
|
|
|
+ Dbg("execute {%s} failed: %d", cmdline, res);
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void ResourceWatcherEntity::OnSysVarEvent(const char* pszKey, const char* pszValue, const char* pszOldValue, const char* pszEntityName)
|
|
|
{
|
|
|
Dbg("OnSysVarEvent pszKey = %s, pszValue = %s", pszKey, pszValue);
|