|
|
@@ -74,13 +74,6 @@ void ResourceWatcherServiceSession::Handle_GetBizLinks(SpReqAnsContext<ResourceW
|
|
|
m_pEntity->GetBizLinks(ctx);
|
|
|
}
|
|
|
|
|
|
-void ResourceWatcherServiceSession::Handle_GetThirdPartyInstallState(SpReqAnsContext<ResourceWatcherService_GetThirdPartyInstallState_Req, ResourceWatcherService_GetThirdPartyInstallState_Ans>::Pointer ctx)
|
|
|
-{
|
|
|
- DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(ResourceWatcherService_LogCode_GetThirdPartyInstallState).setAPI(__FUNCTION__)(__FUNCTION__);
|
|
|
- m_pEntity->GetThirdPartyInstallState(ctx);
|
|
|
-}
|
|
|
-
|
|
|
void ResourceWatcherServiceSession::Handle_InstallThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_InstallThirdPartyProgram_Req, ResourceWatcherService_InstallThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
{
|
|
|
DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
@@ -88,27 +81,6 @@ void ResourceWatcherServiceSession::Handle_InstallThirdPartyProgram(SpReqAnsCont
|
|
|
m_pEntity->InstallThirdPartyProgram(ctx);
|
|
|
}
|
|
|
|
|
|
-void ResourceWatcherServiceSession::Handle_UninstallThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_UninstallThirdPartyProgram_Req, ResourceWatcherService_UninstallThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
-{
|
|
|
- DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(ResourceWatcherService_LogCode_UninstallThirdPartyProgram).setAPI(__FUNCTION__)(__FUNCTION__);
|
|
|
- m_pEntity->UninstallThirdPartyProgram(ctx);
|
|
|
-}
|
|
|
-
|
|
|
-void ResourceWatcherServiceSession::Handle_RestartThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_RestartThirdPartyProgram_Req, ResourceWatcherService_RestartThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
-{
|
|
|
- DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(ResourceWatcherService_LogCode_RestartThirdPartyProgram).setAPI(__FUNCTION__)(__FUNCTION__);
|
|
|
- m_pEntity->RestartThirdPartyProgram(ctx);
|
|
|
-}
|
|
|
-
|
|
|
-void ResourceWatcherServiceSession::Handle_ProcessDetectThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_ProcessDetectThirdPartyProgram_Req, ResourceWatcherService_ProcessDetectThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
-{
|
|
|
- DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(ResourceWatcherService_LogCode_ProcessDetectThirdPartyProgram).setAPI(__FUNCTION__)(__FUNCTION__);
|
|
|
- m_pEntity->ProcessDetectThirdPartyProgram(ctx);
|
|
|
-}
|
|
|
-
|
|
|
void ResourceWatcherServiceSession::Handle_FilesClean(SpReqAnsContext<ResourceWatcherService_FilesClean_Req, ResourceWatcherService_FilesClean_Ans>::Pointer ctx)
|
|
|
{
|
|
|
DbgToBeidou(ctx->link, __FUNCTION__)();
|
|
|
@@ -594,334 +566,6 @@ void ResourceWatcherEntity::InstallThirdPartyProgram(SpReqAnsContext<ResourceWat
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-void ResourceWatcherEntity::UninstallSogou(SpReqAnsContext<ResourceWatcherService_UninstallThirdPartyProgram_Req, ResourceWatcherService_UninstallThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
-{
|
|
|
- ErrorCodeEnum result(Error_Succeed);
|
|
|
- ErrorCodeEnum tmpResult(Error_Succeed);
|
|
|
- CSimpleStringA tmpMsg(true);
|
|
|
-
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to uninstall sogou input...");
|
|
|
-
|
|
|
-#if defined(RVC_OS_LINUX)
|
|
|
- CSimpleStringA strUninstallScriptFile(true);
|
|
|
- SogouInstallInfo info;
|
|
|
- do {
|
|
|
- ErrorCodeEnum ecGet = GetSogouInstallInfo(info);
|
|
|
- if (info.program.IsTSFVersion()) {
|
|
|
- CSimpleStringA shellScriptPath;
|
|
|
- GetFunction()->GetPath("Base", shellScriptPath);
|
|
|
- shellScriptPath += SPLIT_SLASH_STR;
|
|
|
- shellScriptPath += "res" SPLIT_SLASH_STR "RunScript" SPLIT_SLASH_STR;
|
|
|
- strUninstallScriptFile = shellScriptPath + "uninstall_tfs_sogouimebs.sh";
|
|
|
- if (!ExistsFileA(strUninstallScriptFile)) {
|
|
|
- tmpMsg = CSimpleStringA::Format("%s 文件不存在!", strUninstallScriptFile.GetData());
|
|
|
- tmpResult = Error_InvalidState;
|
|
|
- break;
|
|
|
- }
|
|
|
- char app[MAX_PATH] = { '\0' };
|
|
|
- sprintf(app, "bash %s", strUninstallScriptFile.GetData());
|
|
|
- tmpResult = RunShellScript(app);
|
|
|
- if (tmpResult != 0) {
|
|
|
- tmpMsg = CSimpleStringA::Format("执行 '%s' 失败", app);
|
|
|
- }
|
|
|
- else {
|
|
|
- Sleep(300);
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- CSimpleStringA strInstallPkgPath;
|
|
|
- tmpResult = GetSogouPkgDirPath(strInstallPkgPath);
|
|
|
- if (tmpResult == Error_Succeed) {
|
|
|
- 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";
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- tmpMsg = CSimpleStringA::Format(" 指定位置 [Ad] 找不到输入法安装包");
|
|
|
- tmpResult = Error_InvalidState;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } while (false);
|
|
|
-#else
|
|
|
- SogouInstallInfo info;
|
|
|
- GetSogouInstallInfo(info);
|
|
|
- CSimpleStringA uninPath = info.program.strInstallDir + "\\" + info.program.strVersion + "\\Uninstall.exe";
|
|
|
- int startFlag = WinExec(uninPath.GetData(), SW_SHOWNORMAL);
|
|
|
- if (startFlag > 31) {
|
|
|
- tmpMsg = CSimpleStringA::Format("已执行搜狗卸载程序!路径:%s。", uninPath.GetData());
|
|
|
- }
|
|
|
- else {
|
|
|
- tmpMsg = CSimpleStringA::Format("执行搜狗卸载程序异常!路径:%s。", uninPath.GetData());
|
|
|
- tmpResult = Error_Unexpect;
|
|
|
- }
|
|
|
-#endif //RVC_OS_LINUX
|
|
|
-
|
|
|
- ctx->Ans.result = tmpResult;
|
|
|
- ctx->Ans.msg = tmpMsg;
|
|
|
- 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);
|
|
|
-
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHE_UNINSTALL_THIRDPARTYPROGRAM,
|
|
|
- CSimpleStringA::Format("UninstallThirdPartyProgram: ctx-req context: %d, %d, %d", ctx->Req.type, ctx->Req.reserved1, ctx->Req.reserved2));
|
|
|
-
|
|
|
- if (ctx->Req.type == 1) {
|
|
|
- //卸载搜狗输入法
|
|
|
-#if defined(RVC_OS_LINUX)
|
|
|
- UninstallSogouTask* sogouUninstall = new UninstallSogouTask(this);
|
|
|
- sogouUninstall->ctx = ctx;
|
|
|
- GetFunction()->PostThreadPoolTask(sogouUninstall);
|
|
|
- return;
|
|
|
-#else
|
|
|
- UninstallSogou(ctx);
|
|
|
-#endif //RVC_OS_LINUX
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
- tmpMsg = CSimpleStringA::Format("接口调用参数错误");
|
|
|
- result = Error_NotSupport;
|
|
|
- }
|
|
|
- ctx->Ans.result = tmpResult;
|
|
|
- ctx->Ans.msg = tmpMsg;
|
|
|
- ctx->Answer(result);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void ResourceWatcherEntity::RestartThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_RestartThirdPartyProgram_Req, ResourceWatcherService_RestartThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
-{
|
|
|
- ErrorCodeEnum result(Error_Succeed);
|
|
|
- ErrorCodeEnum tmpResult(Error_Succeed);
|
|
|
- CSimpleStringA tmpMsg(true);
|
|
|
-
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHE_RESTART_THIRDPARTYPROGRAM,
|
|
|
- CSimpleStringA::Format("RestartThirdPartyProgram: ctx-req context: %d, %d, %d", ctx->Req.type, ctx->Req.reserved1, ctx->Req.reserved2));
|
|
|
-
|
|
|
- if (ctx->Req.type == 1)
|
|
|
- {
|
|
|
- SogouInstallInfo info;
|
|
|
- GetSogouInstallInfo(info);
|
|
|
-
|
|
|
- if (!info.program.IsTSFVersion())
|
|
|
- {
|
|
|
- //重启搜狗输入法
|
|
|
-#if defined(RVC_OS_WIN)
|
|
|
- CSimpleStringA csBinPath;
|
|
|
- ErrorCodeEnum eErrPath = GetFunction()->GetPath("Bin", csBinPath);
|
|
|
- CSimpleStringA startPath = csBinPath + "\\spScript\\SogouServStarter.bat";
|
|
|
-
|
|
|
- if (eErrPath != Error_Succeed) {
|
|
|
- tmpResult = Error_NotExist;
|
|
|
- tmpMsg = "获取重启脚本路径失败。";
|
|
|
- }
|
|
|
- else if (!ExistsFileA(startPath)) {
|
|
|
- tmpResult = Error_NotExist;
|
|
|
- tmpMsg = CSimpleStringA::Format("搜狗重启脚本不存在。");
|
|
|
- }
|
|
|
- else {
|
|
|
- CAutoArray<CSimpleStringA> pName(2);
|
|
|
- pName[0] = "SogouImeMon.exe";
|
|
|
- pName[1] = "SogouImeWebSrv.exe";
|
|
|
-
|
|
|
- if (!KillProcessFromName(pName[0]) || !KillProcessFromName(pName[1])) {
|
|
|
- tmpMsg = CSimpleStringA::Format("杀死当前搜狗进程失败。");
|
|
|
- tmpResult = Error_Unexpect;
|
|
|
- }
|
|
|
- else {
|
|
|
- STARTUPINFO si = { sizeof(si) };
|
|
|
- PROCESS_INFORMATION pi;
|
|
|
- si.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
- si.wShowWindow = TRUE;
|
|
|
- char* cmdline = const_cast<LPSTR>(startPath.GetData());
|
|
|
- BOOL bRet = ::CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
|
|
|
- WaitForSingleObject(pi.hProcess, INFINITE);
|
|
|
- std::string res = DoCheckCertainProcessStatus(pName);
|
|
|
- if (res.size() > 0) {
|
|
|
- tmpMsg = CSimpleStringA::Format("已成功重启搜狗输入法进程!路径:%s。", startPath.GetData());
|
|
|
- }
|
|
|
- else {
|
|
|
- tmpMsg = CSimpleStringA::Format("重启搜狗进程失败!路径:%s。", startPath.GetData());
|
|
|
- tmpResult = Error_Unexpect;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-#else
|
|
|
- static int old_process_id[2] = { -1, -1 };
|
|
|
- char* relate_processes[2] = { "sogouImeWebSrv", "sogouImeService" };
|
|
|
-
|
|
|
- int count = 3;
|
|
|
- alive_process_info processes[3];
|
|
|
- memset(processes, 0, sizeof(processes));
|
|
|
-
|
|
|
- osutil_detect_unique_app(relate_processes, array_size(relate_processes), &count, processes);
|
|
|
-
|
|
|
- CAutoArray<CSimpleStringA> msgs(array_size(relate_processes));
|
|
|
- int cnt(0);
|
|
|
-
|
|
|
- for (int i = 0; i < array_size(relate_processes); ++i) {
|
|
|
- int k = -1;
|
|
|
- for (int j = 0; j < count; ++j) {
|
|
|
- if (strcmp(processes[j].name, relate_processes[i]) == 0) {
|
|
|
- k = j;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (k != -1) {
|
|
|
- cnt++;
|
|
|
- old_process_id[k] = processes[k].pid;
|
|
|
- std::string sucContent, failedContent;
|
|
|
- CSimpleStringA strCmd = CSimpleStringA::Format("kill -9 %d", old_process_id[k]);
|
|
|
- bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("{%s}:{%s}{%s}", strCmd.GetData(), sucContent.c_str(), failedContent.c_str());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- int cnt2(0);
|
|
|
- if (cnt > 0) {
|
|
|
- ///**TODO(Gifur@7/5/2022): 待优化处理 */
|
|
|
- Sleep(2000);
|
|
|
- int newCount = 3;
|
|
|
- int notSame = 0;
|
|
|
- vector<CSimpleStringA> tKillmsg;
|
|
|
- alive_process_info newProcesses[3];
|
|
|
- memset(newProcesses, 0, sizeof(newProcesses));
|
|
|
- osutil_detect_unique_app(relate_processes, array_size(relate_processes), &newCount, newProcesses);
|
|
|
- for (int i = 0; i < array_size(relate_processes); ++i) {
|
|
|
- int k = -1;
|
|
|
- for (int j = 0; j < count; ++j) {
|
|
|
- if (strcmp(newProcesses[j].name, relate_processes[i]) == 0 && newProcesses[j].pid > 0) {
|
|
|
- k = j;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (k != -1) {
|
|
|
- cnt2++;
|
|
|
- if (newProcesses[k].pid != old_process_id[k]) {
|
|
|
- notSame++;
|
|
|
- }
|
|
|
- else {
|
|
|
- tmpResult = Error_Unexpect;
|
|
|
- CSimpleStringA tmsg = CSimpleStringA::Format("{杀死当前搜狗进程[%s]失败,pid[%d]。}",
|
|
|
- newProcesses[k].name, newProcesses[k].pid);
|
|
|
- tKillmsg.push_back(tmsg);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (cnt2 == 0) {
|
|
|
- tmpMsg = "已杀死搜狗进程。但重启搜狗进程失败,请确认守护进程正常运行。";
|
|
|
- tmpResult = Error_Unexpect;
|
|
|
- }
|
|
|
- else {
|
|
|
- if (tKillmsg.size() != 0) {
|
|
|
- for (int i = 0; i < tKillmsg.size(); ++i) {
|
|
|
- tmpMsg += tKillmsg[i];
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- tmpMsg = "已成功重启搜狗输入法进程。";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- tmpMsg = "当前系统无搜狗进程,请确认已安装搜狗输入法,并重启计算机以尝试启动搜狗输入法!";
|
|
|
- tmpResult = Error_Unexpect;
|
|
|
- }
|
|
|
-#endif //RVC_OS_WIN
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- tmpResult = Error_NotSupport;
|
|
|
- tmpMsg = CSimpleStringA::Format("新搜狗版本,不支持重启功能");
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- tmpResult = Error_Param;
|
|
|
- tmpMsg = CSimpleStringA::Format("接口调用参数错误。");
|
|
|
- }
|
|
|
-
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM) ("用户桌面重启:%s. result:%d.", tmpMsg.GetData(), tmpResult);
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHE_RESTART_THIRDPARTYPROGRAM,
|
|
|
- CSimpleStringA::Format("用户桌面重启:%s. result:%d.", tmpMsg.GetData(), tmpResult));
|
|
|
- ctx->Ans.result = tmpResult;
|
|
|
- ctx->Ans.msg = tmpMsg;
|
|
|
-
|
|
|
- ctx->Answer(result);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void ResourceWatcherEntity::ProcessDetectThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_ProcessDetectThirdPartyProgram_Req, ResourceWatcherService_ProcessDetectThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
-{
|
|
|
- ErrorCodeEnum result(Error_Succeed);
|
|
|
- ErrorCodeEnum tmpResult(Error_Succeed);
|
|
|
-
|
|
|
- CSimpleStringA tmpMsg(true);
|
|
|
- std::string res("");
|
|
|
-
|
|
|
- if (ctx->Req.type == 1) {//检测搜狗输入法进程
|
|
|
- CAutoArray<CSimpleStringA> pName(2);
|
|
|
-#if defined(RVC_OS_WIN)
|
|
|
- pName[0] = "SogouImeMon.exe";
|
|
|
- pName[1] = "SogouImeWebSrv.exe";
|
|
|
-#else
|
|
|
- pName[0] = "sogouImeWebSrv";
|
|
|
- pName[1] = "sogouImeService";
|
|
|
-#endif //RVC_OS_WIN
|
|
|
- res = DoCheckCertainProcessStatus(pName);
|
|
|
- if (res.length() == 0) {
|
|
|
- tmpResult = Error_Failed;
|
|
|
- tmpMsg = "当前系统无搜狗进程";
|
|
|
- }
|
|
|
- else {
|
|
|
- tmpMsg = CSimpleStringA::Format("%s", res.c_str());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- ctx->Ans.result = tmpResult;
|
|
|
- ctx->Ans.msg = tmpMsg;
|
|
|
- ctx->Answer(result);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
ErrorCodeEnum ResourceWatcherEntity::ReportSogouInstallState()
|
|
|
{
|
|
|
CSmartPointer<IEntityFunction> spFunction = GetFunction();
|
|
|
@@ -1228,222 +872,6 @@ BOOL ResourceWatcherEntity::KillProcessFromName(const CSimpleStringA& strProcess
|
|
|
|
|
|
#endif //RVC_OS_LINUX
|
|
|
|
|
|
-void ResourceWatcherEntity::DoCheckSogouProcessStatus()
|
|
|
-{
|
|
|
-#if defined(RVC_OS_WIN)
|
|
|
- if (lastUpgradeInstallTime != 0 && lastUpgradeSwitchTime != 0 && lastUpgradeInstallTime < lastUpgradeSwitchTime) //完整记录了上一次升级的时间
|
|
|
- {
|
|
|
- if (sogouChangeTime.size() != 0) {
|
|
|
- for (int i = 0; i < sogouChangeWarn.size(); i++) {
|
|
|
- if (newestSogouInstall) //搜狗升级
|
|
|
- {
|
|
|
- //正常不用告警
|
|
|
- /* LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, (sogouChangeWarn[i] + "搜狗升级切换1").GetData());
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040250A01Z102")("搜狗升级切换1");*/
|
|
|
- }
|
|
|
- else //非搜狗升级导致的退出
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, (sogouChangeWarn[i] + "异常切换1").GetData());
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040250A01Z103").setResultCode("RTA5A08")("搜狗异常切换1");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- sogouChangeTime.clear();
|
|
|
- sogouChangeWarn.clear();
|
|
|
-
|
|
|
- lastUpgradeInstallTime = 0;
|
|
|
- lastUpgradeSwitchTime = 0;
|
|
|
- newestSogouInstall = false;
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- bool fCheck = false;
|
|
|
- CAutoArray<CSimpleStringA> pName(2);
|
|
|
- pName[0] = "SogouImeMon.exe";
|
|
|
- pName[1] = "SogouImeWebSrv.exe";
|
|
|
- int pSize = pName.GetCount();
|
|
|
-
|
|
|
- static int old_process_id[2] = { -1, -1 };
|
|
|
- static int firstCheck[2] = { -1, -1 };
|
|
|
- CAutoArray<CSimpleStringA> msgs;
|
|
|
- for (int i = 0; i < pSize; ++i) {
|
|
|
- /*old_process_id.push_back(-1);*/
|
|
|
- CSimpleStringA temp("");
|
|
|
- msgs.Append(&temp, 0, 1);
|
|
|
- }
|
|
|
- int cnt(0);
|
|
|
-
|
|
|
- PROCESSENTRY32 pe32;
|
|
|
- pe32.dwSize = sizeof(pe32);
|
|
|
- //获得系统进程快照的句柄
|
|
|
- HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
|
- if (hProcessSnap == INVALID_HANDLE_VALUE) {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("CreateToolhelp32Snapshot error.");
|
|
|
- return;
|
|
|
- }
|
|
|
- for (int i = 0; i < pSize; ++i) {
|
|
|
- int position = -1;
|
|
|
- BOOL bProcess = Process32First(hProcessSnap, &pe32);
|
|
|
- while (bProcess) {
|
|
|
- if (strcmp(pe32.szExeFile, pName[i].GetData()) == 0) {
|
|
|
- position = 1;
|
|
|
- break;
|
|
|
- }
|
|
|
- bProcess = Process32Next(hProcessSnap, &pe32);
|
|
|
- }
|
|
|
-
|
|
|
- if (position != -1 && old_process_id[i] == -1) {
|
|
|
- if (firstCheck[i] == -1) {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Sougou first check!");
|
|
|
- msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"pid\":%d}"
|
|
|
- , pName[i].GetData(), pe32.th32ProcessID);
|
|
|
- firstCheck[i] = 1;
|
|
|
- fCheck = true;
|
|
|
- sogouProcessRun = 1;
|
|
|
- }
|
|
|
- old_process_id[i] = pe32.th32ProcessID;
|
|
|
- }
|
|
|
- else if (position != -1 && (pe32.th32ProcessID != old_process_id[i])) {
|
|
|
- msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"prev\":%d, \"pid\":%d}"
|
|
|
- , pName[i].GetData(), old_process_id[i], pe32.th32ProcessID);
|
|
|
- old_process_id[i] = pe32.th32ProcessID;
|
|
|
-
|
|
|
- }
|
|
|
- else if (position == -1 && old_process_id[i] > 0) {
|
|
|
- msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"prev\":%d, \"pid\":%d}"
|
|
|
- , pName[i].GetData(), old_process_id[i], 0);
|
|
|
- old_process_id[i] = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- std::string uploadInfo("");
|
|
|
- if (cnt > 0) {
|
|
|
- if (cnt > 1) {
|
|
|
- uploadInfo = "{";
|
|
|
- }
|
|
|
- for (int i = 0; i < cnt; ++i) {
|
|
|
- if (i != 0) {
|
|
|
- uploadInfo += ",";
|
|
|
- }
|
|
|
- uploadInfo += msgs[i].GetData();
|
|
|
- }
|
|
|
- if (cnt > 1) {
|
|
|
- uploadInfo += "}";
|
|
|
- }
|
|
|
-
|
|
|
- if (fCheck) //首次检测
|
|
|
- {
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_FIRSTCHECK, uploadInfo.c_str()); //第一次检测
|
|
|
- lastUpgradeInstallTime = 0;
|
|
|
- lastUpgradeSwitchTime = 0;
|
|
|
- newestSogouInstall = false;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040250A01Z101")("搜狗首次检测");
|
|
|
- }
|
|
|
- else if (newestSogouInstall) {
|
|
|
- //LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, (uploadInfo + "搜狗升级切换2").c_str()); //升级安装导致的进程切换视为正常退出
|
|
|
- lastUpgradeInstallTime = 0;
|
|
|
- lastUpgradeSwitchTime = 0;
|
|
|
- newestSogouInstall = false;
|
|
|
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040250A01Z102")("搜狗升级切换2");
|
|
|
- }
|
|
|
- else if (time(0) <= lastSogouChangeEndTime) //lastSogouChangeEndTime为状态'I'结束后的60秒
|
|
|
- {
|
|
|
- //LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, (uploadInfo + "搜狗升级切换3").c_str()); //升级安装导致的进程切换视为正常退出
|
|
|
- lastUpgradeInstallTime = 0;
|
|
|
- lastUpgradeSwitchTime = 0;
|
|
|
- newestSogouInstall = false;
|
|
|
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040250A01Z102")("搜狗升级切换3");
|
|
|
- }
|
|
|
- else {
|
|
|
- if (lastUpgradeInstallTime == 0 && lastUpgradeSwitchTime == 0)//非升级时段
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, (uploadInfo + "异常切换3").c_str()); //其他情况下的进程切换视为异常退出
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040250A01Z103").setResultCode("RTA5A08")("搜狗异常切换3");
|
|
|
- }
|
|
|
- else //升级时段,'I'安装中,但是还没有'S'切换时,出现了搜狗进程切换
|
|
|
- {
|
|
|
- sogouChangeWarn.push_back(CSimpleStringA(uploadInfo.c_str()));
|
|
|
- sogouChangeTime.push_back(time(0));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- SogouInstallInfo info;
|
|
|
- GetSogouInstallInfo(info);
|
|
|
-
|
|
|
- if (!info.program.IsTSFVersion()) //如果是旧版本搜狗,则检测是否启动
|
|
|
- {
|
|
|
- if (sogouProcessRun == 0)//进程未运行
|
|
|
- {
|
|
|
- LogWarn(Severity_Middle, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, "搜狗进程未启动!");
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode("QLR040250A01Z101").setResultCode("RTA5A01")("搜狗未启动!");
|
|
|
- sogouProcessRun = -1; //进程未启动告警一次即可
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- CloseHandle(hProcessSnap);
|
|
|
-
|
|
|
-#else
|
|
|
- static int old_process_id[2] = { -1, -1 };
|
|
|
- char* relate_processes[2] = { "sogouImeWebSrv", "sogouImeService" };
|
|
|
-
|
|
|
- int count = 3;
|
|
|
- alive_process_info processes[3];
|
|
|
- memset(processes, 0, sizeof(processes));
|
|
|
-
|
|
|
- osutil_detect_unique_app(relate_processes, array_size(relate_processes), &count, processes);
|
|
|
-
|
|
|
- CAutoArray<CSimpleStringA> msgs(array_size(relate_processes));
|
|
|
- int cnt(0);
|
|
|
-
|
|
|
- for (int i = 0; i < array_size(relate_processes); ++i) {
|
|
|
- int k = -1;
|
|
|
- for (int j = 0; j < count; ++j) {
|
|
|
- if (strcmp(processes[j].name, relate_processes[i]) == 0) {
|
|
|
- k = j;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (k != -1 && old_process_id[i] == -1) {
|
|
|
- old_process_id[i] = processes[k].pid;
|
|
|
-
|
|
|
- }
|
|
|
- else if (k != -1 && (processes[k].pid != old_process_id[i])) {
|
|
|
- msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"prev\":%d, \"pid\":%d}"
|
|
|
- , relate_processes[i], old_process_id[i], processes[k].pid);
|
|
|
- old_process_id[i] = processes[k].pid;
|
|
|
-
|
|
|
- }
|
|
|
- else if (k == -1 && old_process_id[i] != 0) {
|
|
|
- msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"prev\":%d, \"pid\":%d}"
|
|
|
- , relate_processes[i], old_process_id[i], 0);
|
|
|
- old_process_id[i] = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (cnt > 0) {
|
|
|
- std::string uploadInfo("");
|
|
|
- if (cnt > 1) {
|
|
|
- uploadInfo = "{";
|
|
|
- }
|
|
|
- for (int i = 0; i < cnt; ++i) {
|
|
|
- if (i != 0) {
|
|
|
- uploadInfo += ",";
|
|
|
- }
|
|
|
- uploadInfo += msgs[i].GetData();
|
|
|
- }
|
|
|
- if (cnt > 1) {
|
|
|
- uploadInfo += "}";
|
|
|
- }
|
|
|
-
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, uploadInfo.c_str());
|
|
|
- }
|
|
|
-#endif //RVC_OS_WIN
|
|
|
-}
|
|
|
-
|
|
|
#if defined(RVC_OS_LINUX)
|
|
|
ErrorCodeEnum ResourceWatcherEntity::GetSogouPkgDirPath(CSimpleStringA& strPkgPath)
|
|
|
{
|
|
|
@@ -1905,115 +1333,6 @@ ErrorCodeEnum ResourceWatcherEntity::DeleteUnzipDir()
|
|
|
return 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;
|
|
|
- GetSogouInstallInfo(info);
|
|
|
- ctx->Ans.status = info.IsInstalledSuccess() ? 1 : 0;
|
|
|
- ctx->Ans.path = info.program.strInstallDir;
|
|
|
- ctx->Ans.version = info.program.strVersion;
|
|
|
- ctx->Ans.reserverd1 = info.state.GetInstallTime().ToTimeString();
|
|
|
- ctx->Ans.reserverd2 = "";
|
|
|
- ctx->Ans.reserverd3 = info.program.IsTSFVersion() ? 1 : 0;
|
|
|
- ctx->Ans.reserverd4 = 0;
|
|
|
- }
|
|
|
- else if (ctx->Req.mode == 2) { //检测字体的安装状态
|
|
|
-#if defined(_MSC_VER)
|
|
|
- result = Error_NotImpl;
|
|
|
-#else
|
|
|
- CSimpleStringA strFontDir("/usr/share/fonts/truetype");
|
|
|
- CSimpleStringA strRVCTTFsDir(strFontDir + SPLIT_SLASH_STR + "RVCTTFs");
|
|
|
- if (!ExistsDirA(strRVCTTFsDir)) {
|
|
|
- ctx->Ans.status = 0;
|
|
|
- ctx->Ans.reserverd1 = CSimpleStringA::Format("%s 文件夹不存在", (LPCTSTR)strRVCTTFsDir);
|
|
|
- }
|
|
|
- else {
|
|
|
- CSimpleStringA ttf1 = strRVCTTFsDir + SPLIT_SLASH_STR + "HYQiHei-55S.ttf";
|
|
|
- CSimpleStringA ttf2 = strRVCTTFsDir + SPLIT_SLASH_STR + "HYQiHei-65S.ttf";
|
|
|
- CSimpleStringA ttfdir = strRVCTTFsDir + SPLIT_SLASH_STR + "fonts.dir";
|
|
|
- CSimpleStringA ttfscale = strRVCTTFsDir + SPLIT_SLASH_STR + "fonts.scale";
|
|
|
- CSimpleStringA ttfuuid = strRVCTTFsDir + SPLIT_SLASH_STR + ".uuid";
|
|
|
-
|
|
|
- int existCheck = 0;
|
|
|
- if (!ExistsFileA(ttf1)) {
|
|
|
- existCheck |= 1;
|
|
|
- }
|
|
|
- if (!ExistsFileA(ttf2)) {
|
|
|
- existCheck |= 2;
|
|
|
- }
|
|
|
- if (!ExistsFileA(ttfdir)) {
|
|
|
- existCheck |= 4;
|
|
|
- }
|
|
|
- if (!ExistsFileA(ttfscale)) {
|
|
|
- existCheck |= 8;
|
|
|
- }
|
|
|
- if (!ExistsFileA(ttfuuid)) {
|
|
|
- existCheck |= 16;
|
|
|
- }
|
|
|
- if (existCheck != 0) {
|
|
|
- ctx->Ans.status = 0;
|
|
|
- ctx->Ans.reserverd1 = CSimpleStringA::Format("安装文件不存在:0x%X", existCheck);
|
|
|
- }
|
|
|
- else {
|
|
|
- ctx->Ans.status = 1;
|
|
|
- ctx->Ans.reserverd1 = "";
|
|
|
- ctx->Ans.path = strRVCTTFsDir;
|
|
|
- ctx->Ans.version = "";
|
|
|
- }
|
|
|
- }
|
|
|
-#endif //_MSC_VER
|
|
|
- }
|
|
|
- else if (ctx->Req.mode == 3) { //自定义安装
|
|
|
-#if defined(RVC_OS_WIN)
|
|
|
- result = Error_NotSupport;
|
|
|
-#else
|
|
|
- if (ctx->Req.reserverd3.IsNullOrEmpty()) {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("the req rerverd3 is empty.");
|
|
|
- result = Error_Param;
|
|
|
- }
|
|
|
- else {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to check %s 's install status...", ctx->Req.reserverd3.GetData());
|
|
|
- CSimpleStringA strSoftwareName(ctx->Req.reserverd3);
|
|
|
- CSimpleStringA strSoftwareVersion(ctx->Req.reserverd4);
|
|
|
- CSimpleStringA runItem = CSimpleStringA::Format("dpkg -l | grep %s | awk '{print $3}'", strSoftwareName.GetData());
|
|
|
- std::string additional("");
|
|
|
- std::string succStr, errStr;
|
|
|
- std::string runStr(runItem.GetData());
|
|
|
- if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
|
|
|
- if (succStr.empty()) {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("%s is not installed", strSoftwareName.GetData());
|
|
|
- ctx->Ans.status = 0;
|
|
|
- }
|
|
|
- else {
|
|
|
- succStr = SP::Utility::ToTrim(succStr);
|
|
|
- if (strSoftwareVersion.IsNullOrEmpty() || strSoftwareVersion.Compare(succStr.c_str()) == 0) {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s is installed, version: %s", strSoftwareName.GetData(), succStr.c_str());
|
|
|
- ctx->Ans.status = 1;
|
|
|
- }
|
|
|
- else {
|
|
|
- ctx->Ans.status = 2;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s is installed, but the version<%s> is not the dream one<%s>"
|
|
|
- , strSoftwareName.GetData(), succStr.c_str(), strSoftwareVersion.GetData());
|
|
|
- ctx->Ans.reserverd1 = succStr.c_str();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("Execute <%s> failed.", runItem.GetData());
|
|
|
- result = Error_Process;
|
|
|
- }
|
|
|
- }
|
|
|
-#endif //RVC_OS_WIN
|
|
|
- }
|
|
|
- else {
|
|
|
- result = Error_NotSupport;
|
|
|
- }
|
|
|
- ctx->Answer(result);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
CSimpleStringA ResourceWatcherEntity::GetFilePathWithDir(CSimpleStringA dir, CSimpleStringA fileName)
|
|
|
{
|
|
|
CSimpleStringA tmpPath(""), filePath("");
|
|
|
@@ -2584,27 +1903,6 @@ void ResourceWatcherEntity::FilesClean(SpReqAnsContext<ResourceWatcherService_Fi
|
|
|
ctx->Answer(result);
|
|
|
}
|
|
|
|
|
|
-void ResourceWatcherEntity::OnUpgradeStateEvent(const char* pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, UpgradeManager::UpgradeStateEvent& evt)
|
|
|
-{
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("OnUpgradeStateEvent, cInstallState:%c, strNewVersion:%s.", evt.cInstallState, evt.strNewVersion.GetData());
|
|
|
- CSimpleStringA packName = evt.strPackName;
|
|
|
-
|
|
|
- if (evt.cInstallState == 'I') {
|
|
|
- lastUpgradeInstallTime = time(0);
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("lastUpgradeInstallTime = %lld.", lastUpgradeInstallTime);
|
|
|
- }
|
|
|
-
|
|
|
- if (evt.cInstallState == 'S' || evt.cInstallState == 'C') {
|
|
|
- lastUpgradeSwitchTime = time(0);
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("lastUpgradeSwitchTime = %lld.", lastUpgradeSwitchTime);
|
|
|
- if (evt.strNewVersion.GetLength() == 0) {
|
|
|
- newestSogouInstall = true;
|
|
|
- lastSogouChangeEndTime = lastUpgradeSwitchTime + 60;
|
|
|
- }
|
|
|
- DoCheckSogouProcessStatus();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
void ResourceWatcherEntity::FetchSystemSnapshot(
|
|
|
SpReqAnsContext<ResourceWatcherService_FetchSystemSnapshot_Req, ResourceWatcherService_FetchSystemSnapshot_Ans>::Pointer ctx)
|
|
|
{
|