downloadThumbnailManager.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // downloadThumbnailManager.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/8.
  6. //
  7. #import "downloadThumbnailManager.h"
  8. @implementation downloadThumbnailManager
  9. static downloadThumbnailManager * cur_downloadFileShareInstance = nil;
  10. +(downloadThumbnailManager *)shareInstance;
  11. {
  12. static dispatch_once_t onceToken;
  13. dispatch_once(&onceToken, ^{
  14. cur_downloadFileShareInstance = [[downloadThumbnailManager alloc] init];
  15. });
  16. return cur_downloadFileShareInstance;
  17. }
  18. - (id)init
  19. {
  20. self = [super init];
  21. if (self) {
  22. //[self initManager];
  23. }
  24. return self;
  25. }
  26. - (void)handlToDownloadThumbnailWith:(NSArray*)Arr
  27. {
  28. if(Arr && Arr.count >0){
  29. if (!_waitDownloadTaskArr) {
  30. _waitDownloadTaskArr = [NSMutableArray arrayWithArray:Arr];
  31. }
  32. else{
  33. [_waitDownloadTaskArr addObjectsFromArray:Arr];
  34. }
  35. [self planToDownloadThumbnailFun];
  36. }
  37. }
  38. - (void)planToDownloadThumbnailFun
  39. {
  40. if (!_downloadingTaskArr || _downloadingTaskArr.count == 0) {
  41. _downloadingTaskArr = [NSMutableArray arrayWithArray:_waitDownloadTaskArr];
  42. [_waitDownloadTaskArr removeAllObjects];
  43. }
  44. [self beginDownloadThumbnailFun];
  45. }
  46. - (void)beginDownloadThumbnailFun
  47. {
  48. if (_downloadingTaskArr.count > 0) {
  49. _curDownloadFileModel = _downloadingTaskArr.firstObject;
  50. }
  51. else{
  52. if(_waitDownloadTaskArr && _waitDownloadTaskArr.count>0){
  53. _downloadingTaskArr = [NSMutableArray arrayWithArray:_waitDownloadTaskArr];
  54. [_waitDownloadTaskArr removeAllObjects];
  55. [self beginDownloadThumbnailFun];
  56. }
  57. return;
  58. }
  59. //检测本地是否已经下载文件了
  60. NSString *fileName = [self.curDownloadFileModel getFileNameFun];
  61. NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail];
  62. NSFileManager *manager0 = [NSFileManager defaultManager];
  63. if([manager0 fileExistsAtPath:pathStr]) {
  64. //已经下载过了
  65. [_downloadingTaskArr removeObject:_curDownloadFileModel];
  66. _curDownloadFileModel = nil;
  67. [self beginDownloadThumbnailFun];
  68. return;
  69. }
  70. [[NSNotificationCenter defaultCenter] postNotificationName:downloadThumbnailBeginNotification object:_curDownloadFileModel];
  71. }
  72. - (void)DownloadFileDoneOneFileFun
  73. {
  74. [_downloadingTaskArr removeObject:_curDownloadFileModel];
  75. _curDownloadFileModel = nil;
  76. [self beginDownloadThumbnailFun];
  77. [[NSNotificationCenter defaultCenter] postNotificationName:downloadThumbnailDoneOneNotification object:nil];
  78. }
  79. @end