Browse Source

【2025】【批量】进度显示部分逻辑整理完善

lizhe 2 months ago
parent
commit
8de68b8715
16 changed files with 750 additions and 518 deletions
  1. 3 3
      PDF Office/PDF Master/Class/PDFTools/Compress/Manager/KMCompressManager.swift
  2. 0 2
      PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/Views/OCR/Tool/Manager/KMOCRManager.swift
  3. 0 20
      PDF Office/PDF Master/KMClass/NewBatch/KMBatchManager/KMBatchManager.swift
  4. 3 1
      PDF Office/PDF Master/KMClass/NewBatch/KMBatchWindowController.swift
  5. 643 0
      PDF Office/PDF Master/KMClass/NewBatch/Manager/KMBatchManager.swift
  6. 12 0
      PDF Office/PDF Master/KMClass/NewBatch/View/KMBatchProcessingView/KMBatchProcessingView.swift
  7. 2 1
      PDF Office/PDF Master/KMClass/NewBatch/View/KMBatchProcessingView/Tableview/KMBatchProcessingTableViewModel/KMBatchProcessingTableViewModel.swift
  8. 17 1
      PDF Office/PDF Master/KMClass/NewBatch/View/KMBatchProcessingView/Tableview/Views/Tableview/Views/KMBatchProcessingStateTableCell.swift
  9. 9 0
      PDF Office/PDF Master/KMClass/NewBatch/View/Setting/BatchRemove/KMBatchRemoveView.swift
  10. 9 0
      PDF Office/PDF Master/KMClass/NewBatch/View/Setting/Compress/KMBatchCompressView.swift
  11. 9 0
      PDF Office/PDF Master/KMClass/NewBatch/View/Setting/ConvertPDF/KMBatchConvertPDFView.swift
  12. 13 0
      PDF Office/PDF Master/KMClass/NewBatch/View/Setting/KMBatchBatchSettingItemView/KMBatchSettingItemView.swift
  13. 9 487
      PDF Office/PDF Master/KMClass/NewBatch/View/Setting/KMBatchSettingView.swift
  14. 9 0
      PDF Office/PDF Master/KMClass/NewBatch/View/Setting/OCR/KMBatchOCRView.swift
  15. 9 0
      PDF Office/PDF Master/KMClass/NewBatch/View/Setting/Security/KMBatchSecurityView.swift
  16. 3 3
      PDF Office/PDF Reader Pro.xcodeproj/project.pbxproj

+ 3 - 3
PDF Office/PDF Master/Class/PDFTools/Compress/Manager/KMCompressManager.swift

@@ -15,7 +15,7 @@ class KMCompressManager: NSObject {
                   password: String = "",
                   limit: Bool = false,
                   model: KMCompressSettingModel,
-                  view: NSView,
+                  view: NSView?,
                   completionHandler: (@escaping (Bool, URL) -> Void)) {
         DispatchQueue.main.async {
             NSPanel.savePanel(NSWindow.currentWindow(), true) { panel in
@@ -27,7 +27,7 @@ class KMCompressManager: NSObject {
                     return
                 }
                 
-                view.beginLoading()
+                view?.beginLoading()
                 DispatchQueue.global().async {
                     self.compress(documentURL: documentURL, fileURL: url!, password: password, limit: limit, model: model) { currentPage, totalPages in
                             
@@ -35,7 +35,7 @@ class KMCompressManager: NSObject {
                             return false
                         } completionHandler: { [unowned self] isFinish in
                             DispatchQueue.main.async {
-                                view.endLoading()
+                                view?.endLoading()
                                 if (isFinish) {
                                     if isOpen { /// 开启文档
                                         NSDocumentController.shared.km_safe_openDocument(withContentsOf: url!, display: true) { _, _, _ in

+ 0 - 2
PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/Views/OCR/Tool/Manager/KMOCRManager.swift

@@ -122,8 +122,6 @@ extension KMOCRManager: KMGOCRManagerDelegate {
         self.progress = progress
         self.model = model
         
-        let pages:[Int] = self.fetchPageIndex(document: document, model: model)
-        model.pageRange = pages
         self.saveAsPDFFilePath = saveFilePath
         self.convertOCR(document: document, filePath:saveFilePath, indexs: model.pageRange, language: model.language, type: model.ocrType, saveAsPDF: true)
     }

+ 0 - 20
PDF Office/PDF Master/KMClass/NewBatch/KMBatchManager/KMBatchManager.swift

@@ -1,20 +0,0 @@
-//
-//  KMBatchManager.swift
-//  PDF Master
-//
-//  Created by lizhe on 2023/2/17.
-//
-
-import Cocoa
-
-enum KMBatchManagerSate: String, CaseIterable {
-    case unknow
-    case processing
-}
-
-class KMBatchManager: NSObject {
-    public static let manager = KMBatchManager()
-    fileprivate(set) var state: KMBatchManagerSate = .unknow
-    
-    
-}

+ 3 - 1
PDF Office/PDF Master/KMClass/NewBatch/KMBatchWindowController.swift

@@ -195,7 +195,9 @@ class KMBatchWindowController: NSWindowController {
 extension KMBatchWindowController: KMBatchProcessingViewDelegate {
     func reloadData(data: [KMBatchProcessingTableViewModel]) {
         self.batchData = data
-        self.settingView.filesData = self.batchData
+        
+        KMBatchManager.manager.filesData = data
+        self.settingView.filesData = data
     }
 }
 

+ 643 - 0
PDF Office/PDF Master/KMClass/NewBatch/Manager/KMBatchManager.swift

@@ -0,0 +1,643 @@
+//
+//  KMBatchManager.swift
+//  PDF Master
+//
+//  Created by lizhe on 2023/2/17.
+//
+
+import Cocoa
+
+enum KMBatchManagerSate: Int, CaseIterable {
+    case unknow = 0
+    case processing
+    case complete
+    case error
+}
+
+let kBacthFilesProcessNotification = "kBacthFilesProcessNotification"
+let kBacthProcessNotification = "kBacthProcessNotification"
+
+class KMBatchManager: NSObject {
+    public static let manager = KMBatchManager()
+    fileprivate(set) var state: KMBatchManagerSate = .unknow
+    
+    var filesData: [KMBatchProcessingTableViewModel] = []
+    
+    func batch(type: KMBatchCollectionViewType, data: KMBatchSettingItemViewModel) {
+        let panel = NSOpenPanel()
+        panel.canChooseFiles = false
+        panel.canChooseDirectories = true
+        panel.canCreateDirectories = true
+        panel.beginSheetModal(for: NSWindow.currentWindow()) { response in
+            if response == .cancel {
+                return
+            }
+            
+            let outputFolderPath = (panel.url?.path)!
+            //
+            self.batchUnkown()
+            
+            switch type {
+            case .convertPDF:
+                self.convertPDFExport(data: data, outputFolderPath: outputFolderPath)
+                break
+            case .OCR:
+                self.convertOCRExport(data: data, outputFolderPath: outputFolderPath)
+                break
+            case .compress:
+                self.compressExport(data: data, outputFolderPath: outputFolderPath)
+                break
+            case .security:
+                self.securityExport(data: data, outputFolderPath: outputFolderPath)
+                break
+            case .watermark:
+                
+                break
+            case .background:
+                
+                break
+            case .headerAndFooter:
+                
+                break
+            case .batesNumber:
+                
+                break
+            case .batchRemove:
+                self.removeApplay(data: data, outputFolderPath: outputFolderPath)
+                break
+            default:
+                KMPrint("找不到")
+                break
+            }
+            
+            //
+            self.batchProgress()
+        }
+    }
+}
+
+protocol KMBatchSettingViewExport {}
+extension KMBatchManager: KMBatchSettingViewExport {
+    //MARK: 转档
+    func convertPDFExport(data: KMBatchSettingItemViewModel, outputFolderPath: String) {
+        self.convertFile(outputFolderPath: outputFolderPath, data: data, filesData: self.filesData)
+    }
+    
+    func convertFile(outputFolderPath: String, data: KMBatchSettingItemViewModel, filesData: [KMBatchProcessingTableViewModel]) {
+        if filesData.count != 0 {
+            DispatchQueue.global().async {
+                for i in 0..<filesData.count {
+                    let item = filesData[i]
+                    //创建Document
+                    let filePath = item.filePath
+                    let document = self.fetchDocument(filePath: filePath, model: item)
+                    
+                    let settingData = data as? KMBatchConvertPDFViewModel  ?? KMBatchConvertPDFViewModel()
+                    var fileName = filePath.deletingPathExtension.lastPathComponent
+                    if ((fileName.isEmpty)) {
+                        fileName = NSLocalizedString("Untitled", comment: "")
+                    }
+                    
+                    let convert = self.addConvertParameter(settingData)
+                    
+                    let pageCount = document.pageCount
+                    //获取page
+                    var pages:[Int] = []
+                    for i in 0..<pageCount {
+                        pages.append(Int(i)+1)
+                    }
+                    
+                    convert.outputFolderPath = outputFolderPath
+                    convert.filePath = filePath
+                    convert.outputFileName = fileName
+                    convert.pages = pages
+                    
+                    convert.isAllowOCR = settingData.needRecognizeText
+                    convert.ocrLanguage = settingData.languageType
+                    
+                    item.state = .clock
+                    KMPDFConvertManager.defaultManager.convert(convert: convert, progress: { [unowned self] progressValue in
+                        print("转档进度 - \(progressValue)")
+                        let progress = Float(progressValue) / Float(pageCount)
+                        self.itemProgress(item: item, processValue: progress)
+                    }, completion: { [unowned self] finished, error in
+                        if finished {
+                            if FileManager.default.fileExists(atPath: outputFolderPath) {
+                                NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: outputFolderPath)])
+                            }
+                            self.itemSuccess(item: item)
+                        } else {
+                            self.itemFailure(item: item, error: error! as NSError)
+                        }
+                        
+                        if i == self.filesData.count - 1 {
+                            self.batchSuccess()
+                        }
+                    })
+                }
+            }
+        }
+    }
+    
+    func addConvertParameter(_ data: KMBatchConvertPDFViewModel) -> KMPDFConvert {
+        let settingData = data
+        var convert = KMPDFConvert()
+        
+        switch settingData.convertPDFType {
+        case .word:
+            convert = KMPDFConvertWord()
+            if settingData.layoutSettingType == .flowingText {
+                convert.isAllInOneSheet = false
+            } else {
+                convert.isAllInOneSheet = true
+            }
+        case .excel:
+            convert = KMPDFConvertExcel()
+            if settingData.excelSetting == .separate {
+                convert.isAllInOneSheet = false
+                convert.isExtractTable = false
+            } else if settingData.excelSetting == .format {
+                convert.isAllInOneSheet = true
+                convert.isExtractTable = false
+            } else if settingData.excelSetting == .tables {
+                convert.isAllInOneSheet = false
+                convert.isExtractTable = true
+                
+                switch settingData.excelTablesType {
+                case .oneTable:
+                    convert.extractTableIndex = 0
+                case .pageTable:
+                    convert.extractTableIndex = 1
+                case .allTable:
+                    convert.extractTableIndex = 2
+                default:
+                    KMPrint("未找到")
+                }
+            }
+        case .ppt:
+            convert = KMPDFConvertPPT()
+        case .csv:
+            convert = KMPDFConvertCSV()
+            if settingData.csvOnlyTables {
+                convert.isExtractTable = true
+                switch settingData.excelTablesType {
+                case .oneTable:
+                    convert.extractTableIndex = 0
+                case .pageTable:
+                    convert.extractTableIndex = 1
+                case .allTable:
+                    convert.extractTableIndex = 2
+                default:
+                    KMPrint("未找到")
+                }
+            } else {
+                convert.isExtractTable = false
+            }
+        case .image:
+            convert = KMPDFConvertImage()
+            convert.convertType = data.imageType
+            
+            var dpi: Int = 150
+            if data.imageDpiIndex == 0 {
+                dpi = 50
+            } else if data.imageDpiIndex == 1 {
+                dpi = 72
+            } else if data.imageDpiIndex == 2 {
+                dpi = 96
+            } else if data.imageDpiIndex == 3 {
+                dpi = 150
+            } else if data.imageDpiIndex == 4 {
+                dpi = 300
+            } else if data.imageDpiIndex == 5 {
+                dpi = 600
+            } else {
+                dpi = 150
+            }
+            
+            if (convert.convertType == .jpeg) {
+                (convert as! KMPDFConvertImage).imageType = .JPEG
+                (convert as! KMPDFConvertImage).imageDpi = dpi
+                
+            } else if (convert.convertType == .png) {
+                (convert as! KMPDFConvertImage).imageType = .PNG
+                (convert as! KMPDFConvertImage).imageDpi = dpi
+            } else {
+                (convert as! KMPDFConvertImage).imageDpi = 150
+            }
+        case .html:
+            convert = KMPDFConvertHTML()
+        case .rtf:
+            convert = KMPDFConvertRTF()
+        case .json:
+            convert = KMPDFConvertJson()
+            if settingData.jsonType == .extractText {
+                convert.isAllInOneSheet = false
+            } else {
+                convert.isAllInOneSheet = true
+            }
+        case .text:
+            convert = KMPDFConvertText()
+            
+        default:
+            KMPrint("不清楚")
+        }
+        return convert
+    }
+    
+    //MARK: OCR
+    func convertOCRExport(data: KMBatchSettingItemViewModel, outputFolderPath: String) {
+        self.convertOCR(outputFolderPath: outputFolderPath, data: data as! KMOCRModel, filesData: self.filesData)
+    }
+    
+    func convertOCR(outputFolderPath: String, data: KMOCRModel, filesData: [KMBatchProcessingTableViewModel]?) {
+        let filesData = self.filesData
+        for i in 0..<filesData.count {
+            let item = (filesData[i])
+            let document = CPDFDocument.init(url: URL(fileURLWithPath: item.filePath))
+            if document != nil {
+                //计算需要处理的页面
+                
+                var fileName = item.filePath.deletingPathExtension.lastPathComponent
+                if ((fileName.isEmpty)) {
+                    fileName = NSLocalizedString("Untitled", comment: "")
+                }
+                let path = outputFolderPath + "/" + fileName + ".pdf"
+                
+                KMOCRManager.manager.convertBatchOCR(document: document!, saveFilePath: path, model: data, progress: { [unowned self] progress in
+                    self.itemProgress(item: item, processValue: progress)
+                }) { [unowned self] document, text, error in
+                    if error == nil {
+                        self.itemSuccess(item: item)
+                    } else {
+                        self.itemFailure(item: item, error: error! as NSError)
+                    }
+                    
+                    if i == self.filesData.count - 1 {
+                        self.batchSuccess()
+                    }
+                }
+            }
+        }
+    }
+    
+    //MARK: 压缩
+    func compressExport(data: KMBatchSettingItemViewModel, outputFolderPath: String) {
+        self.compressFile(outputFolderPath: outputFolderPath, data: (data as? KMCompressSettingModel)!, filesData: self.filesData)
+    }
+    
+    func compressFile(outputFolderPath: String, data: KMCompressSettingModel, filesData: [KMBatchProcessingTableViewModel]) {
+        if filesData.count != 0 {
+            for i in 0..<filesData.count {
+                let item = filesData[i]
+                let document = CPDFDocument.init(url: URL(fileURLWithPath: item.filePath))
+                if document != nil {
+                    var fileName = item.filePath.deletingPathExtension.lastPathComponent
+                    if ((fileName.isEmpty)) {
+                        fileName = NSLocalizedString("Untitled", comment: "")
+                    }
+                    let path = outputFolderPath + "/" + fileName + ".pdf"
+                    
+                    KMCompressManager.shared.compress(documentURL: URL(fileURLWithPath: item.filePath), fileURL: URL(fileURLWithPath: path), limit: false, model: data) { currentPage, totalPages in
+                        let progress = Float(currentPage) / Float(totalPages)
+                        self.itemProgress(item: item, processValue: progress)
+                    } cancelHandler: {
+                        return false
+                    } completionHandler: { [unowned self] isFinish in
+                        if isFinish {
+                            self.itemSuccess(item: item)
+                        } else {
+                            self.itemFailure(item: item, error: nil)
+                        }
+                        
+                        if i == self.filesData.count - 1 {
+                            self.batchSuccess()
+                        }
+                    }
+                }
+                
+            }
+        }
+    }
+    
+    //MARK: 安全
+    func securityExport(data: KMBatchSettingItemViewModel, outputFolderPath: String) {
+        self.securityFile(outputFolderPath: outputFolderPath, data: data as! KMBatchSecurityViewModel, filesData: self.filesData)
+    }
+    
+    func securityFile(outputFolderPath: String, data: KMBatchSecurityViewModel, filesData: [KMBatchProcessingTableViewModel]) {
+        if filesData.count != 0 {
+            for i in 0..<filesData.count {
+                let item = filesData[i]
+                let docuemt = CPDFDocument.init(url: URL(fileURLWithPath: item.filePath))
+                if (docuemt != nil) {
+                    var fileName = item.filePath.deletingPathExtension.lastPathComponent
+                    if ((fileName.isEmpty)) {
+                        fileName = NSLocalizedString("Untitled", comment: "")
+                    }
+                    let path = outputFolderPath + "/" + fileName + ".pdf"
+                    
+                    var options: [CPDFDocumentWriteOption : Any] = [:]
+                    //开启密码
+                    if data.isOpenPassword &&
+                        !data.openPasswordString.isEmpty {
+                        options.updateValue(data.openPasswordString, forKey: .userPasswordOption)
+                    }
+//
+                    //权限密码
+                    if data.isPermission &&
+                        !data.permissionString.isEmpty {
+                        options.updateValue(data.permissionString, forKey: .ownerPasswordOption)
+                    }
+                        
+                    // 限制打印
+                    if data.restrictOptions.contains(.print) {
+                        options.updateValue(false, forKey: .allowsPrintingOption)
+                    } else {
+                        options.updateValue(true, forKey: .allowsPrintingOption)
+                    }
+                    
+                    //限制复制
+                    if data.restrictOptions.contains(.copy) {
+                        options.updateValue(false, forKey: .allowsCopyingOption)
+                    } else {
+                        options.updateValue(true, forKey: .allowsCopyingOption)
+                    }
+                    
+                    
+                    let result = docuemt!.write(toFile: path, withOptions: options)
+//                    let result = docuemt!.write(to: URL(fileURLWithPath: path), withOptions: options)
+                    if result {
+                        KMPrint("成功")
+                        self.itemSuccess(item: item)
+                    } else {
+                        KMPrint("失败")
+                        self.itemFailure(item: item, error: nil)
+                    }
+                    
+                    if i == self.filesData.count - 1 {
+                        self.batchSuccess()
+                        NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: outputFolderPath)])
+                    }
+                }
+            }
+        }
+    }
+    
+    
+    func waterMarkApplay(data: KMBatchSettingItemViewModel) {
+
+    }
+    
+//    func waterMarkFile(data: KMWatermarkAdjectiveBaseModel, filesData: [KMBatchProcessingTableViewModel]?) {
+//
+//    }
+    
+    func backgroundApplay(data: KMBatchSettingItemViewModel) {
+        
+    }
+    
+    func backgroundFile(outputFolderPath: String, data: KMBackgroundModel, filesData: [KMBatchProcessingTableViewModel]?) {
+        
+    }
+    
+    
+    func headAndFooterApplay(data: KMBatchSettingItemViewModel) {
+        
+    }
+    
+//    func headAndFooterFile(outputFolderPath: String, data: KMHeaderFooterModel, filesData: [KMBatchProcessingTableViewModel]?) {
+//
+//    }
+    
+    func batesApplay(data: KMBatchSettingItemViewModel) {
+        
+    }
+    
+    func batesFile(outputFolderPath: String, data: KMBatesModel, filesData: [KMBatchProcessingTableViewModel]?) {
+        
+    }
+    
+    
+    func removeApplay(data: KMBatchSettingItemViewModel, outputFolderPath: String) {
+        if (data == nil) {
+            let alert = NSAlert()
+            alert.alertStyle = .critical
+            alert.messageText = "没有找到"
+            alert.runModal()
+            return
+        }
+        
+        let panel = NSOpenPanel()
+        let button = NSButton.init(checkboxWithTitle: "保存后打开文档", target: nil, action: nil)
+        button.state = .on
+        panel.accessoryView = button
+        panel.canChooseFiles = false
+        panel.canChooseDirectories = true
+        panel.canCreateDirectories = true
+        panel.beginSheetModal(for: NSWindow.currentWindow()) { [self] response in
+            if response == .cancel {
+                return
+            }
+            let outputFolderPath = panel.url?.path
+            
+            self.removeFile(outputFolderPath: outputFolderPath!, data: data as! KMBatchRemoveViewModel, filesData: self.filesData)
+        }
+    }
+    
+    func removeFile(outputFolderPath: String, data: KMBatchRemoveViewModel, filesData: [KMBatchProcessingTableViewModel]) {
+        if filesData.count != 0 {
+            for i in 0..<filesData.count {
+                let item = filesData[i]
+//                DispatchQueue.global().async {
+                    var fileName = item.filePath.deletingPathExtension.lastPathComponent
+                    if ((fileName.isEmpty)) {
+                        fileName = NSLocalizedString("Untitled", comment: "")
+                    }
+                    
+                    let path = outputFolderPath + "/" + fileName + ".pdf"
+                    let document = CPDFDocument.init(url: URL(fileURLWithPath: item.filePath))
+                    if document != nil {
+                        if (document!.allowsPrinting == false || document!.allowsCopying == false) {
+                            let alert = NSAlert()
+                            alert.alertStyle = .critical
+                            alert.messageText = "此文档不允许修改"
+                            alert.runModal()
+                            return
+                        }
+                        
+                        if (data.options.contains(.security)) {
+                            
+                        }
+                        
+                        if (data.options.contains(.batesNumber)) {
+                            let property = document!.bates()
+                            property?.clear()
+                        }
+                        if (data.options.contains(.headerAndFooter)) {
+                            let property = document!.headerFooter()
+                            property?.clear()
+                        }
+                        if (data.options.contains(.background)) {
+                            let property = document!.background()
+                            property?.clear()
+                        }
+                        if (data.options.contains(.watermark)) {
+                            let array: Array<CPDFWatermark> = document!.watermarks() ?? []
+                            for model in array {
+                                document!.removeWatermark(model)
+                            }
+                        }
+                        
+                        if (FileManager.default.fileExists(atPath: path)) {
+                            try?FileManager.default.removeItem(atPath: path)
+                        }
+                        
+                        let result = document!.write(to: URL(fileURLWithPath: path))
+                        if (result) {
+                            KMPrint("removeFile成功")
+                            self.itemSuccess(item: item)
+                        } else {
+                            KMPrint("removeFile失败")
+                            self.itemFailure(item: item, error: nil)
+                        }
+                        if i == self.filesData.count - 1 {
+                            self.batchSuccess()
+                        }
+                        NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: outputFolderPath)])
+                    }
+//                }
+            }
+        }
+    }
+}
+
+//MARK: private
+extension KMBatchManager {
+    func fetchDocument(filePath: String, model: KMBatchProcessingTableViewModel) -> CPDFDocument {
+        var document = CPDFDocument(url: URL(fileURLWithPath: filePath))
+        
+        
+        if model.pageRange == .all {
+            
+        } else {
+            let data = KMOCRModel()
+            data.pageRangeType = model.pageRange
+            data.pageRangeString = model.pageRangeString
+           
+            let pages:[Int] = KMOCRManager.manager.fetchPageIndex(document: document!, model: data)
+            
+            var tempDocument = CPDFDocument()
+            for i in 0..<pages.count {
+                let page = document?.page(at: UInt(i))
+                tempDocument?.insertPageObject(page, at: tempDocument?.pageCount ?? 0)
+            }
+            
+            let fileName = filePath.deletingPathExtension.lastPathComponent
+            let isSuccess = tempDocument?.write(toFile: self.fetchTempFilePath(fileName: fileName))
+            if isSuccess != nil {
+                document = tempDocument
+            }
+        }
+        
+        return document ?? CPDFDocument()
+    }
+    
+    func fetchTempFilePath(fileName: String) -> String {
+        let floderPath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier!).stringByAppendingPathComponent("BatchTemp")
+        let filePath = floderPath?.stringByAppendingPathComponent("\(fileName).pdf")
+
+        if let data = floderPath, !FileManager.default.fileExists(atPath: data) {
+            try?FileManager.default.createDirectory(atPath: data, withIntermediateDirectories: false)
+        }
+        if let data = filePath, !FileManager.default.fileExists(atPath: data) {
+            FileManager.default.createFile(atPath: data, contents: nil)
+        }
+        return filePath ?? ""
+    }
+    
+    func removeTempFilePath(filePath: String) {
+        let fileName = filePath.deletingPathExtension.lastPathComponent
+        let path = self.fetchTempFilePath(fileName: fileName)
+        
+        if (FileManager.default.fileExists(atPath: path)) {
+            try?FileManager.default.removeItem(atPath: path)
+        }
+    }
+}
+
+//MARK: Alert
+extension KMBatchManager {
+    func batchUnkown() {
+        self.state = .unknow
+        NotificationCenter.default.post(name: NSNotification.Name(kBacthProcessNotification), object: nil)
+    }
+    
+    func batchProgress() {
+        self.state = .processing
+        NotificationCenter.default.post(name: NSNotification.Name(kBacthProcessNotification), object: nil)
+    }
+    
+    func batchSuccess() {
+        self.state = .complete
+        NotificationCenter.default.post(name: NSNotification.Name(kBacthProcessNotification), object: nil)
+    }
+    
+    func batchFailure() {
+        self.state = .error
+        NotificationCenter.default.post(name: NSNotification.Name(kBacthProcessNotification), object: nil)
+    }
+    
+    func itemProgress(item: KMBatchProcessingTableViewModel, processValue: Float) {
+        if processValue > 0.7 {
+            item.state = .loading70
+        } else {
+            item.state = .loading
+        }
+        NotificationCenter.default.post(name: NSNotification.Name(kBacthFilesProcessNotification), object: item)
+    }
+    
+    func itemSuccess(item: KMBatchProcessingTableViewModel) {
+        self.removeTempFilePath(filePath: item.filePath)
+        item.state = .success
+        NotificationCenter.default.post(name: NSNotification.Name(kBacthFilesProcessNotification), object: item)
+    }
+    
+    func itemFailure(item: KMBatchProcessingTableViewModel, error: NSError?) {
+        self.removeTempFilePath(filePath: item.filePath)
+        item.state = .error
+        NotificationCenter.default.post(name: NSNotification.Name(kBacthFilesProcessNotification), object: item)
+        
+        guard let error = error else { return }
+        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()
+    }
+}
+

+ 12 - 0
PDF Office/PDF Master/KMClass/NewBatch/View/KMBatchProcessingView/KMBatchProcessingView.swift

@@ -44,6 +44,10 @@ class KMBatchProcessingView: BaseXibView {
         // Drawing code here.
     }
     
+    deinit {
+        NotificationCenter.default.removeObserver(self)
+    }
+    
     override func setup() {
         
         self.backgroundColor(ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-low"))
@@ -94,6 +98,8 @@ class KMBatchProcessingView: BaseXibView {
         
         self.tableView.delegate = self
         self.reloadData()
+        
+        NotificationCenter.default.addObserver(self, selector: #selector(bacthFilesProcessingNotification), name: NSNotification.Name(kBacthFilesProcessNotification), object: nil)
     }
     
     func reloadData() {
@@ -309,3 +315,9 @@ extension KMBatchProcessingView: ComponentGroupDelegate {
         self.addFilesMoreButton.reloadData()
     }
 }
+
+extension KMBatchProcessingView {
+    @objc func bacthFilesProcessingNotification() {
+        self.reloadData()
+    }
+}

+ 2 - 1
PDF Office/PDF Master/KMClass/NewBatch/View/KMBatchProcessingView/Tableview/KMBatchProcessingTableViewModel/KMBatchProcessingTableViewModel.swift

@@ -31,6 +31,7 @@ enum KMBatchProcessingTableFileState: String, CaseIterable {
     case success = "icon_tip_success_small" //成功
     case clock = "icon_tip_clock_small" // 等待
     case loading = "icon_tip_loading_small" // 正在进行中
+    case loading70 = "progress-circle-mini" // 正在进行中
     
     static func allValues() -> [String] {
         var array: [String] = []
@@ -52,6 +53,7 @@ class KMBatchProcessingTableViewModel: NSObject {
     private(set) var size: CGSize = NSZeroSize
     private(set) var image: NSImage = NSImage()
     var state: KMBatchProcessingTableFileState = .clock
+    var progressValue: Float = 0
     
     static func initWithFilePath(url:URL) -> KMBatchProcessingTableViewModel {
         let model = KMBatchProcessingTableViewModel.init()
@@ -76,7 +78,6 @@ class KMBatchProcessingTableViewModel: NSObject {
         return model
     }
     
-    
     // MARK: 
     func moniker (x:Float) -> String {
         return x >= 1024.0 ?(x < 1048576.0 ? "M":"G"):"K"

+ 17 - 1
PDF Office/PDF Master/KMClass/NewBatch/View/KMBatchProcessingView/Tableview/Views/Tableview/Views/KMBatchProcessingStateTableCell.swift

@@ -47,11 +47,27 @@ class KMBatchProcessingStateTableCell: KMBatchProcessingTableCell {
     
     override func setup() {
         super.setup()
-        
     }
     
     override func reloadData() {
         super.reloadData()
         self.iconImageView.image = NSImage(named: self.model.state.rawValue)
+        
+        var toolTipString = "Waiting"
+        switch self.model.state {
+        case .clock:
+            toolTipString = "Waiting"
+        case .loading70:
+            toolTipString = "70%"
+        case .error:
+            toolTipString = "Error info"
+        case .loading:
+            toolTipString = "Progressing"
+        case .success:
+            toolTipString = "100%"
+        default:
+            break
+        }
+        self.iconImageView.toolTip = toolTipString
     }
 }

+ 9 - 0
PDF Office/PDF Master/KMClass/NewBatch/View/Setting/BatchRemove/KMBatchRemoveView.swift

@@ -77,6 +77,15 @@ class KMBatchRemoveView: KMBatchSettingItemView {
             self.removeButton.properties.isDisabled = true
         }
     }
+    
+    override func bacthProcessingNotification() {
+        if KMBatchManager.manager.state == .processing {
+            self.removeButton.properties.isDisabled = true
+        } else {
+            self.removeButton.properties.isDisabled = false
+        }
+        self.removeButton.reloadData()
+    }
 }
 
 extension KMBatchRemoveView {

+ 9 - 0
PDF Office/PDF Master/KMClass/NewBatch/View/Setting/Compress/KMBatchCompressView.swift

@@ -41,6 +41,15 @@ class KMBatchCompressView: KMBatchSettingItemView {
     override func reloadData() {
         
     }
+    
+    override func bacthProcessingNotification() {
+        if KMBatchManager.manager.state == .processing {
+            self.applyButton.properties.isDisabled = true
+        } else {
+            self.applyButton.properties.isDisabled = false
+        }
+        self.applyButton.reloadData()
+    }
 }
 
 protocol KMBatchCompressViewAction {}

+ 9 - 0
PDF Office/PDF Master/KMClass/NewBatch/View/Setting/ConvertPDF/KMBatchConvertPDFView.swift

@@ -166,6 +166,15 @@ class KMBatchConvertPDFView: KMBatchSettingItemView {
         view.settingView?.isBatch = true
         return view
     }
+    
+    override func bacthProcessingNotification() {
+        if KMBatchManager.manager.state == .processing {
+            self.convertButton.properties.isDisabled = true
+        } else {
+            self.convertButton.properties.isDisabled = false
+        }
+        self.convertButton.reloadData()
+    }
 }
 
 protocol KMBatchConvertPDFViewAction {}

+ 13 - 0
PDF Office/PDF Master/KMClass/NewBatch/View/Setting/KMBatchBatchSettingItemView/KMBatchSettingItemView.swift

@@ -20,6 +20,10 @@ class KMBatchSettingItemView: BaseXibView {
     }
     
     var batchExport: KMBatchSettingItemViewExport?
+    
+    deinit {
+        NotificationCenter.default.removeObserver(self)
+    }
     override func draw(_ dirtyRect: NSRect) {
         super.draw(dirtyRect)
 
@@ -29,4 +33,13 @@ class KMBatchSettingItemView: BaseXibView {
     func reloadData() {
         
     }
+    
+    override func setup() {
+        NotificationCenter.default.addObserver(self, selector: #selector(bacthProcessingNotification), name: NSNotification.Name(kBacthProcessNotification), object: nil)
+    }
+    
+    func bacthProcessingNotification() {
+        
+    }
+    
 }

+ 9 - 487
PDF Office/PDF Master/KMClass/NewBatch/View/Setting/KMBatchSettingView.swift

@@ -75,55 +75,55 @@ class KMBatchSettingView: BaseXibView {
             case .convertPDF:
                 resultView = KMBatchConvertPDFView.init()
                 resultView.batchExport = { [unowned self] (view, data) in
-                    self.convertPDFExport(data: data)
+                    KMBatchManager.manager.batch(type: type, data: data)
                 }
                 break
             case .OCR:
                 resultView = KMBatchOCRView.init()
                 resultView.batchExport = { [unowned self] (view, data) in
-                    self.ocrExport(data: data)
+                    KMBatchManager.manager.batch(type: type, data: data)
                 }
                 break
             case .compress:
                 resultView = KMBatchCompressView.init()
                 resultView.batchExport = { [unowned self] (view, data) in
-                    self.compressExport(data: data)
+                    KMBatchManager.manager.batch(type: type, data: data)
                 }
                 break
             case .security:
                 resultView = KMBatchSecurityView.init()
                 resultView.batchExport = { [unowned self] (view, data) in
-                    self.securityExport(data: data)
+                    KMBatchManager.manager.batch(type: type, data: data)
                 }
                 break
             case .watermark:
                 resultView = KMBatchWatermarkView.init()
                 resultView.batchExport = { [unowned self] (view, data) in
-                    self.waterMarkApplay(data: data)
+                    KMBatchManager.manager.batch(type: type, data: data)
                 }
                 break
             case .background:
                 resultView = KMBatchBackgroundView.init()
                 resultView.batchExport = { [unowned self] (view, data) in
-                    self.backgroundApplay(data: data)
+                    KMBatchManager.manager.batch(type: type, data: data)
                 }
                 break
             case .headerAndFooter:
                 resultView = KMBatchHeaderAndFooterView.init()
                 resultView.batchExport = { [unowned self] (view, data) in
-                    self.headAndFooterApplay(data: data)
+                    KMBatchManager.manager.batch(type: type, data: data)
                 }
                 break
             case .batesNumber:
                 resultView = KMBatchBatesNumberView.init()
                 resultView.batchExport = { [unowned self] (view, data) in
-                    self.batesApplay(data: data)
+                    KMBatchManager.manager.batch(type: type, data: data)
                 }
                 break
             case .batchRemove:
                 resultView = KMBatchRemoveView.init()
                 resultView.batchExport = { [unowned self] (view, data) in
-                    self.removeApplay(data: data)
+                    KMBatchManager.manager.batch(type: type, data: data)
                 }
                 break
             default:
@@ -145,481 +145,3 @@ class KMBatchSettingView: BaseXibView {
 
 }
 
-protocol KMBatchSettingViewExport {}
-extension KMBatchSettingView: KMBatchSettingViewExport {
-    //MARK: 转档
-    func convertPDFExport(data: KMBatchSettingItemViewModel) {
-        let panel = NSOpenPanel()
-        panel.canChooseFiles = false
-        panel.canChooseDirectories = true
-        panel.canCreateDirectories = true
-        panel.beginSheetModal(for: self.window!) { response in
-            if response == .cancel {
-                return
-            }
-            let outputFolderPath = panel.url?.path
-            
-            self.convertFile(outputFolderPath: outputFolderPath!, data: data, filesData: self.filesData)
-        }
-    }
-    
-    func convertFile(outputFolderPath: String, data: KMBatchSettingItemViewModel, filesData: [KMBatchProcessingTableViewModel]?) {
-        if filesData?.count != 0 {
-            DispatchQueue.global().async {
-                for item in filesData! {
-                    //创建Document
-                    let filePath = item.filePath
-                    let document = CPDFDocument(url: URL(fileURLWithPath: filePath))
-                    
-                    let settingData = data as? KMBatchConvertPDFViewModel  ?? KMBatchConvertPDFViewModel()
-                    var fileName = filePath.deletingPathExtension.lastPathComponent
-                    if ((fileName.isEmpty)) {
-                        fileName = NSLocalizedString("Untitled", comment: "")
-                    }
-                    
-                    let convert = self.addConvertParameter(settingData)
-                    
-                    //获取page
-                    var pages:[Int] = []
-                    for i in 0..<document!.pageCount {
-                        pages.append(Int(i)+1)
-                    }
-                    
-                    convert.outputFolderPath = outputFolderPath
-                    convert.filePath = filePath
-                    convert.outputFileName = fileName
-                    convert.pages = pages
-                    
-                    convert.isAllowOCR = settingData.needRecognizeText
-                    convert.ocrLanguage = settingData.languageType
-                    
-                    KMPDFConvertManager.defaultManager.convert(convert: convert) { [unowned self] finished, error in
-                        if finished {
-                            if FileManager.default.fileExists(atPath: outputFolderPath) {
-                                NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: outputFolderPath)])
-                            }
-                        } 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()
-                        }
-                    }
-                }
-            }
-        }
-    }
-    
-    func addConvertParameter(_ data: KMBatchConvertPDFViewModel) -> KMPDFConvert {
-        let settingData = data
-        var convert = KMPDFConvert()
-        
-        switch settingData.convertPDFType {
-        case .word:
-            convert = KMPDFConvertWord()
-            if settingData.layoutSettingType == .flowingText {
-                convert.isAllInOneSheet = false
-            } else {
-                convert.isAllInOneSheet = true
-            }
-        case .excel:
-            convert = KMPDFConvertExcel()
-            if settingData.excelSetting == .separate {
-                convert.isAllInOneSheet = false
-                convert.isExtractTable = false
-            } else if settingData.excelSetting == .format {
-                convert.isAllInOneSheet = true
-                convert.isExtractTable = false
-            } else if settingData.excelSetting == .tables {
-                convert.isAllInOneSheet = false
-                convert.isExtractTable = true
-                
-                switch settingData.excelTablesType {
-                case .oneTable:
-                    convert.extractTableIndex = 0
-                case .pageTable:
-                    convert.extractTableIndex = 1
-                case .allTable:
-                    convert.extractTableIndex = 2
-                default:
-                    KMPrint("未找到")
-                }
-            }
-        case .ppt:
-            convert = KMPDFConvertPPT()
-        case .csv:
-            convert = KMPDFConvertCSV()
-            if settingData.csvOnlyTables {
-                convert.isExtractTable = true
-                switch settingData.excelTablesType {
-                case .oneTable:
-                    convert.extractTableIndex = 0
-                case .pageTable:
-                    convert.extractTableIndex = 1
-                case .allTable:
-                    convert.extractTableIndex = 2
-                default:
-                    KMPrint("未找到")
-                }
-            } else {
-                convert.isExtractTable = false
-            }
-        case .image:
-            convert = KMPDFConvertImage()
-            convert.convertType = data.imageType
-            
-            var dpi: Int = 150
-            if data.imageDpiIndex == 0 {
-                dpi = 50
-            } else if data.imageDpiIndex == 1 {
-                dpi = 72
-            } else if data.imageDpiIndex == 2 {
-                dpi = 96
-            } else if data.imageDpiIndex == 3 {
-                dpi = 150
-            } else if data.imageDpiIndex == 4 {
-                dpi = 300
-            } else if data.imageDpiIndex == 5 {
-                dpi = 600
-            } else {
-                dpi = 150
-            }
-            
-            if (convert.convertType == .jpeg) {
-                (convert as! KMPDFConvertImage).imageType = .JPEG
-                (convert as! KMPDFConvertImage).imageDpi = dpi
-                
-            } else if (convert.convertType == .png) {
-                (convert as! KMPDFConvertImage).imageType = .PNG
-                (convert as! KMPDFConvertImage).imageDpi = dpi
-            } else {
-                (convert as! KMPDFConvertImage).imageDpi = 150
-            }
-        case .html:
-            convert = KMPDFConvertHTML()
-        case .rtf:
-            convert = KMPDFConvertRTF()
-        case .json:
-            convert = KMPDFConvertJson()
-            if settingData.jsonType == .extractText {
-                convert.isAllInOneSheet = false
-            } else {
-                convert.isAllInOneSheet = true
-            }
-        case .text:
-            convert = KMPDFConvertText()
-            
-        default:
-            KMPrint("不清楚")
-        }
-        return convert
-    }
-    
-    //MARK: OCR
-    func ocrExport(data: KMBatchSettingItemViewModel) {
-        let panel = NSOpenPanel()
-        panel.canChooseFiles = false
-        panel.canChooseDirectories = true
-        panel.canCreateDirectories = true
-        panel.beginSheetModal(for: self.window!) { response in
-            if response == .cancel {
-                return
-            }
-            let outputFolderPath = panel.url?.path
-            
-            self.convertOCR(outputFolderPath: outputFolderPath!, data: data as! KMOCRModel, filesData: self.filesData)
-        }
-    }
-    
-    func convertOCR(outputFolderPath: String, data: KMOCRModel, filesData: [KMBatchProcessingTableViewModel]?) {
-        guard let filesData = self.filesData else { return }
-        if filesData.count != 0 {
-            for item in filesData {
-                let document = CPDFDocument.init(url: URL(fileURLWithPath: item.filePath))
-                if document != nil {
-                    //计算需要处理的页面
-                    data.pageRangeType = item.pageRange
-                    data.pageRangeString = item.pageRangeString
-                   
-                    var fileName = item.filePath.deletingPathExtension.lastPathComponent
-                    if ((fileName.isEmpty)) {
-                        fileName = NSLocalizedString("Untitled", comment: "")
-                    }
-                    let path = outputFolderPath + "/" + fileName + ".pdf"
-                    
-                    KMOCRManager.manager.convertBatchOCR(document: document!, saveFilePath: path, model: data, progress: { progress in
-                        
-                    }) { document, text, error in
-                        
-                    }
-                }
-            }
-        }
-    }
-    
-    func convertOCR(document: CPDFDocument, model: KMOCRModel) {
-//        self.view.window?.windowController.beginLoading()
-        
-        //当前页面需要提前设置
-//        if model.pageRangeType == .current {
-//            model.pageRange = [self.listView.currentPageIndex]
-//        }
-        
-//        self.showProgressWindow(message: "正在转换中....")
-        KMOCRManager.manager.convertOCR(document: document, model: model, progress: { [weak self] progress in
-//            self?.progressC?.message = "正在转换中...."
-//            self?.progressC?.doubleValue = Double(progress * 100)
-        }) { [weak self] document, text, error  in
-//            self?.view.window?.windowController.endLoading()
-//            window.km_quick_endSheet()
-//            self?.hiddenProgressWindow()
-        }
-    }
-    
-    //MARK: 压缩
-    func compressExport(data: KMBatchSettingItemViewModel) {
-        self.compressFile(outputFolderPath: "", data: (data as? KMCompressSettingModel)!, filesData: self.filesData!)
-    }
-    
-    func compressFile(outputFolderPath: String, data: KMCompressSettingModel, filesData: [KMBatchProcessingTableViewModel]?) {
-        if filesData?.count != 0 {
-            for item in filesData! {
-                KMCompressManager.shared.compress(documentURL: URL(fileURLWithPath: item.filePath),
-                                                  limit: false,
-                                                  model: data,
-                                                  view: self) { [unowned self] isFinish, resultURL in
-                    if isFinish {
-                        print("压缩完成")
-                    }
-                }
-                
-            }
-            
-            NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: outputFolderPath)])
-        }
-    }
-    
-    //MARK: 安全
-    func securityExport(data: KMBatchSettingItemViewModel) {
-        let panel = NSOpenPanel()
-        let button = NSButton.init(checkboxWithTitle: "保存后打开文档", target: nil, action: nil)
-        button.state = .on
-        panel.accessoryView = button
-        panel.canChooseFiles = false
-        panel.canChooseDirectories = true
-        panel.canCreateDirectories = true
-        panel.beginSheetModal(for: self.window!) { [self] response in
-            if response == .cancel {
-                return
-            }
-            let outputFolderPath = panel.url?.path
-            
-            self.securityFile(outputFolderPath: outputFolderPath!, data: data as! KMBatchSecurityViewModel, filesData: self.filesData!)
-        }
-    }
-    
-    func securityFile(outputFolderPath: String, data: KMBatchSecurityViewModel, filesData: [KMBatchProcessingTableViewModel]?) {
-        if filesData?.count != 0 {
-            for item in filesData! {
-                let docuemt = CPDFDocument.init(url: URL(fileURLWithPath: item.filePath))
-                if (docuemt != nil) {
-                    var fileName = item.filePath.deletingPathExtension.lastPathComponent
-                    if ((fileName.isEmpty)) {
-                        fileName = NSLocalizedString("Untitled", comment: "")
-                    }
-                    let path = outputFolderPath + "/" + fileName + ".pdf"
-                    
-                    var options: [CPDFDocumentWriteOption : Any] = [:]
-                    //开启密码
-                    if data.isOpenPassword &&
-                        !data.openPasswordString.isEmpty {
-                        options.updateValue(data.openPasswordString, forKey: .userPasswordOption)
-                    }
-//
-                    //权限密码
-                    if data.isPermission &&
-                        !data.permissionString.isEmpty {
-                        options.updateValue(data.permissionString, forKey: .ownerPasswordOption)
-                    }
-                        
-                    // 限制打印
-                    if data.restrictOptions.contains(.print) {
-                        options.updateValue(false, forKey: .allowsPrintingOption)
-                    } else {
-                        options.updateValue(true, forKey: .allowsPrintingOption)
-                    }
-                    
-                    //限制复制
-                    if data.restrictOptions.contains(.copy) {
-                        options.updateValue(false, forKey: .allowsCopyingOption)
-                    } else {
-                        options.updateValue(true, forKey: .allowsCopyingOption)
-                    }
-                    
-                    
-                    let result = docuemt!.write(toFile: path, withOptions: options)
-//                    let result = docuemt!.write(to: URL(fileURLWithPath: path), withOptions: options)
-                    if result {
-                        KMPrint("成功")
-                    } else {
-                        KMPrint("失败")
-                    }
-                    NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: outputFolderPath)])
-                }
-            }
-        }
-    }
-    
-    
-    func waterMarkApplay(data: KMBatchSettingItemViewModel) {
-
-    }
-    
-//    func waterMarkFile(data: KMWatermarkAdjectiveBaseModel, filesData: [KMBatchProcessingTableViewModel]?) {
-//        
-//    }
-    
-    func backgroundApplay(data: KMBatchSettingItemViewModel) {
-        
-    }
-    
-    func backgroundFile(outputFolderPath: String, data: KMBackgroundModel, filesData: [KMBatchProcessingTableViewModel]?) {
-        
-    }
-    
-    
-    func headAndFooterApplay(data: KMBatchSettingItemViewModel) {
-        
-    }
-    
-//    func headAndFooterFile(outputFolderPath: String, data: KMHeaderFooterModel, filesData: [KMBatchProcessingTableViewModel]?) {
-//        
-//    }
-    
-    func batesApplay(data: KMBatchSettingItemViewModel) {
-        
-    }
-    
-    func batesFile(outputFolderPath: String, data: KMBatesModel, filesData: [KMBatchProcessingTableViewModel]?) {
-        
-    }
-    
-    
-    func removeApplay(data: KMBatchSettingItemViewModel) {
-        if (data == nil) {
-            let alert = NSAlert()
-            alert.alertStyle = .critical
-            alert.messageText = "没有找到"
-            alert.runModal()
-            return
-        }
-        
-        let panel = NSOpenPanel()
-        let button = NSButton.init(checkboxWithTitle: "保存后打开文档", target: nil, action: nil)
-        button.state = .on
-        panel.accessoryView = button
-        panel.canChooseFiles = false
-        panel.canChooseDirectories = true
-        panel.canCreateDirectories = true
-        panel.beginSheetModal(for: self.window!) { [self] response in
-            if response == .cancel {
-                return
-            }
-            let outputFolderPath = panel.url?.path
-            
-            self.removeFile(outputFolderPath: outputFolderPath!, data: data as! KMBatchRemoveViewModel, filesData: self.filesData!)
-        }
-    }
-    
-    func removeFile(outputFolderPath: String, data: KMBatchRemoveViewModel, filesData: [KMBatchProcessingTableViewModel]?) {
-        if filesData?.count != 0 {
-            for item in filesData! {
-//                DispatchQueue.global().async {
-                    var fileName = item.filePath.deletingPathExtension.lastPathComponent
-                    if ((fileName.isEmpty)) {
-                        fileName = NSLocalizedString("Untitled", comment: "")
-                    }
-                    
-                    let path = outputFolderPath + "/" + fileName + ".pdf"
-                    let document = CPDFDocument.init(url: URL(fileURLWithPath: item.filePath))
-                    if document != nil {
-                        if (document!.allowsPrinting == false || document!.allowsCopying == false) {
-                            let alert = NSAlert()
-                            alert.alertStyle = .critical
-                            alert.messageText = "此文档不允许修改"
-                            alert.runModal()
-                            return
-                        }
-                        
-                        if (data.options.contains(.security)) {
-                            
-                        }
-                        
-                        if (data.options.contains(.batesNumber)) {
-                            let property = document!.bates()
-                            property?.clear()
-                        }
-                        if (data.options.contains(.headerAndFooter)) {
-                            let property = document!.headerFooter()
-                            property?.clear()
-                        }
-                        if (data.options.contains(.background)) {
-                            let property = document!.background()
-                            property?.clear()
-                        }
-                        if (data.options.contains(.watermark)) {
-                            let array: Array<CPDFWatermark> = document!.watermarks() ?? []
-                            for model in array {
-                                document!.removeWatermark(model)
-                            }
-                        }
-                        
-                        if (FileManager.default.fileExists(atPath: path)) {
-                            try?FileManager.default.removeItem(atPath: path)
-                        }
-                        
-                        let result = document!.write(to: URL(fileURLWithPath: path))
-                        if (result) {
-                            KMPrint("removeFile成功")
-                        } else {
-                            KMPrint("removeFile失败")
-                        }
-                        NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: outputFolderPath)])
-                    }
-//                }
-            }
-        }
-    }
-}
-
-extension KMBatchSettingView {
-    func fetchPageRange(document: CPDFDocument, fileModel: KMBatchProcessingTableViewModel) -> [Int] {
-        return []
-    }
-}

+ 9 - 0
PDF Office/PDF Master/KMClass/NewBatch/View/Setting/OCR/KMBatchOCRView.swift

@@ -83,6 +83,15 @@ class KMBatchOCRView: KMBatchSettingItemView {
         applyButton.properties.state = .normal
         applyButton.reloadData()
     }
+    
+    override func bacthProcessingNotification() {
+        if KMBatchManager.manager.state == .processing {
+            self.applyButton.properties.isDisabled = true
+        } else {
+            self.applyButton.properties.isDisabled = false
+        }
+        self.applyButton.reloadData()
+    }
 }
 
 //MARK: Action

+ 9 - 0
PDF Office/PDF Master/KMClass/NewBatch/View/Setting/Security/KMBatchSecurityView.swift

@@ -49,6 +49,15 @@ class KMBatchSecurityView: KMBatchSettingItemView {
             self.encryptButton.properties.isDisabled = true
         }
     }
+    
+    override func bacthProcessingNotification() {
+        if KMBatchManager.manager.state == .processing {
+            self.encryptButton.properties.isDisabled = true
+        } else {
+            self.encryptButton.properties.isDisabled = false
+        }
+        self.encryptButton.reloadData()
+    }
 }
 
 protocol KMBatchSecurityViewAction { }

+ 3 - 3
PDF Office/PDF Reader Pro.xcodeproj/project.pbxproj

@@ -8420,7 +8420,7 @@
 			children = (
 				AD8B58D92D2B777600150EA6 /* KMBatchWindowController.swift */,
 				AD8B58DA2D2B777600150EA6 /* KMBatchWindowController.xib */,
-				AD8B58DB2D2B777700150EA6 /* KMBatchManager */,
+				AD8B58DB2D2B777700150EA6 /* Manager */,
 				AD8B58D72D2B777600150EA6 /* Source */,
 				AD8B58DD2D2B777700150EA6 /* View */,
 			);
@@ -8435,12 +8435,12 @@
 			path = Source;
 			sourceTree = "<group>";
 		};
-		AD8B58DB2D2B777700150EA6 /* KMBatchManager */ = {
+		AD8B58DB2D2B777700150EA6 /* Manager */ = {
 			isa = PBXGroup;
 			children = (
 				AD8B58DC2D2B777700150EA6 /* KMBatchManager.swift */,
 			);
-			path = KMBatchManager;
+			path = Manager;
 			sourceTree = "<group>";
 		};
 		AD8B58DD2D2B777700150EA6 /* View */ = {