Global.cpp 15 KB

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