common_api.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. #include "stdafx.h"
  2. #include <time.h>
  3. #include "common_api.h"
  4. common_api::common_api(void)
  5. {
  6. m_NotifyEvent = CreateMutexA(NULL, FALSE, NULL);
  7. if (m_NotifyEvent == NULL)
  8. {
  9. printf("CreateMutex error: %d\n", GetLastError());
  10. return;
  11. }
  12. }
  13. common_api::~common_api(void)
  14. {
  15. CloseHandle(m_NotifyEvent);
  16. }
  17. common_api g_common1_for_init;
  18. bool string_2_guid(const char *pstr, GUID &stGuid)
  19. {
  20. string temp;
  21. vector<string> thelist;
  22. if (SplitTo84422222222String(pstr, thelist) == false)
  23. {
  24. return false;
  25. }
  26. temp = "0x";
  27. temp += thelist[0].c_str();
  28. StrToIntT(temp.c_str(), &stGuid.Data1);
  29. //sscanf_s(thelist[0].c_str(), "%08x", &stGuid.Data1);
  30. temp = "0x";
  31. temp += thelist[1].c_str();
  32. StrToIntT(temp.c_str(), &stGuid.Data2);
  33. //sscanf_s(thelist[1].c_str(), "%04x", &stGuid.Data2);
  34. temp = "0x";
  35. temp += thelist[2].c_str();
  36. StrToIntT(temp.c_str(), &stGuid.Data3);
  37. //sscanf_s(thelist[2].c_str(), "%04x", &stGuid.Data3);
  38. for (size_t i = 3; i < 11; i++)
  39. {
  40. //sscanf_s(thelist[i].c_str(), "%02x", &stGuid.Data4[i - 3],2);
  41. temp = "0x";
  42. temp += thelist[i].c_str();
  43. StrToIntT(temp.c_str(), &stGuid.Data4[i - 3]);
  44. }
  45. return true;
  46. }
  47. bool guid_2_string(GUID &stGuid, string &str)
  48. {
  49. char szBuff[MAX_PATH] = { 0 };
  50. sprintf_s(szBuff,"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", stGuid.Data1, stGuid.Data2, stGuid.Data3,
  51. stGuid.Data4[0], stGuid.Data4[1], stGuid.Data4[2], stGuid.Data4[3],
  52. stGuid.Data4[4], stGuid.Data4[5], stGuid.Data4[6], stGuid.Data4[7]);
  53. str = szBuff;
  54. return true;
  55. }
  56. bool AddEnvPath(const char *pPath)
  57. {
  58. DWORD PathLen = 32768;
  59. char *pszPath = new char[PathLen];
  60. DWORD Len = GetEnvironmentVariable("Path", pszPath, PathLen);
  61. if (Len > PathLen)
  62. {
  63. delete[]pszPath;
  64. return false;
  65. }
  66. std::string::size_type pos = 0;
  67. string EnvPath = pszPath;
  68. delete[]pszPath;
  69. //EnvPath.find(pPath, 0);
  70. if ((pos = EnvPath.find(pPath, pos)) == std::string::npos)
  71. {
  72. string NewPath = EnvPath;
  73. NewPath += ";";
  74. NewPath += pPath;
  75. if (SetEnvironmentVariable("Path", NewPath.c_str()) == FALSE)
  76. {
  77. return false;
  78. }
  79. }
  80. return true;
  81. }
  82. __time64_t GetCurrentRealTimeOfStk()
  83. {
  84. __time64_t now;
  85. _time64(&now);
  86. return now;
  87. }
  88. UINT64 GetDay(UINT64 TheTime)
  89. {
  90. struct tm tCur;
  91. _gmtime64_s(&tCur, (__time64_t*)&TheTime);
  92. tCur.tm_sec = 0;
  93. tCur.tm_min = 0;
  94. tCur.tm_hour = 0;
  95. __time64_t CurDay = _mkgmtime64(&tCur);
  96. return (UINT64)CurDay;
  97. }
  98. int CompareTimeByDay(UINT64 Prev, UINT64 Cur)
  99. {
  100. struct tm tPrev,tCur;
  101. _gmtime64_s(&tPrev, (__time64_t*)&Prev);
  102. tPrev.tm_sec = 0;
  103. tPrev.tm_min = 0;
  104. tPrev.tm_hour = 0;
  105. __time64_t PrevDay = _mkgmtime64(&tPrev);
  106. _gmtime64_s(&tCur, (__time64_t*)&Cur);
  107. tCur.tm_sec = 0;
  108. tCur.tm_min = 0;
  109. tCur.tm_hour = 0;
  110. __time64_t CurDay = _mkgmtime64(&tPrev);
  111. if (CurDay == PrevDay)
  112. {
  113. return 0;
  114. }
  115. if (CurDay > PrevDay)
  116. {
  117. return 1;
  118. }
  119. return -1;
  120. }
  121. bool getBusIdFromFilePath(const char *pFilePath,string &BusId)
  122. {
  123. string Path = pFilePath;
  124. size_t readcount = 0;
  125. size_t firstHit = Path.find_first_of('/');
  126. if(firstHit == string::npos || firstHit != 0)
  127. {
  128. return false;
  129. }
  130. size_t SecondHit = Path.find_first_of('/',1);
  131. if(SecondHit == string::npos)
  132. {
  133. BusId = Path.substr(1,Path.size()-1);
  134. }
  135. else
  136. {
  137. BusId = Path.substr(1,SecondHit - 1);
  138. }
  139. if(BusId.size() == 0)
  140. {
  141. return false;
  142. }
  143. return true;
  144. }
  145. void RawToHex(const char *pRaw, DWORD RawLen, string &Hex)
  146. {
  147. char szMsg[4] = { 0 };
  148. Hex.reserve(RawLen * 3);
  149. for (DWORD i = 0; i < RawLen; i++)
  150. {
  151. _snprintf_s(szMsg, 3, "%02X ", pRaw[i]);
  152. Hex += szMsg;
  153. }
  154. }
  155. bool MergeDevicePath(vector<string> &nodes,string &Devpath)
  156. {
  157. Devpath = "";
  158. for (size_t i = 0; i < nodes.size(); i++)
  159. {
  160. if (nodes[i].size() > 0)
  161. {
  162. Devpath += "/";
  163. Devpath += nodes[i];
  164. }
  165. }
  166. return (Devpath.size() > 0);
  167. }
  168. bool SplitStringSub(string &Path, char key, vector<string> &nodes)
  169. {
  170. string node;
  171. size_t readcount = 0;
  172. //nodes.clear();
  173. string::size_type firstHit = Path.find_first_of(key);
  174. if (firstHit == string::npos)
  175. {
  176. if (Path.size() > 0)
  177. {
  178. nodes.push_back(Path);
  179. }
  180. return true;
  181. }
  182. //firstHit += 1;
  183. if (firstHit > 0)
  184. {
  185. node = Path.substr(0, firstHit);
  186. if (node.size() > 0)
  187. {
  188. nodes.push_back(node);
  189. }
  190. }
  191. while (firstHit < Path.size())
  192. {
  193. firstHit += 1;
  194. string::size_type SecondHit = Path.find_first_of(key, firstHit);
  195. if (SecondHit == string::npos)
  196. {
  197. node = Path.substr(firstHit, Path.size() - (firstHit));
  198. if (node.size() > 0)
  199. {
  200. nodes.push_back(node);
  201. }
  202. return true;
  203. }
  204. node = Path.substr(firstHit, SecondHit - (firstHit));
  205. if (node.size() > 0)
  206. {
  207. nodes.push_back(node);
  208. }
  209. firstHit = SecondHit;
  210. }
  211. return (nodes.size() > 0);
  212. }
  213. bool SplitString(const char *pString,string args, vector<string> &nodes)
  214. {
  215. vector<string> req;
  216. vector<string> res;
  217. req.push_back(string(pString));
  218. for (size_t i = 0; i < args.size(); i++)
  219. {
  220. //cut all req by key
  221. for (size_t j = 0; j < req.size(); j++)
  222. {
  223. SplitStringSub(req[j], args[i], res);
  224. }
  225. //clear and reset
  226. req.clear();
  227. req = res;
  228. res.clear();
  229. }
  230. nodes = req;
  231. return true;
  232. }
  233. bool SplitTo84422222222String(const char *pString, vector<string> &nodes)
  234. {
  235. string total;
  236. vector<string> thelist;
  237. SplitString(pString, string("{}-"), thelist);
  238. for (size_t i = 0; i < thelist.size(); i++)
  239. {
  240. total += thelist[i];
  241. }
  242. if (total.size() != 32)
  243. {
  244. return false;
  245. }
  246. string temp;
  247. temp = total.substr(0, 8);//8
  248. nodes.push_back(temp);
  249. temp = total.substr(8, 4);//4
  250. nodes.push_back(temp);
  251. temp = total.substr(12, 4);//4
  252. nodes.push_back(temp);
  253. temp = total.substr(16, 2);//2
  254. nodes.push_back(temp);
  255. temp = total.substr(18, 2);//2
  256. nodes.push_back(temp);
  257. temp = total.substr(20, 2);//2
  258. nodes.push_back(temp);
  259. temp = total.substr(22, 2);//2
  260. nodes.push_back(temp);
  261. temp = total.substr(24, 2);//2
  262. nodes.push_back(temp);
  263. temp = total.substr(26, 2);//2
  264. nodes.push_back(temp);
  265. temp = total.substr(28, 2);//2
  266. nodes.push_back(temp);
  267. temp = total.substr(30, 2);//2
  268. nodes.push_back(temp);
  269. return true;
  270. }
  271. string FormatstdString(const char *fmt, ...)
  272. {
  273. std::string strResult = "";
  274. WaitForSingleObject(g_common1_for_init.m_NotifyEvent, INFINITE);
  275. {
  276. if (NULL != fmt)
  277. {
  278. va_list marker = NULL;
  279. va_start(marker, fmt);
  280. size_t nLength = _vscprintf(fmt, marker) + 1;
  281. std::vector<char> vBuffer(nLength, '\0');
  282. int nWritten = vsnprintf_s(&vBuffer[0], vBuffer.size(), nLength, fmt, marker);
  283. if (nWritten > 0)
  284. {
  285. strResult = &vBuffer[0];
  286. }
  287. va_end(marker);
  288. }
  289. ReleaseMutex(g_common1_for_init.m_NotifyEvent);
  290. }
  291. return strResult;
  292. }
  293. bool SplitDevicePath(const char *pDevicePath, vector<string> &nodes)
  294. {
  295. string node;
  296. string Path = pDevicePath;
  297. size_t readcount = 0;
  298. nodes.clear();
  299. string::size_type firstHit = Path.find_first_of('/');
  300. if (firstHit == string::npos || firstHit != 0)
  301. {
  302. return false;
  303. }
  304. while (firstHit < Path.size())
  305. {
  306. firstHit += 1;
  307. string::size_type SecondHit = Path.find_first_of('/', firstHit);
  308. if (SecondHit == string::npos)
  309. {
  310. node = Path.substr(firstHit, Path.size() - firstHit);
  311. if (node.size() > 0)
  312. {
  313. nodes.push_back(node);
  314. }
  315. return true;
  316. }
  317. node = Path.substr(firstHit, SecondHit - (firstHit));
  318. if (node.size() > 0)
  319. {
  320. nodes.push_back(node);
  321. }
  322. firstHit = SecondHit;
  323. }
  324. return (nodes.size() > 0);
  325. }
  326. string GetProcessDirectory()
  327. {
  328. string ret = "";
  329. char szFilename[MAX_PATH] = { 0 };
  330. DWORD res = GetModuleFileNameA(0, szFilename, MAX_PATH);
  331. if (res == 0)
  332. {
  333. return ret;
  334. }
  335. string fullpath = szFilename;
  336. string::size_type firstHit = fullpath.find_last_of('\\');
  337. if (firstHit == string::npos || firstHit == 0)
  338. {
  339. return ret;
  340. }
  341. ret = fullpath.substr(0, firstHit);//kick last \
  342. return ret;
  343. }
  344. //fullpath must be like X:\filetitle.x.y.z...,or X:/filetitle.x.y.z...
  345. string GetFileTitle(string &fullpath)
  346. {
  347. string ret = "";
  348. string::size_type firstHit = fullpath.find_last_of('\\');
  349. string::size_type firstHitSec = fullpath.find_last_of('/');
  350. if ((firstHit == string::npos || firstHit == 0 || (firstHit + 1 == fullpath.size())) && (firstHitSec == string::npos || firstHitSec == 0 || (firstHitSec + 1 == fullpath.size())))
  351. {
  352. return ret;
  353. }
  354. if (firstHit == string::npos || firstHit == 0 || (firstHit + 1 == fullpath.size()))
  355. {
  356. ret = fullpath.substr(firstHitSec + 1);
  357. }
  358. else if (firstHitSec == string::npos || firstHitSec == 0 || (firstHitSec + 1 == fullpath.size()))
  359. {
  360. ret = fullpath.substr(firstHit + 1);
  361. }
  362. else
  363. {
  364. //effective both
  365. if (firstHit > firstHitSec)
  366. {
  367. ret = fullpath.substr(firstHit + 1);//kick last
  368. }
  369. else
  370. {
  371. ret = fullpath.substr(firstHitSec + 1);//kick last
  372. }
  373. }
  374. //got filetitle with ext
  375. if (ret.size() > 0)
  376. {
  377. string::size_type firstHit = ret.find_first_of('.');
  378. ret = ret.substr(0, firstHit);
  379. }
  380. return ret;
  381. }
  382. string GetFileName(string &fullpath)
  383. {
  384. string ret = "";
  385. string::size_type firstHit = fullpath.find_last_of('\\');
  386. string::size_type firstHitSec = fullpath.find_last_of('/');
  387. if ((firstHit == string::npos || firstHit == 0 || (firstHit + 1 == fullpath.size())) && (firstHitSec == string::npos || firstHitSec == 0 || (firstHitSec + 1 == fullpath.size())))
  388. {
  389. return ret;
  390. }
  391. if (firstHit == string::npos || firstHit == 0 || (firstHit + 1 == fullpath.size()))
  392. {
  393. ret = fullpath.substr(firstHitSec + 1);
  394. }
  395. else if (firstHitSec == string::npos || firstHitSec == 0 || (firstHitSec + 1 == fullpath.size()))
  396. {
  397. ret = fullpath.substr(firstHit + 1);
  398. }
  399. else
  400. {
  401. //effective both
  402. if (firstHit > firstHitSec)
  403. {
  404. ret = fullpath.substr(firstHit + 1);//kick last
  405. }
  406. else
  407. {
  408. ret = fullpath.substr(firstHitSec + 1);//kick last
  409. }
  410. }
  411. //got filetitle with ext
  412. //if (ret.size() > 0)
  413. //{
  414. // string::size_type ExtHit = ret.find_last_of('.');
  415. // if (ExtHit == 0 || ExtHit == string::npos || ((ExtHit + 1) == fullpath.size()))
  416. // {
  417. // ret = "";
  418. // }
  419. // else
  420. // {
  421. // ret = ret.substr(ExtHit + 1);
  422. // }
  423. //}
  424. return ret;
  425. }
  426. string ReplaceFileTitle(string FilePath, string NewTitle)
  427. {
  428. string::size_type ExtHit = FilePath.find_last_of('.');
  429. if (ExtHit != string::npos)
  430. {
  431. FilePath.replace(ExtHit + 1, string::npos, NewTitle);
  432. }
  433. return FilePath;
  434. }
  435. bool CreateFileDirectory(string &FullFilePath)
  436. {
  437. string path = GetFileDirectory(FullFilePath);
  438. string workpath = GetProcessDirectory() + string("\\");
  439. transform(path.begin(), path.end(), path.begin(), tolower);
  440. transform(workpath.begin(), workpath.end(), workpath.begin(), tolower);
  441. vector<string> folders;
  442. string subpath = ReplaceSubString(path, workpath, string(""));
  443. SplitString(subpath.c_str(), string("/\\"), folders);
  444. for (size_t i = 0; i < folders.size(); i++)
  445. {
  446. workpath += folders[i] + string("\\");
  447. DWORD attr = GetFileAttributes(workpath.c_str());
  448. if (attr == (DWORD)-1)
  449. {
  450. if (CreateDirectory(workpath.c_str(), 0) == 0)
  451. {
  452. return false;
  453. }
  454. }
  455. if ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  456. {
  457. return false;
  458. }
  459. }
  460. return true;
  461. }
  462. string GetFileDirectory(string &fullpath)
  463. {
  464. string ret = "";
  465. string::size_type firstHit = fullpath.find_last_of('\\');
  466. string::size_type firstHitSec = fullpath.find_last_of('/');
  467. if ((firstHit == string::npos || firstHit == 0) && (firstHitSec == string::npos || firstHitSec == 0))
  468. {
  469. return ret;
  470. }
  471. if (firstHit == string::npos || firstHit == 0)
  472. {
  473. ret = fullpath.substr(0, firstHitSec);//kick last
  474. }
  475. else if (firstHitSec == string::npos || firstHitSec == 0)
  476. {
  477. ret = fullpath.substr(0, firstHit);//kick last
  478. }
  479. else
  480. {
  481. //effective both
  482. if (firstHit > firstHitSec)
  483. {
  484. ret = fullpath.substr(0, firstHit);//kick last
  485. }
  486. else
  487. {
  488. ret = fullpath.substr(0, firstHitSec);//kick last
  489. }
  490. }
  491. return ret;
  492. }
  493. string ReplaceSubString(string org, string &keystr, string &replacestr)
  494. {
  495. std::string::size_type pos = 0;
  496. std::string::size_type keylen = keystr.size();
  497. std::string::size_type replen = replacestr.size();
  498. while ((pos = org.find(keystr, pos)) != std::string::npos)
  499. {
  500. org.replace(pos, keylen, replacestr);
  501. pos += replen;
  502. }
  503. return org;
  504. }
  505. bool FindSortedSubFiles(string rootFile, vector<string> &filelist)
  506. {
  507. WIN32_FIND_DATA fd;
  508. map<string,FILETIME> sortmap;
  509. ZeroMemory(&fd, sizeof(WIN32_FIND_DATA));
  510. if (rootFile.size() == 0)
  511. {
  512. return false;
  513. }
  514. HANDLE hFile;
  515. BOOL bRet = TRUE;
  516. string rootDir = GetFileDirectory(rootFile);
  517. if (rootDir[rootDir.size() - 1] != '\\')
  518. {
  519. rootDir += "\\";
  520. }
  521. string subpath = rootFile;
  522. subpath += ".*";//log file looks like xxx.log.20161107_185132
  523. hFile = FindFirstFile(subpath.c_str(), &fd);
  524. while (hFile != INVALID_HANDLE_VALUE && bRet)
  525. {
  526. if (fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY &&
  527. strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, ".."))
  528. {
  529. //ignore dir
  530. }
  531. else if (!strcmp(fd.cFileName, ".") || !strcmp(fd.cFileName, ".."))
  532. {
  533. //ignore it
  534. }
  535. else
  536. {
  537. //full file name
  538. subpath = rootDir;
  539. subpath += fd.cFileName;
  540. sortmap[subpath] = fd.ftLastWriteTime;
  541. }
  542. bRet = FindNextFile(hFile, &fd);
  543. }
  544. FindClose(hFile);
  545. //sort it
  546. while (sortmap.size() > 0)
  547. {
  548. ULARGE_INTEGER fTime1 = { 0 };
  549. map<string, FILETIME>::iterator itermax;
  550. map<string, FILETIME>::iterator iter = sortmap.begin();
  551. while (iter != sortmap.end())
  552. {
  553. ULARGE_INTEGER *pfTime2 = (ULARGE_INTEGER *)&(iter->second);
  554. if (fTime1.QuadPart < (*pfTime2).QuadPart)
  555. {
  556. itermax = iter;
  557. }
  558. ++iter;
  559. }
  560. //got bigest one
  561. filelist.push_back(itermax->first);
  562. //del iter
  563. sortmap.erase(itermax);
  564. }
  565. return (filelist.size() > 0);
  566. }
  567. bool FindSubVersionDirs(string rootDir, map<string,vector<string>>& dirlist)
  568. {
  569. WIN32_FIND_DATA fd;
  570. ZeroMemory(&fd, sizeof(WIN32_FIND_DATA));
  571. if (rootDir.size() == 0)
  572. {
  573. return false;
  574. }
  575. HANDLE hFile;
  576. BOOL bRet = TRUE;
  577. if (rootDir[rootDir.size() - 1] != '\\')
  578. {
  579. rootDir += "\\";
  580. }
  581. string subpath = rootDir;
  582. //define the format of the basepath
  583. subpath += "*";
  584. hFile = FindFirstFile(subpath.c_str(), &fd);
  585. while (hFile != INVALID_HANDLE_VALUE && bRet)
  586. {
  587. if ((fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) &&
  588. strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, ".."))
  589. {
  590. string TheDir = rootDir;
  591. TheDir += fd.cFileName;
  592. dirlist[fd.cFileName].push_back(TheDir);
  593. }
  594. else if (!strcmp(fd.cFileName, ".") || !strcmp(fd.cFileName, ".."))
  595. {
  596. //ignore it
  597. }
  598. else
  599. {
  600. //ignore it
  601. }
  602. bRet = FindNextFile(hFile, &fd);
  603. }
  604. FindClose(hFile);
  605. return (dirlist.size() > 0);
  606. }
  607. bool FindSubFiles(string rootDir, vector<string> &filelist,bool Recursive, string strWildcard)
  608. {
  609. WIN32_FIND_DATA fd;
  610. ZeroMemory(&fd, sizeof(WIN32_FIND_DATA));
  611. if (rootDir.size() == 0)
  612. {
  613. return false;
  614. }
  615. HANDLE hFile;
  616. BOOL bRet = TRUE;
  617. if (rootDir[rootDir.size() - 1] != '\\')
  618. {
  619. rootDir += "\\";
  620. }
  621. string subpath = rootDir;
  622. //define the format of the basepath
  623. subpath += strWildcard;
  624. hFile = FindFirstFile(subpath.c_str(), &fd);
  625. while (hFile != INVALID_HANDLE_VALUE && bRet)
  626. {
  627. if ((fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) &&
  628. strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, ".."))
  629. {
  630. if (Recursive)
  631. {
  632. subpath = rootDir;
  633. subpath += fd.cFileName;
  634. FindSubFiles(subpath, filelist);
  635. }
  636. }
  637. else if (!strcmp(fd.cFileName, ".") || !strcmp(fd.cFileName, ".."))
  638. {
  639. //ignore it
  640. }
  641. else
  642. {
  643. //full file name
  644. subpath = rootDir;
  645. subpath += fd.cFileName;
  646. filelist.push_back(subpath);
  647. }
  648. bRet = FindNextFile(hFile, &fd);
  649. }
  650. FindClose(hFile);
  651. return (filelist.size() > 0);
  652. }
  653. string & makeLowerStr(string & src)
  654. {
  655. size_t len = src.size();
  656. for (size_t i = 0; i < len; i++)
  657. {
  658. src.at(i) = tolower(src.at(i));
  659. }
  660. return src;
  661. }