ResourceWatcherFSM.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. #pragma once
  2. #include "stdafx.h"
  3. #include "SpFSM.h"
  4. #define JUS_A_TEST 0
  5. #include "FileInfo.h"
  6. #include <iostream>
  7. #include <iomanip>
  8. #include <fstream>
  9. #include <stdarg.h>
  10. #include <string>
  11. #include <vector>
  12. #include <assert.h>
  13. #include <time.h>
  14. #include <map>
  15. #include <unordered_map>
  16. #if defined(RVC_OS_LINUX)
  17. #include <sys/sysinfo.h>
  18. #include <time.h>
  19. #include <sys/types.h>
  20. #include <dirent.h>
  21. #include <sys/stat.h>
  22. #else
  23. #include <ws2tcpip.h>
  24. #include <tchar.h>
  25. #include <WinCrypt.h>
  26. #include <atlbase.h>
  27. #include <conio.h>
  28. #include "mbnapi.h"
  29. #include <comdef.h>
  30. #endif //RVC_OS_LINUX
  31. using namespace std;
  32. #ifdef RVC_OS_LINUX
  33. #include "FileSimpleComp.h"
  34. #include "CommEntityUtil.hpp"
  35. #else
  36. #pragma comment(lib, "ws2_32.lib")
  37. #pragma comment(lib, "mbnapi_uuid.lib")
  38. #include "ResourceWatcher_UserCode.h"
  39. #include "FileSimpleComp.h"
  40. #include <time.h>
  41. #pragma comment(lib, "Gdi32.lib")
  42. #endif // RVC_OS_LINUX
  43. #define DEFAULT_INTERVAL 1000
  44. #define SYSVAR_DISKSTATEUS_FOR_VIDEO "VideoSpaceStatus" //录像磁盘空间状态系统变量
  45. #define VIDEO_SPACE_UNKNOWN "U" // 未知:未初始化或其他原因
  46. #define VIDEO_SPACE_SUFFICIENT "S" // 空间充足,3,0
  47. #define VIDEO_SPACE_INSUFF_LITTLE "W" // 低级警告:磁盘空间不足以支持七天以上录像,2
  48. #define VIDEO_SPACE_INSUFF_LESS "E" // 高级警告:磁盘空间不足以支持三天以上录像,1
  49. #define VIDEO_SPACE_INSUFF_FATAL "F" // 严重错误:磁盘空间不足以支持一天以上录像, 4
  50. #define OPT_FILE_CMD_SPREAD 0
  51. #define OPT_FILE_CMD_EXECUTE 1
  52. #define OPT_FILE_CMD_DELETE 2
  53. #define OPT_FILE_CMD_CLEAR 3
  54. #define OPT_FILE_CMD_CREATE 4
  55. #define OPT_FILE_CMD_APPEND 5
  56. #define OPT_FILE_CMD_RENAME 6
  57. #define OPT_FILE_RES_SUCCESS 1
  58. #define OPT_FILE_RES_INVALID -1
  59. #define OPT_FILE_RES_FAILED -2
  60. #define OPT_FILE_RES_NOT_SUPPORT -3
  61. #define SYSVAR_FRAMEWORK_FIRST_BOOT "FirstLaunchSinceSysBoot" //框架开机后首次启动标识
  62. #define SYSVAR_FRAMEWORK_FIRST_BOOT_YES "Y"
  63. #define SYSVAR_FRAMEWORK_FIRST_BOOT_NO "N"
  64. //Black sheet access attribute
  65. #define BS_DENY_READ 0x00000001
  66. #define BS_DENY_MODIFY 0x00000002 //Actually Append action.
  67. #define BS_DENY_EXECUTE 0x00000004
  68. #define BS_DENY_DELETE 0x00000008
  69. #define BS_DENY_CREATE 0x00000010
  70. #define BS_DENY_INHERITED 0x10000000
  71. #define BS_ACCESS_ALL ((DWORD)-1)
  72. #define LIMITED_SYS_COUNT 3
  73. static const char* limited_sys_paths[LIMITED_SYS_COUNT] =
  74. {
  75. "Program Files",
  76. "ProgramData",
  77. "Program Files (x86)"
  78. };
  79. #define LIMITED_SYS_PATH(x) \
  80. limited_sys_paths[x]
  81. class CustomSignalEvents;
  82. enum EvtType
  83. {
  84. USER_EVT_RUN = EVT_USER + 1,
  85. USER_EVT_CLEAR_UPLOADEDVIDEOFILES,
  86. USER_EVT_CLEAR_UPLOADEDVIDEOFILES_FINISHED,
  87. USER_EVT_CLEAR_VIDEOFILE_ENHANCE,
  88. USER_EVT_CLEAR_VIDEOFILE_ENHANCE_FINISHED,
  89. USER_EVT_VERSION_CLEAR,
  90. USER_EVT_VERSION_CLEAR_FINISHED
  91. };
  92. enum DealFileType
  93. {
  94. DFT_CenterSetting,
  95. DFT_Ad0
  96. };
  97. #ifdef RVC_OS_LINUX
  98. #else
  99. enum TestActionEnum
  100. {
  101. ACTION_NOTHINGTODO,
  102. ACTION_HANDSHAKE,
  103. ACTION_EXAMINE,
  104. ACTION_RESET,
  105. ACTION_CLOSE,
  106. ACTION_ENTITY_RESTART,
  107. ACTION_OS_RESTART,
  108. ACTION_POWER_RESTART,
  109. };
  110. #endif // RVC_OS_LINUX
  111. #include "ResourceWatcher_server_g.h"
  112. #include "ResourceWatcher_msg_g.h"
  113. using namespace ResourceWatcher;
  114. #ifdef RVC_OS_LINUX
  115. #define MAX_SOFTWARE_INSTALLED_DETECT_COUNT 50
  116. #endif // RVC_OS_LINUX
  117. #define MOD_VERSION "1.0.0.0"
  118. struct CInstallInfoEx : public CInstallInfo
  119. {
  120. CInstallInfoEx(const CInstallInfo& info)
  121. :CInstallInfo(info)
  122. {
  123. /* empty */
  124. }
  125. bool operator < (const CInstallInfoEx& rhs) const
  126. {
  127. CVersion l_version(this->InstallVersion);
  128. DWORD l_timeTick = (DWORD)this->tmSwithOverDate;
  129. CVersion r_version(rhs.InstallVersion);
  130. DWORD r_timeTick = (DWORD)rhs.tmSwithOverDate;
  131. if (l_version == r_version)
  132. return l_timeTick <= r_timeTick;
  133. return l_version > r_version;
  134. }
  135. };
  136. #ifdef RVC_OS_LINUX
  137. //chenjilin hardware change
  138. typedef struct CPUInfoStruct
  139. { // 记录 /proc/stat 中的CPU信息
  140. char name[20];
  141. unsigned int user;
  142. unsigned int nice;
  143. unsigned int system;
  144. unsigned int idle;
  145. unsigned int lowait;
  146. unsigned int irq;
  147. unsigned int softirq;
  148. }CPUInfo;
  149. typedef struct ProcCPUInfoStruct {
  150. unsigned int pid;
  151. char pname[1024];
  152. unsigned long utime; //user time
  153. unsigned long stime; //kernel time
  154. unsigned long cutime; //all user time
  155. unsigned long cstime; //all dead time
  156. }ProcCPUInfo;
  157. typedef struct MemInfoStruct // 记录 /proc/meminfo 中的内存信息
  158. {
  159. char infoName1[20];
  160. unsigned long memTotal;
  161. char infoName2[20];
  162. unsigned long memFree;
  163. char infoName3[20];
  164. unsigned long memAvail;
  165. }MemInfo;
  166. //change end
  167. #else
  168. struct EntityCfgInfo
  169. {
  170. //int resetCount;
  171. int entityRestartCount;
  172. int osRestartCount;
  173. int powerRestartCount;
  174. bool bWaitRestart;
  175. map<ErrorCodeEnum, TestActionEnum> hsInfo;//handshake
  176. map<ErrorCodeEnum, TestActionEnum> examInfo;//examine
  177. map<ErrorCodeEnum, TestActionEnum> resetInfo;//reset
  178. map<ErrorCodeEnum, TestActionEnum> restartInfo;//restart
  179. };
  180. struct EntityRunInfo
  181. {
  182. bool bGetLoadOpt;
  183. bool bRestarting;
  184. int eState;
  185. int eTest;
  186. int loadOpt;
  187. int memoryHighCount;
  188. int cpuRatio;
  189. FILETIME prevSysKernel, prevSysUser;
  190. FILETIME prevProcKernel, prevProcUser;
  191. };
  192. struct CPUInforStruct {
  193. bool bInitialed;
  194. int level;
  195. CSimpleStringA csBrand;
  196. };
  197. #endif // RVC_OS_LINUX
  198. struct SystemBasicInfo
  199. {
  200. CSimpleStringA strManufacturer;
  201. CSimpleStringA strProductName;
  202. CSimpleStringA strSerialNumber;
  203. SystemBasicInfo():strManufacturer(true), strProductName(true), strSerialNumber(true) {}
  204. };
  205. const int DEFAULT_DAY_OF_BACKWARD = 90;
  206. class ResourceWatcherFSM : public FSMImpl<ResourceWatcherFSM>
  207. {
  208. public:
  209. #ifdef RVC_OS_LINUX
  210. ResourceWatcherFSM(void)
  211. :m_IsPadDevice(FALSE),
  212. m_csUploadVideoPath(true),
  213. m_nDayOfBackward(DEFAULT_DAY_OF_BACKWARD),
  214. m_bReadyFlag(false),
  215. m_bVideoClearReady(false),
  216. m_nMinSavedDay(DEFAULT_SAVE_DATE_COUNT),
  217. m_strTerminalNo(true),
  218. m_strDefaultDns(true),
  219. m_strBackupDns(true),
  220. m_nEnableSetDns(0),
  221. m_bFirstRunAfterBoot(FALSE),
  222. m_csDelFileSuffix(true),
  223. m_failDelCnt(0),
  224. m_cpuTop(0)
  225. {
  226. mAllVideoFileSizeCal = 0;
  227. mMaxFileSize = 0;
  228. mUiCalibration = 0;
  229. mUiRequireBytes = 0;
  230. mftAd0RemoveTime = 0;
  231. };
  232. #else
  233. ResourceWatcherFSM(void);
  234. #endif // RVC_OS_LINUX
  235. ~ResourceWatcherFSM(void);
  236. enum { s0, s1, s2, s3 };
  237. BEGIN_FSM_STATE(ResourceWatcherFSM)
  238. FSM_STATE_ENTRY(s0, "Idle", s0_on_entry, s0_on_exit, s0_on_event)
  239. FSM_STATE_ENTRY(s1, "Running", s1_on_entry, s1_on_exit, s1_on_event)
  240. FSM_STATE_ENTRY(s2, "Failed", s2_on_entry, s2_on_exit, s2_on_event)
  241. FSM_STATE_ENTRY(s3, "Listerning", s3_on_entry, s3_on_exit, s3_on_event)
  242. END_FSM_STATE()
  243. BEGIN_FSM_RULE(ResourceWatcherFSM, s0)
  244. FSM_RULE_ENTRY(s0, s1, USER_EVT_RUN, 0)
  245. FSM_RULE_ENTRY(s1, s3, USER_EVT_CLEAR_VIDEOFILE_ENHANCE_FINISHED, 0)
  246. END_FSM_RULE()
  247. virtual ErrorCodeEnum OnInit();
  248. virtual ErrorCodeEnum OnExit();
  249. //进入首页时触发的功能在此
  250. void TriggerAtStatusChanged(bool bMStatus);
  251. void AfterInit();
  252. virtual void s0_on_entry();
  253. virtual void s0_on_exit();
  254. virtual unsigned int s0_on_event(FSMEvent* e);
  255. virtual void s1_on_entry();
  256. virtual void s1_on_exit();
  257. virtual unsigned int s1_on_event(FSMEvent* e);
  258. virtual void s2_on_entry();
  259. virtual void s2_on_exit();
  260. virtual unsigned int s2_on_event(FSMEvent* e);
  261. virtual void s3_on_entry();
  262. virtual void s3_on_exit();
  263. virtual unsigned int s3_on_event(FSMEvent* e);
  264. void SelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext);
  265. BOOL IsFirstRunAfterBoot() const
  266. {
  267. return m_bFirstRunAfterBoot;
  268. }
  269. #ifdef RVC_OS_LINUX
  270. void UploadMonitorSettings();
  271. bool GetMonitorInfo(CSimpleStringA& outInfo);
  272. void DetectSoftwareInstallStatus();
  273. #else
  274. void SetForceDiskCheckFlag(bool flag)
  275. {
  276. m_bNeedForceDiskCheck = flag;
  277. }
  278. #endif // RVC_OS_LINUX
  279. private:
  280. BOOL m_IsPadDevice;
  281. //Video Component
  282. CSimpleStringA m_csUploadVideoPath;
  283. CSimpleStringA m_csDelFileSuffix;
  284. int m_nDayOfBackward;
  285. int m_failDelCnt;
  286. bool m_bReadyFlag;
  287. //Video Component2
  288. priority_queue<TmpFileInfo*, vector<TmpFileInfo*>, Comparetor> m_VideoFiles;
  289. //日期,数量
  290. map<UINT, UINT> VideoDailyRecord;
  291. char mszMaxSizeFilePath[MAX_PATH];
  292. typedef map<UINT, UINT>::const_iterator const_map_cu_iter;
  293. DiskInfo diskInfo;
  294. bool m_bVideoClearReady;
  295. int m_nMinSavedDay;
  296. int m_cpuTop; // CPU资源消耗最高的top进程个数
  297. CSystemStaticInfo m_RvcSysinfo;
  298. typedef std::string bs_key;
  299. typedef DWORD bs_value;
  300. typedef map<bs_key, bs_value> BlackSheet;
  301. typedef BlackSheet::const_iterator const_bs_iter;
  302. typedef BlackSheet::iterator bs_iter;
  303. typedef std::pair<bs_key, bs_value> BlackSheetPair;
  304. std::map<std::string, DWORD> m_forbidDirList;
  305. CSimpleStringA m_strTerminalNo;
  306. CSimpleStringA m_strDefaultDns;
  307. CSimpleStringA m_strBackupDns;
  308. int m_nEnableSetDns;
  309. BOOL m_bFirstRunAfterBoot;
  310. #ifdef RVC_OS_LINUX
  311. time_t mftAd0RemoveTime;
  312. unsigned long long mAllVideoFileSizeCal;
  313. unsigned long long mMaxFileSize;
  314. unsigned long long mUiCalibration;
  315. unsigned long long mUiRequireBytes;
  316. int m_diskLastWarnHour;
  317. #else
  318. FILETIME mftAd0RemoveTime;
  319. ULARGE_INTEGER mAllVideoFileSizeCal;
  320. ULARGE_INTEGER mMaxFileSize;
  321. ULARGE_INTEGER mUiCalibration;
  322. ULARGE_INTEGER mUiRequireBytes;
  323. bool m_DoneDetectAutostart;
  324. //1:将VBS改成EXE,前提是VBS必须已在注册表
  325. //2:设置使用EXE自启动
  326. //3:不设置开机自启动(通过注册表)
  327. int m_forceStartupWithExeFlag;
  328. bool m_bIsVerified;
  329. vector<CSimpleStringA>m_nonSignedFiles;
  330. int m_iNonSignedTotal;
  331. map<CSimpleStringA, EntityCfgInfo> m_entCfgInfo;
  332. map<CSimpleStringA, EntityRunInfo> m_entRunInfo;
  333. vector<CSimpleStringA> m_activeEntity, m_allEntity, m_vKeyEntity, m_vQueryStateEntity;
  334. int m_restartNormal, m_restartSpecial, m_maxOsRestart, m_maxPowerRestart, m_warmLevel, m_diskLastWarnHour;
  335. DWORD m_dwIssueCount, m_dwCaptureCount;
  336. bool m_bInIssue, m_bFirstCalcCpu, m_bEverInMainPage, m_bHaveGetEntityList, m_bFWBEntityAdd;
  337. bool m_bNeedForceDiskCheck;
  338. int m_simulateTest;
  339. CSimpleStringA m_csKeyEntity;
  340. __int64 m_xIdlePre, m_xKernelPre, m_xUserPre;
  341. #endif // RVC_OS_LINUX
  342. int m_iVerify;
  343. int m_iNonSignedDisplay;
  344. int m_cpuHighPercent, m_memHighPercent, m_diskHighPercent;
  345. FILE_LAYOUT_ENTRY m_FileEntry;
  346. BOOL checkActiveBefore;
  347. BOOL firstMpage;
  348. public:
  349. int CleanVideoFiles(int& newDeletedFilesNum, int initFlag = 1);
  350. void CheckDiskFileSpace();
  351. #ifdef RVC_OS_LINUX
  352. LONG CompareVideoFileTime(const time_t* ftCurTime, const time_t* fileTime)
  353. {
  354. if (*ftCurTime == *fileTime) return 0;
  355. if (*ftCurTime < *fileTime) return -1;
  356. return 1;
  357. }
  358. void CalculateBackTime(time_t* ftResultTime, int days);
  359. BOOL CalculateWillUploadDirSize(unsigned long long& uiBytesCal);
  360. void SyncUpdateVideoCreateDaily(const time_t* ft, int minusOrAdd)
  361. {
  362. tm* backtime = localtime(ft);
  363. const UINT uDate = (1900 + backtime->tm_year) * 10000 + (1 + backtime->tm_mon) * 100 + backtime->tm_mday;
  364. VideoDailyRecord[uDate] += minusOrAdd;
  365. }
  366. void RecordVideoFileInfomation(LPCTSTR lpFilePath, struct stat* pWfdata);
  367. int CalculateAllVideoSize(LPCTSTR lpszPath, unsigned long long* puliSpaceBytes);
  368. void AppendVideoSizeTogether();
  369. void CalculateFreeDiskNeeded();
  370. void RecordFreeDiskNeededToRunCfg();
  371. void GetFreeDiskNeededFromRunCfg();
  372. int RemoveExpireVideoFileAndRecord(LPCTSTR dirName, int& deletedFileCnt, int& deleteFailedCnt, const int nFlag);
  373. #else
  374. void CalculateBackTime(PFILETIME ftResultTime, int days);
  375. BOOL CalCulateUploadFileAddition(ULARGE_INTEGER& uiBytesCal);
  376. /*
  377. *-1, First file time is earlier than second file time.
  378. * 0, First file time is equal to second file time
  379. * 1, First file time is later than second file time.
  380. */
  381. LONG CompareVideoFileTime(PFILETIME ftCurTime, PFILETIME fileTime)
  382. {
  383. return CompareFileTime(ftCurTime, fileTime);
  384. }
  385. int ProcessVideoFile(LPCTSTR dirName, int& deletedFileCnt, int& deleteFailedCnt, const int nFlag);
  386. // End Video Component
  387. int ProcessFileSpaceCalculation(LPCTSTR lpszPath, PULARGE_INTEGER puliSpaceBytes);
  388. // Add -Josephus@2017713 16:04:18
  389. #endif // RVC_OS_LINUX
  390. ErrorCodeEnum BizLinkDetect(
  391. SpReqAnsContext<ResourceWatcherService_BizLinkDetect_Req,
  392. ResourceWatcherService_BizLinkDetect_Ans>::Pointer ctx);
  393. ErrorCodeEnum CheckNetType(
  394. SpReqAnsContext<ResourceWatcherService_CheckNetType_Req,
  395. ResourceWatcherService_CheckNetType_Ans>::Pointer ctx);
  396. ErrorCodeEnum GetBizLinks(
  397. SpReqAnsContext<ResourceWatcherService_GetBizLinks_Req,
  398. ResourceWatcherService_GetBizLinks_Ans>::Pointer ctx);
  399. void GetSystemCPUStatus();
  400. void GetSystemMemoryStatus();
  401. void GetSystemDiskStatus();
  402. void HardwareInfoTimer(void* pData);
  403. void DiskCheckTimer(void* pData);
  404. void LinkDetect(int detectType, const char* url, bool& status, unsigned int& delay, int warnFlag = 1);
  405. #if defined(RVC_OS_WIN)
  406. int GetCpuUsageRatio(int pid);
  407. ULONGLONG GetDiskUsedByte();
  408. #endif // RVC_OS_WIN
  409. int ClearSpecifieFile(DealFileType fileType, LPCTSTR dirName, int& deletedFileCnt, int& deleteFailedCnt);
  410. // Start Video Component2 --Josephus at 16:19:56 201755
  411. void ClearVideoQueue();
  412. #ifdef RVC_OS_LINUX
  413. // Start CenterSetting Clear Job --Josephus at 15:57:58 20161210
  414. BOOL RemoveDuplicateCenterSettingFiles();
  415. int RemoveSpecifiedFile(DealFileType fileType, LPCTSTR szFilePath, LPCTSTR szFileName);
  416. // End CenterSetting clear Job
  417. // Has been purified --Josephus at 10:42:55 201759
  418. void PrintVideEmurateResult();
  419. #else
  420. // Start CenterSetting Clear Job --Josephus at 15:57:58 20161210
  421. int DoSomethingWith(DealFileType fileType, LPCTSTR szFilePath, LPCTSTR szFileName);
  422. // End CenterSetting clear Job
  423. void CalCulateFileInfo(LPCTSTR lpFilePath, PWIN32_FIND_DATA pWfdata);
  424. // Has been purified --Josephus at 10:42:55 201759
  425. void PrintResult()
  426. {
  427. char szResult[DEFAULT_OUTPUT_FORMAT_SIZE];
  428. ByteSprintf(szResult, (double)mMaxFileSize.QuadPart);
  429. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Max Video file: %s size: %s", mszMaxSizeFilePath, szResult);
  430. ByteSprintf(szResult, (double)mAllVideoFileSizeCal.QuadPart);
  431. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Totally(size()#%d) directory size: %s", m_VideoFiles.size(), szResult);
  432. }
  433. #endif // RVC_OS_LINUX
  434. void ClearMoreVideoFiles();
  435. bool IsNeedToFirstClear();
  436. void SetSysValAndBroadcast(DWORD dwVal, LPCTSTR lpszMessage);
  437. // End --Josephus at 16:20:02 201755
  438. void CenterSettingDelete();
  439. void AutoDeleteFiles();
  440. BOOL DeleteVersionPackage();
  441. int ProcessFileDelete(LPCTSTR lpszPath, int& nDelSucCnt, int& nDelFailedCnt, bool delDir = false);
  442. // Add Ad0 folder job [4/2/2018 10:53 @Gifur]
  443. BOOL ClearAd0Folder();
  444. BOOL IsTodayDone(int nRecordTime);
  445. BOOL GetSystemBootTime(CSmallDateTime& systemBootTime);
  446. BOOL DetectIsFirstRunAtBoot();
  447. #ifdef RVC_OS_LINUX
  448. /** 返回操作系统当前的版本,比如1032,1010,1031*/
  449. UINT GetSystemDisplayVersion(CSimpleStringA& strVersion);
  450. void UploadSysVersionInfo(UINT& ver);
  451. string MemoryProcessStatus();
  452. long GetCPURunTime(CPUInfo* cpu);
  453. long ReadProcCPURunTime(DWORD pid, ProcCPUInfo* pInfo);
  454. const char* GetItems(const char* buffer, unsigned int item);
  455. void GetOperationDiskStatus();
  456. void GetDiskStatusFrom(LPCTSTR path);
  457. void ConfirmWindowEffectHasBeenOpen();
  458. void switchWindowsEffect(const char* cfgFilePath, bool enable);
  459. /** 1032操作系统版本出现剪贴板和操作中心,需要将剪贴板关掉避免手势唤起
  460. * 统信的人告知可以通过删除剪贴板程序实现……JUST DO IT!
  461. */
  462. void ConfirmDDEClipboardDisable();
  463. void RecoverDDEClipboardEnable();
  464. /** 自己摸索,统信说需要操作系统定制方能解决 [Gifur@202198]*/
  465. void ConfirmNotificationCenterDisable();
  466. #else
  467. BOOL ClearDirRecursiveEx(LPCSTR lpDirPat);
  468. bool CopyExeToRoot(const CSimpleStringA& csVersion);
  469. bool RegOperation();
  470. bool RegRdVtmVersion(CSimpleStringA& VTMpath, CSimpleStringA& vtmVersion);
  471. bool RegWtVtmPath();
  472. bool RegWtVtmVersion();
  473. void CreateLink(const CSimpleStringA& exePath, const CSimpleStringA& csVersion);
  474. bool CreateLinkFile(const CSimpleStringA& szStartAppPath, const CSimpleStringA& szAddCmdLine,
  475. const CSimpleStringA& szDestLnkPath, const CSimpleStringA& szIconPath);
  476. bool GetVtmVersionFromActiveTxt(CSimpleStringA& csVersion);
  477. bool UpdateExe();
  478. bool GetRegValue(HKEY hKey, LPCTSTR lpcszParam, CHAR* pSzValue, DWORD* pDwSizeOfSz);
  479. void DetectAutoStartupCover();
  480. //0:explorer.exe
  481. //1:vbs
  482. //2:vtm.exe
  483. //-1:failed
  484. //-2:do before in day
  485. void DetectAutoStartup(int& vbsType);
  486. ErrorCodeEnum ChangeAutoStartupWithExe(bool resetExplorer = false);
  487. void InitialAutoStartupSetType();
  488. BOOL IsHasSetAutoStartupByFolder();
  489. void DetectVersionHasChangedAndWarn();
  490. void DetectDestopFileAndWarn();
  491. ErrorCodeEnum DetectVTMInstalledBySetup(BOOL& fYes);
  492. void DetectVersionHasChangedAndWarnCover()
  493. {
  494. if (!checkActiveBefore) {
  495. DetectVersionHasChangedAndWarn();
  496. checkActiveBefore = TRUE;
  497. }
  498. }
  499. void VerifySignature();
  500. void VerifySignature(const CSimpleStringA& filePath);
  501. CSimpleStringA GetFileName(const CSimpleStringA& filePath);
  502. bool RetrieveDigitalSignatureInfo(const char* pFilePath);
  503. bool VerifyFirstCertificate(HCERTSTORE hStore, PCMSG_SIGNER_INFO pSignerInfo);
  504. bool VerifyOtherCertificate(PCMSG_SIGNER_INFO pSignerInfo);
  505. int IsWifiConnected();
  506. #endif // RVC_OS_LINUX
  507. void AlarmSystemBasicInfo();
  508. ErrorCodeEnum CatchSystemBasicInfo(SystemBasicInfo& info);
  509. void readVideoStorePath();
  510. };
  511. class RunEvent : public FSMEvent
  512. {
  513. public:
  514. RunEvent() : FSMEvent(USER_EVT_RUN) {}
  515. virtual ~RunEvent() {}
  516. };
  517. struct ClearVideoFilesTask : public ITaskSp
  518. {
  519. ResourceWatcherFSM* m_pFSM;
  520. ClearVideoFilesTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM), m_nInitFlag(1) {}
  521. int m_nInitFlag;
  522. void SetFlag(int nFlag) { m_nInitFlag = nFlag; }
  523. void Process()
  524. {
  525. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_CLEAR_UPLOADEDVIDEOFILES_FINISHED);
  526. int value(0);
  527. fsmEvent->param2 = m_pFSM->CleanVideoFiles(value, m_nInitFlag);
  528. fsmEvent->param1 = value;
  529. m_pFSM->PostEventFIFO(fsmEvent);
  530. }
  531. };
  532. struct ClearVideoFilesEnhanceTask : public ITaskSp
  533. {
  534. ResourceWatcherFSM* m_pFSM;
  535. ClearVideoFilesEnhanceTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  536. void Process()
  537. {
  538. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_CLEAR_VIDEOFILE_ENHANCE_FINISHED);
  539. m_pFSM->ClearMoreVideoFiles();
  540. m_pFSM->PostEventFIFO(fsmEvent);
  541. }
  542. };
  543. struct AutoDeleteFilesTask : public ITaskSp
  544. {
  545. ResourceWatcherFSM* m_pFSM;
  546. AutoDeleteFilesTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  547. void Process()
  548. {
  549. m_pFSM->AutoDeleteFiles();
  550. }
  551. };
  552. #ifdef RVC_OS_LINUX
  553. struct UploadMonitorInfoTask : public ITaskSp
  554. {
  555. ResourceWatcherFSM* m_pFSM;
  556. UploadMonitorInfoTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  557. void Process()
  558. {
  559. m_pFSM->UploadMonitorSettings();
  560. }
  561. };
  562. struct DetectSoftwareInstallStatusTask : public ITaskSp
  563. {
  564. ResourceWatcherFSM* m_pFSM;
  565. DetectSoftwareInstallStatusTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  566. void Process()
  567. {
  568. m_pFSM->DetectSoftwareInstallStatus();
  569. }
  570. };
  571. struct RunTask : public ITaskSp
  572. {
  573. ResourceWatcherFSM* m_pFSM;
  574. RunTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM), m_nInitFlag(1) {}
  575. int m_nInitFlag;
  576. void SetFlag(int nFlag) { m_nInitFlag = nFlag; }
  577. void Process()
  578. {
  579. m_pFSM->ClearAd0Folder();
  580. m_pFSM->RemoveDuplicateCenterSettingFiles();
  581. FSMEvent* fsmEvent = new FSMEvent(USER_EVT_CLEAR_UPLOADEDVIDEOFILES_FINISHED);
  582. int value(0);
  583. fsmEvent->param2 = m_pFSM->CleanVideoFiles(value, m_nInitFlag);
  584. fsmEvent->param1 = value;
  585. m_pFSM->PostEventFIFO(fsmEvent);
  586. }
  587. };
  588. #else
  589. struct CreateLinkTask :public ITaskSp
  590. {
  591. ResourceWatcherFSM* m_pFSM;
  592. CreateLinkTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  593. void Process()
  594. {
  595. m_pFSM->RegOperation();
  596. }
  597. };
  598. struct VerifyDigitSignTask : public ITaskSp
  599. {
  600. ResourceWatcherFSM* m_pFSM;
  601. VerifyDigitSignTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  602. void Process()
  603. {
  604. m_pFSM->VerifySignature();
  605. }
  606. };
  607. #endif // RVC_OS_LINUX
  608. struct CenterSettingDeleteTask : public ITaskSp
  609. {
  610. ResourceWatcherFSM* m_pFSM;
  611. CenterSettingDeleteTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  612. void Process()
  613. {
  614. m_pFSM->CenterSettingDelete();
  615. }
  616. };
  617. struct CheckDiskFileSpaceTask : public ITaskSp
  618. {
  619. ResourceWatcherFSM* m_pFSM;
  620. CheckDiskFileSpaceTask(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM) {}
  621. void Process()
  622. {
  623. m_pFSM->CheckDiskFileSpace();
  624. }
  625. };
  626. struct ClearAd0Task : public ITaskSp
  627. {
  628. ResourceWatcherFSM* m_pFSM;
  629. ClearAd0Task(ResourceWatcherFSM* pFSM) : m_pFSM(pFSM), m_nInitFlag(1) {}
  630. int m_nInitFlag;
  631. void SetFlag(int nFlag) { m_nInitFlag = nFlag; }
  632. void Process()
  633. {
  634. m_pFSM->ClearAd0Folder();
  635. }
  636. };