Browse Source

【主页】快捷工具 - 文件对比选中加密文件,弹密码阻挡窗口添加

lizhe 1 year ago
parent
commit
2f9d536ba5

+ 1 - 4
PDF Office/PDF Master/Class/Common/Base/KMBaseWindowController.swift

@@ -35,10 +35,7 @@ extension KMBaseWindowController {
         guard let document = CPDFDocument.init(url: url) else {
             return completion(false, "")
         }
-        
-        let document2 = PDFDocument(url: url)
-        
-        
+
         // 判断是否为加密文档
         if document.isLocked == false {
             completion(true, "")

+ 37 - 30
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -1224,40 +1224,47 @@ extension KMHomeViewController {
                 return
             }
             
-            DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
-                let controller = KMCompareWindowController(windowNibName: "KMCompareWindowController")
-                self.currentWindowController = controller
-                
-                controller.filePath = openPanel.url!.path
-                
-                controller.cancelAction = { [unowned self] contr in
-                    self.view.window?.endSheet((controller.window)!)
-//                    self.currentWindowController = nil
-                }
-                
-                controller.contentComplete = { [unowned self] controller, pdfCompareContent, result, oldDocument, document in
-                    DispatchQueue.main.async {
-                        self.view.window?.endSheet((controller.window)!)
-//                        self.currentWindowController = nil
+            KMBaseWindowController.checkPassword(url: URL(fileURLWithPath: openPanel.url!.path)) { [unowned self] success, resultPassword in
+                if success {
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
+                        let controller = KMCompareWindowController(windowNibName: "KMCompareWindowController")
+                        self.currentWindowController = controller
+                        
+                        controller.password = resultPassword
+                        controller.filePath = openPanel.url!.path
+                        
+                        controller.cancelAction = { [unowned self] contr in
+                            self.view.window?.endSheet((controller.window)!)
+        //                    self.currentWindowController = nil
+                        }
+                        
+                        controller.contentComplete = { [unowned self] controller, pdfCompareContent, result, oldDocument, document in
+                            DispatchQueue.main.async {
+                                self.view.window?.endSheet((controller.window)!)
+        //                        self.currentWindowController = nil
+                                
+                                self.openContentCompareVC(with: pdfCompareContent, results: result, oldDocument: oldDocument, document: document)
+                            }
+                        }
                         
-                        self.openContentCompareVC(with: pdfCompareContent, results: result, oldDocument: oldDocument, document: document)
+                        controller.coveringComplete = { [unowned self] controller, document in
+                            self.view.window?.endSheet((controller.window)!)
+        //                    self.currentWindowController = nil
+                            
+                            self.openCoveringCompareVC(with: document)
+                        }
+                    
+        //                if index == 1 {
+                            controller.fileType = .content
+        //                } else {
+        //                    controller.fileType = .coverting
+        //                }
+                    
+                        NSWindow.currentWindow().beginSheet(controller.window!)
                     }
-                }
-                
-                controller.coveringComplete = { [unowned self] controller, document in
-                    self.view.window?.endSheet((controller.window)!)
-//                    self.currentWindowController = nil
+                } else {
                     
-                    self.openCoveringCompareVC(with: document)
                 }
-            
-//                if index == 1 {
-                    controller.fileType = .content
-//                } else {
-//                    controller.fileType = .coverting
-//                }
-            
-                NSWindow.currentWindow().beginSheet(controller.window!)
             }
         }
     }

+ 8 - 0
PDF Office/PDF Master/Class/PDFTools/Compare/KMCompareWindowController.swift

@@ -31,6 +31,13 @@ class KMCompareWindowController: KMBaseWindowController {
             }
         }
     }
+    var password: String = "" {
+        didSet {
+            if compareView != nil {
+                self.compareView.password = password
+            }
+        }
+    }
     
     var contentComplete: KMCompareWindowControllerContentComplete?
     var coveringComplete :KMCompareWindowControllerCoveringComplete?
@@ -39,6 +46,7 @@ class KMCompareWindowController: KMBaseWindowController {
         super.windowDidLoad()
 
         // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
+        compareView.password = password
         compareView.filePath = filePath
         compareView.fileType = fileType
         compareView.cancelAction = { [unowned self] view in

+ 6 - 1
PDF Office/PDF Master/Class/PDFTools/Compare/View/KMCompareView.swift

@@ -68,11 +68,16 @@ class KMCompareView: KMBaseXibView {
     var coveringSettingWindowController: KMCompareCoveringSettingWindowController?
     
     var pdfCompareContent: CPDFCompareContent?
+    var password: String = "" {
+        didSet {
+            self.oldPDFView.document?.unlock(withPassword: password)
+        }
+    }
     
     var filePath: String? {
         didSet {
             if filePath?.count != 0 {
-                self.addFilePath(filePath: filePath!)
+                self.addFilePath(filePath: filePath!, password: password)
             }
         }
     }