Преглед на файлове

【编辑工具】安全 - 移除密码机制 添加权限密码移除

lizhe преди 1 година
родител
ревизия
6404a18a58

+ 2 - 1
PDF Office/PDF Master/Class/PDFTools/RemovePassword/New/KMRemovePasswordWindowController.swift

@@ -14,6 +14,7 @@ class KMRemovePasswordWindowController: KMBaseWindowController {
     
     var batchAction: KMBatchActionBlock?
     var doneAction: KMRemovePasswordWindowControllerDoneAction?
+    var password: String = ""
     
     override func windowDidLoad() {
         super.windowDidLoad()
@@ -21,7 +22,7 @@ class KMRemovePasswordWindowController: KMBaseWindowController {
         // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
         
         self.window!.title = NSLocalizedString("PDF Password Remover", comment: "")
-        
+        self.removePasswordView.password = password
         self.removePasswordView.removeAction = { [unowned self] view, files in
             self.doneAction?(self)
 //            self.removeFilesPassword(files: files)

+ 1 - 0
PDF Office/PDF Master/Class/PDFTools/RemovePassword/New/View/KMRemovePasswordView.swift

@@ -28,6 +28,7 @@ class KMRemovePasswordView: KMBaseXibView {
     var lockFilePathArray: [KMFileAttribute] = []
     var lockFileIndex: Int = 0
     var savePath: String = ""
+    var password: String = ""
     
     override func draw(_ dirtyRect: NSRect) {
         super.draw(dirtyRect)

+ 86 - 45
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -3438,58 +3438,99 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
                     self.showSecureWindow(self.listView.document.documentURL)
                     return
                 } else if index == 2 {
-                    let controller = KMRemovePasswordWindowController(windowNibName: "KMRemovePasswordWindowController")
-                    controller.pdfDocument = self.document
-                    self.currentWindowController = controller
-                    
-                    controller.batchAction = { [unowned self] controller, files in
-                        self.view.window?.endSheet((self.currentWindowController.window)!)
-                        self.currentWindowController = nil
+                    if !self.document!.allowsCopying || !self.document!.allowsPrinting {
+                        let alert = NSAlert()
+                        alert.alertStyle = .warning
+                        alert.messageText = NSLocalizedString("Warning", comment: "")
+                        alert.informativeText = NSLocalizedString("This is a secured document. Editing is not permitted.", comment: "")
+                        alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
+                        alert.addButton(withTitle: NSLocalizedString("Remove Security", comment: ""))
+                        alert.beginSheetModal(for: NSWindow.currentWindow()) { returnCode in
+                            if returnCode == .alertSecondButtonReturn {
+                                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.25) { [unowned self] in
+                                    KMBaseWindowController.checkPassword(url: self.document!.documentURL!) { [unowned self] success, resultPassword in
+                                        if success {
+                                            self.document?.unlock(withPassword: resultPassword)
+                                            self.clickChildTool(type: .secure, index: 2)
+                                            //                                        /// 删除安全性设置
+                                            //                                        if (!self.listView.document!.allowsCopying || !self.listView.document!.allowsPrinting) {
+                                            //                                            self.isSaveKeyChain = false
+                                            //                                            self.listView.document.unlock(withPassword: password)
+                                            //                                            self.hiddenSecureLimitTip()
+                                            //                                            self.recordRemoveSecureFlag()
+                                            //                                            self.recordSaveWatermarkFlag(type: .removePassword)
+                                            //
+                                            //                                            let tip = KMRemovePasswordResultTipView()
+                                            //                                            tip.result = .success
+                                            //                                            tip.showInView(superView: (self.listView.superview)!)
+                                            //                                        } else {
+                                            //                                            self.recordRemoveSecureFlag()
+                                            //                                            self.recordSaveWatermarkFlag(type: .removePassword)
+                                            //                                            let tip = KMRemovePasswordResultTipView()
+                                            //                                            tip.result = .success
+                                            //                                            self.hiddenSecureLimitTip()
+                                            //
+                                            //                                            tip.showInView(superView: self.listView.superview!)
+                                            //                                        }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    } else {
+                        let controller = KMRemovePasswordWindowController(windowNibName: "KMRemovePasswordWindowController")
+                        controller.pdfDocument = self.document
+                        self.currentWindowController = controller
                         
-                        self.toolbarController.cancelSelected(KMToolbarToolCompressItemIdentifier)
+                        controller.batchAction = { [unowned self] controller, files in
+                            self.view.window?.endSheet((self.currentWindowController.window)!)
+                            self.currentWindowController = nil
+                            
+                            self.toolbarController.cancelSelected(KMToolbarToolCompressItemIdentifier)
+                            
+                            let batchWindowController = KMBatchOperateWindowController.sharedWindowController
+                                    batchWindowController.window?.makeKeyAndOrderFront("")
+                            let batchOperateFile = KMBatchOperateFile(filePath: files.first?.filePath ?? "")
+                            batchWindowController.switchToOperateType(.RemovePassword, files: [batchOperateFile])
+                            batchWindowController.window?.makeKeyAndOrderFront("")
+                        }
                         
-                        let batchWindowController = KMBatchOperateWindowController.sharedWindowController
-                                batchWindowController.window?.makeKeyAndOrderFront("")
-                        let batchOperateFile = KMBatchOperateFile(filePath: files.first?.filePath ?? "")
-                        batchWindowController.switchToOperateType(.RemovePassword, files: [batchOperateFile])
-                        batchWindowController.window?.makeKeyAndOrderFront("")
-                    }
-                    
-                    controller.cancelAction = { [unowned self] controller in
-                        self.view.window?.endSheet((self.currentWindowController.window)!)
-                        self.currentWindowController = nil
-                    }
-                    
-                    controller.doneAction = {  [unowned self] controller in
-                        self.view.window?.endSheet((self.currentWindowController.window)!)
-                        self.currentWindowController = nil
+                        controller.cancelAction = { [unowned self] controller in
+                            self.view.window?.endSheet((self.currentWindowController.window)!)
+                            self.currentWindowController = nil
+                        }
                         
-                        KMBaseWindowController.checkPassword(url: self.document!.documentURL!) { [unowned self] success, resultPassword in
-                            if success {
-                                /// 删除安全性设置
-                                if (!self.listView.document!.allowsCopying || !self.listView.document!.allowsPrinting) {
-                                    self.isSaveKeyChain = false
-                                    self.listView.document.unlock(withPassword: password)
-                                    self.hiddenSecureLimitTip()
-                                    self.recordRemoveSecureFlag()
-                                    self.recordSaveWatermarkFlag(type: .removePassword)
-                                    
-                                    let tip = KMRemovePasswordResultTipView()
-                                    tip.result = .success
-                                    tip.showInView(superView: (self.listView.superview)!)
-                                } else {
-                                    self.recordRemoveSecureFlag()
-                                    self.recordSaveWatermarkFlag(type: .removePassword)
-                                    let tip = KMRemovePasswordResultTipView()
-                                    tip.result = .success
-                                    self.hiddenSecureLimitTip()
-                                    
-                                    tip.showInView(superView: self.listView.superview!)
+                        controller.doneAction = {  [unowned self] controller in
+                            self.view.window?.endSheet((self.currentWindowController.window)!)
+                            self.currentWindowController = nil
+                            
+                            KMBaseWindowController.checkPassword(url: self.document!.documentURL!) { [unowned self] success, resultPassword in
+                                if success {
+                                    /// 删除安全性设置
+                                    if (!self.listView.document!.allowsCopying || !self.listView.document!.allowsPrinting) {
+                                        self.isSaveKeyChain = false
+                                        self.listView.document.unlock(withPassword: password)
+                                        self.hiddenSecureLimitTip()
+                                        self.recordRemoveSecureFlag()
+                                        self.recordSaveWatermarkFlag(type: .removePassword)
+                                        
+                                        let tip = KMRemovePasswordResultTipView()
+                                        tip.result = .success
+                                        tip.showInView(superView: (self.listView.superview)!)
+                                    } else {
+                                        self.recordRemoveSecureFlag()
+                                        self.recordSaveWatermarkFlag(type: .removePassword)
+                                        let tip = KMRemovePasswordResultTipView()
+                                        tip.result = .success
+                                        self.hiddenSecureLimitTip()
+                                        
+                                        tip.showInView(superView: self.listView.superview!)
+                                    }
                                 }
                             }
                         }
+                        await NSWindow.currentWindow().beginSheet(controller.window!)
                     }
-                    await NSWindow.currentWindow().beginSheet(controller.window!)
                     return
                 }
             } else if type == .comparison {