123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- //
- // downloadThumbnailManager.m
- // 隐私保护
- //
- // Created by xd h on 2024/1/8.
- //
- #import "downloadThumbnailManager.h"
- @implementation downloadThumbnailManager
- static downloadThumbnailManager * cur_downloadFileShareInstance = nil;
- +(downloadThumbnailManager *)shareInstance;
- {
- static dispatch_once_t onceToken;
-
- dispatch_once(&onceToken, ^{
- cur_downloadFileShareInstance = [[downloadThumbnailManager alloc] init];
-
- });
-
- return cur_downloadFileShareInstance;
- }
- - (id)init
- {
- self = [super init];
-
- if (self) {
- //[self initManager];
- }
-
- return self;
- }
- - (void)handlToDownloadThumbnailWith:(NSArray*)Arr
- {
- if(Arr && Arr.count >0){
- if (!_waitDownloadTaskArr) {
- _waitDownloadTaskArr = [NSMutableArray arrayWithArray:Arr];
- }
- else{
- [_waitDownloadTaskArr addObjectsFromArray:Arr];
- }
-
- [self planToDownloadThumbnailFun];
- }
- }
- - (void)planToDownloadThumbnailFun
- {
- if (!_downloadingTaskArr || _downloadingTaskArr.count == 0) {
- _downloadingTaskArr = [NSMutableArray arrayWithArray:_waitDownloadTaskArr];
- [_waitDownloadTaskArr removeAllObjects];
- }
-
- [self beginDownloadThumbnailFun];
- }
- - (void)beginDownloadThumbnailFun
- {
- if (_downloadingTaskArr.count > 0) {
- _curDownloadFileModel = _downloadingTaskArr.firstObject;
- }
- else{
- if(_waitDownloadTaskArr && _waitDownloadTaskArr.count>0){
- _downloadingTaskArr = [NSMutableArray arrayWithArray:_waitDownloadTaskArr];
- [_waitDownloadTaskArr removeAllObjects];
- [self beginDownloadThumbnailFun];
- }
- return;
- }
-
- //检测本地是否已经下载文件了
- NSString *fileName = [self.curDownloadFileModel getFileNameFun];
- NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail];
-
- NSFileManager *manager0 = [NSFileManager defaultManager];
- if([manager0 fileExistsAtPath:pathStr]) {
- //已经下载过了
- [_downloadingTaskArr removeObject:_curDownloadFileModel];
- _curDownloadFileModel = nil;
- [self beginDownloadThumbnailFun];
- return;
- }
-
-
- [[NSNotificationCenter defaultCenter] postNotificationName:downloadThumbnailBeginNotification object:_curDownloadFileModel];
- }
- - (void)DownloadFileDoneOneFileFun
- {
- [_downloadingTaskArr removeObject:_curDownloadFileModel];
- _curDownloadFileModel = nil;
- [self beginDownloadThumbnailFun];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:downloadThumbnailDoneOneNotification object:nil];
- }
- @end
|