12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181 |
- // mod_ResourceWatcher.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #include "mod_ResourceWatcher.h"
- #include "CommEntityUtil.hpp"
- #include "array.h"
- #include "fileutil.h"
- #include "iniutil.h"
- #include "toolkit.h"
- #include "osutil.h"
- #if defined(RVC_OS_LINUX)
- #include "SogouVersion.h"
- #include <winpr/sysinfo.h>
- #endif //RVC_OS_LINUX
- #include "publicFunExport.h"
- #include <map>
- #include <regex.h>
- struct SogouRunVersionInfo
- {
- CSimpleStringA strInstallDir;
- CSimpleStringA strVersion;
- SogouRunVersionInfo():strInstallDir(true),strVersion(true){}
- CSimpleStringA ToString() const {
- CSimpleStringA result(true);
- if(!strInstallDir.IsNullOrEmpty()) {
- result += strInstallDir;
- result += "#";
- }
- if(!strVersion.IsNullOrEmpty()) {
- result += strVersion;
- }
- return result;
- }
- };
- struct SogouInstallStateInfo
- {
- DWORD dwInstalledStatus;
- CSimpleStringA strInstallDate;
- SogouInstallStateInfo():dwInstalledStatus(-1),strInstallDate(true){}
- CSimpleStringA ToString() const {
- CSimpleStringA result(true);
- if(!strInstallDate.IsNullOrEmpty()) {
- //result += strInstallDate;
- result += GetInstallTime().ToTimeString();
- result += "#";
- }
- result += CSimpleStringA::Format("%u", dwInstalledStatus);
- return result;
- }
- CSmallDateTime GetInstallTime() const {
- if(!strInstallDate.IsNullOrEmpty()) {
- DWORD dwSecsSince1970(0);
- sscanf_s(strInstallDate.GetData(), "%u", &dwSecsSince1970);
- dwSecsSince1970 -= 946656000; // 2000-1970
- return CSmallDateTime(dwSecsSince1970);
- }
- return CSmallDateTime::BeginTime;
- }
- };
- struct SogouInstallInfo
- {
- SogouInstallStateInfo state;
- SogouRunVersionInfo program;
- CSimpleStringA Stringfy() const
- {
- return (state.ToString() + "||" + program.ToString());
- }
- bool IsInstalledSuccess() const {
- return (state.dwInstalledStatus == 0);
- }
- };
- void ResourceWatcherServiceSession::Handle_Fetch(
- SpReqAnsContext<ResourceWatcherService_Fetch_Req, ResourceWatcherService_Fetch_Ans>::Pointer ctx)
- {
- m_pEntity->Fetch(ctx);
- }
- void ResourceWatcherServiceSession::Handle_GetDevInfo(
- SpReqAnsContext<ResourceWatcherService_GetDevInfo_Req, ResourceWatcherService_GetDevInfo_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->GetDevInfo(ctx);
- }
- void ResourceWatcherServiceSession::Handle_GetCardSwiper(SpReqAnsContext<ResourceWatcherService_GetCardSwiper_Req, ResourceWatcherService_GetCardSwiper_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->GetCSwiperStatus(ctx);
- }
- void ResourceWatcherServiceSession::Handle_GetCpuType(SpReqAnsContext<ResourceWatcherService_GetCpuType_Req, ResourceWatcherService_GetCpuType_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->GetCPUType(ctx);
- }
- void ResourceWatcherServiceSession::Handle_OperateFile
- (SpReqAnsContext<ResourceWatcherService_OperateFile_Req,
- ResourceWatcherService_OperateFile_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->OperateFile(ctx);
- }
- void ResourceWatcherServiceSession::Handle_ExtractEventLog(
- SpReqAnsContext<ResourceWatcherService_ExtractEventLog_Req, ResourceWatcherService_ExtractEventLog_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->RetrieveEventLog(ctx);
- }
- void ResourceWatcherServiceSession::Handle_UpdateDNS(SpReqAnsContext<ResourceWatcherService_UpdateDNS_Req, ResourceWatcherService_UpdateDNS_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->UpdateDNS(ctx);
- }
- void ResourceWatcherServiceSession::Handle_GetNetworkInfo(SpReqAnsContext<ResourceWatcherService_GetNetworkInfo_Req, ResourceWatcherService_GetNetworkInfo_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- 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 ResourceWatcherServiceSession::Handle_BizLinkDetect(SpReqAnsContext<ResourceWatcherService_BizLinkDetect_Req, ResourceWatcherService_BizLinkDetect_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->BizLinkDetect(ctx);
- }
- void ResourceWatcherServiceSession::Handle_CheckNetType(SpReqAnsContext<ResourceWatcherService_CheckNetType_Req, ResourceWatcherService_CheckNetType_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->CheckNetType(ctx);
- }
- void ResourceWatcherServiceSession::Handle_GetBizLinks(SpReqAnsContext<ResourceWatcherService_GetBizLinks_Req, ResourceWatcherService_GetBizLinks_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->GetBizLinks(ctx);
- }
- void ResourceWatcherServiceSession::Handle_GetTerminalVersionList(SpReqAnsContext<ResourceWatcherService_GetTerminalVersionList_Req, ResourceWatcherService_GetTerminalVersionList_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->GetTerminalVersionList(ctx);
- }
- void ResourceWatcherServiceSession::Handle_ManipulateVersion(SpReqAnsContext<ResourceWatcherService_ManipulateVersion_Req, ResourceWatcherService_ManipulateVersion_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->ManipulateVersion(ctx);
- }
- void ResourceWatcherEntity::UpdateDNS(SpReqAnsContext<ResourceWatcherService_UpdateDNS_Req, ResourceWatcherService_UpdateDNS_Ans>::Pointer ctx)
- {
- ctx->Answer(Error_NotImpl);
- }
- void ResourceWatcherEntity::GetNetworkInfo(SpReqAnsContext<ResourceWatcherService_GetNetworkInfo_Req, ResourceWatcherService_GetNetworkInfo_Ans>::Pointer ctx)
- {
- char buf[512];
- toolkit_interface_address_t* info;
- int count, i;
- toolkit_interface_addresses(&info, &count);
- i = count;
- Dbg("Number of interfaces: %d", count);
- if (count <= 0) {
- ctx->Answer(Error_NotExist);
- return;
- }
- int realCount = 0;
- while (i--) {
- toolkit_interface_address_t& interface = info[i];
- if (interface.address.address4.sin_family == AF_INET/* && !interface.is_internal*/) {
- realCount++;
- }
- }
- if (realCount <= 0) {
- ctx->Answer(Error_NotExist);
- return;
- }
- ctx->Ans.status = 0;
- ctx->Ans.current = "";
- ctx->Ans.ips.Init(realCount);
- ctx->Ans.names.Init(realCount);
- ctx->Ans.macs.Init(realCount);
- ctx->Ans.masks.Init(realCount);
- ctx->Ans.gateways.Init(realCount);
- ctx->Ans.dns.Init(realCount);
- int cnt = 0, active = -1;
- for (i = 0; i < count; ++i) {
- toolkit_interface_address_t& interface = info[i];
- if (interface.address.address4.sin_family == AF_INET) {
- ctx->Ans.names[cnt] = interface.name;
- toolkit_ip4_name(&interface.address.address4, buf, sizeof(buf));
- if (strcmp(buf, "127.0.0.1") != 0) active = cnt;
- ctx->Ans.ips[cnt] = buf;
- ctx->Ans.macs[cnt] = "";
- ctx->Ans.masks[cnt] = "";
- ctx->Ans.gateways[cnt] = "";
- ctx->Ans.dns[cnt] = "";
- cnt++;
- }
- }
- toolkit_free_interface_addresses(info, count);
- const char* parent = "/etc/NetworkManager/system-connections";
- array_header_t* subs;
- subs = fileutil_get_sub_files_a(parent);
- if (subs) {
- for (i = 0; i < subs->nelts; ++i) {
- char path[256] = { 0 };
- char* dir = ARRAY_IDX(subs, i, char*);
- char value[128];
- inifile_read_str_s("connection", "interface-name", "", value, 127, dir);
- if (strlen(value) == 0) continue;
- for (int j = 0; j < realCount; ++j) {
- if (ctx->Ans.names[j].Compare(value) == 0) {
- memset(value, 0, sizeof(value));
- inifile_read_str_s("connection", "id", "", value, 127, dir);
- if (strlen(value) > 0) {
- ctx->Ans.names[j] = CSimpleStringA::Format("%s#%s", value, ctx->Ans.names[j].GetData());
- }
- if (active == j) {
- ctx->Ans.current = ctx->Ans.names[j];
- }
- memset(value, 0, sizeof(value));
- inifile_read_str_s("ethernet", "mac-address", "", value, 127, dir);
- ctx->Ans.macs[j] = value;
- memset(value, 0, sizeof(value));
- inifile_read_str_s("ipv4", "dns", "", value, 127, dir);
- ctx->Ans.dns[j] = value;
- break;
- }
- }
- }
- toolkit_array_free2(subs);
- }
- 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 if (ctx->Req.mode == 2) { //检测字体的安装状态
- 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 = "";
- }
- }
- } else {
- result = Error_NotSupport;
- }
- ctx->Answer(result);
- return;
- }
- ErrorCodeEnum SetFileExecutePriviledge(LPCTSTR lpcszDirOrFilePath)
- {
- ErrorCodeEnum result(Error_Succeed);
- if (ExistsDirA(lpcszDirOrFilePath)) {
- do
- {
- array_header_t* subs;
- subs = fileutil_get_sub_dirs_a(lpcszDirOrFilePath);
- if (subs) {
- for (int i = 0; i < subs->nelts; ++i) {
- char* dir = ARRAY_IDX(subs, i, char*);
- const char* dirname = &dir[strlen(lpcszDirOrFilePath) + 1];
- ErrorCodeEnum tmpResult = SetFileExecutePriviledge(dir);
- if (tmpResult != Error_Succeed) {
- toolkit_array_free2(subs);
- return tmpResult;
- }
- }
- }
- } while (false);
- do {
- array_header_t* subs;
- subs = fileutil_get_sub_files_a(lpcszDirOrFilePath);
- if (subs) {
- for (int i = 0; i < subs->nelts; ++i) {
- char* path = ARRAY_IDX(subs, i, char*);
- mode_t f_attrib = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH;
- if (chmod(path, f_attrib) != 0) {
- Dbg("chmod file priviledge failed, %s, %d", path, errno);
- toolkit_array_free2(subs);
- return Error_Unexpect;
- }
- }
- toolkit_array_free2(subs);
- }
- } while (false);
- } else if(ExistsFileA(lpcszDirOrFilePath)) {
- mode_t f_attrib = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH;
- if (chmod(lpcszDirOrFilePath, f_attrib) != 0) {
- Dbg("chmod file priviledge failed, %s, %d", lpcszDirOrFilePath, errno);
- return Error_Unexpect;
- }
- } else {
- result = Error_InvalidState;
- }
- return result;
- }
- 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() && m_bInitMode) {
- strAdDataDirPath = "/opt/rvc/adData";
- }
- if (strAdDataDirPath.IsNullOrEmpty()) {
- tmpResult = Error_Unexpect;
- tmpMsg = "获取安装包路径Ad失败";
- } 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 = 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", strInstallScriptFile.GetData(), toolkit_strerror(res));
- tmpResult = Error_Process;
- }
- } while (false);
- 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());
- }
- #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);
- }
- } else {
- tmpMsg = CSimpleStringA::Format("%s 执行文件不存在", strInstallScriptFile.GetData());
- tmpResult = Error_NotExist;
- }
- } else {
- tmpMsg = CSimpleStringA::Format("%s 文件不存在", strRunIniFilePath.GetData());
- tmpResult = Error_NotExist;
- }
- }
- }
- }
- if (tmpResult == Error_Succeed) {
- SogouInstallInfo info;
-
- Sleep(1500);
- info.program.strVersion = Sogou_GetVersion();
- const int maxTimes = 5;
- int curTimes = 0;
- while (info.program.strVersion.IsNullOrEmpty() && curTimes < maxTimes) {
- Sleep(2000);
- info.program.strVersion = Sogou_GetVersion();
- curTimes++;
- }
- if (info.program.strVersion.IsNullOrEmpty()) {
- tmpResult = Error_Unexpect;
- tmpMsg = CSimpleStringA::Format("服务启动失败,获取安装版本信息失败");
-
- info.program.strVersion = "重启设备后生效!";
- tmpResult = Error_Succeed;
- tmpMsg = "重启设备后生效!";
- } else {
- //TODO:
- }
- info.state.dwInstalledStatus = Sogou_GetInstallStatus();
- info.state.strInstallDate = Sogou_GetInstallTime();
- info.program.strInstallDir = Sogou_GetInstallPath();
- 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 cmb font input...%d", m_bInitMode);
- 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失败";
- } 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;
- }
- void ResourceWatcherEntity::GetTerminalVersionList(SpReqAnsContext<ResourceWatcherService_GetTerminalVersionList_Req, ResourceWatcherService_GetTerminalVersionList_Ans>::Pointer ctx)
- {
- CSimpleStringA strVersionBaseDir(true);
- GetFunction()->GetPath("RootVer", strVersionBaseDir);
- const CSimpleStringA strActiveFile = strVersionBaseDir + SPLIT_SLASH_STR + "active.txt";
- CSystemStaticInfo staticInfo;
- GetFunction()->GetSystemStaticInfo(staticInfo);
- CSimpleStringA strCurrVer = staticInfo.InstallVersion.ToString();
- Dbg("get current version [%s]", (LPCTSTR)strCurrVer);
- std::vector<std::string> verlist;
- array_header_t* arr;
- arr = fileutil_get_sub_dirs_a(strVersionBaseDir);
- if (arr) {
- do {
- regex_t reg;
- CSimpleStringA strPattern("^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[\(\)A-Za-z_-]*$");
- int ret = regcomp(®, strPattern, REG_EXTENDED | REG_NOSUB);
- if (ret) {
- char ebuff[256];
- regerror(ret, ®, ebuff, 256);
- Dbg("regex failed: %s", ebuff);
- ctx->Ans.msg = CSimpleStringA::Format("内部错误:REGEX %s", ebuff);
- ctx->Ans.current = -1;
- break;
- } else {
- for (int i = 0; i < arr->nelts; ++i) {
- char* versionDir = ARRAY_IDX(arr, i, char*);
- char* versionDirName = &versionDir[strVersionBaseDir.GetLength() + 1];
- ret = regexec(®, versionDirName, 0, NULL, 0);
- if (0 == ret) {
- Dbg("filename %s matched!", versionDirName);
- verlist.push_back(std::string(versionDirName));
- }
- }
- }
- } while (false);
- toolkit_array_free2(arr);
- }
- if (!verlist.empty()) {
- const int count = verlist.size();
- ctx->Ans.index.Init(count);
- ctx->Ans.version.Init(count);
- ctx->Ans.remark.Init(count);
- ctx->Ans.type.Init(count);
- ctx->Ans.status.Init(count);
- for (int i = 0; i < count; ++i) {
- ctx->Ans.index[i] = i;
- ctx->Ans.version[i] = verlist[i].c_str();
- if (verlist[i].compare(strCurrVer.GetData()) == 0) {
- ctx->Ans.current = i;
- }
- ctx->Ans.remark[i] = "";
- ctx->Ans.type[i] = ctx->Ans.status[i] = 0;
- }
- }
- ctx->Answer(Error_Succeed);
- }
- namespace
- {
- bool UpdateCurrentVersionName(LPCTSTR filePath, LPCTSTR versionStr, LPCTSTR backupPath)
- {
- if (fileutil_copy_file(backupPath, filePath) != 0) {
- return false;
- }
- FILE* fp = fopen(filePath, "wb+");
- if (fp == NULL) {
- return false;
- }
- bool result(false);
- do
- {
- int ret = fwrite(versionStr, strlen(versionStr), 1, fp);
- if (ret != 1) {
- Dbg("fwrite failed: %d", ret);
- break;
- }
- fflush(fp);
- fclose(fp);
- fp = fopen(filePath, "rb");
- if (fp != NULL) {
- char value[32] = { 0 };
- int ret2 = fread(value, strlen(versionStr), 1, fp);
- if (ret2 == 1) {
- if (strcmp(value, versionStr) == 0)
- Dbg("read agagin the value is the same!");
- else {
- break;
- }
- }
- }
- result = true;
- } while (false);
- fclose(fp);
- if (!result && backupPath) {
- fileutil_copy_file(filePath, backupPath);
- fileutil_delete_file(backupPath);
- }
- if (result && backupPath) {
- fileutil_delete_file(backupPath);
- }
- return result;
- }
- }
- void ResourceWatcherEntity::ManipulateVersion(SpReqAnsContext<ResourceWatcherService_ManipulateVersion_Req, ResourceWatcherService_ManipulateVersion_Ans>::Pointer ctx)
- {
- ErrorCodeEnum result(Error_Succeed);
- int tmpResult(0);
- CSimpleStringA tmpMsg(true);
- switch (ctx->Req.operation) {
- case 1: //设置为此版本为当前版本
- {
- CSimpleStringA strVersionBaseDir(true);
- GetFunction()->GetPath("RootVer", strVersionBaseDir);
- const CSimpleStringA strActiveFile = strVersionBaseDir + SPLIT_SLASH_STR + "active.txt";
- const CSimpleStringA strActiveFileBackup = strActiveFile + "activebak.txt";
- CSystemStaticInfo staticInfo;
- GetFunction()->GetSystemStaticInfo(staticInfo);
- CSimpleStringA strCurrVer = staticInfo.InstallVersion.ToString();
- Dbg("get current version [%s]", (LPCTSTR)strCurrVer);
- if (!UpdateCurrentVersionName(strActiveFile, ctx->Req.value, strActiveFileBackup)) {
- tmpResult = Error_Unexpect;
- tmpMsg = "切换版本失败";
- }
- }
- break;
- case 2: //删除此版本
- {
- CSimpleStringA strVersionBaseDir(true);
- GetFunction()->GetPath("RootVer", strVersionBaseDir);
- const CSimpleStringA strVersionDirPath = strVersionBaseDir + SPLIT_SLASH_STR + ctx->Req.value;
- if (ExistsDirA(strVersionDirPath)) {
- if (!RemoveDirRecursiveA(strVersionDirPath)) {
- tmpResult = Error_Unexpect;
- tmpMsg = "删除版本失败";
- }
- }
- }
- break;
- default:
- result = Error_NotSupport;
- break;
- }
- ctx->Ans.result = tmpResult;
- ctx->Ans.msg = tmpMsg;
- ctx->Answer(result);
- }
- #if defined(RVC_OS_WIN)
- //1: 32bit process running at 64bit platform
- //0:
- static int Is32R64Platform()
- {
- static int isWow64 = -1;
- typedef BOOL(WINAPI* LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
- if (isWow64 == -1) {
- BOOL bIsWow64 = FALSE;
- LPFN_ISWOW64PROCESS fnIsWow64Process =
- (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process");
- if (NULL != fnIsWow64Process) {
- if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64)) {
- Dbg("detect is running with 64bit or not failed: %u", GetLastError());
- return -1;
- } else {
- isWow64 = bIsWow64 ? 1 : 0;
- }
- }
- }
- return isWow64;
- }
- static bool GetRegistValue(HKEY hKey, LPCTSTR lpcszParam,
- DWORD* pDwValue, CHAR* pSzValue, const DWORD* pDwSizeOfSz)
- {
- if (pDwValue != NULL) {
- DWORD dwType = REG_DWORD;
- DWORD dwValue = 0;
- DWORD dwSize = sizeof(DWORD);
- LONG lResult = RegQueryValueExA(hKey, lpcszParam, NULL, &dwType, (LPBYTE)&dwValue, &dwSize);
- if (lResult == ERROR_SUCCESS) {
- Dbg("Value of \"%s\": %d", lpcszParam, dwValue);
- *pDwValue = dwValue;
- return true;
- } else {
- Dbg("RegQueryValueEx for \"%s\" error, result=%ld.", lpcszParam, lResult);
- return false;
- }
- } else if (pSzValue != NULL) {
- DWORD dwType = REG_SZ;
- DWORD dwSize = MAX_PATH * sizeof(CHAR);
- TCHAR szValue[MAX_PATH + 1] = { 0 };
- LONG lResult = RegQueryValueEx(hKey, lpcszParam, NULL, &dwType, (LPBYTE)szValue, &dwSize);
- if (lResult == ERROR_SUCCESS) {
- Dbg("Value of \"%s\": %s", lpcszParam, szValue);
- strcpy_s(pSzValue, *pDwSizeOfSz, szValue);
- return true;
- } else {
- Dbg("RegQueryValueEx for \"InstallTime\" error, result=%ld.", lResult);
- return false;
- }
- }
- Dbg("invalid param for \"%s\"", lpcszParam);
- return false;
- }
- static LONG GetSogouInstallState(SogouInstallStateInfo& info)
- {
- HKEY hKey;
- LONG lResult = -1;
- DWORD dwFlag = KEY_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS;
- lResult = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\SogouPCIme", 0, dwFlag, &hKey);
- if (lResult == ERROR_SUCCESS) {
- DWORD dwValue = (DWORD)-1;
- const bool res1 = GetRegistValue(hKey, "InstallFlag", &dwValue, NULL, NULL);
- if (res1) {
- info.dwInstalledStatus = dwValue;
- }
- TCHAR szValue[MAX_PATH + 1] = { 0 };
- DWORD dwLength = MAX_PATH;
- //1970 0x83AA7E80
- const bool res2 = GetRegistValue(hKey, "InstallTime", NULL, szValue, &dwLength);
- if (res2) {
- info.strInstallDate = szValue;
- Dbg("InstallTime: %s", info.GetInstallTime().ToTimeString().GetData());
- }
- if (res1 && res2) {
- lResult = 0;
- } else {
- lResult = -1;
- }
- } else {
- Dbg("%s::RegOpenKeyEx error, Result=%ld.", __FUNCTION__, lResult);
- }
- RegCloseKey(hKey);
- return lResult;
- }
- static LONG GetSogouExecuteInfo(SogouRunVersionInfo& info, BOOL f32bit = TRUE)
- {
- HKEY hKey;
- LONG lResult = -1;
- PVOID oldValue = NULL;
- Wow64DisableWow64FsRedirection(&oldValue);
- DWORD dwFlag = KEY_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS;
- lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- f32bit ? "SOFTWARE\\SogouPCIme" : "SOFTWARE\\WOW6432Node\\SogouPCIme", 0, dwFlag, &hKey);
- if (lResult == ERROR_SUCCESS) {
- TCHAR szVersion[MAX_PATH + 1] = { 0 }, szDefault[MAX_PATH + 1] = { 0 };
- DWORD dwLength = MAX_PATH;
- const bool res1 = GetRegistValue(hKey, "Version", NULL, szVersion, &dwLength);
- if (res1) info.strVersion = szVersion;
- const bool res2 = GetRegistValue(hKey, "", NULL, szDefault, &dwLength);
- if (res2) info.strInstallDir = szDefault;
- if (res1 && res2) {
- lResult = 0;
- } else {
- lResult = -1;
- }
- } else {
- Dbg("%s::RegOpenKeyEx(32bit=%d) error, Result=%ld.", __FUNCTION__, f32bit, lResult);
- }
- RegCloseKey(hKey);
- Wow64RevertWow64FsRedirection(oldValue);
- return lResult;
- }
- #endif //RVC_OS_WIN
- ErrorCodeEnum ResourceWatcherEntity::DoCheckInstallStateJob()
- {
- LOG_FUNCTION();
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum err = spFunction->OpenConfig(Config_Run, spConfig);
- BOOL fNeedAlarm = TRUE;
- SogouInstallInfo info;
- #if defined(RVC_OS_WIN)
- GetSogouInstallState(info.state);
- BOOL is32Bit = Is64BitPlatform() ? FALSE : TRUE;
- if (ERROR_FILE_NOT_FOUND == GetSogouExecuteInfo(info.program, is32Bit))
- GetSogouExecuteInfo(info.program, !is32Bit);
- #else
- 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());
- #endif //RVC_OS_WIN
- CSimpleStringA strLastRecord(true);
- err = spConfig->ReadConfigValue("SogouInput", "LastInstalledRecord", strLastRecord);
- if (strLastRecord.IsNullOrEmpty() || info.Stringfy().Compare(strLastRecord) != 0) {
- spConfig->WriteConfigValue("SogouInput", "LastInstalledRecord", info.Stringfy());
- fNeedAlarm = TRUE;
- } else {
- //Report info per day.
- int nLastRecordTime = 0;
- err = spConfig->ReadConfigValueInt("SogouInput", "LastReportTime", nLastRecordTime);
- SYSTEMTIME stTaskTime = CSmallDateTime(nLastRecordTime).ToSystemTime();
- Dbg("Last Sogou install check time: %04d-%02d-%02d %02d:%02d:%02d",
- stTaskTime.wYear, stTaskTime.wMonth, stTaskTime.wDay,
- stTaskTime.wHour, stTaskTime.wMinute, stTaskTime.wSecond);
- SYSTEMTIME stNow = {};
- GetLocalTime(&stNow);
- if (nLastRecordTime > 0 && stTaskTime.wYear == stNow.wYear
- && stTaskTime.wMonth == stNow.wMonth && stTaskTime.wDay == stNow.wDay) {
- //The Same Day
- fNeedAlarm = FALSE;
- } else {
- fNeedAlarm = TRUE;
- }
- }
- if (fNeedAlarm) {
- const DWORD dwUserCode = info.IsInstalledSuccess() ? LOG_ERR_SOGOU_INPUT_INSTALLED : LOG_ERR_SOGOU_INPUT_NOTINSTALLED;
- LogWarn(Severity_Middle, Error_DataCheck, dwUserCode, info.Stringfy());
- spConfig->WriteConfigValue("SogouInput", "LastReportTime",
- CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
- } else {
- Dbg("Do not Report.");
- }
- return Error_Succeed;
- }
- void ResourceWatcherEntity::DoCheckSogouProcessStatus()
- {
- 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_Middle, Error_Debug, LOG_RESOURCEWATCHER_SOGOU_PROCESS_STATUS_CHANGE, uploadInfo.c_str());
- }
- }
- //# all available outputs
- //OUTPUTS = $(xrandr | awk '$2 ~ /connected/ {print $1}')
- //echo outputs : $OUTPUTS
- //# get info from xrandr
- //XRANDR = `xrandr`
- //
- //connectedOutputs = $(echo "$XRANDR" | grep " connected" | sed - e "s/\([A-Z0-9]\+\) connected.*/\1/")
- //activeOutput = $(echo "$XRANDR" | grep - e " connected [^(]" | sed - e "s/\([A-Z0-9]\+\) connected.*/\1/")
- //connected = $(echo $connectedOutputs | wc - w)
- //echo connectedOutputs : ${ connectedOutputs }
- //echo activeOutput : ${ activeOutput }
- //echo connected : ${ connected }
- ErrorCodeEnum ResourceWatcherEntity::ConfigMonitorSetting(const UOS::MonitorInfo& config)
- {
- ErrorCodeEnum result(Error_Succeed);
- CSimpleStringA strExecute("xrandr");
- //Get monitor info
- do {
- std::string sucContent, failedContent;
- CSimpleStringA strCmd("xrandr | grep \" connected\" | sed -e \"s/\([A-Z0-9]\+\) connected.*/\1/\"");
- bool ret = SP::Module::Util::ShelllExecute(strCmd.GetData(), sucContent, failedContent);
- Dbg("{%s}:{%s}{%s}", strCmd.GetData(), sucContent.c_str(), failedContent.c_str());
- } while (false);
- do {
- std::string sucContent, failedContent;
- CSimpleStringA strCmd("xrandr |awk '$2 ~ /connected/ {print $1}'");
- bool ret = SP::Module::Util::ShelllExecute(strCmd.GetData(), sucContent, failedContent);
- Dbg("{%s}:{%s}{%s}", strCmd.GetData(), sucContent.c_str(), failedContent.c_str());
- } while (false);
- CSimpleStringA strCmd(strExecute);
- if (!config.name.empty()) {
- strCmd += CSimpleStringA::Format(" --output %s", config.name.c_str());
- //Set resolution
- if (config.nResolutionX != 0 && config.nResolutionY != 0) {
- CSimpleStringA tmp = CSimpleStringA::Format(" --mode %dx%d", config.nResolutionX, config.nResolutionY);
- strCmd += tmp;
- }
- if (config.refreshRate != 0) {
- CSimpleStringA tmp = CSimpleStringA::Format(" --rate %d", config.refreshRate);
- strCmd += tmp;
- }
- //set primary
- if (config.isPrimary) {
- strCmd += " --primary";
- } else if (config.posDirecttion != -1 && !config.other.empty()) {
- CSimpleStringA posDir(true);
- switch (config.posDirecttion) {
- case 0:
- posDir = "--same-as";
- case 1:
- posDir = "--above";
- break;
- case 2:
- posDir = "--right-of";
- break;
- case 3:
- posDir = "--above";
- break;
- case 4:
- posDir = "--left-of";
- break;
- default:
- result = Error_Param;
- break;
- }
- if (result == Error_Succeed) {
- CSimpleStringA tmp = CSimpleStringA::Format(" %s %s", posDir.GetData(), config.other.c_str());
- strCmd += tmp;
- }
- }
- }
- do
- {
- std::string sucContent, failedContent;
- bool ret = SP::Module::Util::ShelllExecute(strCmd.GetData(), sucContent, failedContent);
- Dbg("{%s}:{%s}{%s}", strCmd.GetData(), sucContent.c_str(), failedContent.c_str());
- } while (false);
- do {
- std::string sucContent, failedContent;
- strCmd = strExecute;
- bool ret = SP::Module::Util::ShelllExecute(strCmd.GetData(), sucContent, failedContent);
- Dbg("{%s}:{%s}{%s}", strCmd.GetData(), sucContent.c_str(), failedContent.c_str());
- } while (false);
- return result;
- }
- std::vector<std::string> ResourceWatcherEntity::GetUserNameList(bool bExcludeRoot)
- {
- std::vector<std::string> results;
- array_header_t* arr;
- arr = fileutil_get_sub_dirs_a("/home");
- if (arr) {
- int i;
- for (i = 0; i < arr->nelts; ++i) {
- char szDestSubDir[256] = { 0 };
- char* dir = ARRAY_IDX(arr, i, char*);
- Dbg("sub dir: %s", dir);
- strcpy(szDestSubDir, dir);
- strcat(szDestSubDir, SPLIT_SLASH_STR);
- strcat(szDestSubDir, ".config/kwinrc");
- if (ExistsFileA(szDestSubDir)) {
- std::string strUserName((const char*)&dir[strlen("/home/")]);
- Dbg("username:%s", strUserName.c_str());
- if (strUserName.compare("root") != 0 || !bExcludeRoot) {
- results.push_back(strUserName);
- }
- }
- }
- toolkit_array_free2(arr);
- }
- return results;
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(ResourceWatcherEntity)
- SP_END_ENTITY_MAP()
|