PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/src/src_kclear/trackcleaner/src/flashgetdownloader.h

https://bitbucket.org/knoss/pcmanager/
C Header | 558 lines | 504 code | 51 blank | 3 comment | 51 complexity | 7f3cc2e73b7f558bfacc0832b7e88289 MD5 | raw file
Possible License(s): LGPL-2.0
  1. #pragma once
  2. #include "CleanProc.h"
  3. #include "i_clean.h"
  4. #include <algorithm>
  5. #include "winosver.h"
  6. #include "fileopt.h"
  7. #include "regopt.h"
  8. #include "apphistory.h"
  9. #include "getinstallpath.h"
  10. #include <string>
  11. #include "kscbase/kscconv.h"
  12. using namespace std;
  13. extern ScanFileCallBack g_fnScanFile;
  14. extern ScanRegCallBack g_fnScanReg;
  15. extern void* g_pMain;
  16. extern std::vector<std::wstring> g_listProcessName;
  17. class CFlashGetDownloader
  18. {
  19. public:
  20. void Start(){m_appHistory.Start(); m_bScan =TRUE;};
  21. void StopScan(){m_appHistory.StopScan(); m_bScan =FALSE;};
  22. public:
  23. BOOL ScanFlashGet()
  24. {
  25. std::wstring str;
  26. g_fnScanFile(g_pMain,BEGINPROC(FLASHGETDOWNLOADER),0,0,0);
  27. std::vector<std::wstring>::iterator it;
  28. for (it = g_listProcessName.begin(); it != g_listProcessName.end(); it++ )
  29. {
  30. str = *it;
  31. transform(str.begin(), str.end(), str.begin(), towlower);
  32. if (str == L"flashget3.exe")
  33. {
  34. str = L"正在运行,跳过";
  35. goto _exit_;
  36. }
  37. }
  38. str = L"";
  39. if (m_bScan)
  40. {
  41. KSearchSoftwareStruct sss;
  42. wstring strPath;
  43. wstring strPath2;
  44. BOOL bRet = FALSE;
  45. WCHAR szPath[MAX_PATH] = {0};
  46. sss.pszMainFileName = TEXT( "flashget3.exe" );
  47. sss.hRegRootKey = HKEY_LOCAL_MACHINE;
  48. sss.pszRegSubKey = _T("SOFTWARE\\FlashGet Network\\FlashGet 3");
  49. sss.pszPathValue = _T("Path");
  50. bRet = SearchSoftwarePath( &sss, strPath );
  51. wcscpy_s(szPath, MAX_PATH - 1, strPath.c_str());
  52. PathRemoveFileSpec(szPath);
  53. strPath = szPath;
  54. strPath += L"\\dat";
  55. CSimpleArray<CString> vec_file;
  56. vec_file.Add(_T("FlashGet3db.db"));
  57. vec_file.Add(_T("FlashGet3db.bak"));
  58. bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, FALSE);
  59. strPath2 = szPath;
  60. strPath2 += L"\\FlashGet\\v3\\dat";
  61. m_appHistory.CommfunFile(FLASHGETDOWNLOADER, strPath.c_str(), vec_file);
  62. OutputDebugString(strPath2.c_str());
  63. m_appHistory.CommfunFile(FLASHGETDOWNLOADER, strPath2.c_str(), vec_file);
  64. }
  65. _exit_:
  66. g_fnScanFile(g_pMain,ENDPROC(FLASHGETDOWNLOADER),str.c_str(),0,0);
  67. return TRUE;
  68. }
  69. private:
  70. CAppHistory m_appHistory;
  71. BOOL m_bScan;
  72. };
  73. class CBitcometDownloader
  74. {
  75. public:
  76. void Start(){m_appHistory.Start(); m_bScan =TRUE;};
  77. void StopScan(){m_appHistory.StopScan(); m_bScan =FALSE;};
  78. public:
  79. BOOL ScanBitComet()
  80. {
  81. std::wstring str;
  82. g_fnScanFile(g_pMain,BEGINPROC(BITCOMETDOWNLOADER),0,0,0);
  83. std::vector<std::wstring>::iterator it;
  84. for (it = g_listProcessName.begin(); it != g_listProcessName.end(); it++ )
  85. {
  86. str = *it;
  87. transform(str.begin(), str.end(), str.begin(), towlower);
  88. if (str == L"bitcomet.exe")
  89. {
  90. str = L"正在运行,跳过";
  91. goto _exit_;
  92. }
  93. }
  94. str = L"";
  95. if (m_bScan)
  96. {
  97. KSearchSoftwareStruct sss;
  98. wstring strPath;
  99. wstring strPath2;
  100. wstring strFile;
  101. BOOL bRet = FALSE;
  102. WCHAR szPath[MAX_PATH] = {0};
  103. sss.pszMainFileName = TEXT( "BitComet.exe" );
  104. sss.nDefPathFolderCSIDL = CSIDL_PROGRAM_FILES;
  105. sss.pszDefPath = TEXT( "BitComet" );
  106. sss.pszUninstallListName = TEXT( "BitComet" );
  107. sss.pszFileDesc = TEXT( "BitComet" );
  108. sss.hRegRootKey = HKEY_CURRENT_USER;
  109. sss.pszRegSubKey = TEXT( "Software\\BitComet" );
  110. sss.pszPathValue = TEXT( "" );
  111. sss.bFolder = TRUE;
  112. bRet = SearchSoftwarePath( &sss, strPath );
  113. wcscpy_s(szPath, MAX_PATH - 1, strPath.c_str());
  114. PathRemoveFileSpec(szPath);
  115. strPath = szPath;
  116. CSimpleArray<CString> vec_file;
  117. vec_file.Add(_T("Downloads.xml"));
  118. ZeroMemory(szPath, MAX_PATH);
  119. bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, FALSE);
  120. strPath2 = szPath;
  121. strPath2 += L"\\";
  122. strPath2 += L"BitComet";
  123. CSimpleArray<CString> vec_file2;
  124. vec_file2.Add(_T("Downloads.xml"));
  125. vec_file2.Add(_T("Downloads.xml.bak"));
  126. g_fnScanFile(g_pMain,BEGINPROC(BITCOMETDOWNLOADER),0,0,0);
  127. // m_appHistory.CommfunFile(BITCOMETDOWNLOADER, strPath.c_str(), vec_file);
  128. strFile = L"Downloads.xml";
  129. CheckComplete(strPath, strFile);
  130. OutputDebugString(strPath2.c_str());
  131. CheckComplete(strPath2, strFile);
  132. //m_appHistory.CommfunFile(BITCOMETDOWNLOADER, strPath2.c_str(), vec_file2);
  133. }
  134. _exit_:
  135. g_fnScanFile(g_pMain,ENDPROC(BITCOMETDOWNLOADER),str.c_str(),0,0);
  136. return TRUE;
  137. }
  138. BOOL CheckComplete(wstring strPath, wstring strFile)
  139. {
  140. strPath += L"\\";
  141. strPath += strFile;
  142. FILE* lpFile = _tfopen(strPath.c_str(), _T("rb"));
  143. TiXmlDocument xmlDoc;
  144. if ( lpFile != NULL )
  145. {
  146. xmlDoc.LoadFile(lpFile);
  147. fclose(lpFile);
  148. if ( xmlDoc.Error() == 0 )
  149. {
  150. OutputDebugString(_T("打开文件成功"));
  151. TiXmlElement* rootNode = xmlDoc.RootElement();
  152. if (rootNode!=NULL)
  153. {
  154. TiXmlElement* nodeGeneral = rootNode->FirstChildElement("Torrents");
  155. if ( nodeGeneral != NULL )
  156. {
  157. TiXmlElement* node = nodeGeneral->FirstChildElement("Torrent");
  158. while (node)
  159. {
  160. const char* szSelectSize = node->Attribute("Size");
  161. const char* szDataDownload = node->Attribute("DataDownload");
  162. USES_CONVERSION;
  163. if(_stricmp(szSelectSize, szDataDownload) == 0)
  164. {
  165. const char* szShowName = node->Attribute("ShowName");
  166. CString strShowName = KUTF8_To_UTF16(szShowName);
  167. CString strFind;
  168. strFind.Format(_T("%s|Torrents|Torrent|%s"), strPath.c_str(), strShowName);
  169. g_fnScanFile(g_pMain,BITCOMETDOWNLOADER,strFind,0,0);
  170. // const char szTorrentFile =
  171. }
  172. node = node->NextSiblingElement("Torrent");
  173. }
  174. node = nodeGeneral->FirstChildElement("Download");
  175. while (node)
  176. {
  177. const char* szSelectSize = node->Attribute("LeftSize");
  178. const char* szDataDownload = node->Attribute("DataDownload");
  179. USES_CONVERSION;
  180. if(_stricmp(szSelectSize, "0") == 0)
  181. {
  182. const char* szShowName = node->Attribute("DetailFile");
  183. CString strShowName = KUTF8_To_UTF16(szShowName);
  184. CString strFind;
  185. strFind.Format(_T("%s|Torrents|Download|%s"), strPath.c_str(), strShowName);
  186. g_fnScanFile(g_pMain,BITCOMETDOWNLOADER,strFind,0,0);
  187. // const char szTorrentFile =
  188. }
  189. node = node->NextSiblingElement("Download");
  190. }
  191. }
  192. else
  193. OutputDebugString(_T("\n没找到相应属性\n"));
  194. }
  195. }
  196. else
  197. OutputDebugString(_T("\n读取文件失败\n"));
  198. }
  199. else
  200. OutputDebugString(_T("\n打开文件失败\n"));
  201. return TRUE;
  202. }
  203. BOOL CleanBitcomet(LPCTSTR strDownload)
  204. {
  205. CString strPath = strDownload;
  206. CSimpleArray<CString> vec_String;
  207. CString strFileTemp;
  208. int iCount = SplitCString1(strPath,vec_String,'|');
  209. if(iCount<3)
  210. {
  211. return FALSE;
  212. }
  213. TiXmlDocument xmlDoc;
  214. //获得文件夹名称改变其属性
  215. iCount = vec_String[0].ReverseFind('\\');
  216. CString strTmp;
  217. if (iCount>0)
  218. {
  219. strTmp = vec_String[0].Mid(0,iCount);
  220. }
  221. DWORD dwErrCode=0;
  222. if(FALSE == SetFileAttributes(strTmp, FILE_ATTRIBUTE_NORMAL))
  223. {
  224. dwErrCode=GetLastError();
  225. }
  226. USES_CONVERSION;
  227. FILE* lpFile = _tfopen(vec_String[0], _T("a+b"));
  228. if ( lpFile != NULL )
  229. {
  230. xmlDoc.LoadFile(lpFile);
  231. fclose(lpFile);
  232. if ( xmlDoc.Error() == 0 )
  233. {
  234. OutputDebugString(_T("\n打开文件成功\n"));
  235. TiXmlElement* rootNode = xmlDoc.RootElement();
  236. if (rootNode !=NULL)
  237. {
  238. TiXmlElement* nodeGeneral = rootNode->FirstChildElement(W2A(vec_String[1]));
  239. if ( nodeGeneral != NULL )
  240. {
  241. TiXmlElement* node = nodeGeneral->FirstChildElement(W2A(vec_String[2]));
  242. while(node)
  243. {
  244. const char* szFinishData= node->Attribute("ShowName");
  245. CString strFinishData = KUTF8_To_UTF16(szFinishData);
  246. const char* szHash= node->Attribute("InfoHashHex");
  247. wchar_t* szTemp = A2W(szHash);
  248. if (szFinishData == NULL)
  249. {
  250. goto Next;
  251. }
  252. if (_wcsicmp(strFinishData, vec_String[3]) == 0)
  253. {
  254. if (!nodeGeneral->RemoveChild(node))
  255. {
  256. OutputDebugString(_T("\n删除子节点失败\n"));
  257. }
  258. else
  259. {
  260. strFileTemp.Format(_T("%s\\archive"), strTmp);
  261. CleanShareAndHistory(strFileTemp, L"MyHistory", vec_String[3], szTemp, L"my_history.xml");
  262. strFileTemp.Format(_T("%s\\share"), strTmp);
  263. CleanShareAndHistory(strFileTemp, L"MyHistory", vec_String[3], szTemp, L"my_shares.xml");
  264. if (!xmlDoc.SaveFile(W2A(vec_String[0])))
  265. {
  266. OutputDebugString(_T("保存失败"));
  267. }
  268. }
  269. break;
  270. }
  271. Next:
  272. szFinishData= node->Attribute("DetailFile");
  273. strFinishData = KUTF8_To_UTF16(szFinishData);
  274. szHash= node->Attribute("FileHash");
  275. szTemp = A2W(szHash);
  276. if (_wcsicmp(strFinishData, vec_String[3]) == 0)
  277. {
  278. OutputDebugString(A2W(szFinishData));
  279. if (!nodeGeneral->RemoveChild(node))
  280. {
  281. OutputDebugString(_T("\n删除子节点失败\n"));
  282. }
  283. else
  284. {
  285. strFileTemp.Format(_T("%s\\archive"), strTmp);
  286. CleanShareAndHistory(strFileTemp, L"MyHistory", vec_String[3], szTemp, L"my_history.xml");
  287. strFileTemp.Format(_T("%s\\share"), strTmp);
  288. CleanShareAndHistory(strFileTemp, L"MyHistory", vec_String[3], szTemp, L"my_shares.xml");
  289. strFileTemp.Format(_T("%s\\torrents"), strTmp);
  290. CleanShareAndHistory(strFileTemp, NULL, vec_String[3], szTemp, NULL);
  291. if (!xmlDoc.SaveFile(W2A(vec_String[0])))
  292. {
  293. OutputDebugString(_T("保存失败"));
  294. }
  295. }
  296. break;
  297. }
  298. node = node->NextSiblingElement(W2A(vec_String[2]));
  299. }
  300. }
  301. }
  302. }
  303. }
  304. return TRUE;
  305. }
  306. BOOL CleanShareAndHistory(LPCTSTR szFilePath, LPCTSTR strHead, LPCTSTR strTitle, LPCTSTR strTorrentName, LPCTSTR strXmlName)
  307. {
  308. CString strFilePath = szFilePath;
  309. strFilePath += L"\\";
  310. strFilePath += strXmlName;
  311. TiXmlDocument xmlDoc;
  312. wstring strFileTrrorent;
  313. //获得文件夹名称改变其属性
  314. int nCount = strFilePath.ReverseFind('\\');
  315. CString strTmp;
  316. if (nCount>0)
  317. {
  318. strTmp = strFilePath.Mid(0,nCount);
  319. }
  320. DWORD dwErrCode=0;
  321. if(FALSE == SetFileAttributes(strTmp, FILE_ATTRIBUTE_NORMAL))
  322. {
  323. dwErrCode=GetLastError();
  324. }
  325. USES_CONVERSION;
  326. FILE* lpFile = _tfopen(strFilePath, _T("a+b"));
  327. if ( lpFile != NULL )
  328. {
  329. xmlDoc.LoadFile(lpFile);
  330. fclose(lpFile);
  331. if ( xmlDoc.Error() == 0 )
  332. {
  333. OutputDebugString(_T("\n打开文件成功\n"));
  334. TiXmlElement* rootNode = xmlDoc.RootElement();
  335. if (rootNode !=NULL)
  336. {
  337. TiXmlElement* nodeGeneral = rootNode->FirstChildElement(W2A(strHead));
  338. if ( nodeGeneral != NULL )
  339. {
  340. TiXmlElement* node = nodeGeneral->FirstChildElement("bt");
  341. while(node)
  342. {
  343. const char* szFinishData= node->Attribute("title");
  344. if (_stricmp(szFinishData, W2A(strTitle)) == 0)
  345. {
  346. if (!nodeGeneral->RemoveChild(node))
  347. {
  348. OutputDebugString(_T("\n删除子节点失败\n"));
  349. }
  350. else
  351. {
  352. if (!xmlDoc.SaveFile(W2A(strFilePath)))
  353. {
  354. OutputDebugString(_T("保存失败"));
  355. }
  356. }
  357. break;
  358. }
  359. node = node->NextSiblingElement("bt");
  360. }
  361. }
  362. }
  363. }
  364. }
  365. strFileTrrorent = szFilePath;
  366. strFileTrrorent += L"\\";
  367. strFileTrrorent += strTorrentName;
  368. strFileTrrorent += L".torrent";
  369. ::DeleteFile(strFileTrrorent.c_str());
  370. strFileTrrorent = szFilePath;
  371. strFileTrrorent += L"\\";
  372. strFileTrrorent += strTitle;
  373. ::DeleteFile(strFileTrrorent.c_str());
  374. return TRUE;
  375. }
  376. inline int SplitCString1(CString strIn, CSimpleArray<CString>& vec_String, TCHAR division)
  377. {
  378. vec_String.RemoveAll();
  379. if (!strIn.IsEmpty())
  380. {
  381. int nCount = 0;
  382. int nPos = -1;
  383. nPos = strIn.Find(division);
  384. CString strTemp = strIn;
  385. while (nPos != -1)
  386. {
  387. CString strSubString = strTemp.Left(nPos);
  388. strTemp = strTemp.Right(strTemp.GetLength() - nPos-1);
  389. nPos = strTemp.Find(division);
  390. nCount++;
  391. vec_String.Add(strSubString);
  392. }
  393. if (nCount == vec_String.GetSize())
  394. {
  395. CString str;
  396. int nSize = strIn.ReverseFind(division);
  397. str = strIn.Right(strIn.GetLength()-nSize-1);
  398. vec_String.Add(str);
  399. }
  400. }
  401. return vec_String.GetSize();
  402. }
  403. private:
  404. CAppHistory m_appHistory;
  405. BOOL m_bScan;
  406. };
  407. class CQQDownloader
  408. {
  409. public:
  410. void Start(){m_appHistory.Start(); m_bScan =TRUE;};
  411. void StopScan(){m_appHistory.StopScan(); m_bScan =FALSE;};
  412. public:
  413. BOOL ScanQQDownloader()
  414. {
  415. std::wstring str;
  416. g_fnScanFile(g_pMain,BEGINPROC(QQDOWNLOADER),0,0,0);
  417. std::vector<std::wstring>::iterator it;
  418. for (it = g_listProcessName.begin(); it != g_listProcessName.end(); it++ )
  419. {
  420. str = *it;
  421. transform(str.begin(), str.end(), str.begin(), towlower);
  422. if (str == L"qqdownload.exe")
  423. {
  424. str = L"正在运行,跳过";
  425. goto _exit_;
  426. }
  427. }
  428. str = L"";
  429. if (m_bScan)
  430. {
  431. wstring strPath;
  432. wstring strPath1;
  433. wstring strPath2;
  434. BOOL bRet = FALSE;
  435. WCHAR szPath[MAX_PATH] = {0};
  436. CSimpleArray<CString> vec_file;
  437. vec_file.Add(_T("History.dat"));
  438. vec_file.Add(_T("BTHistory.dat"));
  439. vec_file.Add(_T("History.dat.xfbak"));
  440. vec_file.Add(_T("HistoryBk.dat"));
  441. WIN32_FIND_DATA wfd = {0};
  442. HANDLE hFile = INVALID_HANDLE_VALUE;
  443. ZeroMemory(szPath, MAX_PATH);
  444. bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA, FALSE);
  445. strPath2 = szPath;
  446. strPath2 += L"\\";
  447. strPath2 += L"Tencent\\QQDownload";
  448. strPath = strPath2;
  449. strPath += L"\\*.*";
  450. hFile = FindFirstFile(strPath.c_str(), &wfd);
  451. if (hFile != INVALID_HANDLE_VALUE)
  452. {
  453. do
  454. {
  455. if (_wcsicmp(L".", wfd.cFileName) != 0 && _wcsicmp(L"..", wfd.cFileName) != 0 && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  456. {
  457. strPath1 += strPath2;
  458. strPath1 += L"\\";
  459. strPath1 += wfd.cFileName;
  460. strPath1 += L"\\Setting";
  461. m_appHistory.CommfunFile(QQDOWNLOADER, strPath1.c_str(), vec_file);
  462. strPath1 = L"";
  463. }
  464. } while(FindNextFile(hFile, &wfd));
  465. ::FindClose(hFile);
  466. }
  467. }
  468. _exit_:
  469. g_fnScanFile(g_pMain,ENDPROC(QQDOWNLOADER),str.c_str(),0,0);
  470. return TRUE;
  471. }
  472. private:
  473. CAppHistory m_appHistory;
  474. BOOL m_bScan;
  475. };