Browse Source

【转档】新增免费转前10页

tangchao 1 year ago
parent
commit
bf52fdbf6c

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

@@ -164,38 +164,6 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "ABEE7E32-599E-4F4F-AD8C-DC8C5ECC067C"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFTools/Convert/Controller/KMConvertBaseWindowController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "310"
-            endingLineNumber = "310"
-            landmarkName = "convertButtonAction()"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "22A761CD-6A79-4BF4-802B-2F120C18200A"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFTools/Convert/Controller/KMConvertBaseWindowController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "528"
-            endingLineNumber = "528"
-            landmarkName = "updatePreView(pageRange:pageString:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent

+ 1 - 1
PDF Office/PDF Master/Class/Common/Tools/KMTools.swift

@@ -414,7 +414,7 @@ extension KMTools {
         if let data = secureOptions, !data.isEmpty {
             _document.write(to: url, withOptions: data)
         } else if (removePWD) {
-            document.writeDecrypt(to: url)
+            _document.writeDecrypt(to: url)
         } else {
             _document.write(to: url)
         }

+ 141 - 79
PDF Office/PDF Master/Class/PDFTools/Convert/Controller/KMConvertBaseWindowController.swift

@@ -150,8 +150,17 @@ class KMConvertBaseWindowController: KMBaseWindowController {
                 self.updatePreView(pageRange: .custom, pageString: string)
             }
         }
-        view?.tipView?.itemClick = { _, _ in
-            Swift.debugPrint("Convert", "Unlock Click", separator: "-")
+        view?.tipView?.itemClick = { [unowned self] _, _ in
+#if VERSION_DMG
+            KMTools.openPurchaseProductWebsite()
+#else
+            Task { @MainActor in
+                if await (KMLightMemberManager.manager.canPayFunction() == false) {
+                    let _ = KMSubscribeWaterMarkWindowController.show(window: self.window!) { isSubscribeSuccess, isWaterMarkExport, isClose in
+                    }
+                }
+            }
+#endif
         }
         
         self.backButtonVC = KMDesignButton.init(withType: .Image)
@@ -314,88 +323,24 @@ class KMConvertBaseWindowController: KMBaseWindowController {
             return
         }
         
-        NSPanel.savePanel(self.window!) { panel in
-            let name = self.prePDFView!.document.documentURL.deletingPathExtension().lastPathComponent
-            panel.nameFieldStringValue = name
-            panel.allowedFileTypes = [self.fileExtension]
-        } completion: { response, url in
-            if (response == .cancel) {
-                return
-            }
-            let outputFolderPath = url!.deletingLastPathComponent().path
-            let convert = self.initConvert()
-            self.convert = convert
-            convert.password = self.documentModel!.password
-            convert.outputFolderPath = outputFolderPath
-            convert.filePath = filePath
-            convert.pages = pages
-            var fileName = url!.deletingPathExtension().lastPathComponent
-            if (self.fileExtension.isEmpty) {
-                fileName = url!.lastPathComponent
-            }
-//            if (fileName.isEmpty) {
-//                fileName = NSLocalizedString("Untitled", comment: "")
-//            }
-            convert.outputFileName = fileName
-            self.convertModelAppendParams(convert: convert)
-            
-            DispatchQueue.main.async {
-                self.showProgressWindow()
-                self.progressController?.maxValue = Double(convert.pages.count)
-            }
-            
-            DispatchQueue.global().async {
-                KMPDFConvertManager.defaultManager.convert(convert: convert, progress: { index in
-                    DispatchQueue.main.async {
-                        self.progressController?.increment(by: 1.0)
+        Task { @MainActor in
+            if await (KMLightMemberManager.manager.canPayFunction() == false) {
+                let _ = KMSubscribeWaterMarkWindowController.show(window: self.window!) { isSubscribeSuccess, isWaterMarkExport, isClose in
+                    if (isClose) {
+                        return
                     }
-                }) { [unowned self] finished, error in
-                    self.hiddenProgressWindow()
-                    
-                    // 清除临时文件
-                    if (FileManager.default.fileExists(atPath: filePath)) {
-                        try?FileManager.default.removeItem(atPath: filePath)
+                    if (isSubscribeSuccess) {
+                        self._convertButtonAction()
+                        return
                     }
-                    if finished {
-                        cancelButtonAction()
-                        if FileManager.default.fileExists(atPath: convert.outputFilePath) {
-                            NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: convert.outputFilePath)])
-                        }
-                    } else {
-                        var errorString = ""
-                        let myError: NSError? = error as? NSError
-                        if myError?.code == 1 {
-                            errorString = NSLocalizedString("Password required or incorrect password. Please re-enter your password and try again", comment: "")
-                        } else if myError?.code == 2 {
-                            errorString = NSLocalizedString("The license doesn't allow the permission", comment: "")
-                        } else if myError?.code == 3 {
-                            errorString = NSLocalizedString("Malloc failure", comment: "")
-                        } else if myError?.code == 4 {
-                            errorString = NSLocalizedString("Unknown error in processing conversion. Please try again later", comment: "")
-                        } else if myError?.code == 5 {
-                            errorString = NSLocalizedString("Unknown error in processing PDF. Please try again later", comment: "")
-                        } else if myError?.code == 6 {
-                            errorString = NSLocalizedString("File not found or could not be opened. Check if your file exists or choose another file to convert", comment: "")
-                        } else if myError?.code == 7 {
-                            errorString = NSLocalizedString("File not in PDF format or corruptead. Change a PDF file and try again", comment: "")
-                        } else if myError?.code == 8 {
-                            errorString = NSLocalizedString("Unsupported security scheme", comment: "")
-                        } else if myError?.code == 9 {
-                            errorString = NSLocalizedString("Page not found or content error", comment: "")
-                        } else {
-                            errorString = NSLocalizedString("Table not found", comment: "")
-                        }
-                        
-                        let alert = NSAlert()
-                        alert.alertStyle = .critical
-                        alert.messageText = NSLocalizedString("Conversion Failed", comment: "")
-                        alert.informativeText = errorString
-                        alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
-                        alert.runModal()
+                    if (isWaterMarkExport) {
+                        self._convertButtonAction(limit: true)
+                        return
                     }
                 }
+                return
             }
-            
+            self._convertButtonAction()
         }
     }
     
@@ -673,6 +618,123 @@ class KMConvertBaseWindowController: KMBaseWindowController {
         return pages
     }
     
+    private func _convertButtonAction(limit: Bool = false) {
+        var pages: [Int] = []
+        let filePath = self.getConvertFileSavePath()
+        if (FileManager.default.fileExists(atPath: filePath)) {
+            try?FileManager.default.removeItem(atPath: filePath)
+        }
+        if (limit) {
+            if let _ = KMTools.saveDocumentForWatermark(document: self.prePDFView!.document, to: URL(fileURLWithPath: filePath), removePWD: true) {
+                for i in 0 ..< self.prePDFView!.document.pageCount {
+                    if (i >= 10) {
+                        break
+                    }
+                    pages.append(Int(i)+1)
+                }
+            }
+        } else {
+            if ((self.prePDFView?.document?.writeDecrypt(to: URL(fileURLWithPath: filePath)))!) {
+                for i in 0 ..< self.prePDFView!.document.pageCount {
+                    pages.append(Int(i)+1)
+                }
+            }
+        }
+        
+        if (pages.count <= 0) {
+            let alert = NSAlert()
+            alert.alertStyle = .warning
+            alert.messageText = NSLocalizedString("Invalid page range or the page number is out of range. Please try again.", comment: "")
+            alert.runModal()
+            return
+        }
+        
+        DispatchQueue.main.async {
+            NSPanel.savePanel(self.window!) { panel in
+                let name = self.prePDFView!.document.documentURL.deletingPathExtension().lastPathComponent
+                panel.nameFieldStringValue = name
+                panel.allowedFileTypes = [self.fileExtension]
+            } completion: { response, url in
+                if (response == .cancel) {
+                    return
+                }
+                let outputFolderPath = url!.deletingLastPathComponent().path
+                let convert = self.initConvert()
+                self.convert = convert
+                convert.password = self.documentModel!.password
+                convert.outputFolderPath = outputFolderPath
+                convert.filePath = filePath
+                convert.pages = pages
+                var fileName = url!.deletingPathExtension().lastPathComponent
+                if (self.fileExtension.isEmpty) {
+                    fileName = url!.lastPathComponent
+                }
+                //            if (fileName.isEmpty) {
+                //                fileName = NSLocalizedString("Untitled", comment: "")
+                //            }
+                convert.outputFileName = fileName
+                self.convertModelAppendParams(convert: convert)
+                
+                DispatchQueue.main.async {
+                    self.showProgressWindow()
+                    self.progressController?.maxValue = Double(convert.pages.count)
+                }
+                
+                DispatchQueue.global().async {
+                    KMPDFConvertManager.defaultManager.convert(convert: convert, progress: { index in
+                        DispatchQueue.main.async {
+                            self.progressController?.increment(by: 1.0)
+                        }
+                    }) { [unowned self] finished, error in
+                        self.hiddenProgressWindow()
+                        
+                        // 清除临时文件
+                        if (FileManager.default.fileExists(atPath: filePath)) {
+                            try?FileManager.default.removeItem(atPath: filePath)
+                        }
+                        if finished {
+                            cancelButtonAction()
+                            if FileManager.default.fileExists(atPath: convert.outputFilePath) {
+                                NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: convert.outputFilePath)])
+                            }
+                        } else {
+                            var errorString = ""
+                            let myError: NSError? = error as? NSError
+                            if myError?.code == 1 {
+                                errorString = NSLocalizedString("Password required or incorrect password. Please re-enter your password and try again", comment: "")
+                            } else if myError?.code == 2 {
+                                errorString = NSLocalizedString("The license doesn't allow the permission", comment: "")
+                            } else if myError?.code == 3 {
+                                errorString = NSLocalizedString("Malloc failure", comment: "")
+                            } else if myError?.code == 4 {
+                                errorString = NSLocalizedString("Unknown error in processing conversion. Please try again later", comment: "")
+                            } else if myError?.code == 5 {
+                                errorString = NSLocalizedString("Unknown error in processing PDF. Please try again later", comment: "")
+                            } else if myError?.code == 6 {
+                                errorString = NSLocalizedString("File not found or could not be opened. Check if your file exists or choose another file to convert", comment: "")
+                            } else if myError?.code == 7 {
+                                errorString = NSLocalizedString("File not in PDF format or corruptead. Change a PDF file and try again", comment: "")
+                            } else if myError?.code == 8 {
+                                errorString = NSLocalizedString("Unsupported security scheme", comment: "")
+                            } else if myError?.code == 9 {
+                                errorString = NSLocalizedString("Page not found or content error", comment: "")
+                            } else {
+                                errorString = NSLocalizedString("Table not found", comment: "")
+                            }
+                            
+                            let alert = NSAlert()
+                            alert.alertStyle = .critical
+                            alert.messageText = NSLocalizedString("Conversion Failed", comment: "")
+                            alert.informativeText = errorString
+                            alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
+                            alert.runModal()
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
     // MARK: Progress
     func showProgressWindow() {
         self.hiddenProgressWindow()