#pragma once #include "stdafx.h" #include "SpFSM.h" #define JUS_A_TEST 0 #include "FileInfo.h" #include #include #include #include #include #include #include #include #include #include #include #if defined(RVC_OS_LINUX) #include #include #include #include #include #include "CommEntityUtil.hpp" #else #include #include #include #include #include #include "mbnapi.h" #include #pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "mbnapi_uuid.lib") #include "ResourceWatcher_UserCode.h" #include #pragma comment(lib, "Gdi32.lib") #endif //RVC_OS_LINUX #include "FileSimpleComp.h" using namespace std; #define SYSVAR_FRAMEWORK_FIRST_BOOT "FirstLaunchSinceSysBoot" //框架开机后首次启动标识 #define SYSVAR_FRAMEWORK_FIRST_BOOT_YES "Y" #define SYSVAR_FRAMEWORK_FIRST_BOOT_NO "N" enum EvtType { USER_EVT_RUN = EVT_USER + 1 }; #include "ResourceWatcher_server_g.h" #include "ResourceWatcher_msg_g.h" using namespace ResourceWatcher; #ifdef RVC_OS_LINUX #define MAX_SOFTWARE_INSTALLED_DETECT_COUNT 50 #endif // RVC_OS_LINUX #define MOD_VERSION "1.0.0.0" struct CInstallInfoEx : public CInstallInfo { CInstallInfoEx(const CInstallInfo& info) :CInstallInfo(info) { /* empty */ } bool operator < (const CInstallInfoEx& rhs) const { CVersion l_version(this->InstallVersion); DWORD l_timeTick = (DWORD)this->tmSwithOverDate; CVersion r_version(rhs.InstallVersion); DWORD r_timeTick = (DWORD)rhs.tmSwithOverDate; if (l_version == r_version) return l_timeTick <= r_timeTick; return l_version > r_version; } }; #ifdef RVC_OS_LINUX //chenjilin hardware change typedef struct CPUInfoStruct { // 记录 /proc/stat 中的CPU信息 char name[20]; unsigned int user; unsigned int nice; unsigned int system; unsigned int idle; unsigned int lowait; unsigned int irq; unsigned int softirq; }CPUInfo; typedef struct ProcCPUInfoStruct { unsigned int pid; char pname[1024]; unsigned long utime; //user time unsigned long stime; //kernel time unsigned long cutime; //all user time unsigned long cstime; //all dead time }ProcCPUInfo; typedef struct MemInfoStruct // 记录 /proc/meminfo 中的内存信息 { char infoName1[20]; unsigned long memTotal; char infoName2[20]; unsigned long memFree; char infoName3[20]; unsigned long memAvail; }MemInfo; //change end #else struct EntityRunInfo { bool bGetLoadOpt; bool bRestarting; int eState; int eTest; int loadOpt; int memoryHighCount; int cpuRatio; FILETIME prevSysKernel, prevSysUser; FILETIME prevProcKernel, prevProcUser; }; struct CPUInforStruct { bool bInitialed; int level; CSimpleStringA csBrand; }; #endif // RVC_OS_LINUX struct SystemBasicInfo { CSimpleStringA strManufacturer; CSimpleStringA strProductName; CSimpleStringA strSerialNumber; SystemBasicInfo():strManufacturer(true), strProductName(true), strSerialNumber(true) {} }; const int DEFAULT_DAY_OF_BACKWARD = 90; class ResourceWatcherFSM : public FSMImpl { public: ResourceWatcherFSM(void); ~ResourceWatcherFSM(void); enum { s0, s1, s2, s3 }; BEGIN_FSM_STATE(ResourceWatcherFSM) FSM_STATE_ENTRY(s0, "Idle", s0_on_entry, s0_on_exit, s0_on_event) FSM_STATE_ENTRY(s1, "Running", s1_on_entry, s1_on_exit, s1_on_event) FSM_STATE_ENTRY(s2, "Failed", s2_on_entry, s2_on_exit, s2_on_event) FSM_STATE_ENTRY(s3, "Listerning", s3_on_entry, s3_on_exit, s3_on_event) END_FSM_STATE() BEGIN_FSM_RULE(ResourceWatcherFSM, s0) FSM_RULE_ENTRY(s0, s1, USER_EVT_RUN, 0) END_FSM_RULE() virtual ErrorCodeEnum OnInit(); virtual ErrorCodeEnum OnExit(); //进入首页时触发的功能在此 void TriggerAtStatusChanged(bool bMStatus); void AfterInit(); virtual void s0_on_entry(); virtual void s0_on_exit(); virtual unsigned int s0_on_event(FSMEvent* e); virtual void s1_on_entry(); virtual void s1_on_exit(); virtual unsigned int s1_on_event(FSMEvent* e); virtual void s2_on_entry(); virtual void s2_on_exit(); virtual unsigned int s2_on_event(FSMEvent* e); virtual void s3_on_entry(); virtual void s3_on_exit(); virtual unsigned int s3_on_event(FSMEvent* e); void SelfTest(EntityTestEnum eTestType, CSmartPointer pTransactionContext); BOOL IsFirstRunAfterBoot() const { return m_bFirstRunAfterBoot; } #ifdef RVC_OS_LINUX void UploadMonitorSettings(); bool GetMonitorInfo(CSimpleStringA& outInfo); bool GetSysActiveStatus(CSimpleStringA& outInfo); void DetectSoftwareInstallStatus(); #else void SetForceDiskCheckFlag(bool flag) { m_bNeedForceDiskCheck = flag; } #endif // RVC_OS_LINUX private: int m_cpuTop; // CPU资源消耗最高的top进程个数 CSystemStaticInfo m_RvcSysinfo; typedef std::string bs_key; typedef DWORD bs_value; typedef map BlackSheet; typedef BlackSheet::const_iterator const_bs_iter; typedef BlackSheet::iterator bs_iter; typedef std::pair BlackSheetPair; std::map m_forbidDirList; CSimpleStringA m_strTerminalNo; BOOL m_bFirstRunAfterBoot; int m_diskLastWarnHour; BOOL m_skipDesktopDetect; #ifdef RVC_OS_WIN vectorm_nonSignedFiles; int m_iNonSignedTotal; bool m_bNeedForceDiskCheck; #endif // RVC_OS_WIN int m_iVerify; int m_iNonSignedDisplay; int m_cpuHighPercent, m_memHighPercent, m_diskHighPercent; BOOL checkActiveBefore; BOOL firstMpage; std::vector keyUserlist; std::vector keyPublist; //std::vector delKeylist; BOOL flag4DeleteKeyAutoStartFile; BOOL flag4DoAutoStartTaskIgnoreBoot; CSimpleStringA m_strCurrentUserName; CSimpleStringA m_strLoginedUserName; public: void CheckDiskFileSpace(); ErrorCodeEnum BizLinkDetect( SpReqAnsContext::Pointer ctx); ErrorCodeEnum CheckNetType( SpReqAnsContext::Pointer ctx); ErrorCodeEnum GetBizLinks( SpReqAnsContext::Pointer ctx); void GetSystemCPUStatus(); void GetSystemMemoryStatus(); void GetSystemDiskStatus(); void GetDiskStatusFrom(LPCTSTR path); void HardwareInfoTimer(void* pData); void DiskCheckTimer(void* pData); void LinkDetect(int detectType, const char* url, bool& status, unsigned int& delay, int warnFlag = 1); time_t GetPathTimeSeconds(const char* inPath); void AutoDeleteFiles(); void CenterSettingDelete(); BOOL DeleteVersionPackage(); void DeleteVideoFiles(); int ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int& nDelFailedCnt, bool delDir, unsigned int saveBackDay = 0); BOOL DetectIsFirstRunAtBoot(); #ifdef RVC_OS_LINUX /** 返回操作系统当前的版本,比如1032,1010,1031*/ UINT GetSystemDisplayVersion(CSimpleStringA& strVersion); void UploadSysVersionInfo(UINT& ver); string MemoryProcessStatus(); long GetCPURunTime(CPUInfo* cpu); long ReadProcCPURunTime(DWORD pid, ProcCPUInfo* pInfo); const char* GetItems(const char* buffer, unsigned int item); void ConfirmWindowEffectHasBeenOpen(); void switchWindowsEffect(const char* cfgFilePath, bool enable); /** 1032操作系统版本出现剪贴板和操作中心,需要将剪贴板关掉避免手势唤起 * 统信的人告知可以通过删除剪贴板程序实现……JUST DO IT! */ void ConfirmDDEClipboardDisable(); void RecoverDDEClipboardEnable(); /** 自己摸索,统信说需要操作系统定制方能解决 [Gifur@202198]*/ void ConfirmNotificationCenterDisable(); #else int GetCpuUsageRatio(int pid); ULONGLONG GetDiskUsedByte(); bool GetVTMExePath(CSimpleStringA& strValue, bool FailIfNotExist); bool CopyExeToRoot(const CSimpleStringA& csVersion, const CSimpleStringA& aimExePath); bool RegOperation4LnkFile(); bool RegRdVtmVersion(CSimpleStringA& VTMpath, CSimpleStringA& vtmVersion, CSimpleStringA& verPath); bool RegWtVtmPath(const CSimpleStringA& vtmExtPath, const CSimpleStringA& rootPath); bool RegWtVtmVersion(const CSimpleStringA& vtmVer); //nType: 0 桌面,2 启动列表 ErrorCodeEnum CreateLink(int nType, const CSimpleStringA& exePath); ErrorCodeEnum CreateLinkFile(const CSimpleStringA& szStartAppPath, const CSimpleStringA& szAddCmdLine, const CSimpleStringA& szDestLnkPath, const CSimpleStringA& szIconPath); bool GetVtmVersionFromActiveTxt(CSimpleStringA& csVersion); bool GetRegValueInt(HKEY hKey, LPCTSTR lpcszParam, DWORD& DwValue); bool GetRegValue(HKEY hKey, LPCTSTR lpcszParam, CSimpleStringA& strValue); void DetectAutoStartupCover(); //0:explorer.exe //1:vbs //2:vtm.exe //3:startmenu lnk from RVCTermimalApplicationSetup //4:startmenu lnk from install scripts //5:startmenu lnk from user customization //-1:failed int DetectAutoStartupType(CSimpleStringA& strValue); ErrorCodeEnum ChangeAutoStartupWithExe(bool resetVBS = false, bool resetExplorer = false); int InitialAutoStartupSetType(); void DeleteDuplicateAutoStartFile(bool toDeleteLastLegity = false); //0:startmenu lnk from RVCTermimalApplicationSetup //1:startmenu lnk from install scripts //2:startmenu lnk from user customization BOOL IsHasSetAutoStartupByFolder(CSimpleStringA& strPath, int& setType); void DetectVersionHasChangedAndWarn(); void DetectDestopFileAndWarn(bool bClear, CSimpleStringA& strFileSaveList); bool SetDesktopSysIcon2Registry(const std::string& key, bool toDisplay); void MakeSureWin8IntoDesktopPageAtLogon(); void DetectAutoStartFileAndWarn(); ErrorCodeEnum DetectVTMInstalledBySetup(BOOL& fYes); void DetectVersionHasChangedAndWarnCover() { if (!checkActiveBefore) { DetectVersionHasChangedAndWarn(); checkActiveBefore = TRUE; } } void VerifySignature(); void DetectAndClearDesktopFile(); void VerifySignature(const CSimpleStringA& filePath); CSimpleStringA GetFileName(const CSimpleStringA& filePath); bool RetrieveDigitalSignatureInfo(const char* pFilePath); bool VerifyFirstCertificate(HCERTSTORE hStore, PCMSG_SIGNER_INFO pSignerInfo); bool VerifyOtherCertificate(PCMSG_SIGNER_INFO pSignerInfo); void DetectWallpaperAndWarn(); void InitCustomAutoStartFileSheet(); void InitUserInfo(); bool IsUserSameName() { return m_strLoginedUserName.Compare(m_strCurrentUserName) == 0; } void GetUserDesktopDirectory(CSimpleStringA& outDir); bool IsDesktopIconExist(CSimpleStringA& strPath); void GetUserStartupDirectory(CSimpleStringA& outDir); bool IsStartupIconExist(CSimpleStringA& strPath); void GetAutoStartFile(std::string& userDirPath, std::vector& userDirFiles, std::string& pubDirPath, std::vector& pubDirFiles); #endif // RVC_OS_LINUX void AlarmSystemBasicInfo(); ErrorCodeEnum CatchSystemBasicInfo(SystemBasicInfo& info); }; class RunEvent : public FSMEvent { public: RunEvent() : FSMEvent(USER_EVT_RUN) {} virtual ~RunEvent() {} }; #ifdef RVC_OS_LINUX struct UploadMonitorInfoTask : public ITaskSp { ResourceWatcherFSM* m_pFSM; UploadMonitorInfoTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {} void Process() { m_pFSM->UploadMonitorSettings(); } }; struct DetectSoftwareInstallStatusTask : public ITaskSp { ResourceWatcherFSM* m_pFSM; DetectSoftwareInstallStatusTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {} void Process() { m_pFSM->DetectSoftwareInstallStatus(); } }; #else struct CreateLinkTask :public ITaskSp { ResourceWatcherFSM* m_pFSM; CreateLinkTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {} void Process() { m_pFSM->RegOperation4LnkFile(); } }; struct VerifyDigitSignTask : public ITaskSp { ResourceWatcherFSM* m_pFSM; VerifyDigitSignTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {} void Process() { m_pFSM->VerifySignature(); } }; struct AggerateAutoStatTask : public ITaskSp { ResourceWatcherFSM* m_pFSM; AggerateAutoStatTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {} void Process() { m_pFSM->DetectWallpaperAndWarn(); m_pFSM->DetectAutoStartupCover(); m_pFSM->RegOperation4LnkFile(); m_pFSM->DetectAndClearDesktopFile(); m_pFSM->MakeSureWin8IntoDesktopPageAtLogon(); m_pFSM->DetectAutoStartFileAndWarn(); } }; #endif // RVC_OS_LINUX //终端版本默认的自动清理策略 struct AutoDeleteFilesTask : public ITaskSp { ResourceWatcherFSM* m_pFSM; AutoDeleteFilesTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {} void Process() { m_pFSM->AutoDeleteFiles(); } }; //通过集中配置执行额外的清理策略 struct CenterSettingDeleteTask : public ITaskSp { ResourceWatcherFSM* m_pFSM; CenterSettingDeleteTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {} void Process() { m_pFSM->CenterSettingDelete(); } }; struct CheckDiskFileSpaceTask : public ITaskSp { ResourceWatcherFSM* m_pFSM; CheckDiskFileSpaceTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {} void Process() { m_pFSM->CheckDiskFileSpace(); } };