// // PDFCompareTest.swift // KdanAuto // // Created by 朱东勇 on 2023/2/16. // import Foundation import AppKit class PDFCompareTest : AutoTest { static var pdfSharedInstance = PDFCompareTest() override class func shared() -> AutoTest? { return pdfSharedInstance } override func clearCacheFiles() { } override func process(_ originPath:String, resultPath:String, complention:@escaping (_ status:Int) -> ()) { DispatchQueue.global().async { autoreleasepool { Thread.sleep(forTimeInterval: 0.3); complention(1) } } } override func compareFiles(_ fileName: String) -> NSArray? { let files = NSMutableArray() let checkDirectory = self.checkFileDirectory() // let originDirectory = self.originFileDirectory() let resultDirectory = self.resultFileDirectory() let fName = NSString(string: fileName).deletingPathExtension // let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf") let resultPath = NSString(string: resultDirectory).appendingPathComponent(fName+".jpg") // let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention) var isDirectory = ObjCBool(false) if FileManager.default.fileExists(atPath: resultPath, isDirectory:&isDirectory) { // compare screenshoot between result file with check file 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: ["jpg"]).contains(ext) { let fileName = NSString(string: fName+".jpg"+"/\(item as! String)").deletingPathExtension items.add(fileName) } } }else { items.add(fName) } let nitems = items.sortedArray { str1, str2 in let s1 = NSString(string: str1 as! String).deletingPathExtension let s2 = NSString(string: str2 as! String).deletingPathExtension if (NSString(string: s1).length != NSString(string: s2).length) { if (NSString(string: s1).length > NSString(string: s2).length) { return .orderedDescending }else { return .orderedAscending } } return NSString(string: s1).compare(s2) } for item in NSArray(array: nitems) { let subFileName = item as! String let rComparePath = NSString(string: resultDirectory).appendingPathComponent(subFileName+".jpg") let cComparePath = NSString(string: checkDirectory).appendingPathComponent(subFileName+".jpg") let fileInfo = NSMutableDictionary.fileInfoWith(fileName, // 实际文档名 refFilePath: (isDirectory.boolValue ? (subFileName+".jpg") : nil), resultPath: rComparePath, comparePath: cComparePath, objc: self) files.add(fileInfo) } } return files } }