|
@@ -6,6 +6,10 @@
|
|
|
//
|
|
|
|
|
|
#import "nasDownloadFileManager.h"
|
|
|
+@interface nasDownloadFileManager ()
|
|
|
+@property (nonatomic, strong)NSLock *lock;
|
|
|
+
|
|
|
+@end
|
|
|
|
|
|
@implementation nasDownloadFileManager
|
|
|
static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
|
|
@@ -29,6 +33,7 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskExeEnd object:nil];
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskExeError object:nil];
|
|
|
|
|
|
+ _lock = [[NSLock alloc] init];
|
|
|
[self initDownloadManagerFun];
|
|
|
}
|
|
|
|
|
@@ -342,25 +347,29 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
|
|
|
|
|
|
if(!model)return;
|
|
|
|
|
|
- if (model.downloadState == customDownloadStateCompleted) {
|
|
|
-
|
|
|
- //1.先做数据保存
|
|
|
- NSDictionary *dataDict = [model downLoadInfoWithFinished:YES];
|
|
|
- [self saveFileInfoWithDict:dataDict with:model.url];
|
|
|
+ //globalBlock(^{
|
|
|
+ if (model.downloadState == customDownloadStateCompleted) {
|
|
|
+
|
|
|
+ //1.先做数据保存
|
|
|
+ NSDictionary *dataDict = [model downLoadInfoWithFinished:YES];
|
|
|
+ [self saveFileInfoWithDict:dataDict with:model.url];
|
|
|
+
|
|
|
+ [self handldDownloadDoneDataBy:model];
|
|
|
+
|
|
|
+ HLog(@"handldDownloadDoneDataBy done")
|
|
|
+ }
|
|
|
+ else if (model.downloadState == customDownloadStateFailed){
|
|
|
+ [self handldDownloadFailDataBy:model];
|
|
|
+ }
|
|
|
|
|
|
- [self handldDownloadDoneDataBy:model];
|
|
|
+ mainBlock(^{
|
|
|
+ [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskFinishedNotification object:model];
|
|
|
+
|
|
|
+ [[webRtcManager shareManager] NasDownloadTaskFinishedNoti:model];
|
|
|
+ });
|
|
|
|
|
|
- HLog(@"handldDownloadDoneDataBy done")
|
|
|
- }
|
|
|
- else if (model.downloadState == customDownloadStateFailed){
|
|
|
- [self handldDownloadFailDataBy:model];
|
|
|
- }
|
|
|
+ // });
|
|
|
|
|
|
- mainBlock(^{
|
|
|
- [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskFinishedNotification object:model];
|
|
|
-
|
|
|
- [[webRtcManager shareManager] NasDownloadTaskFinishedNoti:model];
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
|
|
@@ -657,17 +666,19 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
|
|
|
/** 增加配置信息 */
|
|
|
- (BOOL)saveFileInfoWithDict:(NSDictionary *)dict with:(NSString*)url {
|
|
|
|
|
|
+ HLog(@"saveFileInfoWithDict")
|
|
|
+
|
|
|
if(!dict || !url){
|
|
|
return NO;
|
|
|
}
|
|
|
|
|
|
BOOL flag = NO;
|
|
|
- @synchronized (self) {
|
|
|
+ [_lock lock];
|
|
|
NSString *key = url;
|
|
|
NSMutableDictionary *dictM = [self getDownloadDownList];
|
|
|
[dictM setObject:dict forKey:key];
|
|
|
flag = [dictM writeToFile:[self getDownloadDonePlistPath] atomically:YES];
|
|
|
- }
|
|
|
+ [_lock unlock];
|
|
|
|
|
|
return flag;
|
|
|
|
|
@@ -710,6 +721,7 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
|
|
|
#pragma mark-查询还有没有没处理的任务
|
|
|
- (void)checkDownloadDonePlistInfoFun
|
|
|
{
|
|
|
+ HLog(@"checkDownloadDonePlistInfoFun")
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
|
|
|
NSMutableDictionary *dictM = [[self getDownloadDownList] mutableCopy];
|
|
|
NSMutableArray *needDeletekeyArr = [NSMutableArray array];
|
|
@@ -737,9 +749,13 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
|
|
|
|
|
|
if(needDeletekeyArr.count > 0){
|
|
|
for(NSString*key in needDeletekeyArr){
|
|
|
- [self deleteFileInfoWithUrl:key];
|
|
|
+ //[self deleteFileInfoWithUrl:key];
|
|
|
[dictM removeObjectForKey:key];
|
|
|
}
|
|
|
+
|
|
|
+ //保存更新本地数据
|
|
|
+ [dictM writeToFile:[self getDownloadDonePlistPath] atomically:YES];
|
|
|
+
|
|
|
[needDeletekeyArr removeAllObjects];
|
|
|
}
|
|
|
|