filehelp.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  1. #include "StdAfx.h"
  2. #include "filehelp.h"
  3. #include <shlwapi.h>
  4. // 排序和乱序使用stl;
  5. #include <cstdlib>
  6. #include <ctime>
  7. #include <algorithm>
  8. int myrandom(int i) { return std::rand() % i; }
  9. filehelpImpl::filehelpImpl(void)
  10. {
  11. }
  12. filehelpImpl::~filehelpImpl(void)
  13. {
  14. }
  15. /************************************************************************/
  16. /* 函数:[2/21/2017 Jeff];
  17. /* 描述:;
  18. /* 参数:;
  19. /* [IN] :;
  20. /* [OUT] :;
  21. /* [IN/OUT] :;
  22. /* 返回:void;
  23. /* 注意:;
  24. /* 示例:;
  25. /*
  26. /* 修改:;
  27. /* 日期:;
  28. /* 内容:;
  29. /************************************************************************/
  30. void filehelpImpl::random(IN STR_VEC& vtContent, IN BOOL bSort /* = TRUE */)
  31. {
  32. if (bSort)
  33. {//排序;
  34. std::sort(vtContent.begin(), vtContent.end());
  35. }
  36. else
  37. {//乱序;
  38. //设置随即数生成器的种子;
  39. std::srand(unsigned(std::time(0)));
  40. std::random_shuffle(vtContent.begin(), vtContent.end(), myrandom);
  41. }
  42. }
  43. /************************************************************************/
  44. /* 函数:[2/21/2017 Jeff];
  45. /* 描述:;
  46. /* 参数:;
  47. /* [IN] :;
  48. /* [OUT] :;
  49. /* [IN/OUT] :;
  50. /* 返回:void;
  51. /* 注意:;
  52. /* 示例:;
  53. /*
  54. /* 修改:;
  55. /* 日期:;
  56. /* 内容:;
  57. /************************************************************************/
  58. void filehelpImpl::split(OUT vector<TString>& vtSplit, IN const TString str, IN const TString strSplit)
  59. {
  60. if (str.size() == 0 || strSplit.size() == 0)
  61. return;
  62. INT nIndex = 0;
  63. vtSplit.clear();
  64. TString strtmp = str;
  65. TString strtmp2;
  66. do
  67. {
  68. if (TString::npos != (nIndex = strtmp.find_first_of(strSplit)))
  69. {
  70. strtmp2 = strtmp.substr(0, nIndex);
  71. if (strtmp2.size())vtSplit.push_back(strtmp2);
  72. strtmp = strtmp.substr(nIndex + strSplit.size());
  73. }
  74. } while (strtmp.find_first_of(strSplit) != TString::npos);
  75. if (strtmp.size())
  76. vtSplit.push_back(strtmp);
  77. }
  78. /************************************************************************/
  79. /* 函数:[2/19/2017 Jeff];
  80. /* 描述:保留指定的扩展名文件;
  81. /* 参数:;
  82. /* [IN] keepExt:要保留的扩展名;
  83. /* [OUT] vtfiles:要提取保留扩展名的文件数组;
  84. /* [IN/OUT] :;
  85. /* 返回:void;
  86. /* 注意:;
  87. /* 示例:;
  88. /*
  89. /* 修改:;
  90. /* 日期:;
  91. /* 内容:;
  92. /************************************************************************/
  93. void filehelpImpl::keepdownbyext(IN const TString &keepExt, IN STR_VEC &vtfiles)
  94. {
  95. if (keepExt.find(_T("*.*")) != TString::npos) return;
  96. if (vtfiles.size() == 0) return;
  97. // 获取复制扩展名;
  98. int nIndex = 0;
  99. TString strtmp;
  100. TString strRemainExt(keepExt);
  101. strRemainExt.append(_T("|"));
  102. STR_VEC vtRemainExt;
  103. // 将所有扩展名解析到数组里;
  104. do
  105. {
  106. nIndex = strRemainExt.find(_T('|'));
  107. if (nIndex != TString::npos)
  108. {
  109. strtmp = strRemainExt.substr(0, nIndex);
  110. strRemainExt = strRemainExt.substr(nIndex + 1);
  111. if (strtmp.compare(_T("*.*")))
  112. vtRemainExt.push_back(strtmp);
  113. }
  114. } while (strRemainExt.find(_T('|')) != TString::npos);
  115. STR_VEC vtresult;
  116. // 过滤非复制扩展名的文件,同时去掉缩略图,保留指定复制扩展名的文件;
  117. for (STR_VEC::iterator itExt = vtRemainExt.begin(); itExt != vtRemainExt.end(); itExt++)
  118. {
  119. for (STR_VEC::iterator it = vtfiles.begin(); it != vtfiles.end();)
  120. {
  121. if (match(itExt->substr(1), it->c_str()))
  122. {
  123. vtresult.push_back(*it);
  124. it = vtfiles.erase(it);
  125. }
  126. else
  127. it++;
  128. }
  129. }
  130. vtfiles.clear();
  131. for ( STR_VEC::iterator it = vtresult.begin(); it != vtresult.end(); it++ )
  132. {
  133. vtfiles.push_back(*it);
  134. }
  135. }
  136. void filehelpImpl::keepdownbyext(IN const TString &keepExt, IN const STR_VEC &vtfiles, OUT STR_VEC &vtresult)
  137. {
  138. if (keepExt.find(_T("*.*")) != TString::npos) return;
  139. if (vtfiles.size() == 0) return;
  140. // 获取复制扩展名;
  141. int nIndex = 0;
  142. TString strtmp;
  143. TString strRemainExt(keepExt);
  144. strRemainExt.append(_T("|"));
  145. STR_VEC vtRemainExt;
  146. // 将所有扩展名解析到数组里;
  147. do
  148. {
  149. nIndex = strRemainExt.find(_T('|'));
  150. if (nIndex != TString::npos)
  151. {
  152. strtmp = strRemainExt.substr(0, nIndex);
  153. strRemainExt = strRemainExt.substr(nIndex + 1);
  154. if (strtmp.compare(_T("*.*")))
  155. vtRemainExt.push_back(strtmp);
  156. }
  157. } while (strRemainExt.find(_T('|')) != TString::npos);
  158. #if 0
  159. // 过滤非复制扩展名的文件,同时去掉缩略图,保留指定复制扩展名的文件;
  160. for (STR_VEC::iterator itExt = vtRemainExt.begin(); itExt != vtRemainExt.end(); itExt++)
  161. {
  162. for (STR_VEC::const_iterator it = vtfiles.begin(); it != vtfiles.end(); it++)
  163. {
  164. if (match(itExt->substr(1), it->c_str()))
  165. {
  166. vtresult.push_back(*it);
  167. }
  168. }
  169. }
  170. #else
  171. STR_VEC vt_files;
  172. for (STR_VEC::const_iterator it = vtfiles.begin(); it != vtfiles.end(); it++ )
  173. {// 不能直接用vtresult来复制,因为如果vtresult不为空的情况下,会有异常出现;
  174. vt_files.push_back(*it);
  175. }
  176. for (STR_VEC::iterator itExt = vtRemainExt.begin(); itExt != vtRemainExt.end(); itExt++)
  177. {
  178. for (STR_VEC::iterator it = vt_files.begin(); it != vt_files.end(); )
  179. {
  180. if (match(itExt->substr(1), it->c_str()))
  181. {
  182. vtresult.push_back(*it);
  183. it = vt_files.erase(it);
  184. }
  185. else
  186. it++;
  187. }
  188. }
  189. #endif
  190. }
  191. /************************************************************************/
  192. /* 函数:keepoutext[2/19/2017 Jeff];
  193. /* 描述:移除指定扩展名的文件;
  194. /* 参数:;
  195. /* [IN] :;
  196. /* [OUT] :;
  197. /* [IN/OUT] :;
  198. /* 返回:void;
  199. /* 注意:;
  200. /* 示例:;
  201. /*
  202. /* 修改:;
  203. /* 日期:;
  204. /* 内容:;
  205. /************************************************************************/
  206. void filehelpImpl::keepoutbyext(IN const TString &removeext, IN STR_VEC &vtfiles)
  207. {
  208. if (removeext.find(_T("*.*")) != TString::npos) return;
  209. if (vtfiles.size() == 0) return;
  210. // 获取复制扩展名;
  211. int nIndex = 0;
  212. TString strtmp;
  213. TString strRemoveExt(removeext);
  214. strRemoveExt.append(_T("|"));
  215. STR_VEC vtRemoveExt;
  216. // 将所有扩展名解析到数组里;
  217. do
  218. {
  219. nIndex = strRemoveExt.find(_T('|'));
  220. if (nIndex != TString::npos)
  221. {
  222. strtmp = strRemoveExt.substr(0, nIndex);
  223. strRemoveExt = strRemoveExt.substr(nIndex + 1);
  224. if (strtmp.compare(_T("*.*")))
  225. vtRemoveExt.push_back(strtmp);
  226. }
  227. } while (strRemoveExt.find(_T('|')) != TString::npos);
  228. // 过滤非复制扩展名的文件,同时去掉缩略图,保留指定复制扩展名的文件;
  229. for (STR_VEC::iterator itExt = vtRemoveExt.begin(); itExt != vtRemoveExt.end(); itExt++)
  230. {
  231. for (STR_VEC::iterator it = vtfiles.begin(); it != vtfiles.end();)
  232. {
  233. if (match(itExt->substr(1), it->c_str()))
  234. {
  235. it = vtfiles.erase(it);
  236. }
  237. else
  238. it++;
  239. }
  240. }
  241. }
  242. void filehelpImpl::keepoutbyext(IN const TString &removeext, IN const STR_VEC &vtfiles, OUT STR_VEC &vtresult)
  243. {
  244. if (removeext.find(_T("*.*")) != TString::npos) return;
  245. if (vtfiles.size() == 0) return;
  246. // 获取复制扩展名;
  247. int nIndex = 0;
  248. TString strtmp;
  249. TString strRemoveExt(removeext);
  250. strRemoveExt.append(_T("|"));
  251. STR_VEC vtRemoveExt;
  252. // 将所有扩展名解析到数组里;
  253. do
  254. {
  255. nIndex = strRemoveExt.find(_T('|'));
  256. if (nIndex != TString::npos)
  257. {
  258. strtmp = strRemoveExt.substr(0, nIndex);
  259. strRemoveExt = strRemoveExt.substr(nIndex + 1);
  260. if (strtmp.compare(_T("*.*")))
  261. vtRemoveExt.push_back(strtmp);
  262. }
  263. } while (strRemoveExt.find(_T('|')) != TString::npos);
  264. // 复制到新容器中;
  265. STR_VEC vt_files;
  266. for (STR_VEC::const_iterator it = vtfiles.begin(); it != vtfiles.end(); it++ )
  267. {// 不能直接用vtresult来复制,因为如果vtresult不为空的情况下,会有异常出现;
  268. vt_files.push_back(*it);
  269. }
  270. // 过滤非复制扩展名的文件,同时去掉缩略图,保留指定复制扩展名的文件;
  271. for (STR_VEC::iterator itExt = vtRemoveExt.begin(); itExt != vtRemoveExt.end(); itExt++)
  272. {
  273. for (STR_VEC::iterator it = vt_files.begin(); it != vt_files.end();)
  274. {
  275. if (match(itExt->substr(1), it->c_str()))
  276. {
  277. vtresult.push_back(*it);
  278. it = vt_files.erase(it);
  279. }
  280. else
  281. it++;
  282. }
  283. }
  284. }
  285. void filehelpImpl::keepdowbyname(IN const STR_VEC &vtnames)
  286. {
  287. if ( m_pvtfiles == NULL || m_pvtnames == &vtnames )
  288. return;
  289. INT nIndex = 0;
  290. STR_VEC vt_result_files;
  291. if ( m_pvtnames == NULL)
  292. {
  293. STR_VEC::const_iterator it_name = vtnames.begin();
  294. for ( ; it_name != vtnames.end(); it_name++ )
  295. {
  296. STR_VEC::iterator it_file = m_pvtfiles->begin();
  297. for ( ; it_file != m_pvtfiles->end(); )
  298. {
  299. nIndex = it_file->find_last_of(_T('\\'));
  300. if (TString::npos != nIndex)
  301. {
  302. if (_tcsicmp(it_file->substr(nIndex + 1).c_str(), it_name->c_str()) == 0)
  303. {
  304. vt_result_files.push_back(*it_file);
  305. it_file = m_pvtfiles->erase(it_file);
  306. continue;
  307. }
  308. }
  309. it_file++;
  310. }
  311. }
  312. m_pvtfiles->clear();
  313. for ( STR_VEC::iterator it = vt_result_files.begin(); it != vt_result_files.end(); it++ )
  314. {
  315. m_pvtfiles->push_back(*it);
  316. }
  317. }
  318. else
  319. {
  320. if ( m_pvtnames->size() != m_pvtfiles->size() )
  321. return;
  322. STR_VEC::iterator it_name;
  323. STR_VEC::iterator it_file;
  324. STR_VEC vt_result_names;
  325. for ( STR_VEC::const_iterator it = vtnames.begin(); it != vtnames.end(); it++ )
  326. {
  327. it_name = m_pvtnames->begin();
  328. it_file = m_pvtfiles->begin();
  329. for ( ; it_file != m_pvtfiles->end(), it_name != m_pvtnames->end();)
  330. {
  331. if ( _tcsicmp(it_name->c_str(), it->c_str()) == 0 )
  332. {
  333. vt_result_files.push_back(*it_file);
  334. vt_result_names.push_back(*it_name);
  335. it_file = m_pvtfiles->erase(it_file);
  336. it_name = m_pvtnames->erase(it_name);
  337. continue;
  338. }
  339. it_file++;
  340. it_name++;
  341. }
  342. }
  343. m_pvtfiles->clear();
  344. m_pvtnames->clear();
  345. it_name = vt_result_names.begin();
  346. it_file = vt_result_files.begin();
  347. for ( ; it_file != vt_result_files.end(), it_name != vt_result_names.end(); it_file++, it_name++ )
  348. {
  349. m_pvtfiles->push_back(*it_file);
  350. m_pvtnames->push_back(*it_name);
  351. }
  352. }
  353. }
  354. void filehelpImpl::keepdowbyname(IN const STR_VEC &vtnames, IN STR_VEC &vtfiles)
  355. {
  356. if ( vtnames.size() == 0 )
  357. return;
  358. INT nIndex = 0;
  359. STR_VEC vt_result_files;
  360. STR_VEC::const_iterator it_name = vtnames.begin();
  361. for ( ; it_name != vtnames.end(); it_name++ )
  362. {
  363. STR_VEC::iterator it_file = vtfiles.begin();
  364. for ( ; it_file != vtfiles.end(); )
  365. {
  366. nIndex = it_file->find_last_of(_T('\\'));
  367. if (TString::npos != nIndex)
  368. {
  369. if (_tcsicmp(it_file->substr(nIndex + 1).c_str(), it_name->c_str()) == 0)
  370. {
  371. vt_result_files.push_back(*it_file);
  372. it_file = vtfiles.erase(it_file);
  373. continue;
  374. }
  375. }
  376. it_file++;
  377. }
  378. }
  379. vtfiles.clear();
  380. for ( STR_VEC::iterator it = vt_result_files.begin(); it != vt_result_files.end(); it++ )
  381. {
  382. vtfiles.push_back(*it);
  383. }
  384. }
  385. void filehelpImpl::keepdowbyname(IN const STR_VEC &vtnames, IN const STR_VEC &vtfiles, OUT STR_VEC &vt_result)
  386. {
  387. if ( vtnames.size() == 0 )
  388. return;
  389. INT nIndex = 0;
  390. STR_VEC::const_iterator it_name = vtnames.begin();
  391. for ( ; it_name != vtnames.end(); it_name++ )
  392. {
  393. STR_VEC::const_iterator it_file = vtfiles.begin();
  394. for ( ; it_file != vtfiles.end(); it_file++)
  395. {
  396. nIndex = it_file->find_last_of(_T('\\'));
  397. if (TString::npos != nIndex)
  398. {
  399. if (_tcsicmp(it_file->substr(nIndex + 1).c_str(), it_name->c_str()) == 0)
  400. {
  401. vt_result.push_back(*it_file);
  402. }
  403. }
  404. }
  405. }
  406. }
  407. void filehelpImpl::keepdowbyname_noext(IN const STR_VEC &vtnames)
  408. {
  409. if ( m_pvtfiles == NULL || m_pvtnames == &vtnames )
  410. return;
  411. INT nIndex = 0;
  412. STR_VEC vt_result_files;
  413. if ( m_pvtnames == NULL)
  414. {
  415. INT nIndex2 = 0;
  416. STR_VEC::const_iterator it_name = vtnames.begin();
  417. for ( ; it_name != vtnames.end(); it_name++ )
  418. {
  419. STR_VEC::iterator it_file = m_pvtfiles->begin();
  420. for ( ; it_file != m_pvtfiles->end(); )
  421. {
  422. nIndex = it_file->find_last_of(_T('\\'));
  423. nIndex2 = it_file->find_last_of(_T('.'));
  424. if (TString::npos != nIndex && TString::npos != nIndex2 && nIndex > nIndex2 )
  425. {
  426. if ( _tcsicmp(it_file->substr(nIndex+1,nIndex2 - nIndex - 1).c_str(), it_name->c_str()) == 0)
  427. {
  428. vt_result_files.push_back(*it_file);
  429. it_file = m_pvtfiles->erase(it_file);
  430. continue;
  431. }
  432. }
  433. it_file++;
  434. }
  435. }
  436. m_pvtfiles->clear();
  437. for ( STR_VEC::iterator it = vt_result_files.begin(); it != vt_result_files.end(); it++ )
  438. {
  439. m_pvtfiles->push_back(*it);
  440. }
  441. }
  442. else
  443. {
  444. if ( m_pvtnames->size() != m_pvtfiles->size() )
  445. return;
  446. STR_VEC::iterator it_name;
  447. STR_VEC::iterator it_file;
  448. STR_VEC vt_result_names;
  449. for ( STR_VEC::const_iterator it = vtnames.begin(); it != vtnames.end(); it++ )
  450. {
  451. it_name = m_pvtnames->begin();
  452. it_file = m_pvtfiles->begin();
  453. for ( ; it_file != m_pvtfiles->end(), it_name != m_pvtnames->end();)
  454. {
  455. if ( TString::npos != ( nIndex = it_name->find_last_of(_T('.'))))
  456. {
  457. if ( _tcsicmp(it_name->substr(0, nIndex).c_str(), it->c_str()) == 0 )
  458. {
  459. vt_result_files.push_back(*it_file);
  460. vt_result_names.push_back(*it_name);
  461. it_file = m_pvtfiles->erase(it_file);
  462. it_name = m_pvtnames->erase(it_name);
  463. continue;
  464. }
  465. }
  466. it_file++;
  467. it_name++;
  468. }
  469. }
  470. m_pvtfiles->clear();
  471. m_pvtnames->clear();
  472. it_name = vt_result_names.begin();
  473. it_file = vt_result_files.begin();
  474. for ( ; it_file != vt_result_files.end(), it_name != vt_result_names.end(); it_file++, it_name++ )
  475. {
  476. m_pvtfiles->push_back(*it_file);
  477. m_pvtnames->push_back(*it_name);
  478. }
  479. }
  480. }
  481. void filehelpImpl::keepdowbyname_noext(IN const STR_VEC &vtnames, IN STR_VEC &vtfiles)
  482. {
  483. if ( vtnames.size() == 0 )
  484. return;
  485. INT nIndex = 0;
  486. TString strName;
  487. STR_VEC vt_result_files;
  488. STR_VEC::const_iterator it_name = vtnames.begin();
  489. for ( ; it_name != vtnames.end(); it_name++ )
  490. {
  491. STR_VEC::iterator it_file = vtfiles.begin();
  492. for ( ; it_file != vtfiles.end(); )
  493. {
  494. nIndex = it_file->find_last_of(_T('\\'));
  495. if (TString::npos != nIndex)
  496. {
  497. strName = it_file->substr(nIndex+1);
  498. if ( TString::npos != ( nIndex = strName.find_last_of(_T('.'))))
  499. {
  500. if ( _tcsicmp(strName.substr(0,nIndex).c_str(), it_name->c_str()) == 0)
  501. {
  502. vt_result_files.push_back(*it_file);
  503. it_file = vtfiles.erase(it_file);
  504. continue;
  505. }
  506. }
  507. }
  508. it_file++;
  509. }
  510. }
  511. vtfiles.clear();
  512. for ( STR_VEC::iterator it = vt_result_files.begin(); it != vt_result_files.end(); it++ )
  513. {
  514. vtfiles.push_back(*it);
  515. }
  516. }
  517. void filehelpImpl::keepdowbyname_noext(IN const STR_VEC &vtnames, IN const STR_VEC &vtfiles, OUT STR_VEC &vt_result)
  518. {
  519. if ( vtnames.size() == 0 )
  520. return;
  521. INT nIndex = 0;
  522. TString strName;
  523. STR_VEC::const_iterator it_name = vtnames.begin();
  524. for ( ; it_name != vtnames.end(); it_name++ )
  525. {
  526. STR_VEC::const_iterator it_file = vtfiles.begin();
  527. for ( ; it_file != vtfiles.end(); it_file++)
  528. {
  529. nIndex = it_file->find_last_of(_T('\\'));
  530. if (TString::npos != nIndex)
  531. {
  532. strName = it_file->substr(nIndex+1);
  533. if ( TString::npos != ( nIndex = strName.find_last_of(_T('.'))))
  534. {
  535. if ( _tcsicmp(strName.substr(0,nIndex).c_str(), it_name->c_str()) == 0)
  536. {
  537. vt_result.push_back(*it_file);
  538. }
  539. }
  540. }
  541. }
  542. }
  543. }
  544. void filehelpImpl::subgroupExt(IN const TString &ext1, IN STR_VEC &vt1, IN const TString &ext2, IN STR_VEC &vt2)
  545. {
  546. // if (ext1.find(_T("*.*")) != TString::npos ) return;
  547. // if ( !iscorrectext(ext1) || vt1.size() == 0 ) return;
  548. //
  549. // // 获取复制扩展名;
  550. // int nIndex = 0;
  551. // TString strtmp;
  552. // TString strExt1(ext1);
  553. // strExt1.append(_T("|"));
  554. // STR_VEC vtExt1;
  555. //
  556. // // 将所有扩展名解析到数组里;
  557. // do
  558. // {
  559. // nIndex = strExt1.find(_T('|'));
  560. // if ( nIndex != TString::npos )
  561. // {
  562. // strtmp = strExt1.substr(0,nIndex);
  563. // strExt1 = strExt1.substr(nIndex+1);
  564. //
  565. // if(strtmp.compare(_T("*.*")))
  566. // vtExt1.push_back(strtmp);
  567. // }
  568. // } while ( strExt1.find(_T('|')) != TString::npos );
  569. }
  570. /************************************************************************/
  571. /* 函数:filterbyname[2/21/2017 Jeff];
  572. /* 描述:根据有后缀的文件名(如:001.jpg)来过虑文件;;
  573. /* 参数:;
  574. /* [IN] vtfiles:要被过滤的文件路径数组;
  575. /* [IN] vtnames:要过滤的文件名,每个文件名都有后缀,如:001.jpg;
  576. /* 返回:void;
  577. /* 注意:;
  578. /* 示例:;
  579. /*
  580. /* 修改:;
  581. /* 日期:;
  582. /* 内容:;
  583. /************************************************************************/
  584. void filehelpImpl::filterbyname(IN STR_VEC &vtfiles, IN const STR_VEC &vtnames)
  585. {// 再按名称过滤;
  586. INT nIndex = 0;
  587. TString strName;
  588. for ( STR_VEC::const_iterator it_name = vtnames.begin(); it_name != vtnames.end(); it_name++ )
  589. {
  590. for ( STR_VEC::iterator it_file = vtfiles.begin(); it_file != vtfiles.end(); )
  591. {
  592. nIndex = it_file->find_last_of(_T('\\'));
  593. if (TString::npos != nIndex)
  594. {
  595. strName = it_file->substr(nIndex+1);
  596. if ( _tcsicmp(strName.c_str(), it_name->c_str()) == 0 )
  597. {
  598. it_file = vtfiles.erase(it_file);
  599. continue;
  600. }
  601. }
  602. it_file++;
  603. }
  604. }
  605. }
  606. void filehelpImpl::filterbyname(IN const STR_VEC &vtnames)
  607. {
  608. if ( m_pvtfiles == NULL || m_pvtnames == &vtnames )
  609. return;
  610. INT nIndex = 0;
  611. TString strName;
  612. if ( m_pvtnames == NULL)
  613. {
  614. STR_VEC::const_iterator it_name = vtnames.begin();
  615. for ( ; it_name != vtnames.end(); it_name++ )
  616. {
  617. STR_VEC::iterator it_file = m_pvtfiles->begin();
  618. for ( ; it_file != m_pvtfiles->end(); )
  619. {
  620. nIndex = it_file->find_last_of(_T('\\'));
  621. if (TString::npos != nIndex)
  622. {
  623. strName = it_file->substr(nIndex+1);
  624. if ( _tcsicmp(strName.c_str(), it_name->c_str()) == 0)
  625. {
  626. it_file = m_pvtfiles->erase(it_file);
  627. continue;
  628. }
  629. }
  630. it_file++;
  631. }
  632. }
  633. }
  634. else
  635. {
  636. if ( m_pvtnames->size() != m_pvtfiles->size() )
  637. return;
  638. for ( STR_VEC::const_iterator it = vtnames.begin(); it != vtnames.end(); it++ )
  639. {
  640. STR_VEC::iterator it_name = m_pvtnames->begin();
  641. STR_VEC::iterator it_file = m_pvtfiles->begin();
  642. for ( ; it_file != m_pvtfiles->end(), it_name != m_pvtnames->end();)
  643. {
  644. if ( _tcsicmp(it_name->c_str(), it->c_str()) == 0 )
  645. {
  646. it_file = m_pvtfiles->erase(it_file);
  647. it_name = m_pvtnames->erase(it_name);
  648. continue;
  649. }
  650. it_file++;
  651. it_name++;
  652. }
  653. }
  654. }
  655. }
  656. // 根据无后缀的文件名(如:001)来过虑文件;
  657. void filehelpImpl::filterbyname_noext(IN STR_VEC &vtfiles, IN const STR_VEC &vtnames)
  658. {// 再按名称过滤;
  659. INT nIndex = 0;
  660. INT nIndex2 = 0;
  661. TString strName;
  662. for ( STR_VEC::iterator it_file = vtfiles.begin(); it_file != vtfiles.end(); )
  663. {
  664. nIndex = it_file->find_last_of(_T('\\'));
  665. nIndex2 = it_file->find_last_of(_T('.'));
  666. for ( STR_VEC::const_iterator it_name = vtnames.begin(); it_name != vtnames.end(); it_name++ )
  667. {
  668. if (TString::npos != nIndex && TString::npos != nIndex2 && nIndex2 > nIndex)
  669. {
  670. if ( _tcsicmp(it_file->substr(nIndex+1,nIndex2-nIndex-1).c_str(), it_name->c_str()) == 0)
  671. {
  672. it_file = vtfiles.erase(it_file);
  673. continue;
  674. }
  675. }
  676. it_file++;
  677. }
  678. }
  679. }
  680. void filehelpImpl::filterbyname_noext(IN const STR_VEC &vtnames)
  681. {
  682. if ( m_pvtfiles == NULL || m_pvtnames == &vtnames )
  683. return;
  684. INT nIndex = 0;
  685. TString strName;
  686. if ( m_pvtnames == NULL )
  687. {
  688. INT nIndex2 = 0;
  689. STR_VEC::iterator it_file = m_pvtfiles->begin();
  690. for ( ; it_file != m_pvtfiles->end(); )
  691. {
  692. nIndex = it_file->find_last_of(_T('\\'));
  693. nIndex2 = it_file->find_last_of(_T('.'));
  694. for ( STR_VEC::const_iterator it_name = vtnames.begin(); it_name != vtnames.end(); it_name++ )
  695. {
  696. if (TString::npos != nIndex && TString::npos != nIndex2 && nIndex2 > nIndex)
  697. {
  698. if ( _tcsicmp(it_file->substr(nIndex+1,nIndex2-nIndex-1).c_str(), it_name->c_str()) == 0 )
  699. {
  700. it_file = m_pvtfiles->erase(it_file);
  701. continue;
  702. }
  703. }
  704. it_file++;
  705. }
  706. }
  707. }
  708. else
  709. {
  710. if (m_pvtnames->size() != m_pvtfiles->size())
  711. return;
  712. for ( STR_VEC::const_iterator it = vtnames.begin(); it != vtnames.end(); it++ )
  713. {
  714. STR_VEC::iterator it_name = m_pvtnames->begin();
  715. STR_VEC::iterator it_file = m_pvtfiles->begin();
  716. for ( ; it_file != m_pvtfiles->end(), it_name != m_pvtnames->end();)
  717. {
  718. if ( TString::npos != (nIndex = it_name->find_last_of(_T('.'))) )
  719. {
  720. if ( _tcsicmp(it_name->substr(0, nIndex).c_str(), it->c_str()) == 0 )
  721. {
  722. it_file = m_pvtfiles->erase(it_file);
  723. it_name = m_pvtnames->erase(it_name);
  724. continue;
  725. }
  726. it_file++;
  727. it_name++;
  728. }
  729. }
  730. }
  731. }
  732. }
  733. //////////////////////////////////////////////////////////////////////////
  734. BOOL filehelpImpl::getall(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN OUT STR_VEC *pvtfiles, IN OUT STR_VEC *pvtnames, IN OUT STR_VEC *pvtfolders)
  735. {
  736. // 路径不存在;
  737. if (!PathFileExists(lpfolder))
  738. return FALSE;
  739. // 指针空;
  740. if (!pvtfiles || !pvtnames || !pvtfolders ) return FALSE;
  741. m_pvtfiles = pvtfiles;
  742. m_pvtnames = pvtnames;
  743. m_pvtfolders = pvtfolders;
  744. #if USE_IMGEXT
  745. // 判断扩展名有效性;
  746. if (!iscorrectext(lpfindext)) return FALSE;
  747. #endif
  748. findall(lpfolder);
  749. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  750. {// 需要保留指定后缀;
  751. keepdownbyext(lpfindext, *pvtfiles);
  752. keepdownbyext(lpfindext, *pvtnames);
  753. }
  754. return TRUE;
  755. }
  756. BOOL filehelpImpl::getsubfolder(IN LPCTSTR lpfolder, IN STR_VEC *pvtfolders)
  757. {
  758. // 路径不存在;
  759. if (!PathFileExists(lpfolder))
  760. return FALSE;
  761. // 指针空;
  762. if (pvtfolders == NULL) return FALSE;
  763. m_pvtfolders = pvtfolders;
  764. findsubfolder(lpfolder);
  765. return TRUE;
  766. }
  767. BOOL filehelpImpl::getallsubfolder(IN LPCTSTR lpfolder, IN STR_VEC *pvtfolders)
  768. {
  769. // 路径不存在;
  770. if (!PathFileExists(lpfolder))
  771. return FALSE;
  772. // 指针空;
  773. if (pvtfolders == NULL) return FALSE;
  774. m_pvtfolders = pvtfolders;
  775. findallsubfolder(lpfolder);
  776. return TRUE;
  777. }
  778. //////////////////////////////////////////////////////////////////////////
  779. BOOL filehelpImpl::getfiles_findin_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtfiles)
  780. {
  781. // 路径不存在;
  782. if (!PathFileExists(lpfolder))
  783. return FALSE;
  784. // 指针空;
  785. if (pvtfiles == NULL) return FALSE;
  786. m_pvtfiles = pvtfiles;
  787. #if USE_IMGEXT
  788. // 判断扩展名有效性;
  789. if (!iscorrectext(lpfindext)) return FALSE;
  790. #endif
  791. findfiles_findin_subfolder(lpfolder);
  792. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  793. {// 需要保留指定后缀;
  794. keepdownbyext(lpfindext, *pvtfiles);
  795. }
  796. return TRUE;
  797. }
  798. BOOL filehelpImpl::getfiles_findout_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtfiles)
  799. {
  800. // 路径不存在;
  801. if (!PathFileExists(lpfolder))
  802. return FALSE;
  803. // 指针空;
  804. if (pvtfiles == NULL) return FALSE;
  805. m_pvtfiles = pvtfiles;
  806. #if USE_IMGEXT
  807. // 判断扩展名有效性;
  808. if (!iscorrectext(lpfindext)) return FALSE;
  809. #endif
  810. findfiles_findout_subfolder(lpfolder);
  811. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  812. {// 需要保留指定后缀;
  813. keepdownbyext(lpfindext, *pvtfiles);
  814. }
  815. return TRUE;
  816. }
  817. BOOL filehelpImpl::getfiles_within_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtfiles, IN STR_VEC *pvtfolders)
  818. {
  819. // 路径不存在;
  820. if (!PathFileExists(lpfolder))
  821. return FALSE;
  822. // 指针空;
  823. if (pvtfiles == NULL) return FALSE;
  824. m_pvtfiles = pvtfiles;
  825. m_pvtfolders = pvtfolders;
  826. #if USE_IMGEXT
  827. // 判断扩展名有效性;
  828. if (!iscorrectext(lpfindext)) return FALSE;
  829. #endif
  830. findfiles_within_subfolder(lpfolder);
  831. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  832. {// 需要保留指定后缀;
  833. keepdownbyext(lpfindext, *pvtfiles);
  834. }
  835. return TRUE;
  836. }
  837. //////////////////////////////////////////////////////////////////////////
  838. BOOL filehelpImpl::getfiles_bynames_findin_subfolder( IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC &vtnames, IN STR_VEC *pvtfiles )
  839. {
  840. // 路径不存在;
  841. if (!PathFileExists(lpfolder))
  842. return FALSE;
  843. // 指针空;
  844. if (pvtfiles == NULL) return FALSE;
  845. m_pvtfiles = pvtfiles;
  846. #if USE_IMGEXT
  847. // 判断扩展名有效性;
  848. if (!iscorrectext(lpfindext)) return FALSE;
  849. #endif
  850. findfiles_findin_subfolder(lpfolder);
  851. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  852. {// 需要保留指定后缀;
  853. keepdownbyext(lpfindext, *pvtfiles);
  854. }
  855. // 再按名称过滤;
  856. filterbyname(*pvtfiles, vtnames);
  857. return TRUE;
  858. }
  859. BOOL filehelpImpl::getfiles_bynames_findout_subfolder( IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC &vtnames, IN OUT STR_VEC *pvtfiles )
  860. {
  861. // 路径不存在;
  862. if (!PathFileExists(lpfolder))
  863. return FALSE;
  864. // 指针空;
  865. if (pvtfiles == NULL) return FALSE;
  866. m_pvtfiles = pvtfiles;
  867. #if USE_IMGEXT
  868. // 判断扩展名有效性;
  869. if (!iscorrectext(lpfindext)) return FALSE;
  870. #endif
  871. findfiles_findout_subfolder(lpfolder);
  872. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  873. {// 需要保留指定后缀;
  874. keepdownbyext(lpfindext, *pvtfiles);
  875. }
  876. // 再按名称过滤;
  877. filterbyname(*pvtfiles, vtnames);
  878. return TRUE;
  879. }
  880. BOOL filehelpImpl::getfiles_bynames_within_subfolder( IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC &vtnames, IN STR_VEC *pvtfiles, IN STR_VEC *pvtfolders )
  881. {
  882. // 路径不存在;
  883. if (!PathFileExists(lpfolder))
  884. return FALSE;
  885. // 指针空;
  886. if (pvtfiles == NULL) return FALSE;
  887. m_pvtfiles = pvtfiles;
  888. m_pvtfolders = pvtfolders;
  889. #if USE_IMGEXT
  890. // 判断扩展名有效性;
  891. if (!iscorrectext(lpfindext)) return FALSE;
  892. #endif
  893. findfiles_within_subfolder(lpfolder);
  894. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  895. {// 需要保留指定后缀;
  896. keepdownbyext(lpfindext, *pvtfiles);
  897. }
  898. // 再按名称过滤;
  899. filterbyname(*pvtfiles, vtnames);
  900. return TRUE;
  901. }
  902. //////////////////////////////////////////////////////////////////////////
  903. BOOL filehelpImpl::getnames_findin_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtnames)
  904. {
  905. // 路径不存在;
  906. if (!PathFileExists(lpfolder))
  907. return FALSE;
  908. // 指针空;
  909. if (pvtnames == NULL) return FALSE;
  910. #if USE_IMGEXT
  911. // 判断扩展名有效性;
  912. if (!iscorrectext(lpfindext)) return FALSE;
  913. #endif
  914. m_pvtnames = pvtnames;
  915. findnames_findin_subfolder(lpfolder);
  916. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  917. {// 需要保留指定后缀;
  918. keepdownbyext(lpfindext, *m_pvtnames);
  919. }
  920. return TRUE;
  921. }
  922. BOOL filehelpImpl::getnames_findout_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtnames)
  923. {
  924. // 路径不存在;
  925. if (!PathFileExists(lpfolder))
  926. return FALSE;
  927. // 指针空;
  928. if (pvtnames == NULL) return FALSE;
  929. #if USE_IMGEXT
  930. // 判断扩展名有效性;
  931. if (!iscorrectext(lpfindext)) return FALSE;
  932. #endif
  933. m_pvtnames = pvtnames;
  934. findnames_findout_subfolder(lpfolder);
  935. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  936. {// 需要保留指定后缀;
  937. keepdownbyext(lpfindext, *m_pvtnames);
  938. }
  939. return TRUE;
  940. }
  941. BOOL filehelpImpl::getnames_within_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtnames, IN STR_VEC *pvtfolders)
  942. {
  943. // 路径不存在;
  944. if (!PathFileExists(lpfolder))
  945. return FALSE;
  946. // 指针空;
  947. if (pvtnames == NULL || pvtfolders == NULL )
  948. return FALSE;
  949. m_pvtfolders = pvtfolders;
  950. #if USE_IMGEXT
  951. // 判断扩展名有效性;
  952. if (!iscorrectext(lpfindext)) return FALSE;
  953. #endif
  954. m_pvtnames = pvtnames;
  955. m_pvtfolders = pvtfolders;
  956. findnames_within_subfolder(lpfolder);
  957. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  958. {// 需要保留指定后缀;
  959. keepdownbyext(lpfindext, *m_pvtnames);
  960. }
  961. return TRUE;
  962. }
  963. //////////////////////////////////////////////////////////////////////////
  964. BOOL filehelpImpl::getfilesnames_findin_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtfiles, IN STR_VEC *pvtnames)
  965. {
  966. // 路径不存在;
  967. if (!PathFileExists(lpfolder))
  968. return FALSE;
  969. // 指针空;
  970. if (pvtnames || !pvtnames) return FALSE;
  971. m_pvtfiles = pvtfiles;
  972. m_pvtnames = pvtnames;
  973. #if USE_IMGEXT
  974. // 判断扩展名有效性;
  975. if (!iscorrectext(lpfindext)) return FALSE;
  976. #endif
  977. findfilesnames_findin_subfolder(lpfolder);
  978. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  979. {// 需要保留指定后缀;
  980. keepdownbyext(lpfindext, *pvtnames);
  981. keepdownbyext(lpfindext, *pvtfiles);
  982. }
  983. return TRUE;
  984. }
  985. BOOL filehelpImpl::getfilesnames_findout_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtfiles, IN STR_VEC *pvtnames)
  986. {
  987. // 路径不存在;
  988. if (!PathFileExists(lpfolder))
  989. return FALSE;
  990. // 指针空;
  991. if (pvtnames || !pvtnames) return FALSE;
  992. m_pvtfiles = pvtfiles;
  993. m_pvtnames = pvtnames;
  994. #if USE_IMGEXT
  995. // 判断扩展名有效性;
  996. if (!iscorrectext(lpfindext)) return FALSE;
  997. #endif
  998. findfilesnames_findout_subfolder(lpfolder);
  999. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  1000. {// 需要保留指定后缀;
  1001. keepdownbyext(lpfindext, *pvtnames);
  1002. keepdownbyext(lpfindext, *pvtfiles);
  1003. }
  1004. return TRUE;
  1005. }
  1006. BOOL filehelpImpl::getfilesnames_within_subfolder(IN LPCTSTR lpfolder, IN LPCTSTR lpfindext, IN STR_VEC *pvtfiles, IN STR_VEC *pvtnames, IN STR_VEC *pvtfolders)
  1007. {
  1008. // 路径不存在;
  1009. if (!PathFileExists(lpfolder))
  1010. return FALSE;
  1011. // 指针空;
  1012. if (pvtnames || !pvtnames) return FALSE;
  1013. m_pvtfiles = pvtfiles;
  1014. m_pvtnames = pvtnames;
  1015. m_pvtfolders = pvtfolders;
  1016. #if USE_IMGEXT
  1017. // 判断扩展名有效性;
  1018. if (!iscorrectext(lpfindext)) return FALSE;
  1019. #endif
  1020. findfilesnames_within_subfolder(lpfolder);
  1021. if ( _tcsstr(lpfindext, _T("*.*")) == NULL )
  1022. {// 需要保留指定后缀;
  1023. keepdownbyext(lpfindext, *pvtnames);
  1024. keepdownbyext(lpfindext, *pvtfiles);
  1025. }
  1026. return TRUE;
  1027. }
  1028. #if 1
  1029. //////////////////////////////////////////////////////////////////////////
  1030. BOOL filehelpImpl::comparename_2file(IN LPCTSTR file1, IN LPCTSTR file2)
  1031. {
  1032. if (!file1 || !file2) return FALSE;
  1033. if (!PathFileExists(file1) || !PathFileExists(file2))
  1034. return FALSE;
  1035. TString strfile1 = file1;
  1036. TString strfile2 = file2;
  1037. strfile1 = getfilename(strfile1);
  1038. strfile2 = getfilename(strfile2);
  1039. return !strfile1.compare(strfile2);
  1040. }
  1041. BOOL filehelpImpl::comparename_findin_names(IN LPCTSTR name)
  1042. {
  1043. if (!m_pvtnames || !name) return FALSE;
  1044. for (STR_VEC::iterator it = m_pvtnames->begin(); it != m_pvtnames->end(); it++)
  1045. {
  1046. if ( _tcsicmp(name, it->c_str()) == 0)
  1047. {
  1048. // 打印日志,或提示用户同名文件路径在哪;
  1049. return TRUE;
  1050. }
  1051. }
  1052. return FALSE;
  1053. }
  1054. BOOL filehelpImpl::comparename_findin_names(IN LPCTSTR name, IN STR_VEC &vtnames)
  1055. {
  1056. if (!name) return FALSE;
  1057. for (STR_VEC::iterator it = vtnames.begin(); it != vtnames.end(); it++)
  1058. {
  1059. if ( _tcsicmp(name, it->c_str()) == 0)
  1060. {
  1061. // 打印日志,或提示用户同名文件路径在哪;
  1062. return TRUE;
  1063. }
  1064. }
  1065. return FALSE;
  1066. }
  1067. BOOL filehelpImpl::comparename_findin_files(IN LPCTSTR name, IN STR_VEC &vtfiles)
  1068. {
  1069. if (!name) return FALSE;
  1070. int nIndex = 0;
  1071. for (STR_VEC::iterator it = vtfiles.begin(); it != vtfiles.end(); it++)
  1072. {
  1073. if ((nIndex = it->find_last_of(_T('\\'))) != TString::npos)
  1074. {
  1075. if (_tcsicmp(name, it->substr(nIndex+1).c_str()) == 0)
  1076. {
  1077. // 打印日志,或提示用户同名文件路径在哪;
  1078. return TRUE;
  1079. }
  1080. }
  1081. }
  1082. return FALSE;
  1083. }
  1084. BOOL filehelpImpl::comparename_findin_folder(IN LPCTSTR name, IN LPCTSTR folder, IN LPCTSTR findext, IN BOOL bsubfolder)
  1085. {
  1086. #if USE_IMGEXT
  1087. if (!name || !iscorrectext(findext)) return FALSE;
  1088. #else
  1089. if ( !name ) return FALSE;
  1090. #endif
  1091. STR_VEC vtnames;
  1092. if (bsubfolder)
  1093. {
  1094. if (!getnames_findin_subfolder(folder, findext, &vtnames))
  1095. return FALSE;
  1096. }
  1097. else
  1098. {
  1099. if (!getnames_findout_subfolder(folder, findext, &vtnames))
  1100. return FALSE;
  1101. }
  1102. return comparename_findin_names(name, vtnames);
  1103. }
  1104. INT filehelpImpl::comparenames_findin_names(IN STR_VEC vtSrcnames, IN STR_VEC vtDesnames, OUT STR_VEC *pvtIsonym /* = NULL */)
  1105. {
  1106. if (vtSrcnames.size() == 0 || vtDesnames.size() == 0) return 0;
  1107. INT nCount = 0;
  1108. for (STR_VEC::iterator it1 = vtSrcnames.begin(); it1 != vtSrcnames.end(); it1++)
  1109. {
  1110. for (STR_VEC::iterator it2 = vtDesnames.begin(); it2 != vtDesnames.end(); it2++)
  1111. {
  1112. if (_tcsicmp(it1->c_str(), it2->c_str()) == 0)
  1113. {
  1114. nCount++;
  1115. if (pvtIsonym)
  1116. pvtIsonym->push_back(*it1);
  1117. break;
  1118. }
  1119. }
  1120. }
  1121. return nCount;
  1122. }
  1123. INT filehelpImpl::comparenames_findin_files(IN STR_VEC vtnames, IN STR_VEC vtfiles, IN LPCTSTR findext, OUT STR_VEC *pvtIsonym /* = NULL */)
  1124. {
  1125. if (vtnames.size() == 0 || vtfiles.size() == 0) return 0;
  1126. #if USE_IMGEXT
  1127. if (!iscorrectext(findext)) return 0;
  1128. #endif
  1129. INT nCount = 0;
  1130. for (STR_VEC::iterator it = vtnames.begin(); it != vtnames.end(); it++)
  1131. {
  1132. if (comparename_findin_files(it->c_str(), vtfiles))
  1133. {
  1134. if (pvtIsonym)
  1135. pvtIsonym->push_back(*it);
  1136. nCount++;
  1137. }
  1138. }
  1139. return nCount;
  1140. }
  1141. INT filehelpImpl::comparenames_findin_folder(IN STR_VEC vtnames, IN LPCTSTR folder, IN BOOL bsubfolder, IN LPCTSTR findext, OUT STR_VEC *pvtIsonym /* = NULL */)
  1142. {
  1143. if (vtnames.size() == 0 || !PathFileExists(folder)) return 0;
  1144. #if USE_IMGEXT
  1145. if (!iscorrectext(findext)) return 0;
  1146. #endif
  1147. STR_VEC vtnames2;
  1148. if (bsubfolder)
  1149. {
  1150. getnames_findin_subfolder(folder, findext, &vtnames2);
  1151. }
  1152. else
  1153. {
  1154. getnames_findout_subfolder(folder, findext, &vtnames2);
  1155. }
  1156. return comparenames_findin_names(vtnames, vtnames2, pvtIsonym);
  1157. }
  1158. //////////////////////////////////////////////////////////////////////////
  1159. BOOL filehelpImpl::comparefile_findin_names(IN LPCTSTR file, IN STR_VEC& vtnames)
  1160. {
  1161. if (vtnames.size() == 0) return FALSE;
  1162. if (!file || !PathFileExists(file)) return FALSE;
  1163. TString strfile = file;
  1164. TString name = getfilename(strfile);
  1165. return comparename_findin_names(name.c_str(), vtnames);
  1166. }
  1167. BOOL filehelpImpl::comparefile_findin_files(IN LPCTSTR file, IN STR_VEC& vtfiles, IN LPCTSTR findext)
  1168. {
  1169. if (!file || !PathFileExists(file)) return FALSE;
  1170. #if USE_IMGEXT
  1171. if (!iscorrectext(findext)) return FALSE;
  1172. #endif
  1173. TString strfile = file;
  1174. TString name = getfilename(strfile);
  1175. // 过滤掉不需要的扩展名;
  1176. keepdownbyext(findext, vtfiles);
  1177. return comparename_findin_files(name.c_str(), vtfiles);
  1178. }
  1179. BOOL filehelpImpl::comparefile_findin_folder(IN LPCTSTR file, IN LPCTSTR folder, IN BOOL bsubfolder, IN LPCTSTR findext)
  1180. {
  1181. if (!file || !PathFileExists(file) || !folder || !PathFileExists(folder)) return FALSE;
  1182. #if USE_IMGEXT
  1183. if (!iscorrectext(findext)) return FALSE;
  1184. #endif
  1185. TString strfile = file;
  1186. TString name = getfilename(strfile);
  1187. STR_VEC vtnames;
  1188. if (bsubfolder)
  1189. {
  1190. getnames_findin_subfolder(folder, findext, &vtnames);
  1191. }
  1192. else
  1193. {
  1194. getnames_findout_subfolder(folder, findext, &vtnames);
  1195. }
  1196. return comparename_findin_names(name.c_str(), vtnames);
  1197. }
  1198. INT filehelpImpl::comparefiles_findin_files(IN STR_VEC &vtfiles1, IN STR_VEC &vtfiles2, IN LPCTSTR findext, OUT STR_VEC *pvtIsonym /* = NULL */)
  1199. {
  1200. if (vtfiles1.size() == 0 || vtfiles2.size() == 0) return 0;
  1201. #if USE_IMGEXT
  1202. if (!iscorrectext(findext)) return 0;
  1203. #endif
  1204. // 过滤掉不需要的扩展名;
  1205. keepdownbyext(findext, vtfiles1);
  1206. // 过滤掉不需要的扩展名;
  1207. keepdownbyext(findext, vtfiles2);
  1208. INT nCount = 0;
  1209. TString name;
  1210. for (STR_VEC::iterator it = vtfiles1.begin(); it != vtfiles1.end(); it++)
  1211. {
  1212. name = getfilename(*it);
  1213. if (comparename_findin_files(name.c_str(), vtfiles2))
  1214. {
  1215. if (pvtIsonym)
  1216. pvtIsonym->push_back(name);
  1217. nCount++;
  1218. }
  1219. }
  1220. return nCount;
  1221. }
  1222. INT filehelpImpl::comparefiles_findin_folder(IN STR_VEC &vtfiles, IN LPCTSTR folder, IN BOOL bsubfolder, IN LPCTSTR findext, OUT STR_VEC *pvtIsonym /* = NULL */)
  1223. {
  1224. if (vtfiles.size() == 0 || !folder || !PathFileExists(folder)) return 0;
  1225. #if USE_IMGEXT
  1226. if (!iscorrectext(findext)) return 0;
  1227. #endif
  1228. STR_VEC vtnames;
  1229. if (bsubfolder)
  1230. {
  1231. getnames_findin_subfolder(folder, findext, &vtnames);
  1232. }
  1233. else
  1234. {
  1235. getnames_findout_subfolder(folder, findext, &vtnames);
  1236. }
  1237. return comparenames_findin_files(vtnames, vtfiles, findext, pvtIsonym);
  1238. }
  1239. INT filehelpImpl::comparefolderself(IN LPCTSTR folder, IN LPCTSTR findext, OUT STR_VEC *pvtIsonym /* = NULL */)
  1240. {
  1241. OutputDebugString(_T("\n"));
  1242. #if USE_IMGEXT
  1243. if (!folder || !PathFileExists(folder) || !iscorrectext(findext)) return 0;
  1244. #else
  1245. if (!folder || !PathFileExists(folder) ) return 0;
  1246. #endif
  1247. STR_VEC vtsubfolders;
  1248. vtsubfolders.push_back(folder); // 包含当前目录;
  1249. getsubfolder(folder, &vtsubfolders);
  1250. int n = vtsubfolders.size();
  1251. STR_VEC *pvtfiles = new STR_VEC[n];
  1252. for (STR_VEC::iterator it = vtsubfolders.begin(); it != vtsubfolders.end(); it++)
  1253. {
  1254. getfiles_findin_subfolder(it->c_str(), findext, &pvtfiles[--n]);
  1255. }
  1256. STR_VEC vtnames;
  1257. n = vtsubfolders.size();
  1258. TString name;
  1259. for (int i = 0; i < n; i++)
  1260. {
  1261. for (STR_VEC::iterator it = pvtfiles[i].begin(); it != pvtfiles[i].end(); it++)
  1262. {
  1263. name = getfilename(*it);
  1264. if (comparename_findin_names(name.c_str(), vtnames))
  1265. {
  1266. // 打印日志,提示客户重名的相片;
  1267. OutputDebugString(it->c_str());
  1268. OutputDebugString(_T("\n"));
  1269. pvtIsonym->push_back(it->c_str());
  1270. }
  1271. else
  1272. {
  1273. vtnames.push_back(name);
  1274. }
  1275. }
  1276. }
  1277. if (pvtfiles)
  1278. delete []pvtfiles;
  1279. pvtfiles = NULL;
  1280. return 0;
  1281. }
  1282. INT filehelpImpl::comparefolder_findin_folder(IN LPCTSTR folder1, IN LPCTSTR folder2, IN BOOL bsubfolder, IN LPCTSTR findext, OUT STR_VEC *pvtIsonym /* = NULL */)
  1283. {
  1284. return 0;
  1285. }
  1286. #endif