OnlineProduct.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "OnlineProduct.h"
  2. #include <WinInet.h>
  3. OnlineProduct::OnlineProduct()
  4. {
  5. pDocument = new TiXmlDocument();
  6. }
  7. OnlineProduct::~OnlineProduct()
  8. {
  9. delete pDocument;
  10. pDocument = nullptr;
  11. }
  12. const char* OnlineProduct::GetInstallPageVersion(wstring productUrl)
  13. {
  14. //下载xml文件
  15. wstring SaveFolder = FolderCore::GetOrCreateFolderPath(PathCore::smPath_Temp) + L"/" + L"test.xml";
  16. //调用接口下载前,先清除接口缓存。否则有可能下载到旧内容
  17. //博客:https://blog.csdn.net/yangxiaozi/article/details/121104151?spm=1001.2101.3001.6650.5&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-5-121104151-blog-102068998.235%5Ev38%5Epc_relevant_sort_base3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-5-121104151-blog-102068998.235%5Ev38%5Epc_relevant_sort_base3&utm_relevant_index=10
  18. DeleteUrlCacheEntry(productUrl.c_str());
  19. HRESULT Hfile = URLDownloadToFile(NULL, productUrl.c_str(), SaveFolder.c_str(), 0, NULL);
  20. char* pStr = CharConvert::GetMultiByteW(SaveFolder.c_str());
  21. return LoadXmlA(pStr);
  22. }
  23. const char* OnlineProduct::LoadXmlA(const char* xmlStr)
  24. {
  25. //加载xml文件
  26. if (pDocument == NULL)
  27. pDocument = new TiXmlDocument();
  28. if (!pDocument->LoadFile(xmlStr, TIXML_ENCODING_UNKNOWN))
  29. {
  30. return "";
  31. }
  32. return GetVersionFromXmlA();
  33. }
  34. const char* OnlineProduct::GetVersionFromXmlA()
  35. {
  36. //解析xml
  37. TiXmlElement* pRootElement = pDocument->RootElement();
  38. if (NULL == pRootElement)
  39. {
  40. return "";
  41. }
  42. TiXmlElement* xml_host = pRootElement->FirstChildElement("channel");
  43. if (xml_host == pRootElement || xml_host == NULL)
  44. {
  45. return "";
  46. }
  47. TiXmlElement* item = xml_host->FirstChildElement("item");
  48. if (item == NULL)
  49. {
  50. return "";
  51. }
  52. TiXmlElement* enclosure = item->FirstChildElement("enclosure");
  53. if (enclosure == NULL)
  54. {
  55. return "";
  56. }
  57. const char* URI = enclosure->Attribute("url");
  58. if (URI == NULL)
  59. {
  60. return "";
  61. }
  62. Product::URI_InstallPackge = std::wstring(URI, URI + strlen(URI));
  63. const char* version = enclosure->Attribute("sparkle:version");
  64. if (version == NULL)
  65. {
  66. return "";
  67. }
  68. m_Verstion = version;
  69. return version;
  70. }
  71. wstring OnlineProduct::GetVersionW()
  72. {
  73. return CharConvert::GetWideCharW(&m_Verstion);
  74. }