CDownLoadFile.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "CDownLoadFile.h"
  2. double DownloadProgress::Currentpercentage = 0;
  3. double DownloadProgress::pro_value = 0;
  4. double DownloadProgress::pro_Sum = 0;
  5. bool CDownLoadFile::GetInstallPackage(std::wstring SaveFolder)
  6. {
  7. FolderCore::GetOrCreateFolderPath(PathCore::smPath_Install.c_str());
  8. DownloadProgress progress;
  9. IBindStatusCallback* callback = (IBindStatusCallback*)&progress;
  10. SaveFolder = FolderCore::GetOrCreateFolderPath(SaveFolder) + L"/" + Product::smName_InstallPackage;
  11. //清除缓存资源
  12. DeleteUrlCacheEntry(Product::URI_InstallPackge.c_str());
  13. //下载安装包资源
  14. HRESULT Hfile = URLDownloadToFile(NULL, Product::URI_InstallPackge.c_str(), SaveFolder.c_str(), 0, static_cast<IBindStatusCallback*>(&progress));
  15. if (Hfile == S_OK)
  16. {
  17. if (DownloadProgress::Currentpercentage > 99.0)
  18. {
  19. while (DownloadProgress::pro_value < DownloadProgress::pro_Sum -2)
  20. {
  21. int i = 0;
  22. }
  23. return true;
  24. }
  25. }
  26. else
  27. {
  28. }
  29. return false;
  30. }
  31. #pragma region 检查网络状态
  32. bool NetWorkState::IsNetWorking()
  33. {
  34. DWORD flags;
  35. return InternetGetConnectedState(&flags, 0);
  36. }
  37. bool NetWorkState::IsProxyEnable()
  38. {
  39. long lRet;
  40. HKEY hKey;
  41. TCHAR szBuffer[255] = { 0 };
  42. TCHAR tchData[64];
  43. DWORD dwSize = 255;
  44. lRet = RegOpenKeyEx(HKEY_CURRENT_USER,_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
  45. 0,KEY_READ | KEY_WOW64_64KEY,&hKey);
  46. if (lRet == ERROR_SUCCESS)
  47. {
  48. lRet = RegQueryValueEx(hKey,_T("ProxyEnable"),
  49. NULL,NULL,(LPBYTE)szBuffer,&dwSize);
  50. if (lRet == ERROR_SUCCESS)
  51. {
  52. std::wstring poxyEnable(szBuffer);
  53. if (poxyEnable == L"")
  54. {
  55. return false;
  56. }
  57. }
  58. }
  59. RegCloseKey(hKey);
  60. return true;
  61. }
  62. bool NetWorkState::IsProxyNetError()
  63. {
  64. wstring SaveFolder = FolderCore::GetOrCreateFolderPath(PathCore::smPath_Temp) + L"/" + L"test.xml";
  65. bool IsProxyChecked = false;
  66. long lRet;
  67. HKEY hKey;
  68. TCHAR szBuffer[255] = { 0 };
  69. TCHAR tchData[64];
  70. DWORD dwSize = 255;
  71. lRet = RegOpenKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
  72. 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
  73. if (lRet == ERROR_SUCCESS)
  74. {
  75. lRet = RegQueryValueEx(hKey, _T("ProxyEnable"),
  76. NULL, NULL, (LPBYTE)szBuffer, &dwSize);
  77. if (lRet == ERROR_SUCCESS)
  78. {
  79. std::wstring poxyEnable(szBuffer);
  80. if (poxyEnable == L"")
  81. {
  82. IsProxyChecked = false;
  83. }
  84. else
  85. {
  86. IsProxyChecked = true;
  87. }
  88. }
  89. }
  90. RegCloseKey(hKey);
  91. //如果当前设备有勾选LAN代理服务器,则认为代理网址和端口不对,代理服务器连接失败
  92. return IsProxyChecked;
  93. }
  94. #pragma endregion