Browse Source

1.处理websocket一次下载多个音频文件 只保存一个问题(类似分享下载操作的bug)

huangxiaodong 1 year ago
parent
commit
1e6e268913

+ 2 - 2
创维盒子/双子星云手机.xcodeproj/project.pbxproj

@@ -5740,7 +5740,7 @@
 				CODE_SIGN_IDENTITY = "Apple Development";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Manual;
-				CURRENT_PROJECT_VERSION = 8;
+				CURRENT_PROJECT_VERSION = 9;
 				DEVELOPMENT_TEAM = "";
 				"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6SV76WTUUR;
 				FRAMEWORK_SEARCH_PATHS = (
@@ -5821,7 +5821,7 @@
 				CODE_SIGN_IDENTITY = "Apple Development";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Manual;
-				CURRENT_PROJECT_VERSION = 8;
+				CURRENT_PROJECT_VERSION = 9;
 				DEVELOPMENT_TEAM = "";
 				"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 6SV76WTUUR;
 				FRAMEWORK_SEARCH_PATHS = (

+ 7 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/downloadManager.h

@@ -25,6 +25,8 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic, assign) NSInteger  reDownloadIngSelectIndex;
 @property (nonatomic, assign) BOOL  isNewAddTaskType;
 
+@property (nonatomic, strong) NSMutableDictionary * _Nullable downloadDoneList;
+
 +(downloadManager *)shareInstance;
 #pragma mark 读取数据库数据
 - (void)getDataInDatabaseFun:(BOOL)isReGet complete:(custom_complete_Arr)complete;
@@ -43,6 +45,11 @@ NS_ASSUME_NONNULL_BEGIN
 //检测是否未下载中
 - (BOOL)checkDownloadingFun;
 - (void)checkHadDownloadTaskWithComplete:(custom_complete_B)complete;
+
+#pragma mark-保存完成后 删除此次信息 download done plist
+- (void)deleteDownloadDonePlistInfoBy:(NSString*)fullPath;
+#pragma mark-查询还有没有没处理的任务
+- (void)checkDownloadDonePlistInfoFun;
 @end
 
 NS_ASSUME_NONNULL_END

+ 104 - 1
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/downloadManager.m

@@ -262,7 +262,10 @@ static downloadManager * cur_downloadManager = nil;
 //    NSString *fileName = [_curDownloadFileModel getFileNameFun];
 //    [cachesFileManager removeItemAtPath:fileName type:DownLoadFileType error:nil];
     
-   
+    //1.先做数据保存
+    NSDictionary *dataDict = [_curDownloadFileModel downLoadInfoWithFinished:YES];
+    [self saveFileInfoWithDict:dataDict with:_curDownloadFileModel.path];
+    
     [self DownloadFileChangeingOneFileFun];
     
     if(_isSuspendType){
@@ -601,4 +604,104 @@ static downloadManager * cur_downloadManager = nil;
         
     }];
 }
+
+
+#pragma mark- ws download done plist Path
+- (NSString *)getDownloadDonePlistPath {
+    NSString *fileFolder = [NSString stringWithFormat:@"%@/DownLoadFlie",CachesPatch];;
+    return [fileFolder stringByAppendingPathComponent:@"webSocketDownloadDoneInfo.plist"];;
+}
+
+#pragma mark- download done plist
+- (NSMutableDictionary *)getDownloadDownList {
+    
+    if (!_downloadDoneList) { // 内存没有
+        _downloadDoneList = [[NSDictionary dictionaryWithContentsOfFile:[self getDownloadDonePlistPath]] mutableCopy]; // 本地加载
+        if (!_downloadDoneList) { // 本地没有,分配内存
+            _downloadDoneList = [NSMutableDictionary dictionary];
+        }
+    }
+    return _downloadDoneList;
+}
+
+/**  增加配置信息 */
+- (BOOL)saveFileInfoWithDict:(NSDictionary *)dict with:(NSString*)url {
+    HLog(@"saveFileInfoWithDict:%@",url)
+    if(!dict || !url){
+        return NO;
+    }
+    
+    BOOL flag = NO;
+    @synchronized (self) {
+        NSString *key = url;
+        NSMutableDictionary *dictM =  [self getDownloadDownList];
+        [dictM setObject:dict forKey:key];
+        flag = [dictM writeToFile:[self getDownloadDonePlistPath] atomically:YES];
+    }
+    
+    return flag;
+    
+}
+
+/**  删除配置信息 */
+- (BOOL)deleteFileInfoWithUrl:(NSString *)url {
+    if(!url){
+        return NO;
+    }
+    
+    BOOL flag = NO;
+    @synchronized (self) {
+        NSMutableDictionary *dictM =  [self getDownloadDownList];
+        [dictM removeObjectForKey:url];
+        flag = [dictM writeToFile:[self getDownloadDonePlistPath] atomically:YES];
+    }
+    return flag;
+}
+
+#pragma mark-保存完成后 删除此次信息 download done plist
+- (void)deleteDownloadDonePlistInfoBy:(NSString*)fullPath
+{
+    HLog(@"deleteDownloadDonePlistInfoBy:%@",fullPath)
+    NSMutableDictionary *dictM =  [self getDownloadDownList];
+    for (NSString*key in dictM) {
+        NSDictionary*dict = dictM[key];
+        
+        if ([[dict allKeys] containsObject:@"fullPath"]) {
+            NSString * infofullPath = dict[@"fullPath"];
+
+            if([fullPath isEqualToString:infofullPath]){
+                [self deleteFileInfoWithUrl:key];
+                break;
+            }
+        }
+    }
+}
+
+#pragma mark-查询还有没有没处理的任务
+- (void)checkDownloadDonePlistInfoFun
+{
+    NSMutableDictionary *dictM =  [[self getDownloadDownList] mutableCopy];
+    if(dictM.count > 0){
+        for (NSString*key in dictM) {
+            NSDictionary*dict = dictM[key];
+            couldPhoneFileModel *model = [couldPhoneFileModel mj_objectWithKeyValues:dict];
+            NSString *fileName = [model getFileNameFun];
+            NSString*fullPath = [cachesFileManager getFilePathWithName:fileName type:DownLoadFileType];
+            
+            //判断文件是否还存在
+            if (![[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
+                //不存在 删除信息
+                HLog(@"deleteFileInfoWithUrl:%@",key)
+                [self deleteFileInfoWithUrl:key];
+            }
+            else{//存在 通知保存流程
+                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+                    [[webSocketManager shareInstance] saveDownDoneFileToPhoneFunBy:fullPath withKey:model.path];
+                });
+                break;
+            }
+        }
+        
+    }
+}
 @end

+ 3 - 0
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileRecordViewController.m

@@ -122,6 +122,9 @@
         [self delayChangeUIFunWithIndex:2];
     }
     
+    //检测是否还有没保存的任务
+    [[downloadManager shareInstance] checkDownloadDonePlistInfoFun];
+    
     [self getBackupsDatabaseFun];
     
     if(!_isReceiveType){

+ 2 - 0
创维盒子/双子星云手机/CloudPlayer/Model/couldPhoneFileListModel.h

@@ -50,6 +50,8 @@ typedef enum{
 @property (nonatomic, assign) NSTimeInterval  curTimeInterval;//计算速度用
 
 - (NSString*)getFileNameFun;
+
+- (NSDictionary *)downLoadInfoWithFinished:(BOOL)finished;
 @end
 
 @protocol couldPhoneFileModel;

+ 16 - 0
创维盒子/双子星云手机/CloudPlayer/Model/couldPhoneFileListModel.m

@@ -13,6 +13,22 @@
     return [[NSString alloc] initWithFormat:@"%ld_%@",self.length,self.name];
 }
 
+#pragma mark - get download info
+// 构造回调信息
+- (NSDictionary *)downLoadInfoWithFinished:(BOOL)finished {
+    return  @{
+            @"fileType" : self.fileType,
+                @"path" : self.path,
+                @"path" : self.path,
+                @"name" : self.name,
+              @"length" : @(self.length),
+                @"time" : @(self.time),
+           @"curDownloadStateType" : @(self.curDownloadStateType),
+               @"didDownloadBytes" : @(self.didDownloadBytes),
+            @"isFinished" : @(finished)
+            };
+}
+
 /**
  设置不需要存储的属性, 在模型.m文件中实现该函数.
  */

+ 3 - 0
创维盒子/双子星云手机/cloudPhone/websocket/webSocketManager+downloadFile.h

@@ -13,6 +13,9 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)begindownloadFileFunBy:(couldPhoneFileModel *)couldPhoneFileMod;
 - (void)downloadFileFunServiceResponseFun:(NSData *)fileData with:(BOOL)isDownloadDone;
 - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls;
+
+#pragma mark 处理保存操作
+- (void)saveDownDoneFileToPhoneFunBy:(NSString*)filePath withKey:(NSString *)key;
 @end
 
 NS_ASSUME_NONNULL_END

+ 53 - 2
创维盒子/双子星云手机/cloudPhone/websocket/webSocketManager+downloadFile.m

@@ -130,6 +130,11 @@
 
 - (void)handleDownloadDoneFun
 {
+    if(self.nasFullPath && self.nasFullPath.length >0){
+        HLog(@"前面一个保存流程没走完")
+        return;
+    }
+    
     NSString *fileName = [self.curDownloadFileModel getFileNameFun];
     NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadFileType];
     
@@ -224,11 +229,25 @@
     NSString *fileName = [self.curDownloadFileModel getFileNameFun];
     NSString*filePath = [cachesFileManager getFilePathWithName:fileName type:DownLoadFileType];
     
+    [self saveDownDoneFileToPhoneFunBy:filePath withKey:self.curDownloadFileModel.path];
+}
+
+#pragma mark 处理保存操作
+- (void)saveDownDoneFileToPhoneFunBy:(NSString*)filePath withKey:(NSString *)key{
+    
+    if (self.isShowingFileDocumentPickerType) {
+        HLog(@"上一个任务保存到问题---没保存完");
+        return;
+    }
+    
     if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]){
-        HLog(@"没有找到文件:%@",fileName);
+        HLog(@"没有找到文件:%@",filePath);
         return;
     }
     
+    self.wsDownloadSaveFilePath = filePath;
+    self.wsDownloadDonwPlishPath = key;
+    
     NSURL * fileURL = [NSURL fileURLWithPath:filePath];
     UIDocumentPickerViewController *documentPickerVC = [[UIDocumentPickerViewController alloc] initWithURL:fileURL inMode:UIDocumentPickerModeExportToService];
     // 设置代理
@@ -237,6 +256,8 @@
     documentPickerVC.modalPresentationStyle = UIModalPresentationFormSheet;
     //[self.navigationController presentViewController:documentPickerVC animated:YES completion:nil];
     [ksharedAppDelegate.window.rootViewController presentViewController:documentPickerVC animated:YES completion:nil];
+    
+    self.isShowingFileDocumentPickerType = YES;
 }
  
 
@@ -262,11 +283,23 @@
                         [self checkSaveNasFileAgainFun];
                     });
                 }
+                else{
+                    self.wsDownloadSaveFilePath = nil;
+                    self.wsDownloadDonwPlishPath = nil;
+                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(20 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+                        [self checkSaveWebsocketFileAgainFun];
+                    });
+                }
             } else {
                 NSLog(@"222 fileName : %@", fileName);
                 if(!self.nasFullPath){
                     // websock下载流程
-                    [cachesFileManager removeItemAtPath:fileName type:DownLoadFileType error:nil];
+                    [[NSFileManager defaultManager] removeItemAtPath:self.wsDownloadSaveFilePath error:nil];
+                    //[cachesFileManager removeItemAtPath:fileName type:DownLoadFileType error:nil];
+                    [[downloadManager shareInstance] deleteDownloadDonePlistInfoBy:self.wsDownloadDonwPlishPath];
+                    self.wsDownloadSaveFilePath = nil;
+                    self.wsDownloadDonwPlishPath = nil;
+                    [self checkSaveWebsocketFileAgainFun];
                 }
                 else{
                     //nas下载流程
@@ -277,6 +310,8 @@
                 }
                 
             }
+            
+            self.isShowingFileDocumentPickerType = NO;
         }];
         [urls.firstObject stopAccessingSecurityScopedResource];
     } else {
@@ -287,6 +322,15 @@
                 [self checkSaveNasFileAgainFun];
             });
         }
+        else{
+            self.wsDownloadSaveFilePath = nil;
+            self.wsDownloadDonwPlishPath = nil;
+            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(20 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+                [self checkSaveWebsocketFileAgainFun];
+            });
+        }
+        
+        self.isShowingFileDocumentPickerType = NO;
     }
 }
 
@@ -295,4 +339,11 @@
 {
     [[boxDownloadFileManager shareInstance] checkDownloadDonePlistInfoFun];
 }
+
+#pragma mark 再次读取ws下载完成数据做保存操作
+- (void)checkSaveWebsocketFileAgainFun
+{
+    [[downloadManager shareInstance] checkDownloadDonePlistInfoFun];
+}
+
 @end

+ 5 - 2
创维盒子/双子星云手机/cloudPhone/websocket/webSocketManager+downloadNasFile.m

@@ -11,8 +11,9 @@
 #pragma mark 下载完成
 - (void)NasDownloadTaskFinishedNoti:(customDownloadOperation *)nasDownloadOperation
 {
-    if(self.nasFullPath && self.nasFullPath.length >0){
-        HLog(@"前面一个保存流程没走完")
+    if((self.nasFullPath && self.nasFullPath.length >0)
+       || self.isShowingFileDocumentPickerType){
+            HLog(@"上一个任务保存到问题---没保存完");
         return;
     }
     
@@ -157,6 +158,8 @@
     documentPickerVC.modalPresentationStyle = UIModalPresentationFormSheet;
     //[self.navigationController presentViewController:documentPickerVC animated:YES completion:nil];
     [ksharedAppDelegate.window.rootViewController presentViewController:documentPickerVC animated:YES completion:nil];
+    
+    self.isShowingFileDocumentPickerType = YES;
 }
  
 //同文件 有了代理 走了 downloadFile 里面的 UIDocumentPickerDelegate

+ 8 - 0
创维盒子/双子星云手机/cloudPhone/websocket/webSocketManager.h

@@ -49,6 +49,8 @@ NS_ASSUME_NONNULL_BEGIN
 //下载文件用到
 @property (nonatomic, copy) NSString * _Nullable downloadFileTaskUid;
 @property (nonatomic, strong) couldPhoneFileModel *curDownloadFileModel;
+@property (nonatomic, copy) NSString * _Nullable wsDownloadSaveFilePath;//下载好的ws文件保存路径
+@property (nonatomic, copy) NSString * _Nullable wsDownloadDonwPlishPath;//下载好的ws文件保存key
 
 //备份文件用到
 @property (nonatomic, copy) NSString * _Nullable backupsTaskUid;
@@ -67,6 +69,10 @@ NS_ASSUME_NONNULL_BEGIN
 //下载nas文件用到
 @property (nonatomic, copy) NSString*nasFullPath;
 
+
+//下载nas ws 文件 保存到文件 正在弹框中
+@property (nonatomic, assign) BOOL isShowingFileDocumentPickerType;
+
 @property(nonatomic,assign)BOOL isRebootIngType;//是否重启中
 @property(nonatomic,assign)BOOL isResetingType;//是否恢复出厂中
 @property(nonatomic,assign)BOOL isChangeBoxType;//是否更换盒子
@@ -123,6 +129,8 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)handleDownloadResponseFunBy:(id)message;
 - (void)downloadFileFunServiceResponseFun:(NSData *)fileData with:(BOOL)isDownloadDone;
 - (void)downloadThumbnailFileFunServiceResponseFun:(NSData *)fileData with:(BOOL)isDownloadDone;
+#pragma mark 处理ws保存操作
+- (void)saveDownDoneFileToPhoneFunBy:(NSString*)filePath withKey:(NSString *)key;
 @end
 
 NS_ASSUME_NONNULL_END