CAdsBanner.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "CAdsBanner.h"
  2. CAdsBanner::CAdsBanner()
  3. {
  4. }
  5. std::vector<std::string> CAdsBanner::GetBannerlinkFromJson(std::wstring st)
  6. {
  7. auto SaveFolder = FolderCore::GetOrCreateFolderPath(st) + L"/" + BannerCore::smName_BannerJson;
  8. HRESULT Hfile = URLDownloadToFile(NULL, BannerCore::URI_BannerJson.c_str(), SaveFolder.c_str(), 0,NULL);
  9. //¿í×Ö·ûת¶à×Ö½Ú×Ö·û
  10. char* pStr;
  11. int iwstrLen = WideCharToMultiByte(CP_ACP, 0, SaveFolder.c_str(), -1, 0, 0, 0, 0);
  12. pStr = new char[iwstrLen + 1];
  13. memset(pStr, 0, sizeof(char) * (iwstrLen + 1));
  14. WideCharToMultiByte(CP_ACP, 0, SaveFolder.c_str(), -1, pStr, iwstrLen, 0, 0);
  15. return ReadJsonFromFile(pStr);
  16. }
  17. std::vector<std::string> CAdsBanner::ReadJsonFromFile(const char* file)
  18. {
  19. try {
  20. Json::Reader reader;
  21. Json::Value root;
  22. std::ifstream is;
  23. is.open(file, std::ios::binary);
  24. BannerCollection.clear();
  25. if (reader.parse(is, root))
  26. {
  27. Json::Value val_image;
  28. LanguageType type = CLanguage::GetLocalLanguage(false);
  29. switch (type)
  30. {
  31. case LanguageType::EN_US:
  32. val_image = root["url"]["en"];
  33. break;
  34. case LanguageType::ZH_CN:
  35. val_image = root["url"]["zh-cn"];
  36. break;
  37. case LanguageType::ZH_TW:
  38. val_image = root["url"]["zh-tw"];
  39. break;
  40. default:
  41. val_image = root["url"]["en"];
  42. break;
  43. }
  44. int image_size = val_image.size();
  45. for (int j = 0; j < image_size; ++j)
  46. {
  47. std::string pic_url = val_image[j].asString();
  48. BannerCollection.push_back(pic_url);
  49. }
  50. }
  51. is.close();
  52. }
  53. catch (exception& e) {
  54. }
  55. return BannerCollection;
  56. }
  57. void CAdsBanner::GetBannerJson(std::wstring st)
  58. {
  59. }
  60. bool CAdsBanner::GetImage(std::wstring url, std::wstring saveFolder, int i)
  61. {
  62. HRESULT Hfile = URLDownloadToFile(NULL, url.c_str(), saveFolder.c_str(), 0, NULL);
  63. if (Hfile == S_OK)
  64. return true;
  65. else
  66. return false;
  67. }