Selaa lähdekoodia

转换-新增权限密码的阻挡

tangchao 2 vuotta sitten
vanhempi
commit
3d5426a795

BIN
PDF Office/PDF Office.xcodeproj/project.xcworkspace/xcuserdata/kdanmobile.xcuserdatad/UserInterfaceState.xcuserstate


+ 0 - 16
PDF Office/PDF Office.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -180,22 +180,6 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "C353E38A-4D27-4266-858B-CF8F7AF4A692"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Office/Class/PDFTools/Convert/Controller/KMConvertImageWindowController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "40"
-            endingLineNumber = "40"
-            landmarkName = "convertModelAppendParams(convert:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent

+ 87 - 1
PDF Office/PDF Office/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -369,7 +369,50 @@ extension KMHomeViewController {
             
             let model = KMDocumentModel()
             model.documentURL = panel.url!
-            if model.isLocked {
+            if model.isLocked && model.isEncrypt {
+                let passwordInputWindow = KMPasswordInputWindow().window()
+                passwordInputWindow?.documentURL = model.documentURL
+                passwordInputWindow?.type = .owner
+                
+                passwordInputWindow?.itemClick = {
+                    [self] (index: Int, string: String) in
+                    
+                    self.view.window?.endSheet(passwordInputWindow!)
+                    if index == 2 { /// 解密成功
+                        model.owerPassword = string
+                        
+                        var windowController: KMConvertBaseWindowController!
+                        if view.indexOfSelectedItem == 0 { /// Word
+                            windowController = KMConvertWordWindowController(windowNibName: "KMConvertBaseWindowController")
+                        } else if view.indexOfSelectedItem == 1 {
+                            windowController = KMConvertExcelWindowController(windowNibName: "KMConvertBaseWindowController")
+                        } else if view.indexOfSelectedItem == 2 {
+                            windowController = KMConvertPPTsWindowController(windowNibName: "KMConvertBaseWindowController")
+                        } else if view.indexOfSelectedItem == 3 {
+                            windowController = KMConvertCSVWindowController(windowNibName: "KMConvertBaseWindowController")
+                        } else if view.indexOfSelectedItem == 4 {
+                            windowController = KMConvertImageWindowController(windowNibName: "KMConvertBaseWindowController")
+                        }
+                        
+//                        windowController.documentURL = panel.url!
+                        windowController.documentModel = model
+                        
+                        windowController.itemClick = {
+                           [self] (index: Int) in
+                            if index == 1 { /// 批量转档
+                                self.view.window?.endSheet(convertWindowController.window!)
+                            } else if index == 2 { /// 关闭
+                                self.view.window?.endSheet(convertWindowController.window!)
+                            }
+                        }
+                        
+                        self.view.window?.beginSheet(windowController.window!)
+                        convertWindowController = windowController
+                    }
+                }
+                self.view.window?.beginSheet(passwordInputWindow!)
+                return
+            } else if (model.isLocked) {
                 let passwordInputWindow = KMPasswordInputWindow().window()
                 passwordInputWindow?.documentURL = model.documentURL
                 passwordInputWindow?.type = .open
@@ -394,6 +437,49 @@ extension KMHomeViewController {
                             windowController = KMConvertImageWindowController(windowNibName: "KMConvertBaseWindowController")
                         }
                         
+//                        windowController.documentURL = panel.url!
+                        windowController.documentModel = model
+                        
+                        windowController.itemClick = {
+                           [self] (index: Int) in
+                            if index == 1 { /// 批量转档
+                                self.view.window?.endSheet(convertWindowController.window!)
+                            } else if index == 2 { /// 关闭
+                                self.view.window?.endSheet(convertWindowController.window!)
+                            }
+                        }
+                        
+                        self.view.window?.beginSheet(windowController.window!)
+                        convertWindowController = windowController
+                    }
+                }
+                self.view.window?.beginSheet(passwordInputWindow!)
+                return
+            } else if (model.isEncrypt) {
+                let passwordInputWindow = KMPasswordInputWindow().window()
+                passwordInputWindow?.documentURL = model.documentURL
+                passwordInputWindow?.type = .owner
+                
+                passwordInputWindow?.itemClick = {
+                    [self] (index: Int, string: String) in
+                    
+                    self.view.window?.endSheet(passwordInputWindow!)
+                    if index == 2 { /// 解密成功
+                        model.owerPassword = string
+                        
+                        var windowController: KMConvertBaseWindowController!
+                        if view.indexOfSelectedItem == 0 { /// Word
+                            windowController = KMConvertWordWindowController(windowNibName: "KMConvertBaseWindowController")
+                        } else if view.indexOfSelectedItem == 1 {
+                            windowController = KMConvertExcelWindowController(windowNibName: "KMConvertBaseWindowController")
+                        } else if view.indexOfSelectedItem == 2 {
+                            windowController = KMConvertPPTsWindowController(windowNibName: "KMConvertBaseWindowController")
+                        } else if view.indexOfSelectedItem == 3 {
+                            windowController = KMConvertCSVWindowController(windowNibName: "KMConvertBaseWindowController")
+                        } else if view.indexOfSelectedItem == 4 {
+                            windowController = KMConvertImageWindowController(windowNibName: "KMConvertBaseWindowController")
+                        }
+                        
 //                        windowController.documentURL = panel.url!
                         windowController.documentModel = model
                         

+ 6 - 19
PDF Office/PDF Office/Class/PDFTools/Convert/Controller/KMConvertBaseWindowController.swift

@@ -100,30 +100,17 @@ class KMConvertBaseWindowController: NSWindowController {
         
         if documentModel != nil {
             self.prePDFView.document = PDFDocument(url: documentModel.documentURL)
-            if documentModel.isLocked {
+            if (documentModel.isLocked && documentModel.isEncrypt) {
+                self.prePDFView.document?.unlock(withPassword: documentModel.owerPassword)
+            } else if (documentModel.isLocked) {
                 self.prePDFView.document?.unlock(withPassword: documentModel.password)
+            } else if (documentModel.isEncrypt) {
+                self.prePDFView.document?.unlock(withPassword: documentModel.owerPassword)
             }
+            
             let number: Int = prePDFView.document!.pageCount
             var string = "\(number)"
             totalNumberLabel.stringValue = string
-            
-//            if documentModel.isEncrypt {
-//                let passwordInputWindow = KMPasswordInputWindow().window()
-//                passwordInputWindow?.documentURL = documentModel.documentURL
-//                passwordInputWindow?.type = .owner
-//
-//                passwordInputWindow?.itemClick = {
-//                    [self] (index: Int, string: String) in
-//
-//                    self.window?.endSheet(passwordInputWindow!)
-//                    if index == 2 { /// 解密成功
-//                        documentModel.owerPassword = string
-//                    } else {
-//                        cancelButtonAction()
-//                    }
-//                }
-//                self.window?.beginSheet(passwordInputWindow!)
-//            }
         }
         self.prePDFView.documentView?.enclosingScrollView?.hasVerticalScroller = false
         self.prePDFView.documentView?.enclosingScrollView?.hasHorizontalScroller = false

+ 32 - 12
PDF Office/PDF Office/Class/PDFTools/Secure/Window/KMPasswordInputWindow.swift

@@ -166,19 +166,39 @@ class KMPasswordInputWindow: NSWindow {
             let document = PDFDocument(url: KMPasswordInputWindow.myDocumentURL)
             if KMPasswordInputWindow.myType == .owner {
                 let state = document?.permissionsStatus
-                if document?.permissionsStatus == .user {
-                    if secureTextFiled != nil {
-                        let reuslt = document?.unlock(withPassword: secureTextFiled.password())
-                        if document?.permissionsStatus == .owner { /// 密码正确
-                            guard let callback = KMPasswordInputWindow.myItemClick else {
-                                return
+                if ((document?.isLocked)!) {
+                    if document?.permissionsStatus == PDFDocumentPermissions.none {
+                        if secureTextFiled != nil {
+                            let reuslt = document?.unlock(withPassword: secureTextFiled.password())
+                            if document?.permissionsStatus == .owner { /// 密码正确
+                                guard let callback = KMPasswordInputWindow.myItemClick else {
+                                    return
+                                }
+                                
+                                callback(2, secureTextFiled.password())
+                            } else { /// 密码错误
+                                if passwordErrorLabel != nil {
+                                    passwordErrorLabel.isHidden = false
+                                    secureTextFiled.backgroundView.layer?.borderColor = NSColor.red.cgColor
+                                }
                             }
-                            
-                            callback(2, secureTextFiled.password())
-                        } else { /// 密码错误
-                            if passwordErrorLabel != nil {
-                                passwordErrorLabel.isHidden = false
-                                secureTextFiled.backgroundView.layer?.borderColor = NSColor.red.cgColor
+                        }
+                    }
+                } else {
+                    if document?.permissionsStatus == .user {
+                        if secureTextFiled != nil {
+                            let reuslt = document?.unlock(withPassword: secureTextFiled.password())
+                            if document?.permissionsStatus == .owner { /// 密码正确
+                                guard let callback = KMPasswordInputWindow.myItemClick else {
+                                    return
+                                }
+                                
+                                callback(2, secureTextFiled.password())
+                            } else { /// 密码错误
+                                if passwordErrorLabel != nil {
+                                    passwordErrorLabel.isHidden = false
+                                    secureTextFiled.backgroundView.layer?.borderColor = NSColor.red.cgColor
+                                }
                             }
                         }
                     }