Global.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. #include "stdafx.h"
  2. #include "Global.h"
  3. #include <SetupAPI.h>
  4. #include <InitGuid.h>
  5. #include <WinIoCtl.h>
  6. #include <direct.h>
  7. #include <fcntl.h>
  8. #include <share.h>
  9. #include <sys\stat.h>
  10. #pragma comment(lib, "SetupAPI.lib")
  11. namespace Global
  12. {
  13. //////////////////////////////////////////////////////////////////////////
  14. // 全局变量;
  15. TCHAR g_szCurModuleDir[MAX_PATH] = { 0 };
  16. TCHAR g_szCurModulePath[MAX_PATH] = { 0 };
  17. TCHAR g_szFna[MAX_PATH] = { 0 };
  18. TCHAR g_szConfig[MAX_PATH] = { 0 };
  19. TCHAR g_szLogPath[MAX_PATH] = { 0 };
  20. TCHAR g_szPython27Dir[MAX_PATH] = {0};
  21. TCHAR g_szTVPort[MAX_PATH] = {0};
  22. TCHAR g_szTVReboot[MAX_PATH] = {0};
  23. TCHAR g_szTVShutdown[MAX_PATH] = {0};
  24. BOOL g_bWatchTVPort = FALSE;
  25. bool g_bEnableLog = false;
  26. COleDateTime g_lastTime;
  27. time_t g_time = time(NULL);
  28. ThreadSection g_critSection;
  29. FILE *gp_log_fp = NULL;
  30. //////////////////////////////////////////////////////////////////////////
  31. bool MKDIR(LPCTSTR dir)
  32. {
  33. //////////////////////////////////////////////////////////////////////////
  34. // 创建目录;
  35. int nleft = 0;
  36. int nIndex = -1;
  37. string strdir = dir;
  38. strdir = strdir.substr(0, strdir.find_last_of(_T("\\")));
  39. if (strdir.at(strdir.size() - 1) != _T('\\'))
  40. strdir.append(_T("\\"));
  41. // 共享路径和硬盘盘符;
  42. if (_tcscmp(strdir.substr(0, 2).c_str(), _T("\\\\")) == 0)
  43. nleft = strdir.find_first_of(_T("\\"), 2) + 1; // 去除共享主机名;
  44. else if (strdir.at(2) == _T('\\'))
  45. nleft = 3;
  46. do
  47. {
  48. nIndex = strdir.substr(nleft, -1).find_first_of(_T("\\"));
  49. if (nIndex != string::npos)
  50. {
  51. if (_mkdir(strdir.substr(0, nIndex + nleft).c_str()) == -1 && (errno != EEXIST))
  52. {
  53. WriteTextLog(_T("创建目录失败:%s,错误码:%d"), strdir.substr(0, nIndex + nleft).c_str(), errno);
  54. return false;
  55. }
  56. nleft += nIndex + 1;
  57. }
  58. } while (nIndex != -1);
  59. return true;
  60. };
  61. // 全局函数;
  62. /************************************************************************/
  63. /* 函数:WriteTextLog[7/28/2009 Jeff];
  64. /* 描述:写文本日志;
  65. /* 参数:;
  66. /* [IN] :;
  67. /* 返回:void;
  68. /* 注意:;
  69. /* 示例:;
  70. /*
  71. /* 修改:;
  72. /* 日期:;
  73. /* 内容:;
  74. /************************************************************************/
  75. void WriteTextLog(const TCHAR* format, ...)
  76. {
  77. static ThreadSection _critSection;
  78. AutoThreadSection aSection(&_critSection);
  79. // 将日志内容输入到文件中;
  80. // 获取今年年份;
  81. __time64_t gmt = time(NULL); // 获取当前日历时间(1900-01-01开始的Unix时间戳);
  82. struct tm gmtm = { 0 };
  83. localtime_s(&gmtm, &gmt); // 时间戳转成本地时间;
  84. // 解析出日志路径;
  85. TCHAR szlogpath[MAX_PATH] = { 0 };
  86. _stprintf_s(szlogpath, _T("%srunner-log %02d%02d.txt"), g_szCurModuleDir, gmtm.tm_mon + 1, gmtm.tm_mday);
  87. // 打开或创建文件;
  88. FILE* fp = NULL;
  89. //MKDIR(g_szLogPath);
  90. //if (_taccess(szlogpath, 0) != -1)
  91. #ifndef UNICODE
  92. if (_access(szlogpath, 0) != -1)
  93. #else
  94. if (_taccess(szlogpath, 0) != -1)
  95. #endif
  96. { // 存在;
  97. if (0 == _tfopen_s(&fp, szlogpath, _T("a+")))
  98. // 移动到末尾;
  99. fseek(fp, 0, SEEK_END);
  100. }
  101. else
  102. { // 不存在;
  103. _tfopen_s(&fp, szlogpath, _T("w+"));
  104. }
  105. if (fp == NULL)
  106. return;
  107. // 格式化前设置语言区域;
  108. TCHAR* old_locale = _tcsdup(_tsetlocale(LC_CTYPE, NULL));
  109. _tsetlocale(LC_CTYPE, _T("chs")); //设定中文;
  110. // 格式化日志内容;
  111. va_list args = NULL;
  112. int len = 0;
  113. TCHAR* buffer = NULL;
  114. va_start(args, format);
  115. // _vscprintf doesn't count. terminating '\0'
  116. len = _vsctprintf(format, args) + 1;
  117. buffer = (TCHAR*)malloc(len * sizeof(TCHAR));
  118. _vstprintf_s(buffer, len, format, args);
  119. _ftprintf(fp, _T("%04d-%02d-%02d %02d:%02d:%02d %s\n"), gmtm.tm_year + 1990, gmtm.tm_mon + 1, gmtm.tm_mday, gmtm.tm_hour, gmtm.tm_min, gmtm.tm_sec, buffer);
  120. // 关闭文件,释放资源并设置回原语言区域;
  121. free(buffer);
  122. fclose(fp);
  123. _tsetlocale(LC_CTYPE, old_locale);
  124. free(old_locale); //还原区域设定;
  125. }
  126. void WritePythonLog(LPCTSTR file, const TCHAR* msg)
  127. {
  128. AutoThreadSection aSection(&g_critSection);
  129. // 将日志内容输入到文件中;
  130. // 获取今年年份;
  131. //__time64_t gmt = time(NULL); // 获取当前日历时间(1900-01-01开始的Unix时间戳);
  132. //struct tm gmtm = { 0 };
  133. //localtime_s(&gmtm, &gmt); // 时间戳转成本地时间;
  134. int nErr = -1;
  135. // 打开或创建文件;
  136. FILE* fp = NULL;
  137. #ifndef UNICODE
  138. if (_access(file, 0) != -1)
  139. #else
  140. if (_taccess(file, 0) != -1)
  141. #endif
  142. { // 存在;
  143. if (0 == _tfopen_s(&fp, file, _T("a+")))
  144. {
  145. // 移动到末尾;
  146. fseek(fp, 0, SEEK_END);
  147. }
  148. else
  149. {
  150. WriteTextLog(_T("打开文件失败:%s,%d"), file, GetLastError());
  151. return;
  152. }
  153. }
  154. else
  155. { // 不存在;
  156. MKDIR(file);
  157. if (0 != _tfopen_s(&fp, file, _T("w+")) )
  158. {
  159. WriteTextLog(_T("创建文件失败:%s,%d"), file, GetLastError());
  160. return;
  161. }
  162. }
  163. if (fp == NULL)
  164. {
  165. WriteTextLog(_T("文件句柄空:%s,%d"), file, GetLastError());
  166. return;
  167. }
  168. // 格式化前设置语言区域;
  169. TCHAR* old_locale = _tcsdup(_tsetlocale(LC_CTYPE, NULL));
  170. _tsetlocale(LC_CTYPE, _T("chs")); //设定中文;
  171. //_ftprintf(fp, _T("%04d-%02d-%02d %02d:%02d:%02d %s\n"), gmtm.tm_year + 1990, gmtm.tm_mon + 1, gmtm.tm_mday, gmtm.tm_hour, gmtm.tm_min, gmtm.tm_sec, msg);
  172. _ftprintf(fp, _T("%s"), msg);
  173. // 关闭文件,释放资源并设置回原语言区域;
  174. fclose(fp);
  175. _tsetlocale(LC_CTYPE, old_locale);
  176. free(old_locale); //还原区域设定;
  177. }
  178. // 从注册表获取 Python27路径;
  179. BOOL Python27Dir(LPTSTR lpPython27Dir, int nBufferLen)
  180. {
  181. HKEY hKey;
  182. int ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\WOW6432Node\\Python\\PythonCore\\2.7\\InstallPath"), 0, KEY_QUERY_VALUE, &hKey);
  183. if (ret != ERROR_SUCCESS)
  184. return FALSE;
  185. //读取KEY
  186. DWORD dwType = REG_SZ; //数据类型
  187. DWORD cbData = nBufferLen;
  188. ret = RegQueryValueEx(hKey, _T(""), NULL, &dwType, (LPBYTE)lpPython27Dir, &cbData);
  189. if (ret != ERROR_SUCCESS)
  190. {
  191. RegCloseKey(hKey);
  192. return FALSE;
  193. }
  194. RegCloseKey(hKey);
  195. return TRUE;
  196. }
  197. void ClosePythonLog()
  198. {
  199. AutoThreadSection aSection(&g_critSection);
  200. if ( gp_log_fp )
  201. {
  202. WriteTextLog(_T("关闭文件:%s"), g_szLogPath);
  203. fclose(gp_log_fp);
  204. gp_log_fp = NULL;
  205. }
  206. }
  207. // 去除空格;
  208. std::string& trim(std::string& str)
  209. {
  210. int nIndex = 0;
  211. while ((nIndex = str.find_first_of(' ')) != std::string::npos)
  212. str.erase(nIndex, 1);
  213. return str;
  214. }
  215. // hModule 模块句柄 NULL表示当前模块;
  216. bool GetVersion(IN const TCHAR* fname, OUT WORD* pdwFileVersion, OUT WORD* pdwProductVerion)
  217. {
  218. VS_FIXEDFILEINFO* pVi = NULL;
  219. DWORD dwHandle = 0;
  220. int size = GetFileVersionInfoSize(fname, &dwHandle);
  221. if (size > 0)
  222. {
  223. BYTE* buffer = new BYTE[size];
  224. memset(buffer, 0, size);
  225. if (GetFileVersionInfo(fname, 0, size, buffer))
  226. {
  227. if (VerQueryValue(buffer, _T("\\"), (LPVOID*)& pVi, (PUINT)& size))
  228. {
  229. pdwFileVersion[0] = HIWORD(pVi->dwFileVersionMS);
  230. pdwFileVersion[1] = LOWORD(pVi->dwFileVersionMS);
  231. pdwFileVersion[2] = HIWORD(pVi->dwFileVersionLS);
  232. pdwFileVersion[3] = LOWORD(pVi->dwFileVersionLS);
  233. pdwProductVerion[0] = HIWORD(pVi->dwProductVersionMS);
  234. pdwProductVerion[1] = LOWORD(pVi->dwProductVersionMS);
  235. pdwProductVerion[2] = HIWORD(pVi->dwProductVersionLS);
  236. pdwProductVerion[3] = LOWORD(pVi->dwProductVersionLS);
  237. delete[] buffer;
  238. return true;
  239. }
  240. }
  241. delete[] buffer;
  242. }
  243. return false;
  244. }
  245. BOOL GetVersion(IN HMODULE hModule, OUT DWORD(&dwFVArray)[4], OUT DWORD(&dwPVArray)[4])
  246. {
  247. TCHAR fname[MAX_PATH];
  248. VS_FIXEDFILEINFO* pVi;
  249. DWORD dwHandle;
  250. if (GetModuleFileName(hModule, fname, MAX_PATH))
  251. {
  252. INT nSize = GetFileVersionInfoSize(fname, &dwHandle);
  253. if (nSize > 0)
  254. {
  255. BYTE* pBuffer = new BYTE[nSize];
  256. memset(pBuffer, 0, nSize);
  257. if (GetFileVersionInfo(fname, 0, nSize, pBuffer))
  258. {
  259. if (VerQueryValue(pBuffer, _T("\\"), (LPVOID*)& pVi, (PUINT)& nSize))
  260. {
  261. dwFVArray[0] = HIWORD(pVi->dwFileVersionMS);
  262. dwFVArray[1] = LOWORD(pVi->dwFileVersionMS);
  263. dwFVArray[2] = HIWORD(pVi->dwFileVersionLS);
  264. dwFVArray[3] = LOWORD(pVi->dwFileVersionLS);
  265. dwPVArray[0] = HIWORD(pVi->dwProductVersionMS);
  266. dwPVArray[1] = LOWORD(pVi->dwProductVersionMS);
  267. dwPVArray[2] = HIWORD(pVi->dwProductVersionLS);
  268. dwPVArray[3] = LOWORD(pVi->dwProductVersionLS);
  269. delete[]pBuffer;
  270. return TRUE;
  271. }
  272. }
  273. if (pBuffer)
  274. delete[]pBuffer;
  275. }
  276. }
  277. return FALSE;
  278. }
  279. WCHAR* ASCII2UNICODE(IN LPCCH lpASCIIStr)
  280. {
  281. if (lpASCIIStr == NULL)
  282. return NULL;
  283. // 获取宽字符字节数;
  284. int cchWideChar = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, NULL, 0);
  285. if (cchWideChar == 0)
  286. return NULL;
  287. // 转换成宽字符串;
  288. WCHAR* pWideChar = new WCHAR[cchWideChar + 1];
  289. memset(pWideChar, 0, sizeof(WCHAR) * (cchWideChar + 1));
  290. int nWriteNum = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, pWideChar, cchWideChar);
  291. if (nWriteNum != cchWideChar)
  292. {
  293. if (pWideChar)
  294. delete[] pWideChar;
  295. return NULL;
  296. }
  297. return pWideChar;
  298. }
  299. BOOL UNICODE2UTF8(IN LPWCH lpUNICODEStr, OUT string& strResult)
  300. {
  301. if (lpUNICODEStr == NULL)
  302. return FALSE;
  303. // 获取多字节字符字节数;
  304. int cbMultiByte = WideCharToMultiByte(CP_UTF8, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
  305. if (cbMultiByte == 0)
  306. return FALSE;
  307. // 转换成多字节字符;
  308. CHAR* pResult = new CHAR[cbMultiByte];
  309. memset(pResult, 0, cbMultiByte);
  310. int nWriteNum = WideCharToMultiByte(CP_UTF8, 0, lpUNICODEStr, -1, pResult, cbMultiByte, NULL, NULL);
  311. if (nWriteNum != cbMultiByte)
  312. return FALSE;
  313. strResult = pResult;
  314. if (pResult)
  315. delete[] pResult;
  316. return TRUE;
  317. }
  318. BOOL ASCII2UTF8(IN LPCCH lpASCIIStr, OUT string& strResult)
  319. {
  320. // 将ASCII字符串转成UNICODE字符串;
  321. WCHAR* pWideChar = ASCII2UNICODE(lpASCIIStr);
  322. if (pWideChar == NULL)
  323. return FALSE;
  324. // 再将UICODE转成UTF8;
  325. BOOL bResult = UNICODE2UTF8(pWideChar, strResult);
  326. if (pWideChar)
  327. delete[] pWideChar;
  328. return bResult;
  329. }
  330. string EnCode_UTF8URL(IN const CHAR* pText)
  331. {
  332. string tt = "";
  333. string dd = "";
  334. ASCII2UTF8(pText, tt);
  335. size_t len = tt.length();
  336. for (size_t i = 0; i < len; i++)
  337. {
  338. if (isalnum((BYTE)tt.at(i)))
  339. {
  340. char tempbuff[2] = { 0 };
  341. sprintf_s(tempbuff, "%c", (BYTE)tt.at(i));
  342. dd.append(tempbuff);
  343. }
  344. else if (isspace((BYTE)tt.at(i)))
  345. {
  346. dd.append("+");
  347. }
  348. else
  349. {
  350. char tempbuff[4];
  351. sprintf_s(tempbuff, "%%%X%X", ((BYTE)tt.at(i)) >> 4, ((BYTE)tt.at(i)) % 16);
  352. dd.append(tempbuff);
  353. }
  354. }
  355. return dd;
  356. }
  357. void EnCode_UTF8URL(IN const CHAR* pText, OUT string& strResult)
  358. {
  359. string tt = "";
  360. ASCII2UTF8(pText, tt);
  361. size_t len = tt.length();
  362. for (size_t i = 0; i < len; i++)
  363. {
  364. if (isalnum((BYTE)tt.at(i)))
  365. {
  366. char tempbuff[2] = { 0 };
  367. sprintf_s(tempbuff, "%c", (BYTE)tt.at(i));
  368. strResult.append(tempbuff);
  369. }
  370. else if (isspace((BYTE)tt.at(i)))
  371. {
  372. strResult.append("+");
  373. }
  374. else
  375. {
  376. char tempbuff[4];
  377. sprintf_s(tempbuff, "%%%X%X", ((BYTE)tt.at(i)) >> 4, ((BYTE)tt.at(i)) % 16);
  378. strResult.append(tempbuff);
  379. }
  380. }
  381. }
  382. //做为解Url使用
  383. char CharToInt(char ch)
  384. {
  385. if (ch >= '0' && ch <= '9')return (char)(ch - '0');
  386. if (ch >= 'a' && ch <= 'f')return (char)(ch - 'a' + 10);
  387. if (ch >= 'A' && ch <= 'F')return (char)(ch - 'A' + 10);
  388. return -1;
  389. }
  390. char StrToBin(IN char(&str)[2])
  391. {
  392. char tempWord[2];
  393. char chn;
  394. tempWord[0] = CharToInt(str[0]); //make the B to 11 -- 00001011
  395. tempWord[1] = CharToInt(str[1]); //make the 0 to 0 -- 00000000
  396. chn = (tempWord[0] << 4) | tempWord[1]; //to change the BO to 10110000
  397. return chn;
  398. }
  399. CHAR* UNICODE2ASCII(IN LPWCH lpUNICODEStr)
  400. {
  401. if (lpUNICODEStr == NULL)
  402. return NULL;
  403. // 获取多字节字符字节数;
  404. int cbMultiByte = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
  405. if (cbMultiByte == 0)
  406. return NULL;
  407. // 转换成多字节字符;
  408. CHAR *pMultiByteStr = new CHAR[cbMultiByte + 1];
  409. memset(pMultiByteStr, 0, cbMultiByte + 1);
  410. int nWriteNum = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, pMultiByteStr, cbMultiByte, NULL, NULL);
  411. if (nWriteNum != cbMultiByte)
  412. {
  413. if (pMultiByteStr)
  414. delete[]pMultiByteStr;
  415. return NULL;
  416. }
  417. pMultiByteStr[cbMultiByte] = '\0';
  418. return pMultiByteStr;
  419. }
  420. BOOL UNICODE2ASCII(IN LPWCH lpUNICODEStr, OUT LPCH pASCIIStr, IN CONST INT& nASCIIStrLen)
  421. {
  422. if (lpUNICODEStr == NULL)
  423. return FALSE;
  424. // 获取多字节字符字节数;
  425. int cbMultiByte = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
  426. if (cbMultiByte == 0 || cbMultiByte >= nASCIIStrLen)
  427. return FALSE;
  428. // 转换成多字节字符;
  429. memset((void*)pASCIIStr, 0, nASCIIStrLen);
  430. int nWriteNum = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, pASCIIStr, cbMultiByte, NULL, NULL);
  431. if (nWriteNum != cbMultiByte)
  432. {
  433. return FALSE;
  434. }
  435. return TRUE;
  436. }
  437. /************************************************************************/
  438. /* 函数:[7/26/2016 IT];
  439. /* 描述:;
  440. /* 参数:;
  441. /* [IN] :;
  442. /* [OUT] :;
  443. /* [IN/OUT] :;
  444. /* 返回:void;
  445. /* 注意:;
  446. /* 示例:;
  447. /*
  448. /* 修改:;
  449. /* 日期:;
  450. /* 内容:;
  451. /************************************************************************/
  452. string DeCode_URLUNICODE(IN const CHAR* pURLText)
  453. {
  454. string str = pURLText;
  455. string strResult = "";
  456. INT nIndex = 0;
  457. string strTemp = "";
  458. while (str.find("\\u", 0, 2) != string::npos)
  459. {
  460. nIndex = str.find("\\u", 0, 2);
  461. strResult.append(str.substr(0, nIndex));
  462. strTemp = str.substr(nIndex + 2, 4);
  463. str = str.substr(nIndex + 2 + 4);
  464. CHAR szReturn[10] = { 0 };
  465. union __UNION_VAR_INT {
  466. BYTE ch[2];
  467. int value;
  468. }unionVarInt;
  469. unionVarInt.ch[0] = (CharToInt(strTemp.at(2)) << 4) | (CharToInt(strTemp.at(3)) & 0x00FF);
  470. unionVarInt.ch[1] = (CharToInt(strTemp.at(0)) << 4) | (CharToInt(strTemp.at(1)) & 0x00FF);
  471. WCHAR szWide[2] = { 0 };
  472. szWide[0] = unionVarInt.value;
  473. UNICODE2ASCII(szWide, szReturn, 10);
  474. strResult.append(szReturn);
  475. }
  476. strResult.append(str);
  477. return strResult;
  478. }
  479. // 通过注册表查找系统当前串口信息;
  480. BOOL IsValidString(LPCTSTR lpszString)
  481. {
  482. if (lpszString == NULL)
  483. return FALSE;
  484. do
  485. {
  486. // ASCII可显示的字符;
  487. if (*lpszString < 32 || *lpszString > 126)
  488. {
  489. return FALSE;
  490. }
  491. } while (*++lpszString);
  492. return TRUE;
  493. }
  494. BOOL Python27Dir()
  495. {
  496. HKEY hKey;
  497. int ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\WOW6432Node\\Python\\PythonCore\\2.7\\InstallPath"), 0, KEY_QUERY_VALUE, &hKey);
  498. if (ret != ERROR_SUCCESS)
  499. return FALSE;
  500. //读取KEY
  501. DWORD dwType = REG_SZ; //数据类型
  502. DWORD cbData = MAX_PATH;
  503. ret = RegQueryValueEx(hKey, _T(""), NULL, &dwType, (LPBYTE)g_szPython27Dir, &cbData);
  504. if (ret != ERROR_SUCCESS)
  505. {
  506. RegCloseKey(hKey);
  507. return FALSE;
  508. }
  509. RegCloseKey(hKey);
  510. return TRUE;
  511. }
  512. void GetResourceCfg()
  513. {
  514. // 配置文件;
  515. Python27Dir();
  516. TCHAR szConfig[MAX_PATH] = {0};
  517. _stprintf_s(szConfig, _T("%sLib\\site-packages\\ssat_sdk\\config\\resource_run.cfg"), g_szPython27Dir);
  518. // 电视串口号;
  519. GetPrivateProfileString(_T("COMM"), _T("serial_communicator_port"), NULL, g_szTVPort, MAX_PATH, szConfig);
  520. // 重启关键字;
  521. g_bWatchTVPort = GetPrivateProfileInt(_T("Abnormal"), _T("Watch"), 0, szConfig);
  522. // 重启关键字;
  523. GetPrivateProfileString(_T("Abnormal"), _T("reboot"), NULL, g_szTVReboot, MAX_PATH, szConfig);
  524. // 关机关键字;
  525. GetPrivateProfileString(_T("Abnormal"), _T("shutdown"), NULL, g_szTVShutdown, MAX_PATH, szConfig);
  526. }
  527. void Split(std::string str1, std::string str2, std::vector<std::string> &vt)
  528. {
  529. if ( str1.size() == 0 || str2.size() == 0 )
  530. return;
  531. int npos = str1.find(str2);
  532. while( std::string::npos != npos )
  533. {
  534. vt.push_back(str1.substr(0, npos));
  535. str1 = str1.substr(npos + str2.size());
  536. npos = str1.find(str2);
  537. }
  538. if ( str1.size() )
  539. vt.push_back(str1);
  540. }
  541. } // namespace Global