|
@@ -49,7 +49,6 @@
|
|
|
#pragma comment(lib, "WtsApi32.lib")
|
|
|
#include "Mmdeviceapi.h"
|
|
|
#include "Propidl.h"
|
|
|
-#include "Functiondiscoverykeys_devpkey.h"
|
|
|
#pragma comment(lib, "pdh.lib")
|
|
|
#pragma comment(lib,"winmm.lib" )
|
|
|
#pragma comment(lib, "shell32.lib")
|
|
@@ -63,8 +62,6 @@
|
|
|
const int MAX_MAINLINK_CHECK_TIME = 5000;
|
|
|
const int TIMER_MAINLINK_CHECK = 4;
|
|
|
#else
|
|
|
-const int TIMER_ID_CLEARVIDEO_ENHANCE = 1;
|
|
|
-const int THOUSAND = 1024;
|
|
|
const int MILLION = 1048576;
|
|
|
#endif // RVC_OS_LINUX
|
|
|
static int hardwareCheckTime = 60 * 1000; //初始化硬件检测间隔
|
|
@@ -76,11 +73,7 @@ static int memWarnThreshold = 10; //初始化CUP、内存告警阈值次数
|
|
|
static int diskCheckTime = 4 * 60 * 60 * 1000; //初始化硬盘检测间隔
|
|
|
static int diskCheckFlag = 1;
|
|
|
|
|
|
-#define DIV (1024 * 1024)
|
|
|
-#define DAY_DIV (24 * 60 * 60)
|
|
|
-#define HOURS_DIV (60 * 60)
|
|
|
-#define MINUS_DIV (60)
|
|
|
-
|
|
|
+#define MAX_SOFTWARE_INSTALLED_DETECT_COUNT 50
|
|
|
#ifndef RVC_OS_LINUX
|
|
|
#define ENCODING (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING)
|
|
|
#endif // !RVC_OS_LINUX
|
|
@@ -98,7 +91,6 @@ const char* CMB_LINK_FILE_NAME = "招商银行可视柜台.lnk";
|
|
|
#endif
|
|
|
const char* STRATUP_FILENAME_FROM_SCRIPTS = "spexplorerauto.lnk";
|
|
|
|
|
|
-
|
|
|
#if defined(RVC_OS_WIN)
|
|
|
//https://blog.csdn.net/aflyeaglenku/article/details/51742820
|
|
|
typedef struct _dmi_header
|
|
@@ -132,7 +124,6 @@ void ResourceWatcherFSM::GetAutoStartFile(std::string& userDirPath, std::vector<
|
|
|
char* filename = strrchr(file, '\\');
|
|
|
if (filename != NULL) { filename += 1; }
|
|
|
else { filename = file; }
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("filename:%s", filename);
|
|
|
pubDirFiles.push_back(std::string(filename));
|
|
|
}
|
|
|
toolkit_array_free2(arr);
|
|
@@ -150,7 +141,6 @@ void ResourceWatcherFSM::GetAutoStartFile(std::string& userDirPath, std::vector<
|
|
|
char* filename = strrchr(file, '\\');
|
|
|
if (filename != NULL) { filename += 1; }
|
|
|
else { filename = file; }
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("filename:%s", filename);
|
|
|
userDirFiles.push_back(std::string(filename));
|
|
|
}
|
|
|
toolkit_array_free2(arr);
|
|
@@ -160,11 +150,25 @@ void ResourceWatcherFSM::GetAutoStartFile(std::string& userDirPath, std::vector<
|
|
|
|
|
|
#endif //RVC_OS_WIN
|
|
|
|
|
|
+struct SetupSoftInfo
|
|
|
+{
|
|
|
+ std::string displayName; //软件名称
|
|
|
+ std::string publisher; //发行商
|
|
|
+ std::string displayVersion; //版本
|
|
|
+ std::string installDate; //安装日期
|
|
|
+ std::string uninstallString; //卸载命令及参数
|
|
|
+ bool quietFalg;
|
|
|
+ bool systemCompoentFalg;
|
|
|
+ void Display()
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("软件名称:%s|发行商:%s|版本:%s|安装日期:%s|卸载命令:%s|系统组件:%s",displayName.c_str(), publisher.c_str(), displayVersion.c_str(), installDate.c_str(), uninstallString.c_str(), systemCompoentFalg ? "Y":"N");
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
ResourceWatcherFSM::ResourceWatcherFSM(void)
|
|
|
- :m_strTerminalNo(true),
|
|
|
- m_bFirstRunAfterBoot(FALSE),
|
|
|
+ :m_bFirstRunAfterBoot(FALSE),
|
|
|
m_cpuTop(0), flag4DeleteKeyAutoStartFile(false), flag4DoAutoStartTaskIgnoreBoot(FALSE), m_skipDesktopDetect(FALSE)
|
|
|
- , m_strCurrentUserName(true), m_strLoginedUserName(true)
|
|
|
+ , m_strLoginedUserName(true)
|
|
|
{
|
|
|
#ifdef RVC_OS_WIN
|
|
|
m_iNonSignedTotal = 0;
|
|
@@ -172,7 +176,6 @@ ResourceWatcherFSM::ResourceWatcherFSM(void)
|
|
|
#endif // RVC_OS_WIN
|
|
|
}
|
|
|
|
|
|
-
|
|
|
ResourceWatcherFSM::~ResourceWatcherFSM(void)
|
|
|
{
|
|
|
}
|
|
@@ -181,8 +184,6 @@ void ResourceWatcherFSM::s0_on_entry()
|
|
|
{
|
|
|
#if defined(RVC_OS_WIN)
|
|
|
this->PostEventFIFO(new RunEvent());
|
|
|
- BOOL fInstallBySetup(FALSE);
|
|
|
- ErrorCodeEnum rc = DetectVTMInstalledBySetup(fInstallBySetup);
|
|
|
#endif //RVC_OS_WIN
|
|
|
}
|
|
|
|
|
@@ -225,49 +226,6 @@ void ResourceWatcherFSM::s1_on_exit()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-void ResourceWatcherFSM::s2_on_entry()
|
|
|
-{
|
|
|
-}
|
|
|
-
|
|
|
-unsigned int ResourceWatcherFSM::s2_on_event(FSMEvent* e)
|
|
|
-{
|
|
|
- unsigned int unRes = 0;
|
|
|
- switch (e->iEvt)
|
|
|
- {
|
|
|
- case USER_EVT_RUN:
|
|
|
- {
|
|
|
- e->SetHandled();
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- return unRes;
|
|
|
-}
|
|
|
-
|
|
|
-void ResourceWatcherFSM::s2_on_exit()
|
|
|
-{
|
|
|
-}
|
|
|
-
|
|
|
-void ResourceWatcherFSM::s3_on_entry()
|
|
|
-{
|
|
|
-}
|
|
|
-
|
|
|
-unsigned int ResourceWatcherFSM::s3_on_event(FSMEvent* e)
|
|
|
-{
|
|
|
- unsigned int unRes = 0;
|
|
|
- switch (e->iEvt)
|
|
|
- {
|
|
|
- case USER_EVT_RUN:
|
|
|
- {
|
|
|
- e->SetHandled();
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- return unRes;
|
|
|
-}
|
|
|
-
|
|
|
-void ResourceWatcherFSM::s3_on_exit()
|
|
|
-{
|
|
|
-}
|
|
|
|
|
|
#ifdef RVC_OS_LINUX
|
|
|
bool ResourceWatcherFSM::GetMonitorInfo(CSimpleStringA& outInfo)
|
|
@@ -346,9 +304,9 @@ void ResourceWatcherFSM::TriggerAtStatusChanged(bool bMStatus)
|
|
|
else {
|
|
|
RecoverDDEClipboardEnable();
|
|
|
}
|
|
|
- GetEntityBase()->GetFunction()->PostThreadPoolTask(new DetectSoftwareInstallStatusTask(this));
|
|
|
#endif //RVC_OS_LINUX
|
|
|
AlarmSystemBasicInfo();
|
|
|
+ GetEntityBase()->GetFunction()->PostThreadPoolTask(new DetectSoftwareInstallStatusTask(this));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -364,17 +322,10 @@ ErrorCodeEnum ResourceWatcherFSM::OnInit()
|
|
|
GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spRunConfig);
|
|
|
GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
|
|
|
erroCode = GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_RvcSysinfo);
|
|
|
- m_strTerminalNo = m_RvcSysinfo.strTerminalID;
|
|
|
m_bFirstRunAfterBoot = DetectIsFirstRunAtBoot();
|
|
|
if (m_bFirstRunAfterBoot) {
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("First time to run after system boot.");
|
|
|
}
|
|
|
-#if defined(RVC_OS_WIN)
|
|
|
- if (m_bFirstRunAfterBoot) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-#endif //RVC_OS_WIN
|
|
|
|
|
|
spCtSettingConfig->ReadConfigValueInt(m_pEntity->GetEntityName(), "DisplayCnt", m_iNonSignedDisplay);
|
|
|
if (m_iNonSignedDisplay <= 0)
|
|
@@ -444,16 +395,10 @@ void ResourceWatcherFSM::AfterInit()
|
|
|
|
|
|
#if defined(RVC_OS_WIN)
|
|
|
InitUserInfo();
|
|
|
- if (m_bFirstRunAfterBoot) {
|
|
|
+ if (m_bFirstRunAfterBoot || flag4DoAutoStartTaskIgnoreBoot) {
|
|
|
InitCustomAutoStartFileSheet();
|
|
|
AggerateAutoStatTask* task = new AggerateAutoStatTask(this);
|
|
|
GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
|
|
|
- }
|
|
|
- else if(flag4DoAutoStartTaskIgnoreBoot){
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Do AutoStart Job from CenterSettings");
|
|
|
- InitCustomAutoStartFileSheet();
|
|
|
- AggerateAutoStatTask* task = new AggerateAutoStatTask(this);
|
|
|
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
|
|
|
}
|
|
|
DetectVersionHasChangedAndWarnCover();
|
|
|
#else
|
|
@@ -533,39 +478,104 @@ ErrorCodeEnum ResourceWatcherFSM::BizLinkDetect(
|
|
|
|
|
|
}
|
|
|
|
|
|
+int ResourceWatcherFSM::ExpandDir(LPCTSTR macorStr, CSimpleStringA& outDir)
|
|
|
+{
|
|
|
+ const int len = macorStr == NULL ? 0 : strlen(macorStr);
|
|
|
+ if (len == 0) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (len < strlen("$(1)") /*最小的长度*/) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ CSimpleStringA strOrigin(macorStr);
|
|
|
+ int end = 0;
|
|
|
+ if (!(strOrigin.IsStartWith("$(") && (end = strOrigin.IndexOf(")")) >= 3)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ for (int i = strlen("$("); i < end; ++i) {
|
|
|
+ if (!((strOrigin[i] >= 'a' && strOrigin[i] <= 'z') || (strOrigin[i] >= 'A' && strOrigin[i] <= 'Z'))) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ char macroInnerStr[MAX_PATH] = { 0 };
|
|
|
+ int nIndex = 0;
|
|
|
+ bool bUtilMeetMacroMark = false;
|
|
|
+ const char* pStr = macorStr;
|
|
|
+ int startIndex = 0;
|
|
|
+ for (; *pStr != '\0'; pStr++, startIndex++)
|
|
|
+ {
|
|
|
+ if (!bUtilMeetMacroMark)
|
|
|
+ {
|
|
|
+ if (*pStr == '$' && *(pStr + 1) == '(')
|
|
|
+ {
|
|
|
+ pStr++;
|
|
|
+ startIndex++;
|
|
|
+ bUtilMeetMacroMark = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (*pStr == ')')
|
|
|
+ {
|
|
|
+ startIndex++;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ macroInnerStr[nIndex++] = *pStr;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LOG_ASSERT(nIndex != 0);
|
|
|
+ ErrorCodeEnum erroCode = GetEntityBase()->GetFunction()->GetPath(macroInnerStr, outDir);
|
|
|
+ if (erroCode != Error_Succeed) {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Get original path of $(%s) failed with error 0x%x", macorStr, erroCode);
|
|
|
+ return -2;
|
|
|
+ }
|
|
|
+ return startIndex;
|
|
|
+}
|
|
|
+
|
|
|
//通过集中配置额外执行的清理策略
|
|
|
void ResourceWatcherFSM::CenterSettingDelete()
|
|
|
{
|
|
|
- string p;
|
|
|
CSmartPointer<IConfigInfo> spCtSettingConfig;
|
|
|
GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
|
|
|
- CSimpleStringA upPath(""), tempPath(""), tPath("");
|
|
|
+ CSimpleStringA tempPath("");
|
|
|
int closeRmDir = 0, backDay = 0;
|
|
|
spCtSettingConfig->ReadConfigValue("ResourceWatcher", "DocumentCleanPath", tempPath);
|
|
|
spCtSettingConfig->ReadConfigValueInt("ResourceWatcher", "DocumentCleanCloseRmDir", closeRmDir);
|
|
|
spCtSettingConfig->ReadConfigValueInt("ResourceWatcher", "DocumentCleanBackDay", backDay);
|
|
|
+
|
|
|
if (tempPath.GetLength() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
+ CSimpleStringA implePath(true);
|
|
|
+ int nIndex(0);
|
|
|
+ if (tempPath.IsStartWith("$(") && (nIndex = ExpandDir(tempPath.GetData(), implePath)) > 0) {
|
|
|
+ CSimpleStringA newPath(implePath);
|
|
|
+ if (nIndex < tempPath.GetLength()) {
|
|
|
+ newPath += tempPath.SubString(nIndex);
|
|
|
+ }
|
|
|
+ tempPath = newPath;
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("innner:[%s]", tempPath.GetData());
|
|
|
+ }
|
|
|
+
|
|
|
ErrorCodeEnum erroCode = Error_Succeed;
|
|
|
CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
|
|
|
- CSmartPointer<IConfigInfo> spConfigRun;
|
|
|
bool bFailFlag = false;
|
|
|
|
|
|
//执行清理逻辑
|
|
|
- bool delDir = (closeRmDir == 0) ? true : false;
|
|
|
- upPath = tempPath;
|
|
|
- int nDelSuc = 0, nDelFail = 0, nFileCount = 0;
|
|
|
- nFileCount = ProcessFileDelete("RTA5A14", upPath.GetData(), nDelSuc, nDelFail, delDir, backDay);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Process result(%s): count(%d), suc(%d), failed(%d).", upPath.GetData(), nFileCount, nDelSuc, nDelFail);
|
|
|
- if (nDelFail != 0) {
|
|
|
+ const bool delDir = (closeRmDir == 0) ? true : false;
|
|
|
+ DeleteResult delResult;
|
|
|
+ DeleteParam delParam(tempPath.GetData());
|
|
|
+ delParam.saveBackDay = backDay;
|
|
|
+ delParam.SetRmDirFlag(delDir);
|
|
|
+ delParam.rtaCode = "RTA5A14";
|
|
|
+ const int nFileCount = ProcessFileDelete(delParam, delResult);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Process result(%s): count(%d), suc(%d), failed(%d).", tempPath.GetData(), nFileCount, delResult.sucCnt, delResult.failCnt);
|
|
|
+ if (delResult.failCnt != 0) {
|
|
|
bFailFlag = true;
|
|
|
- //break;
|
|
|
}
|
|
|
-
|
|
|
- if (!bFailFlag)
|
|
|
- {
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_WARN_FILE_DELETE_SUC, CSimpleStringA::Format("Delete files in [%s] success", tempPath.GetData()));
|
|
|
+ else {
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_WARN_FILE_DELETE_SUC, CSimpleStringA::Format("Delete files in [%s] success", tempPath.GetData()));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -609,122 +619,113 @@ time_t ResourceWatcherFSM::GetPathTimeSeconds(const char* inPath)
|
|
|
}
|
|
|
|
|
|
//所有文件删除功能都用这个函数来处理
|
|
|
-//bool delDir:控制是否将目录也一并删除,false 保留目录, true 删除目录
|
|
|
-//int saveBackDay:保存多少天内的文件, 默认参数,默认值为0,即不保存。(delDir = true时,该参数强制为0)
|
|
|
-int ResourceWatcherFSM::ProcessFileDelete(CSimpleStringA rtaCode, LPCTSTR lpszPath, int& nDelSucCnt, int& nDelFailedCnt, bool delDir, unsigned int saveBackDay)
|
|
|
+int ResourceWatcherFSM::ProcessFileDelete(const DeleteParam& delParam, DeleteResult& delResult)
|
|
|
{
|
|
|
int fileCnt = 0;
|
|
|
|
|
|
- DWORD attrs = GetFileAttributesA(lpszPath);
|
|
|
+ DWORD attrs = GetFileAttributesA(delParam.path);
|
|
|
if (attrs == INVALID_FILE_ATTRIBUTES)
|
|
|
{
|
|
|
- CSimpleStringA errMsg = CSimpleStringA::Format("Can not find path:[%s], GLE = %u.", lpszPath, GetLastError());
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(rtaCode.GetData()).setAPI("DeleteFiles")(errMsg.GetData());
|
|
|
- LogWarn(Severity_Middle, Error_Debug, LOG_WARN_FILE_DELETE_FAILED, errMsg.GetData());
|
|
|
- nDelFailedCnt++;
|
|
|
+ CSimpleStringA errMsg = CSimpleStringA::Format("Can not find path:[%s], GLE = %u.", delParam.path.GetData(), GetLastError());
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(delParam.logCode).setResultCode(delParam.rtaCode).setAPI("DeleteFiles")(errMsg.GetData());
|
|
|
+ LogWarn(Severity_Middle, Error_Debug, LOG_WARN_FILE_DELETE_FAILED, errMsg);
|
|
|
+ delResult.failCnt++;
|
|
|
}
|
|
|
else if (attrs & FILE_ATTRIBUTE_DIRECTORY) //文件夹类型
|
|
|
{
|
|
|
- if (delDir == true) //若要删除目录,则不保留任何文件
|
|
|
+ if (delParam.delDirFlag) //若要删除目录,则不保留任何文件
|
|
|
{
|
|
|
- saveBackDay = 0;
|
|
|
- bool deleteDir;
|
|
|
- deleteDir = RemoveDirRecursiveA(lpszPath);
|
|
|
+ bool deleteDir = RemoveDirRecursiveA(delParam.path);
|
|
|
if (!deleteDir)
|
|
|
{
|
|
|
- CSimpleStringA errMsg = CSimpleStringA::Format("RemoveDir [%s] failed, GLE = %u.", lpszPath, GetLastError());
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(rtaCode.GetData()).setAPI("DeleteFiles")(errMsg.GetData());
|
|
|
+ CSimpleStringA errMsg = CSimpleStringA::Format("RemoveDir [%s] failed, GLE = %u.", delParam.path.GetData(), GetLastError());
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(delParam.logCode).setResultCode(delParam.rtaCode).setAPI("DeleteFiles")(errMsg.GetData());
|
|
|
LogWarn(Severity_Middle, Error_Debug, LOG_WARN_FILE_DELETE_FAILED, errMsg.GetData());
|
|
|
- nDelFailedCnt++;
|
|
|
+ delResult.failCnt++;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- nDelSucCnt++;
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setLogCode(delParam.logCode)("Remove directory(%s) succ.", delParam.path.GetData());
|
|
|
+ delResult.sucCnt++;
|
|
|
fileCnt++;
|
|
|
}
|
|
|
return fileCnt;
|
|
|
}
|
|
|
|
|
|
- bool delSubDir = true; //默认移除子目录
|
|
|
array_header_t* arr;
|
|
|
- arr = fileutil_get_sub_dirs_a(lpszPath);
|
|
|
+ arr = fileutil_get_sub_dirs_a(delParam.path.GetData());
|
|
|
if (arr)
|
|
|
{
|
|
|
int i;
|
|
|
for (i = 0; i < arr->nelts; ++i)//子目录
|
|
|
{
|
|
|
char* tmp = ARRAY_IDX(arr, i, char*);
|
|
|
-
|
|
|
- if (saveBackDay != 0)
|
|
|
+ bool delSubDir = true; //默认移除子目录
|
|
|
+ if (delParam.saveBackDay != 0)
|
|
|
{
|
|
|
//读取路径时间
|
|
|
time_t lSystemTime;
|
|
|
time(&lSystemTime);
|
|
|
|
|
|
time_t fileTime = GetPathTimeSeconds(tmp); //获取路径的最后改动时间
|
|
|
- int delDays = (lSystemTime - fileTime) / SECONDS_OF_DAY;
|
|
|
-
|
|
|
- if (delDays <= saveBackDay) //未达需要清理的天数阈值,保留目录
|
|
|
+ const int delDays = (lSystemTime - fileTime) / SECONDS_OF_DAY;
|
|
|
+ if (delDays <= delParam.saveBackDay) //未达需要清理的天数阈值,保留目录
|
|
|
{
|
|
|
delSubDir = false;
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("[%s]存留天数[%d], 删除阈值[%u], 保留目录.", tmp, (int)delDays, saveBackDay);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("[%s]存留天数[%d], 删除阈值[%u], 保留目录.", tmp, (int)delDays, delParam.saveBackDay);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- int tDelSucCnt = 0, tDelFailedCnt = 0;
|
|
|
- fileCnt += ProcessFileDelete(rtaCode, tmp, tDelSucCnt, tDelFailedCnt, delSubDir, saveBackDay); //子目录递归处理
|
|
|
- nDelFailedCnt += tDelFailedCnt;
|
|
|
- nDelSucCnt += tDelSucCnt;
|
|
|
+ DeleteParam subDelParam(delParam);
|
|
|
+ subDelParam.path = tmp;
|
|
|
+ subDelParam.SetRmDirFlag(delSubDir);
|
|
|
+ fileCnt += ProcessFileDelete(subDelParam, delResult); //子目录递归处理
|
|
|
}
|
|
|
toolkit_array_free2(arr);
|
|
|
}
|
|
|
|
|
|
- arr = fileutil_get_sub_files_a(lpszPath); //子文件
|
|
|
+ arr = fileutil_get_sub_files_a(delParam.path); //子文件
|
|
|
if (arr) {
|
|
|
int i;
|
|
|
for (i = 0; i < arr->nelts; ++i) {
|
|
|
char* tmp = ARRAY_IDX(arr, i, char*);
|
|
|
- int tDelSucCnt = 0, tDelFailedCnt = 0;
|
|
|
- fileCnt += ProcessFileDelete(rtaCode, tmp, tDelSucCnt, tDelFailedCnt, delDir, saveBackDay); //子目录递归处理
|
|
|
- nDelFailedCnt += tDelFailedCnt;
|
|
|
- nDelSucCnt += tDelSucCnt;
|
|
|
+ DeleteParam subDelParam(delParam);
|
|
|
+ subDelParam.path = tmp;
|
|
|
+ fileCnt += ProcessFileDelete(subDelParam, delResult); //子目录递归处理
|
|
|
}
|
|
|
toolkit_array_free2(arr);
|
|
|
}
|
|
|
}
|
|
|
else //文件类型
|
|
|
{
|
|
|
- if (saveBackDay != 0)
|
|
|
+ if (delParam.saveBackDay != 0)
|
|
|
{
|
|
|
//读取文件时间
|
|
|
time_t lSystemTime;
|
|
|
time(&lSystemTime);
|
|
|
|
|
|
- time_t fileTime = GetPathTimeSeconds(lpszPath); //获取文件的最后改动时间
|
|
|
- int delDays = (lSystemTime - fileTime) / SECONDS_OF_DAY;
|
|
|
-
|
|
|
- if (delDays < saveBackDay) // 未达到需要清理的天数阈值,无需清理
|
|
|
+ time_t fileTime = GetPathTimeSeconds(delParam.path); //获取文件的最后改动时间
|
|
|
+ const int delDays = (lSystemTime - fileTime) / SECONDS_OF_DAY;
|
|
|
+ if (delDays < delParam.saveBackDay) // 未达到需要清理的天数阈值,无需清理
|
|
|
{
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("[%s]存留天数[%d], 删除阈值[%u],无需清理.", lpszPath, (int)delDays, saveBackDay);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("[%s]存留天数[%d], 删除阈值[%u],无需清理.", delParam.path.GetData(), delDays, delParam.saveBackDay);
|
|
|
return fileCnt;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (RemoveFileA(lpszPath) == true)
|
|
|
+ if (RemoveFileA(delParam.path) == true)
|
|
|
{
|
|
|
- nDelSucCnt++;
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setLogCode(delParam.logCode)("Remove file(%s) succ.", delParam.path.GetData());
|
|
|
+ delResult.sucCnt++;
|
|
|
fileCnt++;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- nDelFailedCnt++;
|
|
|
- CSimpleStringA errMsg = CSimpleStringA::Format("RemoveFileA [%s] failed, GLE = %u.", lpszPath, GetLastError());
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(rtaCode.GetData()).setAPI("DeleteFiles")(errMsg.GetData());
|
|
|
+ delResult.failCnt++;
|
|
|
+ CSimpleStringA errMsg = CSimpleStringA::Format("RemoveFileA [%s] failed, GLE = %u.", delParam.path.GetData(), GetLastError());
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(delParam.logCode).setResultCode(delParam.rtaCode.GetData()).setAPI("DeleteFiles")(errMsg.GetData());
|
|
|
LogWarn(Severity_Middle, Error_Debug, LOG_WARN_FILE_DELETE_FAILED, errMsg.GetData());
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
return fileCnt;
|
|
|
}
|
|
|
|
|
@@ -915,16 +916,20 @@ BOOL ResourceWatcherFSM::DeleteVersionPackage()
|
|
|
}
|
|
|
|
|
|
CSimpleStringA tVerPath;
|
|
|
- int nDelSuc = 0, nDelFail = 0, nFileCount = 0;
|
|
|
+ DeleteResult delResult;
|
|
|
+ int nFileCount = 0;
|
|
|
#ifdef RVC_OS_LINUX
|
|
|
tVerPath = verPath + SPLIT_SLASH_STR + (*riter).ToString();
|
|
|
#else
|
|
|
tVerPath = verPath + "\\" + (*riter).ToString();
|
|
|
#endif // RVC_OS_LINUX
|
|
|
- nFileCount = ProcessFileDelete("RTA5A12", tVerPath.GetData(), nDelSuc, nDelFail, true); //版本文件夹连目录一起清理
|
|
|
+ DeleteParam delParam(tVerPath.GetData());
|
|
|
+ delParam.rtaCode = "RTA5A12";
|
|
|
+ delParam.SetRmDirFlag();//版本文件夹连目录一起清理
|
|
|
+ nFileCount = ProcessFileDelete(delParam, delResult);
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Delete Version result(%s): count(%d), suc(%d), failed(%d).",
|
|
|
- tVerPath.GetData(), nFileCount, nDelSuc, nDelFail);
|
|
|
- if (nDelFail)
|
|
|
+ tVerPath.GetData(), nFileCount, delResult.sucCnt, delResult.failCnt);
|
|
|
+ if (delResult.failCnt > 0)
|
|
|
{
|
|
|
bFailFlag = true;
|
|
|
}
|
|
@@ -982,10 +987,12 @@ void ResourceWatcherFSM::DeleteVideoFiles()
|
|
|
DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("get LocalVideo error. error = %u.", Error);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- int nDelSuc = 0, nDelFail = 0, nFileCount = 0;
|
|
|
- nFileCount = ProcessFileDelete("RTA5A13", videoPath.GetData(), nDelSuc, nDelFail, false, backDays);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Delete [Video] result(%s): count(%d), suc(%d), failed(%d).", videoPath.GetData(), nFileCount, nDelSuc, nDelFail);
|
|
|
+ DeleteResult delResult;
|
|
|
+ DeleteParam delParam(videoPath.GetData());
|
|
|
+ delParam.rtaCode = "RTA5A13";
|
|
|
+ delParam.saveBackDay = backDays;
|
|
|
+ const int nFileCount = ProcessFileDelete(delParam, delResult);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Delete [Video] result(%s): count(%d), suc(%d), failed(%d).", videoPath.GetData(), nFileCount, delResult.sucCnt, delResult.failCnt);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -2027,7 +2034,6 @@ void ResourceWatcherFSM::DetectDestopFileAndWarn(bool bClear, CSimpleStringA& st
|
|
|
char* filename = strrchr(file, '\\');
|
|
|
if (filename != NULL) { filename += 1; }
|
|
|
else { filename = file; }
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("filename:%s", filename);
|
|
|
bool toRecord = true;
|
|
|
if (bClear) {
|
|
|
std::string strLowFileName = SP::Utility::ToLower(std::string(filename));
|
|
@@ -2063,7 +2069,6 @@ void ResourceWatcherFSM::DetectDestopFileAndWarn(bool bClear, CSimpleStringA& st
|
|
|
char* dirname = strrchr(dir, '\\');
|
|
|
if (dirname != NULL) { dirname += 1; }
|
|
|
else { dirname = dir; }
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("dir name:%s", dirname);
|
|
|
bool toRecord = true;
|
|
|
if (bClear) {
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("remove desktop dir:%s", dirname);
|
|
@@ -2364,33 +2369,6 @@ void ResourceWatcherFSM::DetectAutoStartFileAndWarn()
|
|
|
LogWarn(Severity_Low, Error_Debug, LOG_RESOURCEWATCHER_DEBUG_KEY_STARTUPFILES, keyset_str.c_str());
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum ResourceWatcherFSM::DetectVTMInstalledBySetup(BOOL& fYes)
|
|
|
-{
|
|
|
- HKEY key;
|
|
|
- ErrorCodeEnum result(Error_Succeed);
|
|
|
- fYes = FALSE;
|
|
|
- CSimpleStringA regPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{123BBC1D-8555-4E90-96CA-70E678FF5C24}_is1";
|
|
|
- LONG lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regPath, 0, KEY_ALL_ACCESS, &key);
|
|
|
- if (ERROR_SUCCESS == lResult) {
|
|
|
- fYes = TRUE;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Found {123BBC1D-8555-4E90-96CA-70E678FF5C24}");
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_INFO_INSTALL_BY_SETUP, "Intalled by Setup");
|
|
|
- }
|
|
|
- else if (ERROR_FILE_NOT_FOUND == lResult)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Not Found {123BBC1D-8555-4E90-96CA-70E678FF5C24}");
|
|
|
- fYes = FALSE;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("RegOpenKeyEx For{123BBC1D-8555-4E90-96CA-70E678FF5C24} error, Result=%ld.", lResult);
|
|
|
- fYes = FALSE;
|
|
|
- result = Error_Unexpect;
|
|
|
- }
|
|
|
- RegCloseKey(key);
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
bool ResourceWatcherFSM::RegRdVtmVersion(CSimpleStringA& VTMpath, CSimpleStringA& vtmVersion, CSimpleStringA& verPath)
|
|
|
{
|
|
|
bool bRet = false;
|
|
@@ -3889,62 +3867,6 @@ void ResourceWatcherFSM::InitCustomAutoStartFileSheet()
|
|
|
|
|
|
void ResourceWatcherFSM::InitUserInfo()
|
|
|
{
|
|
|
- if (m_bFirstRunAfterBoot) {
|
|
|
- LPITEMIDLIST lp;
|
|
|
- CHAR lstr[MAX_PATH] = "";
|
|
|
- //CSIDL_COMMON_STARTUP: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
|
|
|
- HRESULT hr = SHGetSpecialFolderLocation(0, CSIDL_COMMON_STARTUP, &lp);
|
|
|
- if (SUCCEEDED(hr)) {
|
|
|
- memset(lstr, 0, strlen(lstr));
|
|
|
- SHGetPathFromIDListA(lp, lstr);
|
|
|
- CSimpleStringA s = lstr;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CSIDL_COMMON_STARTUP: %s", s.GetData());
|
|
|
- }
|
|
|
- hr = SHGetSpecialFolderLocation(0, CSIDL_STARTUP, &lp);
|
|
|
- if (SUCCEEDED(hr)) {
|
|
|
- memset(lstr, 0, strlen(lstr));
|
|
|
- SHGetPathFromIDListA(lp, lstr);
|
|
|
- CSimpleStringA s = lstr;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CSIDL_STARTUP: %s", s.GetData());
|
|
|
- }
|
|
|
- //CSIDL_COMMON_DESKTOPDIRECTORY: C:\Users\Public\Desktop
|
|
|
- hr = SHGetSpecialFolderLocation(0, CSIDL_COMMON_DESKTOPDIRECTORY, &lp);
|
|
|
- if (SUCCEEDED(hr)) {
|
|
|
- memset(lstr, 0, strlen(lstr));
|
|
|
- SHGetPathFromIDListA(lp, lstr);
|
|
|
- CSimpleStringA s = lstr;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CSIDL_COMMON_DESKTOPDIRECTORY: %s", s.GetData());
|
|
|
- }
|
|
|
- //CSIDL_DESKTOP: C:\Users\szzt\Desktop
|
|
|
- hr = SHGetSpecialFolderLocation(0, CSIDL_DESKTOP, &lp);
|
|
|
- if (SUCCEEDED(hr)) {
|
|
|
- memset(lstr, 0, strlen(lstr));
|
|
|
- SHGetPathFromIDListA(lp, lstr);
|
|
|
- CSimpleStringA s = lstr;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CSIDL_DESKTOP: %s", s.GetData());
|
|
|
- }
|
|
|
- //CSIDL_DESKTOPDIRECTORY: C:\Users\szzt\Desktop
|
|
|
- hr = SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, &lp);
|
|
|
- if (SUCCEEDED(hr)) {
|
|
|
- memset(lstr, 0, strlen(lstr));
|
|
|
- SHGetPathFromIDListA(lp, lstr);
|
|
|
- CSimpleStringA s = lstr;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CSIDL_DESKTOPDIRECTORY: %s", s.GetData());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- const DWORD INFO_BUFFER_SIZE = 128;
|
|
|
- char infoBuf[INFO_BUFFER_SIZE];
|
|
|
- ZeroMemory(infoBuf, INFO_BUFFER_SIZE);
|
|
|
- DWORD bufCharCount = INFO_BUFFER_SIZE;
|
|
|
- if (!GetUserName(infoBuf, &bufCharCount)) {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetUserName failed, GLE=%u", GetLastError());
|
|
|
- }
|
|
|
- else {
|
|
|
- m_strCurrentUserName = infoBuf;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Current user name:%s", m_strCurrentUserName.GetData());
|
|
|
- }
|
|
|
-
|
|
|
DWORD dwSessionId = WTSGetActiveConsoleSessionId();
|
|
|
LPTSTR pBuffer = NULL;
|
|
|
DWORD dwBufferLen;
|
|
@@ -3960,9 +3882,6 @@ void ResourceWatcherFSM::InitUserInfo()
|
|
|
if (pBuffer) {
|
|
|
WTSFreeMemory(pBuffer);
|
|
|
}
|
|
|
- const int diff_flag = IsUserSameName() ? 0 : 1;
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_INFO_USRNAME_INFO, CSimpleStringA::Format("{\"subject\":\"user_info\",\"username\":\"%s\",\"login_username\":\"%s\",\"diff\":%d}"
|
|
|
- ,m_strCurrentUserName.GetData(), m_strLoginedUserName.GetData(), diff_flag));
|
|
|
}
|
|
|
|
|
|
void ResourceWatcherFSM::ToListCurrentUserStartupFile(const std::string& userDirPath, std::vector<std::string>& files, std::vector<std::string>& keyfiles)
|
|
@@ -3971,7 +3890,6 @@ void ResourceWatcherFSM::ToListCurrentUserStartupFile(const std::string& userDir
|
|
|
fulPath += "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
|
|
|
files.clear();
|
|
|
keyfiles.clear();
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("startup path:%s", fulPath.c_str());
|
|
|
if (ExistsDirA(fulPath.c_str())) {
|
|
|
auto arr = fileutil_get_sub_files(fulPath.c_str());
|
|
|
if (arr != NULL) {
|
|
@@ -3980,7 +3898,6 @@ void ResourceWatcherFSM::ToListCurrentUserStartupFile(const std::string& userDir
|
|
|
char* filename = strrchr(file, '\\');
|
|
|
if (filename != NULL) { filename += 1; }
|
|
|
else { filename = file; }
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("filename:%s", filename);
|
|
|
files.push_back(std::string(filename));
|
|
|
}
|
|
|
toolkit_array_free2(arr);
|
|
@@ -4007,7 +3924,7 @@ void ResourceWatcherFSM::GetCommDesktopDirectory(CSimpleStringA& outDir)
|
|
|
memset(lstr, 0, strlen(lstr));
|
|
|
SHGetPathFromIDListA(lp, lstr);
|
|
|
outDir = lstr;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CSIDL_COMMON_DESKTOPDIRECTORY: %s", outDir.GetData());
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CSIDL_COMMON_DESKTOPDIRECTORY: %s", outDir.GetData());
|
|
|
}
|
|
|
else {
|
|
|
DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SHGetSpecialFolderLocation for CSIDL_COMMON_DESKTOPDIRECTORY failed:%u", hr);
|
|
@@ -4026,7 +3943,7 @@ void ResourceWatcherFSM::GetUserDesktopDirectory(CSimpleStringA& outDir)
|
|
|
memset(lstr, 0, strlen(lstr));
|
|
|
SHGetPathFromIDListA(lp, lstr);
|
|
|
outDir = lstr;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CSIDL_DESKTOP: %s", outDir.GetData());
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CSIDL_DESKTOP: %s", outDir.GetData());
|
|
|
}
|
|
|
else {
|
|
|
DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SHGetSpecialFolderLocation for CSIDL_DESKTOP failed:%u", hr);
|
|
@@ -4063,7 +3980,7 @@ void ResourceWatcherFSM::GetCommStartupDirectory(CSimpleStringA& outDir)
|
|
|
memset(lstr, 0, strlen(lstr));
|
|
|
SHGetPathFromIDListA(lp, lstr);
|
|
|
outDir = lstr;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CSIDL_COMMON_STARTUP: %s", outDir.GetData());
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CSIDL_COMMON_STARTUP: %s", outDir.GetData());
|
|
|
}
|
|
|
else {
|
|
|
DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SHGetSpecialFolderLocation for CSIDL_COMMON_STARTUP failed:%u", hr);
|
|
@@ -4082,7 +3999,7 @@ void ResourceWatcherFSM::GetUserStartupDirectory(CSimpleStringA& outDir)
|
|
|
memset(lstr, 0, strlen(lstr));
|
|
|
SHGetPathFromIDListA(lp, lstr);
|
|
|
outDir = lstr;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CSIDL_STARTUP: %s", outDir.GetData());
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CSIDL_STARTUP: %s", outDir.GetData());
|
|
|
}
|
|
|
else {
|
|
|
DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SHGetSpecialFolderLocation for CSIDL_STARTUP failed:%u", hr);
|
|
@@ -4140,6 +4057,111 @@ const char* dmi_string(const dmi_header* dm, BYTE s)
|
|
|
return bp;
|
|
|
}
|
|
|
|
|
|
+void FetchSoftewareInstall(vector<SetupSoftInfo>& stupInfo, DWORD& dwInitFlag)
|
|
|
+{
|
|
|
+ DWORD dwFlag = KEY_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS;
|
|
|
+ if (dwInitFlag == 0 && Is32R64Platform() != 0) {
|
|
|
+ dwInitFlag = 1;
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("with KEY_WOW64_64KEY");
|
|
|
+ dwFlag |= KEY_WOW64_64KEY;
|
|
|
+ }
|
|
|
+ HKEY hKey;
|
|
|
+ DWORD dwCount = MAX_PATH;
|
|
|
+ LONG lResult = RegOpenKeyEx(dwInitFlag != 2 ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 0, dwFlag, &hKey);
|
|
|
+ if (lResult == ERROR_SUCCESS) {
|
|
|
+ if (RegQueryInfoKey(hKey, NULL, NULL, NULL, &dwCount, NULL, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
|
|
|
+ for (int i = 0; i < (int)dwCount; i++) {
|
|
|
+ DWORD dwRegSize = MAX_PATH;
|
|
|
+ TCHAR szValue[MAX_PATH + 1] = { 0 };
|
|
|
+ memset(szValue, '\0', MAX_PATH + 1);
|
|
|
+ RegEnumKeyEx(hKey, i, szValue, &dwRegSize, NULL, NULL, NULL, NULL);
|
|
|
+ //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%d:%s",i,szValue);
|
|
|
+ DWORD dwType;
|
|
|
+ HKEY hSubKey;
|
|
|
+ if (RegOpenKeyEx(hKey, szValue, NULL, KEY_READ, &hSubKey) == ERROR_SUCCESS)
|
|
|
+ {
|
|
|
+ SetupSoftInfo info;
|
|
|
+ info.displayName = szValue;
|
|
|
+ info.quietFalg = info.systemCompoentFalg = false;
|
|
|
+
|
|
|
+ TCHAR regBufferValue[MAX_PATH] = { 0 };
|
|
|
+ dwRegSize = MAX_PATH;
|
|
|
+ RegQueryValueEx(hSubKey, "DisplayName", 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize);
|
|
|
+ if (strcmp(regBufferValue, "") != 0) {
|
|
|
+ info.displayName = regBufferValue;//软件名称
|
|
|
+ }
|
|
|
+
|
|
|
+ dwRegSize = MAX_PATH;
|
|
|
+ memset(regBufferValue, '\0', MAX_PATH);
|
|
|
+ RegQueryValueEx(hSubKey, "DisplayVersion", 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize);
|
|
|
+ info.displayVersion = regBufferValue; //版本
|
|
|
+
|
|
|
+ /*
|
|
|
+ dwRegSize = MAX_PATH;
|
|
|
+ memset(regBufferValue, '\0', MAX_PATH);
|
|
|
+ RegQueryValueEx(hSubKey, "Publisher", 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize);
|
|
|
+ info.publisher = regBufferValue;//发行商
|
|
|
+
|
|
|
+ dwRegSize = MAX_PATH;
|
|
|
+ memset(regBufferValue, '\0', MAX_PATH);
|
|
|
+ // 判断是否能在注册表中获取到安装时间, 否取子项创建时间
|
|
|
+ if (RegQueryValueEx(hSubKey, "InstallDate", 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize) == ERROR_SUCCESS)
|
|
|
+ {
|
|
|
+ info.installDate = regBufferValue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FILETIME fileLastTime;
|
|
|
+ RegQueryInfoKey(hSubKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, &fileLastTime);
|
|
|
+ SYSTEMTIME sTime, stLocal;
|
|
|
+ FileTimeToSystemTime(&fileLastTime, &sTime);
|
|
|
+ SystemTimeToTzSpecificLocalTime(NULL, &sTime, &stLocal);
|
|
|
+ TCHAR tchTime[MAX_PATH] = { 0 };
|
|
|
+ _stprintf(tchTime, "%d%02d%02d", stLocal.wYear, stLocal.wMonth, stLocal.wDay);
|
|
|
+ info.installDate = tchTime;
|
|
|
+ }
|
|
|
+ dwRegSize = MAX_PATH;
|
|
|
+ memset(regBufferValue, '\0', MAX_PATH);
|
|
|
+ RegQueryValueEx(hSubKey, "UninstallString", 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize);
|
|
|
+ info.uninstallString = regBufferValue;//卸载命令及参数
|
|
|
+
|
|
|
+ dwRegSize = MAX_PATH;
|
|
|
+ memset(regBufferValue, '\0', MAX_PATH);
|
|
|
+ RegQueryValueEx(hSubKey, "QuietUninstallString", 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize);
|
|
|
+ if (strcmp(regBufferValue, "") != 0)
|
|
|
+ {
|
|
|
+ info.uninstallString = regBufferValue;
|
|
|
+ info.quietFalg = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ do
|
|
|
+ {
|
|
|
+ DWORD dwType = REG_DWORD;
|
|
|
+ DWORD dwValue = 0;
|
|
|
+ DWORD dwSize = sizeof(DWORD);
|
|
|
+ lResult = RegQueryValueExA(hSubKey, "SystemComponent", NULL, &dwType, (LPBYTE)&dwValue, &dwSize);
|
|
|
+ if (dwValue == 1) {
|
|
|
+ info.systemCompoentFalg = true;
|
|
|
+ }
|
|
|
+ } while (false);
|
|
|
+ */
|
|
|
+ dwRegSize = MAX_PATH;
|
|
|
+ memset(regBufferValue, '\0', MAX_PATH);
|
|
|
+ // 取ParentKeyName键值,判断是否是补丁信息, 是补丁信息键值为"OperatingSystem"
|
|
|
+ RegQueryValueEx(hSubKey, "ParentKeyName", 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize);
|
|
|
+ if (info.displayName != "" && (0 != strcmp(regBufferValue, "OperatingSystem"))) //判断是否是补丁信息
|
|
|
+ {
|
|
|
+ stupInfo.push_back(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ RegCloseKey(hSubKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RegCloseKey(hKey);
|
|
|
+}
|
|
|
+
|
|
|
#endif // _MSC_VER end硬件资源监控相关系统功能 CPU、内存、硬盘、网络wifi
|
|
|
|
|
|
#ifdef RVC_OS_LINUX
|
|
@@ -4331,8 +4353,6 @@ ErrorCodeEnum ResourceWatcherFSM::CatchSystemBasicInfo(SystemBasicInfo& info)
|
|
|
}
|
|
|
return Error_Succeed;
|
|
|
#endif //RVC_OS_WIN
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
void ResourceWatcherFSM::AlarmSystemBasicInfo()
|
|
@@ -4375,81 +4395,135 @@ BOOL ResourceWatcherFSM::DetectIsFirstRunAtBoot()
|
|
|
return bSet;
|
|
|
}
|
|
|
|
|
|
-#ifdef RVC_OS_LINUX
|
|
|
void ResourceWatcherFSM::DetectSoftwareInstallStatus()
|
|
|
{
|
|
|
- CSmartPointer<IConfigInfo> spCtSettingConfig;
|
|
|
- GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
|
|
|
- CSimpleStringA strSoftwaresNames[MAX_SOFTWARE_INSTALLED_DETECT_COUNT];
|
|
|
- CSimpleStringA strSoftwaresVers[MAX_SOFTWARE_INSTALLED_DETECT_COUNT];
|
|
|
- int nNameCounts = 0;
|
|
|
- for (int i = 0; i < MAX_SOFTWARE_INSTALLED_DETECT_COUNT; i++) {
|
|
|
- strSoftwaresNames[i] = "";
|
|
|
- strSoftwaresVers[i] = "";
|
|
|
+ CSmartPointer<IConfigInfo> spCtSettingConfig;
|
|
|
+ GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spCtSettingConfig);
|
|
|
+ CSimpleStringA strSoftwaresNames[MAX_SOFTWARE_INSTALLED_DETECT_COUNT];
|
|
|
+ CSimpleStringA strSoftwaresVers[MAX_SOFTWARE_INSTALLED_DETECT_COUNT];
|
|
|
+ int nNameCounts = 0;
|
|
|
+ for (int i = 0; i < MAX_SOFTWARE_INSTALLED_DETECT_COUNT; i++) {
|
|
|
+ strSoftwaresNames[i] = "";
|
|
|
+ strSoftwaresVers[i] = "";
|
|
|
+#if defined(RVC_OS_LINUX)
|
|
|
CSimpleStringA item = CSimpleStringA::Format("SoftwareInstallDetect%d", i);
|
|
|
- CSimpleStringA value(true);
|
|
|
- spCtSettingConfig->ReadConfigValue(GetEntityBase()->GetEntityName(), item, value);
|
|
|
- if (value.IsNullOrEmpty()) {
|
|
|
- break;
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CenterSettings:[%s]", value.GetData());
|
|
|
- if (value.IndexOf("#") != -1) {
|
|
|
- /** CSimpleString会带Trim操作,在这里不适用 [Gifur@202485]*/
|
|
|
- auto items = SP::Utility::Split(std::string(value.GetData()), '#');
|
|
|
- strSoftwaresNames[i] = items[0].c_str();
|
|
|
- strSoftwaresVers[i] = items[1].c_str();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- strSoftwaresNames[i] = value;
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Detect SoftDetect from CentralSetting, %d: [%s],[%s],[%s]"
|
|
|
- , i, item.GetData(), strSoftwaresNames[i].GetData(), strSoftwaresVers[i].GetData());
|
|
|
- nNameCounts++;
|
|
|
- }
|
|
|
+#else
|
|
|
+ CSimpleStringA item = CSimpleStringA::Format("SoftwareInstallDetectWIN%d", i);
|
|
|
+#endif //RVC_OS_LINUX
|
|
|
+ CSimpleStringA value(true);
|
|
|
+ spCtSettingConfig->ReadConfigValue(GetEntityBase()->GetEntityName(), item, value);
|
|
|
+ if (value.IsNullOrEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (value.IndexOf("#") != -1) {
|
|
|
+ /** CSimpleString会带Trim操作,在这里不适用 [Gifur@202485]*/
|
|
|
+ auto items = SP::Utility::Split(std::string(value.GetData()), '#');
|
|
|
+ strSoftwaresNames[i] = items[0].c_str();
|
|
|
+ strSoftwaresVers[i] = items[1].c_str();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ strSoftwaresNames[i] = value;
|
|
|
+ }
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Detect SoftDetect from CentralSetting, %d: [%s],[%s],[%s]"
|
|
|
+ , i, item.GetData(), strSoftwaresNames[i].GetData(), strSoftwaresVers[i].GetData());
|
|
|
+ nNameCounts++;
|
|
|
+ }
|
|
|
|
|
|
- if (nNameCounts > 0) {
|
|
|
+ if (nNameCounts > 0) {
|
|
|
|
|
|
+#if defined(RVC_OS_WIN)
|
|
|
+ vector<SetupSoftInfo> stupInfo;
|
|
|
+ DWORD dwInitFlag(0);
|
|
|
+ FetchSoftewareInstall(stupInfo, dwInitFlag);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("1software size:%d", stupInfo.size());
|
|
|
+ if (dwInitFlag == 1) {
|
|
|
+ FetchSoftewareInstall(stupInfo, dwInitFlag);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("2software size:%d", stupInfo.size());
|
|
|
+ }
|
|
|
+ dwInitFlag = 2;
|
|
|
+ FetchSoftewareInstall(stupInfo, dwInitFlag);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("3software size:%d", stupInfo.size());
|
|
|
for (int i = 0; i < nNameCounts; ++i) {
|
|
|
- CSimpleStringA runItem = CSimpleStringA::Format("dpkg -l | grep \"%s\" | awk '{print $3}'", strSoftwaresNames[i].GetData());
|
|
|
- std::string additional("");
|
|
|
- std::string succStr, errStr;
|
|
|
- std::string runStr(runItem.GetData());
|
|
|
- if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
|
|
|
- if (succStr.empty()) {
|
|
|
- CSimpleStringA strMsg = CSimpleStringA::Format("{\"software_name\":\"%s\", \"version_status\":\"not installed\",\"detect_flag\":0}", strSoftwaresNames[i].GetData());
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_WARN_SOFTWARE_DETECT_NOT_EXISTS_BASE + i, strMsg);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SoftwareInstallStatus")(strMsg.GetData());
|
|
|
+ bool found(false);
|
|
|
+ for (int j = 0; j < stupInfo.size(); j++) {
|
|
|
+ if (strSoftwaresNames[i].Compare(stupInfo[j].displayName.c_str()) == 0) {
|
|
|
+ if (strSoftwaresVers[i].IsNullOrEmpty() || strSoftwaresVers[i].Compare(stupInfo[j].displayVersion.c_str()) == 0) {
|
|
|
+ CSimpleStringA strMsg = CSimpleStringA::Format("{\"software_name\":\"%s\", \"version_status\":\"%s\", \"detect_flag\":1}"
|
|
|
+ , stupInfo[j].displayName.c_str(), stupInfo[j].displayVersion.c_str());
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_WARN_SOFTWARE_DETECT_EXISTS_BASE_WIN + i, strMsg);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SoftwareInstallStatus")(strMsg.GetData());
|
|
|
+ found = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ CSimpleStringA strMsg = CSimpleStringA::Format("{\"software_name\":\"%s\", \"version_status\":\"%s\", \"expected\":\"%s\",\"detect_flag\":0}"
|
|
|
+ , stupInfo[j].displayName.c_str(), stupInfo[j].displayVersion.c_str(), strSoftwaresVers[i].GetData());
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_WARN_SOFTWARE_DETECT_NOT_EXISTS_BASE_WIN + i, strMsg);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SoftwareInstallStatus")(strMsg.GetData());
|
|
|
+ found = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- succStr = SP::Utility::ToTrim(succStr);
|
|
|
- if (strSoftwaresVers[i].IsNullOrEmpty() || strSoftwaresVers[i].Compare(succStr.c_str()) == 0) {
|
|
|
- CSimpleStringA strMsg = CSimpleStringA::Format("{\"software_name\":\"%s\", \"version_status\":\"%s\",\"detect_flag\":1}"
|
|
|
- , strSoftwaresNames[i].GetData(), succStr.c_str(), strSoftwaresVers[i].GetData());
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_WARN_SOFTWARE_DETECT_EXISTS_BASE + i, strMsg);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SoftwareInstallStatus")(strMsg.GetData());
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CSimpleStringA strMsg = CSimpleStringA::Format("{\"software_name\":\"%s\", \"version_status\":\"%s\", \"expected\":\"%s\",\"detect_flag\":0}"
|
|
|
- , strSoftwaresNames[i].GetData(), succStr.c_str(), strSoftwaresVers[i].GetData());
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_WARN_SOFTWARE_DETECT_NOT_EXISTS_BASE + i, strMsg);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SoftwareInstallStatus")(strMsg.GetData());
|
|
|
- }
|
|
|
+ }
|
|
|
+ if (!found) {
|
|
|
+ if (stupInfo.size() > 0) {
|
|
|
+ CSimpleStringA strMsg = CSimpleStringA::Format("{\"software_name\":\"%s\", \"version_status\":\"not installed\",\"detect_flag\":0}", strSoftwaresNames[i].GetData());
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_WARN_SOFTWARE_DETECT_NOT_EXISTS_BASE_WIN + i, strMsg);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SoftwareInstallStatus")(strMsg.GetData());
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CSimpleStringA strMsg = CSimpleStringA::Format("{\"software_name\":\"%s\", \"version_status\":\"detect failed\", \"expected\":\"%s\",\"detect_flag\":0}"
|
|
|
- , strSoftwaresNames[i].GetData(), strSoftwaresVers[i].GetData());
|
|
|
- LogWarn(Severity_Low, Error_Debug, LOG_WARN_SOFTWARE_DETECT_EXISTS_STATUS_FAILED, strMsg);
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("SoftwareInstallStatus").setResultCode("RTA5A0D")(strMsg.GetData());
|
|
|
+ else {
|
|
|
+ CSimpleStringA strMsg = CSimpleStringA::Format("{\"software_name\":\"%s\", \"version_status\":\"detect failed\", \"expected\":\"%s\",\"detect_flag\":0}"
|
|
|
+ , strSoftwaresNames[i].GetData(), strSoftwaresVers[i].GetData());
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_WARN_SOFTWARE_DETECT_EXISTS_STATUS_FAILED, strMsg);
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("SoftwareInstallStatus").setResultCode("RTA5A0D")(strMsg.GetData());
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+#else
|
|
|
+ for (int i = 0; i < nNameCounts; ++i) {
|
|
|
+ CSimpleStringA runItem = CSimpleStringA::Format("dpkg -l | grep \"%s\" | awk '{print $3}'", strSoftwaresNames[i].GetData());
|
|
|
+ std::string additional("");
|
|
|
+ std::string succStr, errStr;
|
|
|
+ std::string runStr(runItem.GetData());
|
|
|
+ if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
|
|
|
+ if (succStr.empty()) {
|
|
|
+ CSimpleStringA strMsg = CSimpleStringA::Format("{\"software_name\":\"%s\", \"version_status\":\"not installed\",\"detect_flag\":0}", strSoftwaresNames[i].GetData());
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_WARN_SOFTWARE_DETECT_NOT_EXISTS_BASE + i, strMsg);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SoftwareInstallStatus")(strMsg.GetData());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ succStr = SP::Utility::ToTrim(succStr);
|
|
|
+ if (strSoftwaresVers[i].IsNullOrEmpty() || strSoftwaresVers[i].Compare(succStr.c_str()) == 0) {
|
|
|
+ CSimpleStringA strMsg = CSimpleStringA::Format("{\"software_name\":\"%s\", \"version_status\":\"%s\",\"detect_flag\":1}"
|
|
|
+ , strSoftwaresNames[i].GetData(), succStr.c_str());
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_WARN_SOFTWARE_DETECT_EXISTS_BASE + i, strMsg);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SoftwareInstallStatus")(strMsg.GetData());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ CSimpleStringA strMsg = CSimpleStringA::Format("{\"software_name\":\"%s\", \"version_status\":\"%s\", \"expected\":\"%s\",\"detect_flag\":0}"
|
|
|
+ , strSoftwaresNames[i].GetData(), succStr.c_str(), strSoftwaresVers[i].GetData());
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_WARN_SOFTWARE_DETECT_NOT_EXISTS_BASE + i, strMsg);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SoftwareInstallStatus")(strMsg.GetData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ CSimpleStringA strMsg = CSimpleStringA::Format("{\"software_name\":\"%s\", \"version_status\":\"detect failed\", \"expected\":\"%s\",\"detect_flag\":0}"
|
|
|
+ , strSoftwaresNames[i].GetData(), strSoftwaresVers[i].GetData());
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_WARN_SOFTWARE_DETECT_EXISTS_STATUS_FAILED, strMsg);
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("SoftwareInstallStatus").setResultCode("RTA5A0D")(strMsg.GetData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif //RVC_OS_WIN
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+#ifdef RVC_OS_LINUX
|
|
|
UINT ResourceWatcherFSM::GetSystemDisplayVersion(CSimpleStringA& strVersion)
|
|
|
{
|
|
|
UINT result = 0;
|