Selaa lähdekoodia

1.集成下载相关

huangxiaodong 9 kuukautta sitten
vanhempi
commit
c65b1e1978

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

@@ -488,6 +488,10 @@
 		6B49BFBC2C90472600E17406 /* webRtcManager+StatisticsReport.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B49BFB92C90472600E17406 /* webRtcManager+StatisticsReport.h */; };
 		6B49BFBD2C90472600E17406 /* webRtcManager+StatisticsReport.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B49BFB92C90472600E17406 /* webRtcManager+StatisticsReport.h */; };
 		6B49BFBE2C90472600E17406 /* webRtcManager+StatisticsReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B49BFBA2C90472600E17406 /* webRtcManager+StatisticsReport.m */; };
+		6B49BFC72C943CE800E17406 /* webRtcManager+downloadNasFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B49BFC62C943CE700E17406 /* webRtcManager+downloadNasFile.m */; };
+		6B49BFC82C943CE800E17406 /* webRtcManager+downloadNasFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B49BFC52C943CE700E17406 /* webRtcManager+downloadNasFile.h */; };
+		6B49BFC92C943CE800E17406 /* webRtcManager+downloadNasFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B49BFC52C943CE700E17406 /* webRtcManager+downloadNasFile.h */; };
+		6B49BFCA2C943CE800E17406 /* webRtcManager+downloadNasFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B49BFC62C943CE700E17406 /* webRtcManager+downloadNasFile.m */; };
 		6B4C0F622C0314BA0070EF2E /* DFPlayerFileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B4C0F4C2C0314BA0070EF2E /* DFPlayerFileManager.h */; };
 		6B4C0F632C0314BA0070EF2E /* DFPlayerFileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B4C0F4C2C0314BA0070EF2E /* DFPlayerFileManager.h */; };
 		6B4C0F642C0314BA0070EF2E /* DFPlayerFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4C0F4D2C0314BA0070EF2E /* DFPlayerFileManager.m */; };
@@ -1822,6 +1826,8 @@
 		6B4835FC2B9172D7001FC9BA /* usbInsertAnimation.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = usbInsertAnimation.json; sourceTree = "<group>"; };
 		6B49BFB92C90472600E17406 /* webRtcManager+StatisticsReport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "webRtcManager+StatisticsReport.h"; sourceTree = "<group>"; };
 		6B49BFBA2C90472600E17406 /* webRtcManager+StatisticsReport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "webRtcManager+StatisticsReport.m"; sourceTree = "<group>"; };
+		6B49BFC52C943CE700E17406 /* webRtcManager+downloadNasFile.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "webRtcManager+downloadNasFile.h"; sourceTree = "<group>"; };
+		6B49BFC62C943CE700E17406 /* webRtcManager+downloadNasFile.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "webRtcManager+downloadNasFile.m"; sourceTree = "<group>"; };
 		6B4B0B692BEF087E00B62C22 /* 隐私保护.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "隐私保护.entitlements"; sourceTree = "<group>"; };
 		6B4B0B6A2BEF16F200B62C22 /* 计算器.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "计算器.entitlements"; sourceTree = "<group>"; };
 		6B4C0F4C2C0314BA0070EF2E /* DFPlayerFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DFPlayerFileManager.h; sourceTree = "<group>"; };
@@ -3064,6 +3070,8 @@
 				6B3E7A812C89CC1300B032C4 /* webRtcManager.m */,
 				6B49BFB92C90472600E17406 /* webRtcManager+StatisticsReport.h */,
 				6B49BFBA2C90472600E17406 /* webRtcManager+StatisticsReport.m */,
+				6B49BFC52C943CE700E17406 /* webRtcManager+downloadNasFile.h */,
+				6B49BFC62C943CE700E17406 /* webRtcManager+downloadNasFile.m */,
 			);
 			path = webRtcManager;
 			sourceTree = "<group>";
@@ -4127,6 +4135,7 @@
 				6B5D867A2C22D6E9008D25EA /* NASLastFileView.h in Headers */,
 				6B7DDF302C424B5E00EBDFDD /* RcGameWQKeyChain.h in Headers */,
 				181E84F72A8F451D00292B96 /* MineViewCell.h in Headers */,
+				6B49BFC82C943CE800E17406 /* webRtcManager+downloadNasFile.h in Headers */,
 				6B2C1E4E2C070ADE00FDCF82 /* ZFUtilities.h in Headers */,
 				6B8661D72BBA53B600B19846 /* noticeModel.h in Headers */,
 				6B2C1E462C070ADE00FDCF82 /* ZFSmallFloatControlView.h in Headers */,
@@ -4412,6 +4421,7 @@
 				6B5D867B2C22D6E9008D25EA /* NASLastFileView.h in Headers */,
 				6B7DDF312C424B5E00EBDFDD /* RcGameWQKeyChain.h in Headers */,
 				6BD506E12B9576A4006E7CB0 /* MineViewCell.h in Headers */,
+				6B49BFC92C943CE800E17406 /* webRtcManager+downloadNasFile.h in Headers */,
 				6B2C1E4F2C070ADE00FDCF82 /* ZFUtilities.h in Headers */,
 				6B8661D82BBA53B600B19846 /* noticeModel.h in Headers */,
 				6B2C1E472C070ADE00FDCF82 /* ZFSmallFloatControlView.h in Headers */,
@@ -5001,6 +5011,7 @@
 				6B42A2142C40DC3D000555BB /* previewLandscapeTopMoreView.m in Sources */,
 				6BD507392B9576A4006E7CB0 /* downloadManager.m in Sources */,
 				6BD5073A2B9576A4006E7CB0 /* FMDatabaseQueue.m in Sources */,
+				6B49BFCA2C943CE800E17406 /* webRtcManager+downloadNasFile.m in Sources */,
 				6B2C1E412C070ADE00FDCF82 /* ZFPortraitControlView.m in Sources */,
 				6BD5073B2B9576A4006E7CB0 /* customLaunchView.m in Sources */,
 				6BD5073C2B9576A4006E7CB0 /* HWSetViewController.m in Sources */,
@@ -5368,6 +5379,7 @@
 				6B42A2122C40DC3D000555BB /* previewLandscapeTopMoreView.m in Sources */,
 				6B5D40402B4CE40F000965CF /* downloadManager.m in Sources */,
 				A08A950027E9A4E400C544BB /* FMDatabaseQueue.m in Sources */,
+				6B49BFC72C943CE800E17406 /* webRtcManager+downloadNasFile.m in Sources */,
 				6B2C1E402C070ADE00FDCF82 /* ZFPortraitControlView.m in Sources */,
 				6BF52CA72AD7D3BE00A617DB /* customLaunchView.m in Sources */,
 				A031DD7A27EC713A00909527 /* HWSetViewController.m in Sources */,

+ 2 - 2
创维盒子/双子星云手机/Class/Set/uploadFile/uploadFileManager/boxDownloadFileManager.m

@@ -359,7 +359,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
         [[NSNotificationCenter defaultCenter] postNotificationName:nasShareDownloadTaskFinishedNotification object:model];
         
-        [[webSocketManager shareInstance] NasDownloadTaskFinishedNoti:model];
+        [[webRtcManager shareManager] NasDownloadTaskFinishedNoti:model];
     });
 }
 
@@ -645,7 +645,7 @@ static boxDownloadFileManager * cur_boxDownloadFileShareInstance = nil;
             }
             else{//存在 通知保存流程
                 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-                    [[webSocketManager shareInstance] NasDownloadTaskFinishedNoti:model];
+                    [[webRtcManager shareManager] NasDownloadTaskFinishedNoti:model];
                 });
                 break;
             }

+ 2 - 2
创维盒子/双子星云手机/NAS/nasDownloadManager/nasDownloadFileManager.m

@@ -368,7 +368,7 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
         [[NSNotificationCenter defaultCenter] postNotificationName:nasDownloadTaskFinishedNotification object:model];
         
-        [[webSocketManager shareInstance] NasDownloadTaskFinishedNoti:model];
+        [[webRtcManager shareManager] NasDownloadTaskFinishedNoti:model];
     });
 }
 
@@ -676,7 +676,7 @@ static nasDownloadFileManager * cur_nasDownloadFileManager = nil;
             }
             else{//存在 通知保存流程
                 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-                    [[webSocketManager shareInstance] NasDownloadTaskFinishedNoti:model];
+                    [[webRtcManager shareManager] NasDownloadTaskFinishedNoti:model];
                 });
                 break;
             }

+ 17 - 0
创维盒子/双子星云手机/webRtc/webRtcManager/webRtcManager+downloadNasFile.h

@@ -0,0 +1,17 @@
+//
+//  webRtcManager+downloadNasFile.h
+//  双子星云手机
+//
+//  Created by xd h on 2024/9/13.
+//
+
+#import "webRtcManager.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface webRtcManager (downloadNasFile)
+#pragma mark 下载完成
+- (void)NasDownloadTaskFinishedNoti:(customDownloadOperation *)nasDownloadOperation;
+@end
+
+NS_ASSUME_NONNULL_END

+ 255 - 0
创维盒子/双子星云手机/webRtc/webRtcManager/webRtcManager+downloadNasFile.m

@@ -0,0 +1,255 @@
+//
+//  webRtcManager+downloadNasFile.m
+//  双子星云手机
+//
+//  Created by xd h on 2024/9/13.
+//
+
+#import "webRtcManager+downloadNasFile.h"
+
+@implementation webRtcManager (downloadNasFile)
+#pragma mark 下载完成
+- (void)NasDownloadTaskFinishedNoti:(customDownloadOperation *)nasDownloadOperation
+{
+    if((self.nasFullPath && self.nasFullPath.length >0)
+       || self.isShowingFileDocumentPickerType){
+            HLog(@"上一个任务保存到问题---没保存完");
+        return;
+    }
+    
+    curDownloadmodel = nasDownloadOperation;
+    KWeakSelf
+    if (curDownloadmodel.downloadState == customDownloadStateCompleted) {
+        mainBlock(^{
+            [weakSelf handldDownloadDoneToSaveBy:self->curDownloadmodel];
+        });
+    }
+}
+
+#pragma mark 下载完后处理保持流程
+- (void)handldDownloadDoneToSaveBy:(customDownloadOperation*)model{
+    //解码
+    NSString * urlString = [model.url stringByRemovingPercentEncoding];
+    //[model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+    NSArray *nameArr= [urlString componentsSeparatedByString:@"."];
+    
+    NSString * pathStr= [customDownloadCacheManager getFullPathByOldFullPath:model.fullPath];
+    NSString * decodePathStr= [pathStr stringByRemovingPercentEncoding];
+    
+    HLog(@"downloadNasFile:%@\n%@\n%@",urlString,pathStr,[pathStr stringByRemovingPercentEncoding])
+    
+    if(![pathStr isEqualToString:decodePathStr]){
+        // 尝试移动(即重命名)文件
+        NSError *error = nil;
+        NSFileManager *fileManager = [NSFileManager defaultManager];
+        BOOL success = [fileManager moveItemAtPath:pathStr toPath:decodePathStr error:&error];
+
+        if (success) {
+            NSLog(@"文件重命名成功!");
+        } else {
+            NSLog(@"文件重命名失败: %@", error);
+        }
+        
+        pathStr = decodePathStr;
+    }
+    
+    
+    
+    HLog(@"%@,",pathStr);
+    if (nameArr.count >= 2) {
+        NSString *lastName = nameArr.lastObject;
+        
+        lastName = [lastName lowercaseString];
+        
+        if([iTools canSaveFileToAlbumByPhoto:YES withName:lastName])
+        {//可以保持到相册
+            UIImage *image = [UIImage imageWithContentsOfFile:pathStr];
+            if(image){
+                [self loadImageFinished:image with:pathStr];
+            }
+                
+        }
+        else if([iTools canSaveFileToAlbumByPhoto:NO withName:lastName]){//可以保持到相册
+            [self loadVideoFinishedBy:pathStr];
+            
+        }
+        else{//保存到文件
+            [self loadOtherDataFinishedBy:pathStr];
+        }
+    }
+}
+
+
+- (void)loadImageFinished:(UIImage *)image with:(NSString*)fullPath
+{
+    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
+         //写入图片到相册
+         PHAssetChangeRequest *req = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
+            
+     } completionHandler:^(BOOL success, NSError * _Nullable error) {
+         //NSLog(@"success = %d, error = %@", success, error);
+         if (success) {
+             HLog(@"已将图片保存至相册");
+             //
+             [[NSFileManager defaultManager] removeItemAtPath:fullPath error:nil];
+//             if(self->curYCDownloadItem){
+//                 [YCDownloadManager stopDownloadWithItem:self->curYCDownloadItem];
+//                 self->curYCDownloadItem = nil;
+//             }
+             
+             [[boxDownloadFileManager shareInstance] deleteDownloadDonePlistInfoBy:fullPath];
+             
+         } else {
+             HLog(@"未能将图片保存至相册");
+             mainBlock(^{
+                 [self loadOtherDataFinishedBy:fullPath];
+             });
+         }
+         
+    }];
+}
+
+- (void)loadVideoFinishedBy:(NSString*)fullPath
+{
+    NSString*pathStr = fullPath;
+    
+    PHPhotoLibrary *photoLibrary = [PHPhotoLibrary sharedPhotoLibrary];
+    [photoLibrary performChanges:^{
+        [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:[NSURL
+    fileURLWithPath:pathStr]];
+    } completionHandler:^(BOOL success, NSError * _Nullable error) {
+        if (success) {
+            HLog(@"已将视频保存至相册");
+            //
+            [[NSFileManager defaultManager] removeItemAtPath:pathStr error:nil];
+//            if(self->curYCDownloadItem){
+//                [YCDownloadManager stopDownloadWithItem:self->curYCDownloadItem];
+//                self->curYCDownloadItem = nil;
+//            }
+            
+            [[boxDownloadFileManager shareInstance] deleteDownloadDonePlistInfoBy:fullPath];
+        } else {
+            HLog(@"未能将视频保存至相册");
+            mainBlock(^{
+                [self loadOtherDataFinishedBy:fullPath];
+            });
+        }
+        
+    }];
+}
+
+
+//下载音频 文件等
+- (void)loadOtherDataFinishedBy:(NSString*)fullPath
+{
+    NSString*filePath = fullPath;
+    self.nasFullPath = fullPath;
+    
+    if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]){
+        HLog(@"没有找到文件:%@",filePath);
+        return;
+    }
+    
+    
+    NSURL * fileURL = [NSURL fileURLWithPath:filePath];
+    
+    UIDocumentPickerViewController *documentPickerVC = [[UIDocumentPickerViewController alloc] initWithURL:fileURL inMode:UIDocumentPickerModeExportToService];
+    // 设置代理
+    documentPickerVC.delegate = self;
+    // 设置模态弹出方式
+    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
+#pragma mark - UIDocumentPickerDelegate
+- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
+    // 获取授权
+    BOOL fileUrlAuthozied = [urls.firstObject startAccessingSecurityScopedResource];
+    if (fileUrlAuthozied) {
+        // 通过文件协调工具来得到新的文件地址,以此得到文件保护功能
+        NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
+        NSError *error;
+        
+        [fileCoordinator coordinateReadingItemAtURL:urls.firstObject options:0 error:&error byAccessor:^(NSURL *newURL) {
+            // 读取文件
+            NSString *fileName = [newURL lastPathComponent];
+            NSError *error = nil;
+            //NSData *fileData = [NSData dataWithContentsOfURL:newURL options:NSDataReadingMappedIfSafe error:&error];
+            if (error) {
+                // 读取出错
+                if(self.nasFullPath){
+                    self.nasFullPath = nil;
+                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(20 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+                        [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下载流程
+                    //[[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下载流程
+                    [[NSFileManager defaultManager] removeItemAtPath:self.nasFullPath error:nil];
+                    [[boxDownloadFileManager shareInstance] deleteDownloadDonePlistInfoBy:self.nasFullPath];
+                    [[nasDownloadFileManager shareInstance] deleteDownloadDonePlistInfoBy:self.nasFullPath];
+                    self.nasFullPath = nil;
+                    [self checkSaveNasFileAgainFun];
+                }
+                
+            }
+            
+            self.isShowingFileDocumentPickerType = NO;
+        }];
+        [urls.firstObject stopAccessingSecurityScopedResource];
+    } else {
+        // 授权失败
+        if(self.nasFullPath){
+            self.nasFullPath = nil;
+            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(20 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+                [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;
+    }
+}
+
+#pragma mark 再次读取下载完成数据做保存操作
+- (void)checkSaveNasFileAgainFun
+{
+    [[boxDownloadFileManager shareInstance] checkDownloadDonePlistInfoFun];
+    
+    [[nasDownloadFileManager shareInstance] checkDownloadDonePlistInfoFun];
+}
+
+#pragma mark 再次读取ws下载完成数据做保存操作
+- (void)checkSaveWebsocketFileAgainFun
+{
+    [[downloadManager shareInstance] checkDownloadDonePlistInfoFun];
+}
+@end

+ 18 - 0
创维盒子/双子星云手机/webRtc/webRtcManager/webRtcManager.h

@@ -13,6 +13,11 @@
 NS_ASSUME_NONNULL_BEGIN
 
 @interface webRtcManager : NSObject
+{
+    //下载nas相关
+    customDownloadOperation* curDownloadmodel;
+}
+
 /** 实例化对象(单例) */
 + (instancetype)shareManager;
 
@@ -28,6 +33,14 @@ NS_ASSUME_NONNULL_BEGIN
 @property(nonatomic,assign)BOOL isDiDChangePhoneSizeType;//是否修改了分辨率(如果是 进去云机需要重设解码器)
 
 @property(nonatomic,assign) RTCDataChannelState  channelState;
+
+#pragma mark 分类属性
+#pragma mark 下载nas文件用到
+@property (nonatomic, copy) NSString*nasFullPath;
+//下载nas ws 文件 保存到文件 正在弹框中
+@property (nonatomic, assign) BOOL isShowingFileDocumentPickerType;
+
+
 #pragma mark 开始链接
 - (void)beginToLinkWebRtcFun;
 #pragma mark 重新链接
@@ -61,6 +74,11 @@ NS_ASSUME_NONNULL_BEGIN
 //获取备份文件夹列表
 - (void)getBackupFolderListFun;
 
+
+
+#pragma mark 分类方向
+#pragma mark nas下载完成
+- (void)NasDownloadTaskFinishedNoti:(customDownloadOperation *)nasDownloadOperation;
 @end
 
 NS_ASSUME_NONNULL_END

+ 1 - 0
创维盒子/双子星云手机/webRtc/webRtcManager/webRtcManager.m

@@ -9,6 +9,7 @@
 #import "webRtcManager+StatisticsReport.h"
 #import "RcGameWQKeyChain.h"
 #import "errorAlertTool.h"
+#import "webRtcManager+downloadNasFile.h"
 
 @interface webRtcManager ()<MediaStreamClientEventsDelegate>
 {