downloadManager.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. //
  2. // downloadManager.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/9.
  6. //
  7. #import "downloadManager.h"
  8. #import "cachesFileManager.h"
  9. #import "AFNetworkReachabilityManager.h"
  10. @interface downloadManager ()
  11. /**检测任务10s后 无反馈重新开始 */
  12. @property (nonatomic, assign) NSInteger taskRenewTime; //
  13. @end
  14. @implementation downloadManager
  15. static downloadManager * cur_downloadManager = nil;
  16. +(downloadManager *)shareInstance;
  17. {
  18. static dispatch_once_t onceToken;
  19. dispatch_once(&onceToken, ^{
  20. cur_downloadManager = [[downloadManager alloc] init];
  21. });
  22. return cur_downloadManager;
  23. }
  24. - (id)init
  25. {
  26. self = [super init];
  27. if (self) {
  28. //[self initManager];
  29. }
  30. return self;
  31. }
  32. #pragma mark 读取数据库数据
  33. - (void)getDataInDatabaseFun:(BOOL)isReGet complete:(custom_complete_Arr)complete
  34. {
  35. if(_databaseArr && _databaseArr.count == 3 && !isReGet){
  36. complete(_databaseArr);
  37. return;
  38. }
  39. if(!_databaseArr)
  40. {
  41. _databaseArr = [NSMutableArray new];
  42. }
  43. //KWeakSelf
  44. //dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
  45. // NSLock *lock = [NSLock new];
  46. // [lock lock];
  47. [couldPhoneFileModel bg_findAsync:download_tableName limit:0 orderBy:nil desc:YES complete:^(NSArray * _Nullable array) {
  48. NSMutableArray *failArr = [NSMutableArray new];
  49. NSMutableArray *doneArr = [NSMutableArray new];
  50. NSMutableArray *otherArr = [NSMutableArray new];
  51. if(array && array.count >0){
  52. for (couldPhoneFileModel * curModel in array) {
  53. if(curModel.curDownloadStateType == downloadStateFail){
  54. [failArr addObject:curModel];
  55. }
  56. else if(curModel.curDownloadStateType == downloadStateDone){
  57. [doneArr addObject:curModel];
  58. }
  59. else{
  60. [otherArr addObject:curModel];
  61. }
  62. }
  63. }
  64. NSLock *lock = [NSLock new];
  65. [lock lock];
  66. NSMutableArray *newArr = [NSMutableArray new];
  67. [newArr addObject:otherArr];
  68. [newArr addObject:doneArr];
  69. [newArr addObject:failArr];
  70. self->_databaseArr = newArr;
  71. [lock unlock];
  72. complete(self->_databaseArr);
  73. }];
  74. // [lock unlock];
  75. //});
  76. }
  77. -(void)handleCouldPhoneFileModelToDownloadFileDataFunBy:(NSMutableArray*)indexPathsForSelectedItems complete:(custom_complete_Arr)complete
  78. {
  79. if(!indexPathsForSelectedItems && indexPathsForSelectedItems.count == 0){
  80. complete(nil);
  81. return;
  82. }
  83. if(ksharedAppDelegate.DisabledFileTransferType){
  84. if(ksharedAppDelegate.isImageNewFor130){
  85. [[iToast makeText:NSLocalizedString(@"File_Transfer_Disable_tip",nil)] show];
  86. }
  87. else{
  88. [[iToast makeText:NSLocalizedString(@"File_Transfer_Disable_tip2",nil)] show];
  89. }
  90. complete(_databaseArr);
  91. return;
  92. }
  93. for (couldPhoneFileModel*model in indexPathsForSelectedItems) {
  94. model.bg_tableName = download_tableName;
  95. }
  96. _isNewAddTaskType = YES;
  97. KWeakSelf
  98. //查
  99. [self getDataInDatabaseFun:YES complete:^(NSMutableArray * _Nonnull Arr) {
  100. //排重
  101. NSMutableArray *newDownArr = [weakSelf checkDownloadTaskRepeatFun:indexPathsForSelectedItems];
  102. if(newDownArr.count>0){
  103. //存
  104. [couldPhoneFileModel bg_saveOrUpdateArrayAsync:newDownArr complete:^(BOOL isSuccess) {
  105. //再查
  106. [weakSelf getDataInDatabaseFun:YES complete:^(NSMutableArray * _Nonnull Arr) {
  107. complete(Arr);
  108. [weakSelf planToDownloadFileFun];
  109. }];
  110. }];
  111. }
  112. else{
  113. complete(Arr);
  114. [weakSelf planToDownloadFileFun];
  115. }
  116. }];
  117. }
  118. #pragma mark 检测是否有下载任务重复
  119. - (NSMutableArray*)checkDownloadTaskRepeatFun:(NSMutableArray*)indexPathsForSelectedItems
  120. {
  121. if(!_databaseArr || _databaseArr.count != 3){
  122. return indexPathsForSelectedItems;
  123. }
  124. NSMutableArray *downloadArr = _databaseArr[0];
  125. NSMutableArray *newTaskArr = [NSMutableArray new];
  126. for (couldPhoneFileModel*model in indexPathsForSelectedItems) {
  127. NSString *fileName = [model getFileNameFun];
  128. BOOL isNeedAddType = YES;
  129. for (couldPhoneFileModel* hadModel in downloadArr) {
  130. NSString *hadFileName = [hadModel getFileNameFun];
  131. if([fileName isEqualToString:hadFileName]){
  132. isNeedAddType = NO;
  133. break;
  134. }
  135. }
  136. if(isNeedAddType){
  137. [newTaskArr addObject:model];
  138. }
  139. }
  140. return newTaskArr;
  141. }
  142. - (void)planToDownloadFileFun
  143. {
  144. if(!_databaseArr || _databaseArr.count != 3){
  145. return;
  146. }
  147. _downLoadFileModelDataArr = [NSMutableArray arrayWithArray:_databaseArr[0]];
  148. [self beginDownloadFileFun];
  149. }
  150. - (void)beginDownloadFileFun
  151. {
  152. if(_downLoadFileModelDataArr.count == 0)
  153. {
  154. [self didDownloadAllTaskDoneFun];
  155. return;
  156. }
  157. BOOL isCanUseCellular = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_canUse_Cellular_all)];
  158. if(!isCanUseCellular){//不允许流量上传
  159. //
  160. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN){
  161. mainBlock(^{
  162. [[NSNotificationCenter defaultCenter] postNotificationName:downloadFileSuspendAllNotification object:nil];
  163. [[iToast makeText:NSLocalizedString(@"File_Transfer_By_Cellular_tip",nil)] show];
  164. });
  165. return;
  166. }
  167. }
  168. if(ksharedAppDelegate.DisabledFileTransferType){
  169. if(ksharedAppDelegate.isImageNewFor130){
  170. [[iToast makeText:NSLocalizedString(@"File_Transfer_Disable_tip",nil)] show];
  171. }
  172. else{
  173. [[iToast makeText:NSLocalizedString(@"File_Transfer_Disable_tip2",nil)] show];
  174. }
  175. return;
  176. }
  177. self.taskRenewTime = [iTools getNowTimeStamp];
  178. _isSuspendType = NO;
  179. _isDownloadIngType = YES;
  180. if(_reDownloadIngSelectIndex > 0
  181. && _reDownloadIngSelectIndex < _downLoadFileModelDataArr.count){
  182. _curDownloadFileModel = _downLoadFileModelDataArr[_reDownloadIngSelectIndex];
  183. }
  184. else
  185. {
  186. _curDownloadFileModel = _downLoadFileModelDataArr.firstObject;
  187. }
  188. if(!_curDownloadFileModel){
  189. return;
  190. }
  191. // //做个异常处理
  192. // if(_databaseArr.count == 3 && _isNewAddTaskType){
  193. // NSMutableArray *downloadIngArr = _databaseArr[0];
  194. // if(_downLoadFileModelDataArr.count != downloadIngArr.count){
  195. // _databaseArr[0] = [NSMutableArray arrayWithArray:_downLoadFileModelDataArr];
  196. // }
  197. // }
  198. if(![iTools checkFreeDiskSpaceInBytesIsOK:_curDownloadFileModel.length]){
  199. mainBlock(^{
  200. [[iToast makeText:NSLocalizedString(@"phone_space_Insufficient",nil)] show];
  201. });
  202. return;
  203. }
  204. _curDownloadFileModel.curDownloadStateType = downloadStateUploading;
  205. [[webSocketManager shareInstance] begindownloadFileFunBy:_curDownloadFileModel];
  206. }
  207. - (void)DownloadFileDoneOneFileFun
  208. {
  209. self.taskRenewTime = [iTools getNowTimeStamp];
  210. _curDownloadFileModel.curDownloadStateType = downloadStateDone;
  211. // NSString *fileName = [_curDownloadFileModel getFileNameFun];
  212. // [cachesFileManager removeItemAtPath:fileName type:DownLoadFileType error:nil];
  213. //1.先做数据保存
  214. NSDictionary *dataDict = [_curDownloadFileModel downLoadInfoWithFinished:YES];
  215. [self saveFileInfoWithDict:dataDict with:_curDownloadFileModel.path];
  216. [self DownloadFileChangeingOneFileFun];
  217. if(_isSuspendType){
  218. return;
  219. }
  220. [self beginDownloadFileFun];
  221. }
  222. - (void)DownloadFileFailOneFileFun
  223. {
  224. self.taskRenewTime = [iTools getNowTimeStamp];
  225. _curDownloadFileModel.curDownloadStateType = downloadStateFail;
  226. [self DownloadFileChangeingOneFileFun];
  227. if(_isSuspendType){
  228. return;
  229. }
  230. [self beginDownloadFileFun];
  231. }
  232. - (void)DownloadFileChangeingOneFileFun
  233. {
  234. self.taskRenewTime = [iTools getNowTimeStamp];
  235. if(_curDownloadFileModel.curDownloadStateType == downloadStateDone){
  236. [_downLoadFileModelDataArr removeObject:_curDownloadFileModel];
  237. [self handleDatabaseArrDeleteObjectInDownloading:_curDownloadFileModel];
  238. [self handleDatabaseArrAddObjectInDone:_curDownloadFileModel];
  239. }
  240. else if(_curDownloadFileModel.curDownloadStateType == uploadStateFail){
  241. [_downLoadFileModelDataArr removeObject:_curDownloadFileModel];
  242. [self handleDatabaseArrDeleteObjectInDownloading:_curDownloadFileModel];
  243. [self handleDatabaseArrAddObjectInFail:_curDownloadFileModel];
  244. }
  245. [_curDownloadFileModel bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  246. //HLog(@"%@ 写入 %@", model.filename, isSuccess ? @"成功":@"失败");
  247. }];
  248. if(!_isSuspendType || _curDownloadFileModel.curDownloadStateType != uploadStateSuspend){
  249. [[NSNotificationCenter defaultCenter] postNotificationName:downloadFileRefreshNotification object:_curDownloadFileModel];
  250. }
  251. }
  252. - (void)handleDatabaseArrDeleteObjectInDownloading:(couldPhoneFileModel*)model
  253. {
  254. NSLock *lock = [NSLock new];
  255. [lock lock];
  256. if(_databaseArr && _databaseArr.count == 3 ){
  257. NSMutableArray *ingArr = _databaseArr[0];
  258. NSInteger count = ingArr.count;
  259. [ingArr removeObject:model];
  260. NSInteger atferDelCount = ingArr.count;
  261. if(count == atferDelCount){
  262. for (couldPhoneFileModel*preModel in ingArr) {
  263. if(preModel.bg_id.integerValue == model.bg_id.integerValue){
  264. [ingArr removeObject:preModel];
  265. break;
  266. }
  267. }
  268. }
  269. NSInteger atferDelCount2 = ingArr.count;
  270. if(count == atferDelCount2){
  271. // HLog(@"\n\n\nerror:下载中的任务没有删除掉database bgid:%@\n\n\n\n",model.bg_id);
  272. }
  273. }
  274. [lock unlock];
  275. }
  276. - (void)handleDatabaseArrAddObjectInDone:(couldPhoneFileModel*)model
  277. {
  278. NSLock *lock = [NSLock new];
  279. [lock lock];
  280. if(_databaseArr && _databaseArr.count == 3 ){
  281. NSMutableArray *doneArr = _databaseArr[1];
  282. if(model){
  283. [doneArr insertObject:model atIndex:0];
  284. }
  285. }
  286. [lock unlock];
  287. }
  288. - (void)handleDatabaseArrAddObjectInFail:(couldPhoneFileModel*)model
  289. {
  290. NSLock *lock = [NSLock new];
  291. [lock lock];
  292. if(_databaseArr && _databaseArr.count == 3 ){
  293. NSMutableArray *failArr = _databaseArr[2];
  294. if(model){
  295. [failArr insertObject:model atIndex:0];
  296. }
  297. }
  298. [lock unlock];
  299. }
  300. - (void)suspendDownloadFileFun:(BOOL)isSuspendAll withModel:(couldPhoneFileModel*)model
  301. {
  302. if(isSuspendAll){
  303. _isSuspendType = YES;
  304. [[NSNotificationCenter defaultCenter] postNotificationName:downloadFileSuspendAllNotification object:nil];
  305. // for (couldPhoneFileModel *couldPhoneFileMod in _downLoadFileModelDataArr) {
  306. // couldPhoneFileMod.curDownloadStateType = downloadStateSuspend;
  307. // }
  308. [self changeDownloadState:downloadStateSuspend withModelArr:_downLoadFileModelDataArr complete:^(BOOL isSuccess) {
  309. [self->_downLoadFileModelDataArr removeAllObjects];
  310. }];
  311. }
  312. else{
  313. couldPhoneFileModel *curModel = _curDownloadFileModel;
  314. if(model){
  315. curModel = model;
  316. }
  317. else{
  318. _isSuspendType = YES;
  319. }
  320. [self changeDownloadState:downloadStateSuspend withModelArr:@[curModel] complete:^(BOOL isSuccess) {
  321. [self->_downLoadFileModelDataArr removeObject:model];
  322. if(curModel.bg_id.integerValue == self->_curDownloadFileModel.bg_id.integerValue){
  323. //开启下一个任务
  324. _reDownloadIngSelectIndex = -1;
  325. [self beginDownloadFileFun];
  326. }
  327. }];
  328. }
  329. }
  330. - (void)reDownloadFileFunBy:(NSMutableArray*)Arr withAll:(BOOL)isAllType
  331. {
  332. if(!_downLoadFileModelDataArr){
  333. _downLoadFileModelDataArr = [NSMutableArray new];
  334. }
  335. if(isAllType)
  336. {
  337. _isNewAddTaskType = YES;
  338. _downLoadFileModelDataArr = [NSMutableArray arrayWithArray:Arr];
  339. _reDownloadIngSelectIndex = -1;
  340. }
  341. else{
  342. _isNewAddTaskType = NO;
  343. _reDownloadIngSelectIndex = 0;
  344. NSMutableArray *curArr = [NSMutableArray arrayWithArray:Arr];
  345. for (uploadFileDataModel*addModel in curArr){
  346. [_downLoadFileModelDataArr insertObject:addModel atIndex:0];
  347. }
  348. }
  349. [self changeDownloadState:downloadStateUploading withModelArr:_downLoadFileModelDataArr complete:^(BOOL isSuccess) {
  350. }];
  351. [self beginDownloadFileFun];
  352. }
  353. - (void)handleDatabaseArrByDelete:(couldPhoneFileModel*)delModel
  354. {
  355. if(_databaseArr && _databaseArr.count == 3 ){
  356. if(delModel.curDownloadStateType == downloadStateDone)
  357. {
  358. NSMutableArray *arr = _databaseArr[1];
  359. [arr removeObject:delModel];
  360. }
  361. else if(delModel.curDownloadStateType == downloadStateFail){
  362. NSMutableArray *arr = _databaseArr[2];
  363. [arr removeObject:delModel];
  364. }
  365. else{
  366. NSMutableArray *arr = _databaseArr[0];
  367. [arr removeObject:delModel];
  368. }
  369. }
  370. }
  371. - (void)deleteDownloadFileRecordBy:(NSMutableArray *)delArr withDelCache:(BOOL)isDelCache
  372. {
  373. //逻辑待优化
  374. BOOL isSuc = false;
  375. BOOL isDelUploadingModel = false;
  376. NSMutableArray *curDelArr = [NSMutableArray arrayWithArray:delArr];
  377. for (couldPhoneFileModel *couldPhoneFileMod in curDelArr) {
  378. NSMutableString* where = [[NSMutableString alloc] initWithString:@"where "];
  379. NSString *curStr = [NSString stringWithFormat:@"%@=%@ ",bg_sqlKey(@"bg_id"),bg_sqlValue(couldPhoneFileMod.bg_id)];
  380. [where appendString:curStr];
  381. [couldPhoneFileModel bg_deleteAsync:download_tableName where:where complete:^(BOOL isSuccess) {
  382. }];
  383. //isSuc = [couldPhoneFileModel bg_delete:download_tableName where:where];
  384. [self handleDatabaseArrByDelete:couldPhoneFileMod];
  385. if(couldPhoneFileMod.bg_id.integerValue == _curDownloadFileModel.bg_id.integerValue){
  386. isDelUploadingModel = YES;
  387. [self suspendDownloadFileFun:NO withModel:_curDownloadFileModel];
  388. }
  389. }
  390. if(isDelUploadingModel){
  391. _isDownloadIngType = NO;
  392. if(_downLoadFileModelDataArr > 0){
  393. [self beginDownloadFileFun];
  394. }
  395. }
  396. [[NSNotificationCenter defaultCenter] postNotificationName:downloadFileRefreshNotification object:_curDownloadFileModel];
  397. }
  398. //修改文件上传的状态
  399. - (void)changeDownloadState:(downloadStateType)curDownloadStateType withModelArr:(NSArray*)modelArr complete:(custom_complete_B)complete
  400. {
  401. for (couldPhoneFileModel * model in modelArr) {
  402. model.curDownloadStateType = curDownloadStateType;
  403. }
  404. if(modelArr.count == 0){
  405. return;
  406. }
  407. [couldPhoneFileModel bg_saveOrUpdateArrayAsync:modelArr complete:^(BOOL isSuccess) {
  408. complete(YES);
  409. }];
  410. }
  411. //检查是否需要重新下载
  412. - (void)checkReDownloadFileFun
  413. {
  414. if(!_curDownloadFileModel){
  415. return;
  416. }
  417. if(_isSuspendType){
  418. return;
  419. }
  420. NSInteger curTime = [iTools getNowTimeStamp];
  421. if(self.taskRenewTime == 0){
  422. return;
  423. }
  424. if(curTime - self.taskRenewTime < 10){
  425. return;
  426. }
  427. if(![iTools checkFreeDiskSpaceInBytesIsOK:_curDownloadFileModel.length]){
  428. mainBlock(^{
  429. [[iToast makeText:NSLocalizedString(@"phone_space_Insufficient",nil)] show];
  430. });
  431. _curDownloadFileModel = nil;
  432. return;
  433. }
  434. [[webSocketManager shareInstance] begindownloadFileFunBy:_curDownloadFileModel];
  435. }
  436. - (BOOL)checkDownloadingFun
  437. {
  438. if(!_curDownloadFileModel){
  439. return NO;
  440. }
  441. // if(_curDownloadFileModel.curDownloadStateType == downloadStateDone
  442. // ||_curDownloadFileModel.curDownloadStateType == downloadStateFail
  443. // ||_curDownloadFileModel.curDownloadStateType == downloadStateSuspend){
  444. // return NO;
  445. // }
  446. if(_isSuspendType){
  447. return NO;
  448. }
  449. return YES;
  450. }
  451. - (void)didDownloadAllTaskDoneFun
  452. {
  453. _curDownloadFileModel = nil;
  454. [[NSNotificationCenter defaultCenter] postNotificationName:downloadFileAllTaskDoneNotification object:nil];
  455. }
  456. - (void)checkHadDownloadTaskWithComplete:(custom_complete_B)complete
  457. {
  458. [self getDataInDatabaseFun:NO complete:^(NSMutableArray * _Nonnull Arr) {
  459. mainBlock(^{
  460. if(!Arr || Arr.count != 3){
  461. complete(NO);
  462. }
  463. else{
  464. NSArray *firstArr = Arr[0];
  465. if(firstArr.count >0){
  466. complete(YES);
  467. }
  468. else{
  469. complete(NO);
  470. }
  471. }
  472. });
  473. }];
  474. }
  475. #pragma mark- ws download done plist Path
  476. - (NSString *)getDownloadDonePlistPath {
  477. NSString *fileFolder = [NSString stringWithFormat:@"%@/DownLoadFlie",CachesPatch];;
  478. return [fileFolder stringByAppendingPathComponent:@"webSocketDownloadDoneInfo.plist"];;
  479. }
  480. #pragma mark- download done plist
  481. - (NSMutableDictionary *)getDownloadDownList {
  482. if (!_downloadDoneList) { // 内存没有
  483. _downloadDoneList = [[NSDictionary dictionaryWithContentsOfFile:[self getDownloadDonePlistPath]] mutableCopy]; // 本地加载
  484. if (!_downloadDoneList) { // 本地没有,分配内存
  485. _downloadDoneList = [NSMutableDictionary dictionary];
  486. }
  487. }
  488. return _downloadDoneList;
  489. }
  490. /** 增加配置信息 */
  491. - (BOOL)saveFileInfoWithDict:(NSDictionary *)dict with:(NSString*)url {
  492. HLog(@"saveFileInfoWithDict:%@",url)
  493. if(!dict || !url){
  494. return NO;
  495. }
  496. BOOL flag = NO;
  497. @synchronized (self) {
  498. NSString *key = url;
  499. NSMutableDictionary *dictM = [self getDownloadDownList];
  500. [dictM setObject:dict forKey:key];
  501. flag = [dictM writeToFile:[self getDownloadDonePlistPath] atomically:YES];
  502. }
  503. return flag;
  504. }
  505. /** 删除配置信息 */
  506. - (BOOL)deleteFileInfoWithUrl:(NSString *)url {
  507. if(!url){
  508. return NO;
  509. }
  510. BOOL flag = NO;
  511. @synchronized (self) {
  512. NSMutableDictionary *dictM = [self getDownloadDownList];
  513. [dictM removeObjectForKey:url];
  514. flag = [dictM writeToFile:[self getDownloadDonePlistPath] atomically:YES];
  515. }
  516. return flag;
  517. }
  518. #pragma mark-保存完成后 删除此次信息 download done plist
  519. - (void)deleteDownloadDonePlistInfoBy:(NSString*)fullPath
  520. {
  521. HLog(@"deleteDownloadDonePlistInfoBy:%@",fullPath)
  522. NSMutableDictionary *dictM = [self getDownloadDownList];
  523. for (NSString*key in dictM) {
  524. NSDictionary*dict = dictM[key];
  525. if ([[dict allKeys] containsObject:@"fullPath"]) {
  526. NSString * infofullPath = dict[@"fullPath"];
  527. if([fullPath isEqualToString:infofullPath]){
  528. [self deleteFileInfoWithUrl:key];
  529. break;
  530. }
  531. }
  532. }
  533. }
  534. #pragma mark-查询还有没有没处理的任务
  535. - (void)checkDownloadDonePlistInfoFun
  536. {
  537. NSMutableDictionary *dictM = [[self getDownloadDownList] mutableCopy];
  538. if(dictM.count > 0){
  539. for (NSString*key in dictM) {
  540. NSDictionary*dict = dictM[key];
  541. couldPhoneFileModel *model = [couldPhoneFileModel mj_objectWithKeyValues:dict];
  542. NSString *fileName = [model getFileNameFun];
  543. NSString*fullPath = [cachesFileManager getFilePathWithName:fileName type:DownLoadFileType];
  544. //判断文件是否还存在
  545. if (![[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
  546. //不存在 删除信息
  547. HLog(@"deleteFileInfoWithUrl:%@",key)
  548. [self deleteFileInfoWithUrl:key];
  549. }
  550. else{//存在 通知保存流程
  551. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  552. [[webSocketManager shareInstance] saveDownDoneFileToPhoneFunBy:fullPath withKey:model.path];
  553. });
  554. break;
  555. }
  556. }
  557. }
  558. }
  559. @end