Parcourir la source

【分包下载】下载XML流程串接

lizhe il y a 1 an
Parent
commit
f69ac7a53d

+ 0 - 19
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -1273,8 +1273,6 @@
 		AD53B70529ACC65500D61E81 /* KMMailHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = AD53B70429ACC65500D61E81 /* KMMailHelper.m */; };
 		AD53B70629ACC65500D61E81 /* KMMailHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = AD53B70429ACC65500D61E81 /* KMMailHelper.m */; };
 		AD53B70729ACC65500D61E81 /* KMMailHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = AD53B70429ACC65500D61E81 /* KMMailHelper.m */; };
-		AD61B7AB2A9DC6F600D346C1 /* KMResourceDownloadManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD61B7AA2A9DC6F500D346C1 /* KMResourceDownloadManager.swift */; };
-		AD61B7AC2A9DC6F600D346C1 /* KMResourceDownloadManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD61B7AA2A9DC6F500D346C1 /* KMResourceDownloadManager.swift */; };
 		AD61B7AD2A9DC6F600D346C1 /* KMResourceDownloadManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD61B7AA2A9DC6F500D346C1 /* KMResourceDownloadManager.swift */; };
 		AD61B7AE2A9DD06C00D346C1 /* libDocumentAI.3.2.2.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = AD8DD2922A972486007CC9D0 /* libDocumentAI.3.2.2.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
 		AD61B7AF2A9DD06F00D346C1 /* libonnxruntime.1.14.1.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = AD8DD2962A97248E007CC9D0 /* libonnxruntime.1.14.1.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
@@ -1544,7 +1542,6 @@
 		ADB2D6FD294882B70029D2B3 /* KMTextFieldStepperView.xib in Resources */ = {isa = PBXBuildFile; fileRef = ADB2D6FC294882B70029D2B3 /* KMTextFieldStepperView.xib */; };
 		ADB2D6FE294882B70029D2B3 /* KMTextFieldStepperView.xib in Resources */ = {isa = PBXBuildFile; fileRef = ADB2D6FC294882B70029D2B3 /* KMTextFieldStepperView.xib */; };
 		ADB2D6FF294882B70029D2B3 /* KMTextFieldStepperView.xib in Resources */ = {isa = PBXBuildFile; fileRef = ADB2D6FC294882B70029D2B3 /* KMTextFieldStepperView.xib */; };
-		ADB595BA2AA8543F00D778B7 /* KMResourceDownload.m in Sources */ = {isa = PBXBuildFile; fileRef = ADB595B82AA8543F00D778B7 /* KMResourceDownload.m */; };
 		ADB5E50E2A3703E6007110A8 /* KMInAppPurchaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD0E8AAF2A31B76300DBFD3C /* KMInAppPurchaseManager.swift */; };
 		ADB5E5122A371131007110A8 /* KMSubscribeWaterMarkWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB5E5102A371131007110A8 /* KMSubscribeWaterMarkWindowController.swift */; };
 		ADB5E5132A371131007110A8 /* KMSubscribeWaterMarkWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADB5E5102A371131007110A8 /* KMSubscribeWaterMarkWindowController.swift */; };
@@ -4201,8 +4198,6 @@
 		ADB2D6F1294741720029D2B3 /* KMPrintPaperSetView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMPrintPaperSetView.xib; sourceTree = "<group>"; };
 		ADB2D6F8294882AE0029D2B3 /* KMTextFieldStepperView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMTextFieldStepperView.swift; sourceTree = "<group>"; };
 		ADB2D6FC294882B70029D2B3 /* KMTextFieldStepperView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMTextFieldStepperView.xib; sourceTree = "<group>"; };
-		ADB595B82AA8543F00D778B7 /* KMResourceDownload.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMResourceDownload.m; sourceTree = "<group>"; };
-		ADB595B92AA8543F00D778B7 /* KMResourceDownload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMResourceDownload.h; sourceTree = "<group>"; };
 		ADB5E5102A371131007110A8 /* KMSubscribeWaterMarkWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSubscribeWaterMarkWindowController.swift; sourceTree = "<group>"; };
 		ADB5E5112A371131007110A8 /* KMSubscribeWaterMarkWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMSubscribeWaterMarkWindowController.xib; sourceTree = "<group>"; };
 		ADB5E5182A3711CB007110A8 /* KMSubscribeWaterMarkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSubscribeWaterMarkView.swift; sourceTree = "<group>"; };
@@ -6119,16 +6114,6 @@
 			path = Websocket;
 			sourceTree = "<group>";
 		};
-		9FC444F32AA5E82700D7187C /* Resource Download */ = {
-			isa = PBXGroup;
-			children = (
-				ADB595B92AA8543F00D778B7 /* KMResourceDownload.h */,
-				ADB595B82AA8543F00D778B7 /* KMResourceDownload.m */,
-			);
-			name = "Resource Download";
-			path = "PDF Master/Class/Resource Download";
-			sourceTree = SOURCE_ROOT;
-		};
 		9FDD0F58294AB3E7000C4DAD /* ViewController */ = {
 			isa = PBXGroup;
 			children = (
@@ -8055,7 +8040,6 @@
 				BB2C6A7328F2656000478A33 /* PDFWindowController */,
 				9FBA0EE728FFC2DD001117AF /* Appearance */,
 				9FBDA7272A4D326800A972F3 /* Websocket */,
-				9FC444F32AA5E82700D7187C /* Resource Download */,
 			);
 			path = Class;
 			sourceTree = "<group>";
@@ -10901,7 +10885,6 @@
 				BBD1F77C296F9BE000343885 /* KMPageEditSettingBaseWindowController.swift in Sources */,
 				8931683A296E436B0073EA59 /* KMSignatureWindowController.m in Sources */,
 				BB2F184A2A0C911B0003F65E /* KMBaseWindowController.swift in Sources */,
-				AD61B7AB2A9DC6F600D346C1 /* KMResourceDownloadManager.swift in Sources */,
 				BBF38A5A294F2B760086D025 /* KMWatermarkPositionView.swift in Sources */,
 				89E93EDE2999DA6D00F10F66 /* KMNoteFilterCollevtionViewItem.m in Sources */,
 				BBB7B4912A03AD2A00B58A5A /* KMPDFEditToolbar.swift in Sources */,
@@ -12245,7 +12228,6 @@
 				BB146FF7299DC0D100784A6A /* OIDAuthorizationService+Mac.m in Sources */,
 				BB6DD822293497B6001F0544 /* KMSecureEncryptModel.swift in Sources */,
 				BBB9B31D299A5D6D004F3235 /* KMCloudOperation.m in Sources */,
-				AD61B7AC2A9DC6F600D346C1 /* KMResourceDownloadManager.swift in Sources */,
 				BB16473A29E7A4C30044DFBE /* NSTextView+KMExtension.m in Sources */,
 				AD9527BB295291F20039D2BC /* KMPrintPage.swift in Sources */,
 				ADE3C1AC29A4779E00793B13 /* KMPrintAccessoryController.swift in Sources */,
@@ -12501,7 +12483,6 @@
 				899700E128F3A9F2009AF911 /* KMHomeWindowController.swift in Sources */,
 				89D2D30529504E5E00BFF5FE /* KMSharingServicePicker+ESSSharingServicePickerMenu.m in Sources */,
 				BB9DCCA12A0A2B0A0024A6F1 /* KMConvertSettingView.swift in Sources */,
-				ADB595BA2AA8543F00D778B7 /* KMResourceDownload.m in Sources */,
 				BB8F4578295AFA2D0037EA22 /* KMHeaderFooterAdjectiveInfoBaseView.swift in Sources */,
 				F3F0B27529B8ACD000722957 /* CPDFListViewDragObject.m in Sources */,
 				F34BF9552953DA91002C25A2 /* NSGeometry+PDFListView.m in Sources */,

+ 7 - 6
PDF Office/PDF Master/Class/KMResourceDownload/KMResourceDownloadManager.swift

@@ -127,12 +127,13 @@ extension KMResourceDownloadManager: XMLParserDelegate {
     
     func dealXML(content: String) -> String {
         // 1. 定义 XML 内容,包括版本号
-        let xmlContent = """
-        <root>
-            <version>1.0</version>
-            <resourceURL>http://test-pdf-pro.kdan.cn:3021/downloads/DocumentAI.bundle.zip</resourceURL>
-        </root>
-        """
+//        let xmlContent = """
+//        <root>
+//            <version>1.0</version>
+//            <resourceURL>http://test-pdf-pro.kdan.cn:3021/downloads/DocumentAI.bundle.zip</resourceURL>
+//        </root>
+//        """
+        let xmlContent = content
 
         // 2. 创建目标文件夹(如果不存在的话)
         let fileManager = FileManager.default

+ 0 - 36
PDF Office/PDF Master/Class/Resource Download/KMResourceDownload.h

@@ -1,36 +0,0 @@
-//
-//  KMResourceDownload.h
-//  PDF Master DMG
-//
-//  Created by wanjun on 2023/8/1.
-//
-
-#import <Foundation/Foundation.h>
-
-NS_ASSUME_NONNULL_BEGIN
-typedef NS_ENUM(NSUInteger, KMResourceDownloadState) {
-    KMResourceDownloadStateNone,
-    KMResourceDownloadStateSuccess,
-    KMResourceDownloadStateUnzipFailed,
-    KMResourceDownloadStateMoveFailed
-};
-
-typedef void(^KMResourceDownloadResult)(BOOL isSuccessful, KMResourceDownloadState state);
-typedef void(^KMResourceDownloadProgress)(double progress);
-
-@interface KMResourceDownload : NSObject
-+ (KMResourceDownload *)manager;
-
-@property(nonatomic, copy) KMResourceDownloadResult downloadResultBlock;
-
-@property(nonatomic, copy) KMResourceDownloadProgress progressBlock;
-
-- (void)downloadFrameworkProgress:(KMResourceDownloadProgress)currentProgress result:(KMResourceDownloadResult)result;
-
-- (BOOL)documentAIBundleIsExist;
-
-- (void)cancelDownload;
-
-@end
-
-NS_ASSUME_NONNULL_END

+ 0 - 162
PDF Office/PDF Master/Class/Resource Download/KMResourceDownload.m

@@ -1,162 +0,0 @@
-//
-//  KMResourceDownload.m
-//  PDF Master DMG
-//
-//  Created by wanjun on 2023/8/1.
-//
-
-#import "KMResourceDownload.h"
-#import <ZipArchive/ZipArchive.h>
-//#if __has_include(<DateTools/DateTools.h>)
-//    #import <DateTools/DateTools.h>
-//    #define HAS_DOCUMENTAI_FRAMEWORK 1
-//#else
-//    #define HAS_DOCUMENTAI_FRAMEWORK 0
-//#endif
-
-#define kResourcePath [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask].firstObject.path
-
-@interface KMResourceDownload()
-@property (nonatomic, strong) NSURLSessionDownloadTask *downloadTask;
-@end
-
-@implementation KMResourceDownload
-static KMResourceDownload *_manager;
-+ (KMResourceDownload *)manager {
-    static dispatch_once_t onceToken;
-    dispatch_once(&onceToken, ^{
-        _manager = [[KMResourceDownload alloc] init];
-    });
-    return _manager;
-}
-
-- (void)downloadFrameworkProgress:(KMResourceDownloadProgress)currentProgress result:(KMResourceDownloadResult)result {
-    self.downloadResultBlock = result;
-    self.progressBlock = currentProgress;
-    
-    if (self.downloadTask == nil) {
-        
-        NSString *urlString = @"http://test-pdf-pro.kdan.cn:3021/downloads/DocumentAI.bundle.zip";
-        NSURL *url = [NSURL URLWithString:urlString];
-        
-        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
-        NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
-
-        NSURLSessionDownloadTask *downloadTask = [session downloadTaskWithURL:url];
-        [downloadTask resume];
-        self.downloadTask = downloadTask;
-    } else {
-        [self dealDownLoadResult:NO state:KMResourceDownloadStateNone];
-    }
-}
-
-// 解压 framework 文件
-- (void)unzipFrameworkAtURL:(NSURL *)zipURL toDestination:(NSString *)destinationPath {
-    // 解压逻辑,使用 Foundation 框架的 NSFileManager 或其他解压库
-    NSFileManager *fileManager = [NSFileManager defaultManager];
-    // 根据压缩文件类型选择解压方法
-    BOOL success = NO;
-    if ([zipURL.path.pathExtension isEqualToString:@"zip"]) {
-        // 使用系统自带的解压方法,需要引入 libz.tbd 库
-        success = [SSZipArchive unzipFileAtPath:zipURL.path
-                                     toDestination:destinationPath];
-    } else {
-        // 如果是其他类型的压缩文件,可以使用第三方库,如 SSZipArchive 等进行解压
-        // success = [SSZipArchive unzipFileAtPath:tempFilePath toDestination:destinationPath];
-    }
-    
-    if (success) {
-        NSLog(@"File unzipped successfully!");
-        [fileManager removeItemAtPath:zipURL.path error:nil];
-
-    } else {
-        NSLog(@"Failed to unzip file.");
-        [self dealDownLoadResult:NO state:KMResourceDownloadStateUnzipFailed];
-    }
-}
-
-// 加载 framework 文件
-- (void)loadFramework:(NSString *)destinationPath {
-    NSError *error = nil;
-
-    NSBundle *frameworkBundle = [NSBundle bundleWithPath:kResourcePath];
-    if (![frameworkBundle loadAndReturnError:&error]) {
-        NSLog(@"Error loading bundle: %@", error);
-        [self dealDownLoadResult:NO state:KMResourceDownloadStateNone];
-        return;
-    }
-    
-    // 使用 framework 中的代码和资源
-//#if HAS_DOCUMENTAI_FRAMEWORK
-//    NSDate *selectedDate = [NSDate dateWithTimeIntervalSinceNow:-24*60*60*6+100];
-//    NSString *week = [NSDate weekTimeAgoSinceDate:selectedDate];
-//    NSLog(@"week == %@", week);
-//#else
-//    // 其他处理或者警告用户没有导入 SomeFramework
-//    NSLog(@"没有库");
-//#endif
-}
-
-- (BOOL)documentAIBundleIsExist {
-    NSString *filePath = [kResourcePath stringByAppendingPathComponent:@"DocumentAI.bundle"];
-    
-    NSFileManager *fileManager = [NSFileManager defaultManager];
-    if ([fileManager fileExistsAtPath:filePath]) {
-        return YES;
-    } else {
-        return NO;
-    }
-}
-
-- (void)cancelDownload {
-    [self.downloadTask cancel];
-    self.downloadTask = nil;
-    self.progressBlock = nil;
-    self.downloadResultBlock = nil;
-}
-
-- (void)dealDownLoadResult:(BOOL)isSuccess state:(KMResourceDownloadState)state {
-    dispatch_async(dispatch_get_main_queue(), ^{
-        if (self.downloadResultBlock) {
-            self.downloadResultBlock(isSuccess, state);
-            [self cancelDownload];
-        }
-    });
-}
-#pragma mark - NSURLSessionDelegate
-
-- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
-    // 计算下载进度
-    double progress = (double)totalBytesWritten / (double)totalBytesExpectedToWrite;
-    
-    // 可以在这里更新UI或执行其他操作
-    NSLog(@"下载进度:%f", progress);
-    
-    if (self.progressBlock) {
-        self.progressBlock(progress);
-    }
-}
-
-- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
-    // Move the downloaded file to APP Contents/Frameworks folder
-    NSFileManager *fileManager = [NSFileManager defaultManager];
-    NSString *resourcePath = kResourcePath;
-    NSString *destinationPath = [kResourcePath stringByAppendingPathComponent:@"DocumentAI.bundle.zip"];
-
-    NSError *moveError = nil;
-    [fileManager moveItemAtURL:location toURL:[NSURL fileURLWithPath:destinationPath] error:&moveError];
-    if (moveError) {
-        NSLog(@"Failed to move framework: %@", moveError);
-        [self dealDownLoadResult:NO state:KMResourceDownloadStateMoveFailed];
-        return;
-    } else {
-        NSLog(@"Framework downloaded and installed successfully!");
-    }
-    
-    // 解压 framework 文件
-    [self unzipFrameworkAtURL:[NSURL fileURLWithPath:destinationPath] toDestination:resourcePath];
-    
-    [self dealDownLoadResult:YES state:KMResourceDownloadStateSuccess];
-}
-
-@end

+ 0 - 1
PDF Office/PDF Master/PDF_Master DMG-Bridging-Header.h

@@ -84,4 +84,3 @@
 #import "CPDFListView+Extension.h"
 #import "KMSignatureHelpViewController.h"
 #import <Sparkle/Sparkle.h>
-#import "KMResourceDownload.h"