PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/src_kclear/trackcleaner/src/thunderdownloader.cpp

https://bitbucket.org/knoss/pcmanager/
C++ | 347 lines | 289 code | 54 blank | 4 comment | 50 complexity | fddeda7b91d7d0060056fa256392a663 MD5 | raw file
Possible License(s): LGPL-2.0
  1. #include "ThunderDownloader.h"
  2. #include "getinstallpath.h"
  3. #include <shlwapi.h>
  4. #include <map>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <string>
  8. extern std::vector<std::wstring> g_listProcessName;
  9. std::map<std::string, std::string>g_ms;
  10. #pragma comment(lib, "shlwapi.lib")
  11. CThunderDownloader::CThunderDownloader(void)
  12. {
  13. }
  14. CThunderDownloader::~CThunderDownloader(void)
  15. {
  16. }
  17. BOOL CThunderDownloader::ScanThunder()
  18. {
  19. KSearchSoftwareStruct sss;
  20. wstring strPath;
  21. wstring strPath2;
  22. WCHAR szPath[MAX_PATH] = {0};
  23. CSimpleArray<CString> vec_file;
  24. CSimpleArray<CString> vec_file2;
  25. BOOL bRet = FALSE;
  26. sss.pszMainFileName = TEXT( "Thunder.exe" );
  27. sss.nDefPathFolderCSIDL = CSIDL_PROGRAM_FILES;
  28. sss.pszDefPath = TEXT( "Thunder Network\\Thunder" );
  29. sss.hRegRootKey = HKEY_LOCAL_MACHINE;
  30. sss.pszRegSubKey = TEXT( "SOFTWARE\\Thunder Network\\ThunderOem\\thunder_backwnd" );
  31. sss.pszPathValue = TEXT( "Path" );
  32. sss.bFolder = FALSE;
  33. sss.pszUninstallListName = TEXT( "迅雷5" );
  34. sss.pszFileDesc = TEXT( "Thunder" );
  35. bRet = SearchSoftwarePath( &sss, strPath2 );
  36. wcscpy_s(szPath, MAX_PATH - 1, strPath2.c_str());
  37. PathRemoveFileSpec(szPath);
  38. PathRemoveFileSpec(szPath);
  39. strPath2 = szPath;
  40. g_fnScanFile(g_pMain,BEGINPROC(THUNDERDOWNLOADER),0,0,0);
  41. std::wstring str;
  42. std::vector<std::wstring>::iterator it;
  43. for (it = g_listProcessName.begin(); it != g_listProcessName.end(); it++ )
  44. {
  45. str = *it;
  46. transform(str.begin(), str.end(), str.begin(), towlower);
  47. if (str == L"thunder.exe")
  48. {
  49. str = L"正在运行,跳过";
  50. goto Exit;
  51. }
  52. }
  53. str = L"";
  54. vec_file.Add(_T("SearchHistory.xml"));
  55. vec_file2.Add(_T("ThunderStorage.dat"));
  56. if (m_bScan)
  57. {
  58. WCHAR szPathEx[MAX_PATH] = {0};
  59. //BOOL bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_COMMON_APPDATA, FALSE);
  60. UINT uResult = GetSystemDirectory(szPathEx, MAX_PATH);
  61. if (uResult > 3 && szPathEx[1] == TEXT(':') && szPathEx[2] == TEXT('\\'))
  62. {
  63. szPathEx[2] = TEXT('\0');
  64. }
  65. if (szPathEx != NULL)
  66. {
  67. strPath = szPathEx;
  68. strPath += L"\\Users\\Public\\Thunder Network";
  69. WIN32_FIND_DATA wfd = {0};
  70. HANDLE hFile = INVALID_HANDLE_VALUE;
  71. wstring strTemp;
  72. strTemp = strPath;
  73. strTemp += L"\\thunder_*.*";
  74. hFile = FindFirstFile(strTemp.c_str(),&wfd);
  75. OutputDebugString(strTemp.c_str());
  76. if (hFile != INVALID_HANDLE_VALUE)
  77. {
  78. do
  79. {
  80. if ((wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
  81. && _wcsicmp(L".", wfd.cFileName) != 0 && _wcsicmp(L"..", wfd.cFileName) != 0)
  82. {
  83. wstring strTemp2;
  84. wstring strTemp3;
  85. strTemp2 = strPath;
  86. strTemp2 += L"\\";
  87. strTemp2 += wfd.cFileName;
  88. strTemp3 = strTemp2;
  89. strTemp2 += L"\\Profiles\\Program\\ThunderStorage.dat";
  90. if (PathFileExists(strTemp2.c_str()))
  91. {
  92. strTemp3 += L"\\Profiles\\Program";
  93. m_appHistory.CommfunFile(THUNDERDOWNLOADER, strTemp3.c_str(), vec_file2);
  94. //ModifySqlite(strTemp3, L"ThunderStorage.dat");
  95. }
  96. }
  97. } while(FindNextFile(hFile, &wfd));
  98. ::FindClose(hFile);
  99. }
  100. }
  101. //m_appHistory.CommfunFile(THUNDERDOWNLOADER, strPath.c_str(), vec_file);
  102. wstring strFile;
  103. strFile = L"ThunderStorage.dat";
  104. strPath2 += _T("\\UserData\\Profiles\\Program");
  105. //ModifySqlite(strPath2, strFile);
  106. m_appHistory.CommfunFile(THUNDERDOWNLOADER, strPath2.c_str(), vec_file2);
  107. }
  108. Exit:
  109. g_fnScanFile(g_pMain,ENDPROC(THUNDERDOWNLOADER),str.c_str(),0,0);
  110. return TRUE;
  111. }
  112. BOOL CThunderDownloader::ModifySqlite(std::wstring strPath, std::wstring strFile)
  113. {
  114. sqlite3* pDB = NULL;
  115. sqlite3_stmt* sspStart = NULL;
  116. BOOL bRet = FALSE;
  117. g_ms.clear();
  118. if(m_bScan)
  119. {
  120. // g_fnScanFile(g_pMain,BEGINPROC(PPTV_PLAYER),0,0,0);
  121. wstring strFullPath;
  122. strFullPath = strPath;
  123. strFullPath += L"\\";
  124. strFullPath += strFile;
  125. int nResult = -1;
  126. BOOL bRet = FALSE;
  127. WCHAR szPath[MAX_PATH] = {0};
  128. char* szError = NULL;
  129. string szDataPath;
  130. szDataPath = UnicodeToUtf8(strFullPath);
  131. nResult = sqlite3_open(szDataPath.c_str(), &pDB);
  132. if (nResult != SQLITE_OK)
  133. {
  134. goto _exit_;
  135. }
  136. nResult = sqlite3_prepare(pDB, "select * from BaseTaskInfo where status = 11", -1, &sspStart, 0);
  137. if (nResult != SQLITE_OK)
  138. {
  139. goto _exit_;
  140. }
  141. nResult = sqlite3_step(sspStart);
  142. while(nResult == SQLITE_ROW)
  143. {
  144. int nType = sqlite3_column_int(sspStart, 2);
  145. if (nType == 11)
  146. {
  147. const char* szName = (char*)sqlite3_column_text(sspStart, 21);
  148. const char* szTaskID = (char*)sqlite3_column_text(sspStart, 0);
  149. g_ms.insert(pair<string, string>(szName, szTaskID));
  150. wstring strName;
  151. strName = Utf8ToUnicode(szName);
  152. wstring strOutPut;
  153. strOutPut = strFullPath;
  154. strOutPut += L"|";
  155. strOutPut += L"BaseTaskInfo";
  156. strOutPut += L"|";
  157. strOutPut += strName;
  158. g_fnScanFile(g_pMain, THUNDERDOWNLOADER, strOutPut.c_str(), 0, 0);
  159. }
  160. nResult = sqlite3_step(sspStart);
  161. }
  162. }
  163. bRet = TRUE;
  164. _exit_:
  165. // g_fnScanFile(g_pMain,ENDPROC(PPTV_PLAYER),0,0,0);
  166. if (sspStart)
  167. {
  168. sqlite3_finalize(sspStart);
  169. sspStart = NULL;
  170. }
  171. if (pDB)
  172. {
  173. sqlite3_close(pDB);
  174. pDB = NULL;
  175. }
  176. return bRet;
  177. }
  178. BOOL CThunderDownloader::CleanThunder(LPCTSTR lpszFile)
  179. {
  180. int nResult = -1;
  181. wstring strPathFile;
  182. wstring strFileName;
  183. wstring strDbTable;
  184. sqlite3* pDB;
  185. sqlite3_stmt* sspStart = NULL;
  186. BOOL bRet = FALSE;
  187. CSimpleArray<CString>vec_String;
  188. int nSize = SplitCString1(lpszFile, vec_String, '|');
  189. strPathFile = vec_String[0];
  190. strFileName = vec_String[2];
  191. strDbTable = vec_String[1];
  192. string szPathFile;
  193. string szFileName;
  194. string szDbTable;
  195. szPathFile = UnicodeToUtf8(strPathFile);
  196. szFileName = UnicodeToUtf8(strFileName);
  197. szDbTable = UnicodeToUtf8(strDbTable);
  198. nResult = sqlite3_open(szPathFile.c_str(), &pDB);
  199. char* szError = NULL;
  200. char szSql[MAX_PATH] = {0};
  201. if(szDbTable.empty()||szFileName.empty())
  202. goto _exit_;
  203. sprintf_s(szSql, MAX_PATH - 1, "delete from %s where FileName = '%s'", szDbTable.c_str(), szFileName.c_str());
  204. nResult = sqlite3_exec(pDB, szSql, 0, 0, &szError);
  205. if(nResult != SQLITE_OK)
  206. {
  207. bRet = FALSE;
  208. goto _exit_;
  209. }
  210. // nResult = sqlite3_step(sspStart);
  211. if (g_ms[szFileName].empty())
  212. goto _exit_;
  213. sprintf_s(szSql, MAX_PATH - 1, "delete from GenericTaskInfo where TaskID='%s'", g_ms[szFileName].c_str());
  214. nResult = sqlite3_exec(pDB, szSql, 0, 0, &szError);
  215. if(nResult != SQLITE_OK)
  216. {
  217. bRet = FALSE;
  218. goto _exit_;
  219. }
  220. if (g_ms[szFileName].empty())
  221. goto _exit_;
  222. sprintf_s(szSql, MAX_PATH - 1, "delete from BlockRec where TaskID='%s'", g_ms[szFileName].c_str());
  223. nResult = sqlite3_exec(pDB, szSql, 0, 0, &szError);
  224. if(nResult != SQLITE_OK)
  225. {
  226. bRet = FALSE;
  227. goto _exit_;
  228. }
  229. sprintf_s(szSql, MAX_PATH - 1, "delete from TaskExtraInfo where TaskID='%s'", g_ms[szFileName].c_str());
  230. nResult = sqlite3_exec(pDB, szSql, 0, 0, &szError);
  231. if(nResult != SQLITE_OK)
  232. {
  233. bRet = FALSE;
  234. goto _exit_;
  235. }
  236. // nResult = sqlite3_step(sspStart);
  237. sprintf_s(szSql, MAX_PATH - 1, "update Category set CategoryDetailInfo='' where CategoryDescription='已下载'");
  238. nResult = sqlite3_exec(pDB, szSql, 0, 0, &szError);
  239. if(nResult != SQLITE_OK)
  240. {
  241. bRet = FALSE;
  242. goto _exit_;
  243. }
  244. sprintf_s(szSql, MAX_PATH - 1, "update Category set IDList='' where CategoryDescription='已下载'");
  245. nResult = sqlite3_exec(pDB, szSql, 0, 0, &szError);
  246. if(nResult != SQLITE_OK)
  247. {
  248. bRet = FALSE;
  249. goto _exit_;
  250. }
  251. _exit_:
  252. if(sspStart)
  253. {
  254. sqlite3_finalize(sspStart);
  255. sspStart = NULL;
  256. }
  257. if(pDB)
  258. {
  259. sqlite3_close(pDB);
  260. pDB = NULL;
  261. }
  262. return TRUE;
  263. }
  264. int CThunderDownloader::SplitCString1(CString strIn, CSimpleArray<CString>& vec_String, TCHAR division)
  265. {
  266. vec_String.RemoveAll();
  267. if (!strIn.IsEmpty())
  268. {
  269. int nCount = 0;
  270. int nPos = -1;
  271. nPos = strIn.Find(division);
  272. CString strTemp = strIn;
  273. while (nPos != -1)
  274. {
  275. CString strSubString = strTemp.Left(nPos);
  276. strTemp = strTemp.Right(strTemp.GetLength() - nPos-1);
  277. nPos = strTemp.Find(division);
  278. nCount++;
  279. vec_String.Add(strSubString);
  280. }
  281. if (nCount == vec_String.GetSize())
  282. {
  283. CString str;
  284. int nSize = strIn.ReverseFind(division);
  285. str = strIn.Right(strIn.GetLength()-nSize-1);
  286. vec_String.Add(str);
  287. }
  288. }
  289. return vec_String.GetSize();
  290. }