123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //
- // PDFCompareTest.swift
- // KdanAuto
- //
- // Created by 朱东勇 on 2023/2/16.
- //
- import Foundation
- import AppKit
- class PDFCompareTest : AutoTest {
-
- override class func shared() -> AutoTest? {
- return PDFCompareTest()
- }
-
- 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
- }
-
- }
|