Pārlūkot izejas kodu

优化 - 转档回执及性能优化

zhudongyong 2 gadi atpakaļ
vecāks
revīzija
cce41e0bf0

+ 136 - 126
KdanAutoTest/KdanAuto/Class/AutoTestCase/AutoTest.swift

@@ -55,7 +55,7 @@ class AutoTest : NSObject, AutoTestProtocal {
                 object?._extention = String(cExtention)
                 object?._name = String(cName)
                 if nil != cParams {
-                    object?._params = cParams!;
+                    object?._params = cParams ?? [:];
                 }
                 cacheObjects.setValue(object, forKey: key)
                 
@@ -165,76 +165,102 @@ class AutoTest : NSObject, AutoTestProtocal {
             var tCount = Int(0)
             
             for fileName in files {
-                let fName = NSString(string: fileName).deletingPathExtension
-                let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
-                let resultPath = NSString(string: resultDirectory).appendingPathComponent(fName+"."+_extention)
-                let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention)
-                
-                
-                reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】开始转换文件 \"\(fName)\"\n",
-                                                                    attributes:[.foregroundColor : NSColor.blue]))
-                // ...
-                // 执行转换过程
-                var success = process(originPath, resultPath: resultPath)
-                
-                
-                var isDirectory = ObjCBool(false)
-                if FileManager.default.fileExists(atPath: resultPath, isDirectory:&isDirectory) && success {
-                    // compare screenshoot between result file with check file
-                    if needCompare {
-                        let items = NSMutableArray()
-                        if (isDirectory.boolValue) {
-                            let searchItems = try! FileManager.default.contentsOfDirectory(atPath: resultPath)
-                            for item in NSArray(array: searchItems) {
-                                let ext = NSString(string: item as! String).pathExtension.lowercased()
-                                if (NSArray(array: [_extention]).contains(ext)) {
-                                    let fileName = NSString(string: fName+"."+_extention+"/\(item as! String)").deletingPathExtension
-                                    items.add(fileName)
+                autoreleasepool {
+                    let fName = NSString(string: fileName).deletingPathExtension
+                    let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
+                    let resultPath = NSString(string: resultDirectory).appendingPathComponent(fName+"."+_extention)
+                    //                let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention)
+                    
+                    
+                    reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】开始转换文件 \"\(fName)\"\n",
+                                                                        attributes:[.foregroundColor : NSColor.blue]))
+                    // ...
+                    // 执行转换过程
+                    let status = process(originPath, resultPath: resultPath)
+                    
+                    
+                    var isDirectory = ObjCBool(false)
+                    if FileManager.default.fileExists(atPath: resultPath, isDirectory:&isDirectory) && status == 1 {
+                        // compare screenshoot between result file with check file
+                        if needCompare {
+                            let items = NSMutableArray()
+                            if (isDirectory.boolValue) {
+                                let searchItems = try! FileManager.default.contentsOfDirectory(atPath: resultPath)
+                                for item in NSArray(array: searchItems) {
+                                    let ext = NSString(string: item as! String).pathExtension.lowercased()
+                                    if (NSArray(array: [_extention]).contains(ext)) {
+                                        let fileName = NSString(string: fName+"."+_extention+"/\(item as! String)").deletingPathExtension
+                                        items.add(fileName)
+                                    }
                                 }
+                            }else {
+                                items.add(fName)
                             }
-                        }else {
-                            items.add(fName)
-                        }
-                        
-                        var subDegree = Double(0);
-                        var subCount = Int(0)
-                        
-                        for item in items {
-                            autoreleasepool {
-                                let subFileName = item as! String
-                                let subResultPath = NSString(string: resultDirectory).appendingPathComponent(subFileName+"."+_extention)
-                                
-                                reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subFileName+".\(_extention)")\"快照生成中\n",
-                                                                                    attributes:[.foregroundColor : NSColor.black]))
-                                let rComparePath = NSString(string: resultDirectory).appendingPathComponent(subFileName+".jpg")
-                                let cComparePath = NSString(string: checkDirectory).appendingPathComponent(subFileName+".jpg")
-                                
-                                
-                                let processThumbSemaphore = DispatchSemaphore(value: 0)
-                                var processSuccess = false
-                                let thumbnailQueue = DispatchQueue.global()
-                                thumbnailQueue.async {
-                                    processSuccess = ProcessThumbnal.process(subResultPath, desPath: rComparePath, outputSize: CGSize.init(width: 2048, height: 2048))
+                            
+                            var subDegree = Double(0);
+                            var subCount = Int(0)
+                            
+                            for item in items {
+                                autoreleasepool {
+                                    let subFileName = item as! String
+                                    let subResultPath = NSString(string: resultDirectory).appendingPathComponent(subFileName+"."+_extention)
+                                    
+                                    reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subFileName+".\(_extention)")\"快照生成中\n",
+                                                                                        attributes:[.foregroundColor : NSColor.black]))
+                                    let rComparePath = NSString(string: resultDirectory).appendingPathComponent(subFileName+".jpg")
+                                    let cComparePath = NSString(string: checkDirectory).appendingPathComponent(subFileName+".jpg")
                                     
-                                    if ( processSuccess &&
-                                         FileManager.default.fileExists(atPath: rComparePath)) {
+                                    
+                                    let processThumbSemaphore = DispatchSemaphore(value: 0)
+                                    var processSuccess = false
+                                    let thumbnailQueue = DispatchQueue.global()
+                                    thumbnailQueue.async {
+                                        processSuccess = ProcessThumbnal.process(subResultPath, desPath: rComparePath, outputSize: CGSize.init(width: 2048, height: 2048))
                                         
-                                        var isDirectory = ObjCBool(false)
-                                        if FileManager.default.fileExists(atPath: rComparePath, isDirectory: &isDirectory) && isDirectory.boolValue {
-                                            // 单个文件生成批量快照目录情形
-                                            let subImages = try! FileManager.default.contentsOfDirectory(atPath: rComparePath)
-                                            for subImageName in subImages {
-                                                let pathCompotent = "/"+subImageName
-                                                let degree = ImageProcess.compareJPEG(String(rComparePath+pathCompotent), checkPath: String(cComparePath+pathCompotent), processCover: true)
+                                        if ( processSuccess &&
+                                             FileManager.default.fileExists(atPath: rComparePath)) {
+                                            
+                                            var isDirectory = ObjCBool(false)
+                                            if FileManager.default.fileExists(atPath: rComparePath, isDirectory: &isDirectory) && isDirectory.boolValue {
+                                                // 单个文件生成批量快照目录情形
+                                                let subImages = try! FileManager.default.contentsOfDirectory(atPath: rComparePath)
+                                                for subImageName in subImages {
+                                                    let pathCompotent = "/"+subImageName
+                                                    let degree = ImageProcess.compareJPEG(String(rComparePath+pathCompotent), checkPath: String(cComparePath+pathCompotent), processCover: true)
+                                                    
+                                                    
+                                                    NSLog(String("文件夹,\(subFileName+".jpg"+pathCompotent)"))
+                                                    
+                                                    TestDegreeManager.shared().set(degree, fileType: self.fileType(), type: self.type(),
+                                                                                   fileName: fileName, refFilePath: subFileName+".jpg"+pathCompotent)
+                                                    
+                                                    if degree == -1 {
+                                                        self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath+pathCompotent)\"快照对比失败,生成快照失败或无比对文件\n",
+                                                                                                                 attributes:[.foregroundColor : NSColor.red]))
+                                                    }else {
+                                                        var color = NSColor.black
+                                                        if fabs(degree-100.0) >= 0.01 {
+                                                            color = NSColor.red
+                                                        }
+                                                        subDegree += degree
+                                                        subCount += 1
+                                                        
+                                                        self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath+pathCompotent)\"快照对比完成,图像相似度 \(degree)%\n",
+                                                                                                                 attributes:[.foregroundColor : color]))
+                                                    }
+                                                }
+                                            }else {
+                                                // 单个文件生成单个快照文件情形
                                                 
+                                                let degree = ImageProcess.compareJPEG(rComparePath, checkPath: cComparePath, processCover: true)
                                                 
-                                                NSLog(String("文件夹,\(subFileName+".jpg"+pathCompotent)"))
+                                                NSLog(String("文件夹,\(subFileName+".jpg")"))
                                                 
                                                 TestDegreeManager.shared().set(degree, fileType: self.fileType(), type: self.type(),
-                                                                               fileName: fileName, refFilePath: subFileName+".jpg"+pathCompotent)
+                                                                               fileName: fileName, refFilePath: subFileName+".jpg")
                                                 
                                                 if degree == -1 {
-                                                    self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath+pathCompotent)\"快照对比失败,生成快照失败或无比对文件\n",
+                                                    self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照对比失败,生成快照失败或无比对文件\n",
                                                                                                              attributes:[.foregroundColor : NSColor.red]))
                                                 }else {
                                                     var color = NSColor.black
@@ -244,62 +270,46 @@ class AutoTest : NSObject, AutoTestProtocal {
                                                     subDegree += degree
                                                     subCount += 1
                                                     
-                                                    self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath+pathCompotent)\"快照对比完成,图像相似度 \(degree)%\n",
+                                                    self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照对比完成,图像相似度 \(degree)%\n",
                                                                                                              attributes:[.foregroundColor : color]))
                                                 }
                                             }
                                         }else {
-                                            // 单个文件生成单个快照文件情形
-                                            
-                                            let degree = ImageProcess.compareJPEG(rComparePath, checkPath: cComparePath, processCover: true)
-                                            
-                                            NSLog(String("非文件夹,\(subFileName+".jpg")"))
-                                            
-                                            TestDegreeManager.shared().set(degree, fileType: self.fileType(), type: self.type(),
-                                                                           fileName: fileName, refFilePath: subFileName+".jpg")
-                                            
-                                            if degree == -1 {
-                                                self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照对比失败,生成快照失败或无比对文件\n",
-                                                                                                         attributes:[.foregroundColor : NSColor.red]))
-                                            }else {
-                                                var color = NSColor.black
-                                                if fabs(degree-100.0) >= 0.01 {
-                                                    color = NSColor.red
-                                                }
-                                                subDegree += degree
-                                                subCount += 1
-                                                
-                                                self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照对比完成,图像相似度 \(degree)%\n",
-                                                                                                         attributes:[.foregroundColor : color]))
-                                            }
+                                            self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照生成失败\n",
+                                                                                                     attributes:[.foregroundColor : NSColor.red]))
                                         }
-                                    }else {
-                                        self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照生成失败\n",
-                                                                                                 attributes:[.foregroundColor : NSColor.red]))
+                                        
+                                        processThumbSemaphore.signal()
                                     }
-                                    
-                                    processThumbSemaphore.signal()
+                                    processThumbSemaphore.wait()
                                 }
-                                processThumbSemaphore.wait()
                             }
+                            
+                            if subCount != 0 {
+                                subDegree = subDegree/Double(subCount)
+                            }else {
+                                subDegree = 0.0
+                            }
+                            
+                            TestDegreeManager.shared().set(subDegree,
+                                                           fileType: self.fileType(),
+                                                           type: self.type(),
+                                                           fileName: fileName)
+                            tDegree += subDegree;
+                            tCount += 1
                         }
-                        
-                        if subCount != 0 {
-                            subDegree = subDegree/Double(subCount)
-                        }else {
-                            subDegree = 0.0
+                    }else {
+                        if (status == 0) {
+                            reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档失败!\n",
+                                                                                attributes:[.foregroundColor : NSColor.red]))
+                        }else if (status == -1 || status == -2) {
+                            reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"文档无法打开!\n",
+                                                                                attributes:[.foregroundColor : NSColor.red]))
+                        }else if (status == -3) {
+                            reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档中 Crash!\n",
+                                                                                attributes:[.foregroundColor : NSColor.red]))
                         }
-                        
-                        TestDegreeManager.shared().set(subDegree,
-                                                       fileType: self.fileType(),
-                                                       type: self.type(),
-                                                       fileName: fileName)
-                        tDegree += subDegree;
-                        tCount += 1
                     }
-                }else {
-                    reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档失败!\n",
-                                                                        attributes:[.foregroundColor : NSColor.red]))
                 }
             }
             
@@ -313,19 +323,19 @@ class AutoTest : NSObject, AutoTestProtocal {
         }
     }
     
-    func process(_ originPath:String, resultPath:String) -> Bool {
-        process(originPath, resultPath: resultPath, params: self.params())
+    func process(_ originPath:String, resultPath:String) -> Int {
+        return process(originPath, resultPath: resultPath, params: self.params())
     }
     
-    func process(_ originPath:String, resultPath:String, params:NSDictionary) -> Bool {
+    func process(_ originPath:String, resultPath:String, params:NSDictionary) -> Int {
         // ...
         // 执行转换过程
         let convertSemaphore = DispatchSemaphore(value: 0)
-        var success = false
+        var status = Int(1)
         let convertQueue = DispatchQueue.global()
         convertQueue.async {
             autoreleasepool {
-                success = FileConverter.shared().converter(originPath, inDesPath: resultPath, params: params)
+                status = FileConverter.shared().converter(originPath, inDesPath: resultPath, params: params)
                 
                 // 修复转 PNG 实际图片为 JPG 问题, 导致无法匹配问题
                 if (NSArray(array: ["png", "PNG"]).contains(NSString(string: resultPath).pathExtension)) {
@@ -345,7 +355,7 @@ class AutoTest : NSObject, AutoTestProtocal {
         }
         convertSemaphore.wait()
         
-        return success
+        return status
     }
     
     func testReport() -> NSAttributedString? {
@@ -377,14 +387,14 @@ class AutoTest : NSObject, AutoTestProtocal {
     func canUpdateRefImage() -> Bool {
         let files = DataModel.shared.originFilesFor(_fileType, type: _type) as [String]
         let checkDirectory = self.checkFileDirectory()
-        let originDirectory = self.originFileDirectory()
+//        let originDirectory = self.originFileDirectory()
         let resultDirectory = self.resultFileDirectory()
         
         for fileName in files {
             let fName = NSString(string: fileName).deletingPathExtension
-            let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
+//            let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
             let resultPath = NSString(string: resultDirectory).appendingPathComponent(fName+"."+_extention)
-            let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention)
+//            let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention)
             
             
             var isDirectory = ObjCBool(false)
@@ -437,13 +447,13 @@ class AutoTest : NSObject, AutoTestProtocal {
     
     func canUpdateRefImage(_ fileName:String) -> Bool {
         let checkDirectory = self.checkFileDirectory()
-        let originDirectory = self.originFileDirectory()
+//        let originDirectory = self.originFileDirectory()
         let resultDirectory = self.resultFileDirectory()
         
         let fName = NSString(string: fileName).deletingPathExtension
-        let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
+//        let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
         let resultPath = NSString(string: resultDirectory).appendingPathComponent(fName+"."+_extention)
-        let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention)
+//        let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention)
         
         
         var isDirectory = ObjCBool(false)
@@ -487,13 +497,13 @@ class AutoTest : NSObject, AutoTestProtocal {
     
     func updateRefImage(_ fileName:String) {
         let checkDirectory = self.checkFileDirectory()
-        let originDirectory = self.originFileDirectory()
+//        let originDirectory = self.originFileDirectory()
         let resultDirectory = self.resultFileDirectory()
         
         let fName = NSString(string: fileName).deletingPathExtension
-        let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
+//        let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
         let resultPath = NSString(string: resultDirectory).appendingPathComponent(fName+"."+_extention)
-        let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention)
+//        let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention)
         
         
         var isDirectory = ObjCBool(false)
@@ -548,7 +558,7 @@ class AutoTest : NSObject, AutoTestProtocal {
         let files = NSMutableArray()
         
         let checkDirectory = self.checkFileDirectory()
-        let originDirectory = self.originFileDirectory()
+//        let originDirectory = self.originFileDirectory()
         let resultDirectory = self.resultFileDirectory()
         
         let fName = NSString(string: fileName).deletingPathExtension
@@ -623,7 +633,7 @@ class AutoTest : NSObject, AutoTestProtocal {
     
     // check File Exist
     func hasOriginFile() -> Bool {
-        if nil != self.originFileDirectory() && FileManager.default.fileExists(atPath: self.originFileDirectory()) {
+        if FileManager.default.fileExists(atPath: self.originFileDirectory()) {
             let files = try? FileManager.default.subpathsOfDirectory(atPath: self.originFileDirectory())
             return (files ?? []).count > 0
         }
@@ -632,7 +642,7 @@ class AutoTest : NSObject, AutoTestProtocal {
     }
     
     func hasResultFile() -> Bool {
-        if nil != self.resultFileDirectory() && FileManager.default.fileExists(atPath: self.resultFileDirectory()) {
+        if FileManager.default.fileExists(atPath: self.resultFileDirectory()) {
             let files = try? FileManager.default.subpathsOfDirectory(atPath: self.resultFileDirectory())
             return (files ?? []).count > 0
         }
@@ -664,7 +674,7 @@ extension AutoTest {
     func stringToImage(_ string:String) ->NSImage? {
         let length = Int(string.lengthOfBytes(using: .utf8)/2)
         
-        var bytes = malloc(length)!
+        let bytes = malloc(length)!
         
         for i in 0..<length {
             let index = i
@@ -672,7 +682,7 @@ extension AutoTest {
             bytes.storeBytes(of: UInt8(hexForString(subString)), as: UInt8.self)
         }
         
-        var data = Data.init(bytes: bytes, count: length)
+        let data = Data.init(bytes: bytes, count: length)
         let image = NSImage.init(data: data)
         
         return image

+ 2 - 2
KdanAutoTest/KdanAuto/Class/AutoTestCase/PDFCompareTest.swift

@@ -19,9 +19,9 @@ class PDFCompareTest : AutoTest {
         
     }
    
-    override func process(_ originPath:String, resultPath:String) -> Bool {
+    override func process(_ originPath:String, resultPath:String) -> Int {
         
-        return true
+        return 1
     }
     
     override func compareFiles(_ fileName: String) -> NSArray? {

+ 12 - 4
KdanAutoTest/KdanAuto/Class/AutoTestCase/StringAutoTest.swift

@@ -68,9 +68,9 @@ class CharacterAutoTest : AutoTest {
                                                                attributes:[.foregroundColor : NSColor.black]))
             // ...
             // 执行转换过程
-            var success = process(originPath, resultPath: resultPath)
+            var status = process(originPath, resultPath: resultPath)
             
-            if FileManager.default.fileExists(atPath: resultPath) && success {
+            if FileManager.default.fileExists(atPath: resultPath) && status == 1 {
                 if checkString && FileManager.default.fileExists(atPath: checkPath) {
                     // Load check file
                     let checkData = NSData.init(contentsOfFile: checkPath) as! Data
@@ -274,8 +274,16 @@ class CharacterAutoTest : AutoTest {
                     processThumbSemaphore.wait()
                 }
             }else {
-                reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档失败!\n",
-                                                              attributes:[.foregroundColor : NSColor.red]))
+                if (status == 0) {
+                    reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档失败!\n",
+                                                                        attributes:[.foregroundColor : NSColor.red]))
+                }else if (status == -1 || status == -2) {
+                    reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"文档无法打开!\n",
+                                                                        attributes:[.foregroundColor : NSColor.red]))
+                }else if (status == -3) {
+                    reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档中 Crash!\n",
+                                                                        attributes:[.foregroundColor : NSColor.red]))
+                }
             }
             
         }

+ 12 - 4
KdanAutoTest/KdanAuto/Class/AutoTestCase/TextColorAutoTest.swift

@@ -89,13 +89,13 @@ class TextColorAutoTest : AutoTest {
                                                           attributes:[.foregroundColor : NSColor.blue]))
             // ...
             // 执行转换过程
-            var success = process(originPath, resultPath: resultPath)
+            var status = process(originPath, resultPath: resultPath)
             
             
             var maxCount = 0;
             var succCount = 0;
             
-            if FileManager.default.fileExists(atPath: resultPath) && success {
+            if FileManager.default.fileExists(atPath: resultPath) && status == 1 {
                 // 转换成功
                 if (checkRGB) {
 #if true // 新文档框排形式
@@ -315,8 +315,16 @@ class TextColorAutoTest : AutoTest {
                     
                 }
             }else {
-                reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档失败!\n",
-                                                              attributes:[.foregroundColor : NSColor.red]))
+                if (status == 0) {
+                    reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档失败!\n",
+                                                                        attributes:[.foregroundColor : NSColor.red]))
+                }else if (status == -1 || status == -2) {
+                    reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"文档无法打开!\n",
+                                                                        attributes:[.foregroundColor : NSColor.red]))
+                }else if (status == -3) {
+                    reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档中 Crash!\n",
+                                                                        attributes:[.foregroundColor : NSColor.red]))
+                }
             }
         }
         

+ 5 - 1
KdanAutoTest/KdanAuto/Class/CompareViewController/ImageCompareCellView.swift

@@ -70,10 +70,14 @@ class ImageCompareCellView : NSTableCellView {
     public func setFileInfo(_ fileInfo:NSMutableDictionary) {
         _fileInfo = fileInfo;
         
+        _segmentedControl.selectedSegment = 0;
+        
         if nil != _fileInfo {
             autoreleasepool {
                 let comparePath = _fileInfo.comparePath()
                 let resultPath = _fileInfo.resultPath()
+                _imageView03.image = nil;
+                _imageView04.image = nil;
                 
                 DispatchQueue.global().async {
                     let image = NSImage.init(contentsOfFile: comparePath)
@@ -175,7 +179,7 @@ class ImageCompareCellView : NSTableCellView {
                         var image2 = nil as NSImage?
                         
                         autoreleasepool {
-                            let coverPath = NSString(format: "%@_cover.png", NSString(string: resultPath).deletingPathExtension) as! String
+                            let coverPath = NSString(format: "%@_cover.png", NSString(string: resultPath).deletingPathExtension) as String
                             
                             if FileManager.default.fileExists(atPath: coverPath) {
                                 image2 = NSImage.init(contentsOfFile: coverPath)

+ 3 - 2
KdanAutoTest/KdanAuto/Class/DataModel/DataModel.swift

@@ -75,7 +75,7 @@ class DataModel : NSObject {
         let subPaths = NSMutableArray(array: items ?? [])
         subPaths.remove(".DS_Store")
         
-        var index = 0 as! Int
+        var index = Int(0)
         while (index < subPaths.count) {
             let item = subPaths.object(at: index)
             index += 1
@@ -83,7 +83,8 @@ class DataModel : NSObject {
             let filePath = path.appendingPathComponent(item as! String);
             
             var isDirectory = ObjCBool(false)
-            if (!FileManager.default.fileExists(atPath: filePath, isDirectory: &isDirectory) || isDirectory.boolValue) {
+            if (!FileManager.default.fileExists(atPath: filePath, isDirectory: &isDirectory) || isDirectory.boolValue ||
+                NSString(string: filePath).contains(".DS_Store")) {
                 subPaths.remove(item);
                 index -= 1
             }

+ 8 - 12
KdanAutoTest/KdanAuto/Class/Norrmal/ActivityView/ActivityView.swift

@@ -39,18 +39,14 @@ class ActivityView : NSView {
     public override init(frame frameRect: NSRect) {
         super.init(frame: frameRect)
         
-        if (self != nil) {
-            loadSubviews()
-        }
+        loadSubviews()
     }
     
     
     public required init?(coder: NSCoder) {
         super.init(coder: coder)
         
-        if (self != nil) {
-            loadSubviews()
-        }
+        loadSubviews()
     }
     
     
@@ -80,9 +76,9 @@ class ActivityView : NSView {
         let width = self.frame.width
         let height = self.frame.height
         
-        if nil == _titleLbl {
-            _titleLbl = NSTextField.init(frame: self.frame)
-        }
+//        if nil == _titleLbl {
+//            _titleLbl = NSTextField.init(frame: self.frame)
+//        }
         _titleLbl.isSelectable = false
         _titleLbl.isEditable = false
         if nil == _titleLbl.superview {
@@ -98,9 +94,9 @@ class ActivityView : NSView {
         _titleLbl.layer?.borderWidth = 1
         _titleLbl.layer?.cornerRadius = 4
         
-        if nil == _activityView {
-            _activityView = NSProgressIndicator.init(frame: self.bounds)
-        }
+//        if nil == _activityView {
+//            _activityView = NSProgressIndicator.init(frame: self.bounds)
+//        }
         _activityView.controlSize = .small
         _activityView.style = .spinning
         if nil == _activityView.superview {

+ 8 - 8
KdanAutoTest/KdanAuto/Class/Norrmal/AutoTestAdvanceSettingView.swift

@@ -81,8 +81,8 @@ class AutoTestAdvanceSettingView : NSView, NSTableViewDataSource, NSTableViewDel
         _addBtn.isHidden = nil == _autoTestObj;
         if nil != _autoTestObj {
             _titleLbl.stringValue = "【"+(_autoTestObj?.fileType() ?? "")+"】"+(_autoTestObj?.name() ?? "")
-            let checkKeys = _autoTestObj?.keys() as! NSArray
-            let selectKeys = _autoTestObj?.selectedKeys() as! NSArray
+            let checkKeys = NSArray(array: _autoTestObj?.keys() ?? [])
+            let selectKeys = NSArray(array: _autoTestObj?.selectedKeys() ?? [])
             
             if _keyViews == nil {
                 _keyViews = NSMutableArray()
@@ -158,9 +158,9 @@ class AutoTestAdvanceSettingView : NSView, NSTableViewDataSource, NSTableViewDel
     
     /// IBActionn
     @IBAction func keyChecked(_ sender:NSButton) {
-        var currentSelectedKeys = NSMutableArray()
+        let currentSelectedKeys = NSMutableArray()
         
-        let checkKeys = _autoTestObj?.keys() as! NSArray
+        let checkKeys = NSArray(array: _autoTestObj?.keys() ?? [])
         
         for btn in _keyViews {
             let cBtn = btn as! NSButton
@@ -218,7 +218,7 @@ class AutoTestAdvanceSettingView : NSView, NSTableViewDataSource, NSTableViewDel
         openPanel.accessoryView = comboBox;
         
         if openPanel.runModal() == NSApplication.ModalResponse.OK {
-            var paths = NSMutableArray()
+            let paths = NSMutableArray()
             
             if openPanel.urls.count != 0 {
                 for url in openPanel.urls {
@@ -236,7 +236,7 @@ class AutoTestAdvanceSettingView : NSView, NSTableViewDataSource, NSTableViewDel
                     path = openPanel.url?.absoluteString
                 }
                 if nil != path {
-                    paths.add(path)
+                    paths.add(path!)
                 }
                 
             }
@@ -410,10 +410,10 @@ class AutoTestAdvanceSettingView : NSView, NSTableViewDataSource, NSTableViewDel
     func fileCellNeedShowReport(_ cell: TestFileCellView, fileName: String, sender:NSButton) {
         let files = _autoTestObj?.compareFiles(fileName) ?? []
         
-        if nil != files && files.count > 0 {
+        if files.count > 0 {
             let compareVC = CompareViewController.shared()
             compareVC.setFiles(files)
-            let point = sender.convert(sender.frame.origin, to: self)
+            let point = sender.convert(CGPoint(x: 0, y: 0), to: self)
             compareVC.showIn(self, rect: NSRect.init(origin: point, size: sender.frame.size))
         }
     }

+ 1 - 1
KdanAutoTest/KdanAuto/Class/Norrmal/Cell/AutoTestCellInfo.swift

@@ -17,7 +17,7 @@ class AutoTestCellInfo : NSObject {
     var _row : Int! = 0
     
     class func initWithRow(_ row:Int) -> AutoTestCellInfo {
-        var cellInfo = AutoTestCellInfo()
+        let cellInfo = AutoTestCellInfo()
         cellInfo._row = row
 
         var index = 0

+ 2 - 1
KdanAutoTest/KdanAuto/Class/Norrmal/Cell/TestCaseCellView.swift

@@ -179,7 +179,8 @@ class TestCaseCellView : NSTableCellView {
             let compareVC = CompareViewController.shared()
             compareVC.setFiles(files)
             
-            let point = sender.convert(sender.frame.origin, to: self.window?.contentView)
+            let point = sender.convert(CGPoint(x: 0, y: 0),
+                                       to: self.window?.contentView)
             compareVC.showIn(self.window?.contentView, rect: NSRect.init(origin: point, size: sender.frame.size))
         }
         return

+ 129 - 104
KdanAutoTest/KdanAuto/Class/Tools/FileConveter/FileConverter.swift

@@ -29,23 +29,24 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
     var pages:[Int] = []
     var pathExtension = ""
     var convertQueue = DispatchQueue.main
+    var operateQueue = OperationQueue()
     
     var semaphore:DispatchSemaphore? = DispatchSemaphore.init(value: 0)
     var accessSemaphore:DispatchSemaphore? = DispatchSemaphore.init(value: 1)
-    var didSuccess:Bool = false
+    var didSuccess:Int = 1
     
     static var instance = FileConverter()
     class func shared() -> FileConverter {
         return instance
     }
     
-    func converter(_ inSrcPath: String, inDesPath: String) -> Bool {
+    func converter(_ inSrcPath: String, inDesPath: String) -> Int {
         return converter(inSrcPath, inDesPath: inDesPath, params: nil)
     }
     
-    func converter(_ inSrcPath: String, inDesPath: String, params:NSDictionary?) -> Bool {
+    func converter(_ inSrcPath: String, inDesPath: String, params:NSDictionary?) -> Int {
         if !FileManager.default.fileExists(atPath: inSrcPath) {
-            return false
+            return -1
         }
         
         accessSemaphore?.wait()
@@ -56,6 +57,10 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
         if FileManager.default.fileExists(atPath: desPath) {
             try! FileManager.default.removeItem(atPath: desPath)
         }
+        let directory = NSString(string: desPath).deletingLastPathComponent
+        if !FileManager.default.fileExists(atPath: directory) {
+            try! FileManager.default.createDirectory(atPath: directory, withIntermediateDirectories: true)
+        }
         let attributy = try! FileManager.default.attributesOfItem(atPath: srcPath)
         let fileType = attributy[FileAttributeKey.type] as! FileAttributeType
         if NSString(string: FileAttributeType.typeSymbolicLink.rawValue).isEqual(to: fileType.rawValue) {
@@ -73,7 +78,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
 //        let outputPath = NSString(string: self.desPath).deletingPathExtension
 //        let output = self.desPath
         let password = params?.value(forKey: "password")
-        let tParams = params as? NSDictionary
+        let tParams = params ?? [:]
         let useOldLibValue = params?.value(forKey: "useOldLib")
     
         var useOldLib = false;
@@ -92,6 +97,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
             let document = PDFDocument(url: url)
             if document == nil {
                 self.accessSemaphore?.signal()
+                self.didSuccess = -2;
                 return
             }
             let pageCount = document!.pageCount
@@ -102,126 +108,144 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
             }
             
             if  !useOldLib && NSArray(array: ["jpg", "JPG", "png", "PNG"]).contains(self.pathExtension) {
-                autoreleasepool {
-                    let cachePath = NSString(string: self.desPath).deletingPathExtension+".zip"
-                    self.pdfConverter = CPDFConverterImg.init(url: url, password: nil)
-                    if (nil == self.pdfConverter && nil != password) {
-                        self.pdfConverter = CPDFConverterImg.init(url: url, password: password as? String)
-                    }
-                    self.pdfConverter?.delegate = self
-                    self.options = CPDFConvertImgOptions()
-                    if (NSArray(array: ["jpg", "JPG"]).contains(self.pathExtension)) {
-                        (self.options as! CPDFConvertImgOptions).type = .JPEG
-                    }else {
-                        (self.options as! CPDFConvertImgOptions).type = .PNG
+                self.operateQueue.addOperation {
+                    autoreleasepool {
+                        let cachePath = NSString(string: self.desPath).deletingPathExtension+".zip"
+                        self.pdfConverter = CPDFConverterImg.init(url: url, password: nil)
+                        if (nil == self.pdfConverter && nil != password) {
+                            self.pdfConverter = CPDFConverterImg.init(url: url, password: password as? String)
+                        }
+                        self.pdfConverter?.delegate = self
+                        self.options = CPDFConvertImgOptions()
+                        if (NSArray(array: ["jpg", "JPG"]).contains(self.pathExtension)) {
+                            (self.options as! CPDFConvertImgOptions).type = .JPEG
+                        }else {
+                            (self.options as! CPDFConvertImgOptions).type = .PNG
+                        }
+                        self.pdfConverter?.convert(toFilePath: cachePath, pageIndexs: self.pages, options: self.options)
                     }
-                    self.pdfConverter?.convert(toFilePath: cachePath, pageIndexs: self.pages, options: self.options)
                 }
             }else if !useOldLib && NSArray(array: ["ppt", "PPT", "PPTX", "pptx"]).contains(self.pathExtension) {
-                autoreleasepool {
-                    self.pdfConverter = CPDFConverterPPT.init(url: url, password: nil)
-                    if (nil == self.pdfConverter && nil != password) {
-                        self.pdfConverter = CPDFConverterPPT.init(url: url, password: password as? String)
+                self.operateQueue.addOperation {
+                    autoreleasepool {
+                        self.pdfConverter = CPDFConverterPPT.init(url: url, password: nil)
+                        if (nil == self.pdfConverter && nil != password) {
+                            self.pdfConverter = CPDFConverterPPT.init(url: url, password: password as? String)
+                        }
+                        self.pdfConverter?.delegate = self
+                        self.options = CPDFConvertPPTOptions()
+                        self.pdfConverter?.convert(toFilePath: self.desPath,
+                                                   pageIndexs: self.pages, options: self.options)
                     }
-                    self.pdfConverter?.delegate = self
-                    self.options = CPDFConvertPPTOptions()
-                    self.pdfConverter?.convert(toFilePath: self.desPath,
-                                               pageIndexs: self.pages, options: self.options)
                 }
             }else if !useOldLib && NSArray(array: ["doc", "DOC", "docx", "DOCX"]).contains(self.pathExtension) {
-                autoreleasepool {
-                    self.pdfConverter = CPDFConverterWord.init(url: url, password: nil)
-                    if (nil == self.pdfConverter && nil != password) {
-                        self.pdfConverter = CPDFConverterWord.init(url: url, password: password as? String)
+                self.operateQueue.addOperation {
+                    autoreleasepool {
+                        self.pdfConverter = CPDFConverterWord.init(url: url, password: nil)
+                        if (nil == self.pdfConverter && nil != password) {
+                            self.pdfConverter = CPDFConverterWord.init(url: url, password: password as? String)
+                        }
+                        self.pdfConverter?.delegate = self
+                        self.options = CPDFConvertWordOptions()
+                        self.pdfConverter?.convert(toFilePath: self.desPath,
+                                                   pageIndexs: self.pages, options: self.options)
                     }
-                    self.pdfConverter?.delegate = self
-                    self.options = CPDFConvertWordOptions()
-                    self.pdfConverter?.convert(toFilePath: self.desPath,
-                                               pageIndexs: self.pages, options: self.options)
                 }
             }else if !useOldLib && NSArray(array: ["xls", "XLS", "xlsx", "XLSX"]).contains(self.pathExtension) {
-                autoreleasepool {
-                    self.pdfConverter = CPDFConverterExcel.init(url: url, password: nil)
-                    if (nil == self.pdfConverter && nil != password) {
-                        self.pdfConverter = CPDFConverterExcel.init(url: url, password: password as? String)
+                self.operateQueue.addOperation {
+                    autoreleasepool {
+                        self.pdfConverter = CPDFConverterExcel.init(url: url, password: nil)
+                        if (nil == self.pdfConverter && nil != password) {
+                            self.pdfConverter = CPDFConverterExcel.init(url: url, password: password as? String)
+                        }
+                        self.pdfConverter?.delegate = self
+                        self.options = CPDFConvertExcelOptions()
+                        self.pdfConverter?.convert(toFilePath: self.desPath,
+                                                                  pageIndexs: self.pages, options: self.options)
                     }
-                    self.pdfConverter?.delegate = self
-                    self.options = CPDFConvertExcelOptions()
-                    self.pdfConverter?.convert(toFilePath: self.desPath,
-                                               pageIndexs: self.pages, options: self.options)
                 }
             }else if !useOldLib && NSArray(array: ["csv", "CSV"]).contains(self.pathExtension) {
-                autoreleasepool {
-                    self.pdfConverter = CPDFConverterCsv.init(url: url, password: nil)
-                    if (nil == self.pdfConverter && nil != password) {
-                        self.pdfConverter = CPDFConverterCsv.init(url: url, password: password as? String)
+                self.operateQueue.addOperation {
+                    autoreleasepool {
+                        self.pdfConverter = CPDFConverterCsv.init(url: url, password: nil)
+                        if (nil == self.pdfConverter && nil != password) {
+                            self.pdfConverter = CPDFConverterCsv.init(url: url, password: password as? String)
+                        }
+                        self.pdfConverter?.delegate = self
+                        self.options = CPDFConvertCsvOptions()
+                        self.pdfConverter?.convert(toFilePath: self.desPath,
+                                                                  pageIndexs: self.pages, options: self.options)
                     }
-                    self.pdfConverter?.delegate = self
-                    self.options = CPDFConvertCsvOptions()
-                    self.pdfConverter?.convert(toFilePath: self.desPath,
-                                               pageIndexs: self.pages, options: self.options)
                 }
             }else if !useOldLib && NSArray(array: ["html", "HTML"]).contains(self.pathExtension) {
-                autoreleasepool {
-                    let cachePath = NSString(string: self.desPath).deletingPathExtension+".zip"
-                    self.pdfConverter = CPDFConverterHtml.init(url: url, password: nil)
-                    if (nil == self.pdfConverter && nil != password) {
-                        self.pdfConverter = CPDFConverterHtml.init(url: url, password: password as? String)
-                    }
-                    self.pdfConverter?.delegate = self
-                    self.options = CPDFConvertHtmlOptions()
-                    if ((tParams?.value(forKey: "paneOptions") as? NSNumber) != nil) {
-                        (self.options as! CPDFConvertHtmlOptions).paneOptions = CPDFConvertHtmlPageAndNavigationPaneOptions(rawValue: (tParams?.value(forKey: "paneOptions") as! NSNumber).intValue)!
+                self.operateQueue.addOperation {
+                    autoreleasepool {
+                        let cachePath = NSString(string: self.desPath).deletingPathExtension+".zip"
+                        self.pdfConverter = CPDFConverterHtml.init(url: url, password: nil)
+                        if (nil == self.pdfConverter && nil != password) {
+                            self.pdfConverter = CPDFConverterHtml.init(url: url, password: password as? String)
+                        }
+                        self.pdfConverter?.delegate = self
+                        self.options = CPDFConvertHtmlOptions()
+                        if ((tParams.value(forKey: "paneOptions") as? NSNumber) != nil) {
+                            (self.options as! CPDFConvertHtmlOptions).paneOptions = CPDFConvertHtmlPageAndNavigationPaneOptions(rawValue: (tParams.value(forKey: "paneOptions") as! NSNumber).intValue)!
+                        }
+                        self.pdfConverter?.convert(toFilePath: cachePath,
+                                                                  pageIndexs: self.pages, options: self.options)
                     }
-                    self.pdfConverter?.convert(toFilePath: cachePath,
-                                               pageIndexs: self.pages, options: self.options)
                 }
             }else if !useOldLib && NSArray(array: ["rtf", "RTF"]).contains(self.pathExtension) {
-                autoreleasepool {
-                    self.pdfConverter = CPDFConverterRtf.init(url: url, password: nil)
-                    if (nil == self.pdfConverter && nil != password) {
-                        self.pdfConverter = CPDFConverterRtf.init(url: url, password: password as? String)
-                    }
-                    self.pdfConverter?.delegate = self
-                    self.options = CPDFConvertRtfOptions()
-                    self.pdfConverter?.convert(toFilePath: self.desPath,
-                                               pageIndexs: self.pages, options: self.options)
+                self.operateQueue.addOperation {
+                    autoreleasepool {
+                        self.pdfConverter = CPDFConverterRtf.init(url: url, password: nil)
+                        if (nil == self.pdfConverter && nil != password) {
+                            self.pdfConverter = CPDFConverterRtf.init(url: url, password: password as? String)
+                        }
+                        self.pdfConverter?.delegate = self
+                        self.options = CPDFConvertRtfOptions()
+                        self.pdfConverter?.convert(toFilePath: self.desPath,
+                                                                  pageIndexs: self.pages, options: self.options)
+                   }
                 }
             }else if !useOldLib && NSArray(array: ["txt", "TXT"]).contains(self.pathExtension) {
-                autoreleasepool {
-                    self.pdfConverter = CPDFConverterTxt.init(url: url, password: nil)
-                    if (nil == self.pdfConverter && nil != password) {
-                        self.pdfConverter = CPDFConverterTxt.init(url: url, password: password as? String)
+                self.operateQueue.addOperation {
+                    autoreleasepool {
+                        self.pdfConverter = CPDFConverterTxt.init(url: url, password: nil)
+                        if (nil == self.pdfConverter && nil != password) {
+                            self.pdfConverter = CPDFConverterTxt.init(url: url, password: password as? String)
+                        }
+                        self.pdfConverter?.delegate = self
+                        self.options = CPDFConvertTxtOptions()
+                        self.pdfConverter?.convert(toFilePath: self.desPath,
+                                                                  pageIndexs: self.pages, options: self.options)
                     }
-                    self.pdfConverter?.delegate = self
-                    self.options = CPDFConvertTxtOptions()
-                    self.pdfConverter?.convert(toFilePath: self.desPath,
-                                               pageIndexs: self.pages, options: self.options)
                 }
             }else {
-                autoreleasepool {
-                    if self.fpConverter == nil {
-                        self.fpConverter = CPDFConverterFP.init()
-                        self.fpConverter?.setDelegate(self)
-                    }else {
-                        self.fpConverter?.stopConvertsionIfNeed()
-                    }
-                    
-                    var needMerge = NSArray(array: ["csv", "CSV"]).contains(self.pathExtension)
-                    let dpi = tParams?.value(forKey: "KMPDFConvertOptionsKeyImageDPI")
-                    if (needMerge && tParams?.value(forKey: "CPDFConvertOptionsKeyAllInOneSheet") != nil) {
-                        needMerge = (tParams?.value(forKey: "CPDFConvertOptionsKeyAllInOneSheet") as! NSNumber).boolValue
-                    }
-                    
-                    self.fpConverter?.convertPDF(atPath: self.srcPath,
-                                                 pdfPassword: password as? String,
-                                                 pdfPageIndexs: self.pages,
-                                                 destDocType: self.pathExtension,
-                                                 destDocPath: self.desPath,
-                                                 moreOptions: [
-                                                    "KMPDFConvertOptionsKeyImageDPI" : (dpi as? String) ?? "72",
-                                                    "CPDFConvertOptionsKeyAllInOneSheet":NSNumber(booleanLiteral: needMerge)
-                                                 ])
+                self.operateQueue.addOperation {
+                    autoreleasepool {
+                        if self.fpConverter == nil {
+                            self.fpConverter = CPDFConverterFP.init()
+                            self.fpConverter?.setDelegate(self)
+                        }else {
+                            self.fpConverter?.stopConvertsionIfNeed()
+                        }
+                        
+                        var needMerge = NSArray(array: ["csv", "CSV"]).contains(self.pathExtension)
+                        let dpi = tParams.value(forKey: "KMPDFConvertOptionsKeyImageDPI")
+                        if (needMerge && tParams.value(forKey: "CPDFConvertOptionsKeyAllInOneSheet") != nil) {
+                            needMerge = (tParams.value(forKey: "CPDFConvertOptionsKeyAllInOneSheet") as! NSNumber).boolValue
+                        }
+                        
+                        self.fpConverter?.convertPDF(atPath: self.srcPath,
+                                                     pdfPassword: password as? String,
+                                                     pdfPageIndexs: self.pages,
+                                                     destDocType: self.pathExtension,
+                                                     destDocPath: self.desPath,
+                                                     moreOptions: [
+                                                        "KMPDFConvertOptionsKeyImageDPI" : (dpi as? String) ?? "72",
+                                                        "CPDFConvertOptionsKeyAllInOneSheet":NSNumber(booleanLiteral: needMerge)
+                                                     ])
+                   }
                 }
             }
         }
@@ -234,11 +258,12 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
     
     /// CPDFConverterDelegate
     func converter(_ converter: CPDFConverter!, didStartConvert error: Error!) {
+        didSuccess = 0;
         
     }
     
     func converter(_ converter: CPDFConverter!, didEndConvert error: Error!) {
-        didSuccess = nil == error
+        didSuccess = nil == error ? 1 : 0
         
         autoreleasepool {
             sleep(2)
@@ -273,7 +298,7 @@ class FileConverter : NSObject, CPDFConverterDelegate, CPDFConverterFPDelegate {
     /// CPDFConverterFPDelegate
     func fppdfConverter(_ converter: Any!, didEndConversion error: Error!) {
         autoreleasepool {
-            didSuccess = nil == error
+            didSuccess = nil == error ? 1 : 0
             self.fpConverter?.stopConvertsionIfNeed()
             
             sleep(2)

+ 15 - 15
KdanAutoTest/KdanAuto/Class/Tools/ImageProcess/ImageProcess.swift

@@ -32,27 +32,27 @@ class ImageProcess : NSObject {
             
             let rWidth = resultImageRep.pixelsWide
             let rHeight = resultImageRep.pixelsHigh
-            let rBitPerPixel = resultImageRep.bitsPerPixel / 8
-            let rBytePerRow = resultImageRep.bytesPerRow
+//            let rBitPerPixel = resultImageRep.bitsPerPixel / 8
+//            let rBytePerRow = resultImageRep.bytesPerRow
             
             let cWidth = checkImageRep.pixelsWide
             let cHeight = checkImageRep.pixelsHigh
-            let cBitPerPixel = checkImageRep.bitsPerPixel / 8
-            let cBytePerRow = checkImageRep.bytesPerRow
+//            let cBitPerPixel = checkImageRep.bitsPerPixel / 8
+//            let cBytePerRow = checkImageRep.bytesPerRow
             
             let maxWidth = min(rWidth, cWidth) - 1
             let maxHeight = min(rHeight, cHeight) - 1
             
             // check background color
             // 挑选图片 对角斜线 上的相素进行识别
-            var markInfo = NSMutableDictionary.init()
+            let markInfo = NSMutableDictionary.init()
             for w in 0...maxWidth {
                 let x = Int(w)
                 for mark in 0...1 {
                     let color = checkImageRep.colorAt(x: min(x, cWidth-1), y: min(mark == 0 ? x : (maxWidth - x), (cHeight-1))) as! NSColor
                     
                     if (markInfo[color] != nil) {
-                        let count = (markInfo[color] as? NSNumber)!.intValue ?? 0
+                        let count = (markInfo[color] as? NSNumber)!.intValue
                         
                         markInfo[color] = NSNumber.init(value: count + 1)
                     }else {
@@ -64,7 +64,7 @@ class ImageProcess : NSObject {
             var maxCount = Int(0);
             var bgColor : NSColor = NSColor.clear
             for color in markInfo.allKeys {
-                let count = (markInfo[color] as? NSNumber)!.intValue ?? 0
+                let count = (markInfo[color] as? NSNumber)!.intValue
                 
                 if count > maxCount {
                     maxCount = count
@@ -72,15 +72,15 @@ class ImageProcess : NSObject {
                 }
             }
             
-            if nil != bgColor {
-                NSLog(String("识别到背景色\(bgColor)"))
-            }
-            
-            let bg_r = Int(bgColor.redComponent*255);
-            let bg_g = Int(bgColor.redComponent*255);
-            let bg_b = Int(bgColor.redComponent*255);
-            let bg_a = Int(bgColor.redComponent*255);
+//            if nil != bgColor {
+//                NSLog(String("识别到背景色\(bgColor)"))
+//            }
             
+//            let bg_r = Int(bgColor.redComponent*255);
+//            let bg_g = Int(bgColor.redComponent*255);
+//            let bg_b = Int(bgColor.redComponent*255);
+//            let bg_a = Int(bgColor.redComponent*255);
+//
             let data = NSMutableData.init(length: cWidth * cHeight * 4)
             // Compare
             let compareDifValue = DataModel.shared.comparativeDifference()

+ 1 - 1
KdanAutoTest/KdanAuto/ViewController.swift

@@ -312,7 +312,7 @@ class ViewController : NSViewController, SettingViewControllerDelegate, AutoTest
             let compareVC = CompareViewController.shared()
             compareVC.setFiles(files)
             
-            let point = sender.convert(sender.frame.origin, to: self.view.window?.contentView)
+            let point = sender.convert(CGPoint(x: 0, y: 0), to: self.view.window?.contentView)
             compareVC.showIn(self.view.window?.contentView, rect: NSRect.init(origin: point, size: sender.frame.size))
         }
         return

+ 2 - 2
KdanAutoTest/ProcessCheckFile/Process/ProcessThumbnal.swift

@@ -26,8 +26,8 @@ class ProcessThumbnal : NSObject {
     class func process(_ filePath:String, desPath:String, outputSize:CGSize) -> Bool {
         if NSArray(array: ["PDF", "pdf"]).contains(NSString(string: filePath).pathExtension) {
             return autoreleasepool {
-                let success = FileConverter.shared().converter(filePath, inDesPath: desPath)
-                return success
+                let status = FileConverter.shared().converter(filePath, inDesPath: desPath)
+                return status == 1
             }
         }
         

+ 169 - 0
Use Guide/Use Guide.md

@@ -134,6 +134,175 @@ KdanAuto 里面直接集成转换 SDK,能够对指定目录内的文档,进
 ![](3.5.6.png)
 
 
+	
+###6、类型及参数配置
+####配置表中,目前有预置 *PDF、RTF、Word、PPT、Excel、CSV、HTML、TXT、JPEG、PNG、GIF、TIFF、TGA、BMP、JPEG2000*格式类型,其中PDF 暂时考虑用作命令行注释编辑工具,批量执行文档结果对照测试项;而*RTF、Word、PPT、Excel、CSV、HTML、TXT、JPEG、PNG、GIF、TIFF、TGA、BMP、JPEG2000*为自动化转档测试对照测试项;
+
+- PDF
+	用于 *命令行工具*,注释、编辑等操作,批量操作文档自动化校对选项
+	
+- Word
+	用于 *PDF to Word*,转档自动化测试及结果自动化对照测试项
+	
+- Excel
+	用于 *PDF to Excel*,转档自动化测试及结果自动化对照测试项
+	
+		 Note:
+		     - 只能对照每份文档的左上角部分;
+		     - 交互式表单无法识别(不确定是不是所有)
+	
+- PPT
+	用于 *PDF to PPT*,转档自动化测试及结果自动化对照测试项, 
+	
+		 Note:只能对照每份文档的第一页
+	
+- CSV
+	用于 *PDF to CSV*,转档自动化测试及结果自动化对照测试项
 
+		 Note:
+		     - 只能对照每份文档的左上角部分;
+	
+- HTML
+	用于 *PDF to HTML*,转档自动化测试及结果自动化对照测试项
+	
+		 Note:
+		     - 新库转档出来是 zip
+	
+- RTF
+ 	用于 *PDF to RTF*,转档自动化测试及结果自动化对照测试项
+	
+		 Note:
+		     - 新库 RTF 格式,不支持预览,需要用 WPS 等软件才能打开看效果;
+	
+- TXT
+	用于 *PDF to TXT*,转档自动化测试及结果自动化对照测试项
+	
+- PNG
+	用于 *PDF 转  PNG *图片格式,转档自动化测试及结果自动化对照测试项
+	
+		 Note:
+		     - 新库转档出来是 zip
 	
+- JPEG
+	用于 *PDF 转  JPEG *图片格式,转档自动化测试及结果自动化对照测试项
 	
+		 Note:
+		     - 新库转档出来是 zip
+	
+- GIF
+	用于 *PDF 转  GIF *图片格式,转档自动化测试及结果自动化对照测试项
+	
+- TIFF
+	用于 *PDF 转  TIFF *图片格式,转档自动化测试及结果自动化对照测试项
+	
+- TGA
+	用于 *PDF 转  TGA *图片格式,转档自动化测试及结果自动化对照测试项
+	
+- BMP
+	用于 *PDF 转  BMP *图片格式,转档自动化测试及结果自动化对照测试项
+	
+- JPEG2000
+	用于 *PDF 转  JPEG2000 *图片格式,转档自动化测试及结果自动化对照测试项
+	
+	
+
+####支持的参数有 *Type(必选)*、*Name(必选)*、*Extetion(必选)*、*Class(必选)*、*Params(可选)*, 对应参数介绍如下:
+
+【Type】
+  *Type*为对应格式选项下,*识别类型*,同时对应于当前格式下,测试类型目录,例如 【JPEG】格式下面的【DPI-300】测试类型
+    
+【Name】
+*Name*为当前 *Type*,在 App 中显示的别名,例如“对照识别”“DPI-300对照识别”
+
+【Extention】
+*Extention*为当前*Type*文件处理后,所得到的文件的后缀
+
+【Class】
+*Class*为当前格式、当前类型(*Type*),用来做自动化处理的 TestCase 类,与测试代码进行关联,其中通用对照测试使用*AutoTest*,PDF 命令行工具使用*PDFCompareTest*
+
+【Params】
+*Params*为各自动化测试文件格式中,可以再从外部(不需要重新编译App)来控制的参数配置,其中各种格式对应的控制参数如下表:
+
+	- password:PDF 文档密码,String 类型
+	- useOldLib:转档类型中,确认是用旧版本转档库 或是 用新库,NSNumber类型(0/1) 或 String 类型(TRUE,FALSE)
+	- paneOptions:HTML 格式,导出 HTML 页面及导航样式 
+		- CPDFConvertHtmlSinglePage = 0,                       // Single page with no navigation.
+	    	- CPDFConvertHtmlSinglePageNavigationByBookmarks = 1,  // Navigate single page using bookmarks from PDF.
+	    	- CPDFConvertHtmlMultiplePages = 2,                    // Multiple pages with no split.
+	    	- CPDFConvertHtmlMultiplePagesSplitByBookmarks = 3     // Split multiple pages using bookmarks from PDF.
+	- KMPDFConvertOptionsKeyImageDPI: 老转档库 DPI 参数,常规设置有50、72、96、144、300、600,String类型,默认72
+	- CPDFConvertOptionsKeyAllInOneSheet:老库 PDF 转CSV,多页合并为一个文档, Bool
+ 
+####不同格式对应控制参数
+- PDF: PDF 文档快照对照
+	- password, 所导入PDF 文档的密码,String 类型
+
+- RTF:转档及结果对照
+	-  password, 所导入文档的密码
+	-  useOldLib:转档类型中,确认是用旧版本转档库 或是 用新转档库,NSNumber类型(0/1) 或 String 类型(TRUE,FALSE),默认缺失时使用新转档库
+
+- Word:转档及结果对照
+	-  password, 所导入文档的密码
+	-  useOldLib:转档类型中,确认是用旧版本转档库 或是 用新转档库,NSNumber类型(0/1) 或 String 类型(TRUE,FALSE),默认缺失时使用新转档库
+
+- PPT:转档及结果对照
+	-  password, 所导入文档的密码
+	-  useOldLib:转档类型中,确认是用旧版本转档库 或是 用新转档库,NSNumber类型(0/1) 或 String 类型(TRUE,FALSE),默认缺失时使用新转档库
+
+- Excel:转档及结果对照
+	-  password, 所导入文档的密码
+	-  useOldLib:转档类型中,确认是用旧版本转档库 或是 用新转档库,NSNumber类型(0/1) 或 String 类型(TRUE,FALSE),默认缺失时使用新转档库
+
+- CSV:转档及结果对照
+	-  password, 所导入文档的密码
+	-  useOldLib:转档类型中,确认是用旧版本转档库 或是 用新转档库,NSNumber类型(0/1) 或 String 类型(TRUE,FALSE),默认缺失时使用新转档库
+	-  CPDFConvertOptionsKeyAllInOneSheet:老库 PDF 转CSV,多页合并为一个文档, Bool
+
+- HTML:转档及结果对照
+	-  password, 所导入文档的密码
+	-  useOldLib:转档类型中,确认是用旧版本转档库 或是 用新转档库,NSNumber类型(0/1) 或 String 类型(TRUE,FALSE),默认缺失时使用新转档库
+	-  paneOptions:HTML 格式,导出 HTML 页面及导航样式 
+		- CPDFConvertHtmlSinglePage = 0,                       // Single page with no navigation.
+	    	- CPDFConvertHtmlSinglePageNavigationByBookmarks = 1,  // Navigate single page using bookmarks from PDF.
+	    	- CPDFConvertHtmlMultiplePages = 2,                    // Multiple pages with no split.
+	    	- CPDFConvertHtmlMultiplePagesSplitByBookmarks = 3     // Split multiple pages using bookmarks from PDF.
+
+- TXT:转档及结果对照
+	-  password, 所导入文档的密码
+	-  useOldLib:转档类型中,确认是用旧版本转档库 或是 用新转档库,NSNumber类型(0/1) 或 String 类型(TRUE,FALSE),默认缺失时使用新转档库
+
+- JPEG:转档及结果对照
+	-  password, 所导入文档的密码
+	-  useOldLib:转档类型中,确认是用旧版本转档库 或是 用新转档库,NSNumber类型(0/1) 或 String 类型(TRUE,FALSE),默认缺失时使用新转档库
+	-  KMPDFConvertOptionsKeyImageDPI: 老转档库 DPI 参数,常规设置有50、72、96、144、300、600,String类型,默认72
+
+- PNG:转档及结果对照
+	-  password, 所导入文档的密码
+	-  useOldLib:转档类型中,确认是用旧版本转档库 或是 用新转档库,NSNumber类型(0/1) 或 String 类型(TRUE,FALSE),默认缺失时使用新转档库
+	-  KMPDFConvertOptionsKeyImageDPI: 老转档库 DPI 参数,常规设置有50、72、96、144、300、600,String类型,默认72
+
+- GIF:转档及结果对照
+	-  password, 所导入文档的密码
+	-  KMPDFConvertOptionsKeyImageDPI: 老转档库 DPI 参数,常规设置有50、72、96、144、300、600,String类型,默认72
+
+- TIFF:转档及结果对照
+	-  password, 所导入文档的密码
+	-  KMPDFConvertOptionsKeyImageDPI: 老转档库 DPI 参数,常规设置有50、72、96、144、300、600,String类型,默认72
+
+- TGA:转档及结果对照
+	-  password, 所导入文档的密码
+	-  KMPDFConvertOptionsKeyImageDPI: 老转档库 DPI 参数,常规设置有50、72、96、144、300、600,String类型,默认72
+
+- BMP:转档及结果对照
+	-  password, 所导入文档的密码
+	-  KMPDFConvertOptionsKeyImageDPI: 老转档库 DPI 参数,常规设置有50、72、96、144、300、600,String类型,默认72
+
+- JPEG2000:转档及结果对照
+	-  password, 所导入文档的密码
+	-  KMPDFConvertOptionsKeyImageDPI: 老转档库 DPI 参数,常规设置有50、72、96、144、300、600,String类型,默认72
+
+###7、问题备注
+- PPT、Word、HTML、TXT、RTF 只有第一页能展示
+-  交互式表单,新库解析看起来有问题
+-  老库注释会丢失
+-  古代法制史(打印版).pdf 等比较多文档乱码