download.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include <array.h>
  3. #include <locale>
  4. #include <codecvt>
  5. #include <string>
  6. //GBK转UTF码类
  7. class chs_codecvt : public std::codecvt_byname<wchar_t, char, std::mbstate_t> {
  8. public:
  9. //因不同平台,名称不同,故这里做转换,统一取出不同平台下面的GBK码
  10. #ifdef RVC_OS_WIN
  11. chs_codecvt() : codecvt_byname("chs") { }//zh_CN.GBK or .936
  12. #else
  13. chs_codecvt() : codecvt_byname("zh_CN.GBK") { }
  14. #endif // RVC_OS_WIN
  15. };
  16. typedef struct download_file_t {
  17. //char name[64];
  18. char name[256];
  19. int length;
  20. //char md5[16];
  21. char md5[32];
  22. }download_file_t;
  23. // xml must be have <?xml version="1.0" encoding="utf-8" ?>
  24. array_header_t* download_parse_filelist(const char *xml, int n);
  25. void download_free_filelist(array_header_t* arr);
  26. //int download_check_filelist(const char *base_dir, array_header_t* arr);
  27. //0:表示下载的文件在文件列表里不存在 1:需要下载 2:下载完成
  28. int new_download_check_filelist(const char *base_dir, array_header_t* arr,download_file_t *downloadFile);
  29. //0:删除失败,1删除成功
  30. int download_delete_file(const char *base_dir,download_file_t *downloadFile);
  31. typedef struct download_storage_t {
  32. char temp_path[MAX_PATH];
  33. char info_path[MAX_PATH];
  34. #ifdef RVC_OS_WIN
  35. HANDLE temp_handle;
  36. HANDLE info_handle;
  37. #else
  38. FILE* temp_handle;
  39. FILE* info_handle;
  40. #endif
  41. int offset_block_id;
  42. int length;
  43. }download_storage_t;
  44. //null表示开打失败,否则打开成功
  45. download_storage_t *download_storage_open(const char *base_dir, download_file_t *file);
  46. void download_storage_close(download_storage_t *storage,bool renameFlag,bool deleteFlag);
  47. int download_storage_update(download_storage_t *storage, char *buf, int n);
  48. //0:md5一致,1,2不一致
  49. int download_check_MD5(download_storage_t *storage,download_file_t *dfile);
  50. //int download_get_storage_block_id(const char *base_dir, download_file_t *file, int *block_id);