|
@@ -21,9 +21,7 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
|
var _extention : String = "rtf"
|
|
|
var _name : String = "对照测试"
|
|
|
var _params : NSDictionary = [:]
|
|
|
- var _complention:(AutoTest,NSAttributedString?) -> () = {(obj,rep) in
|
|
|
-
|
|
|
- }
|
|
|
+ let compareImageQueue = OperationQueue()
|
|
|
|
|
|
class func autoTestFor(_ fileType:NSString ,type:NSString) -> AutoTest? {
|
|
|
let key = String(fileType) + "." + String(type)
|
|
@@ -39,9 +37,9 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
|
// }
|
|
|
|
|
|
let fileTypes = testTypeInfo[fileType] as! NSArray
|
|
|
-
|
|
|
+
|
|
|
let clsname = "KdanAuto"//Bundle.main.infoDictionary! ["CFBundleExecutable"]
|
|
|
-
|
|
|
+
|
|
|
for item in fileTypes {
|
|
|
let cItem = item as! NSDictionary
|
|
|
|
|
@@ -94,6 +92,10 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
|
return _name
|
|
|
}
|
|
|
|
|
|
+ func extention() -> String {
|
|
|
+ return _extention
|
|
|
+ }
|
|
|
+
|
|
|
func params() -> NSDictionary {
|
|
|
return _params
|
|
|
}
|
|
@@ -140,237 +142,271 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
|
|
|
|
// Auto Test
|
|
|
func autoTest(_ complention:@escaping (_ object:AutoTest, _ report:NSAttributedString?) -> ()) {
|
|
|
- self._complention = complention
|
|
|
- DispatchQueue.global().async {
|
|
|
- self.autoTest()
|
|
|
-
|
|
|
- DispatchQueue.main.async {
|
|
|
- self._complention(self, nil)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func autoTest() {
|
|
|
clearCacheFiles()
|
|
|
|
|
|
+ NSLog(String("转换\(self.type())"))
|
|
|
+ let needCompare = self.selectedKeys().contains("快照")
|
|
|
+
|
|
|
+ if !needCompare {
|
|
|
+ // 未勾选 ”快照“ 选项
|
|
|
+ self._status = .Finished
|
|
|
+ complention(self, self.reportString)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if hasOriginFile() {
|
|
|
- NSLog(String("转换\(self.type())"))
|
|
|
- let needCompare = self.selectedKeys().contains("快照")
|
|
|
-
|
|
|
- if !needCompare {
|
|
|
- _status = .Finished
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- _status = .Process
|
|
|
- reportString = NSMutableAttributedString.init(string: "\n【\(String(self.fileType())) - \(self.name())】快照比对开始!\n",
|
|
|
- attributes:[.foregroundColor : NSColor.blue])
|
|
|
- let files = DataModel.shared.originFilesFor(_fileType, type: _type) as [String]
|
|
|
-
|
|
|
- let checkDirectory = self.checkFileDirectory()
|
|
|
- let originDirectory = self.originFileDirectory()
|
|
|
- let resultDirectory = self.resultFileDirectory()
|
|
|
-
|
|
|
- if (files.count > 0) {
|
|
|
- try? FileManager.default.createDirectory(atPath: checkDirectory, withIntermediateDirectories: true);
|
|
|
- try? FileManager.default.createDirectory(atPath: resultDirectory, withIntermediateDirectories: true);
|
|
|
- }
|
|
|
-
|
|
|
- var tDegree = Double(0);
|
|
|
- var tCount = Int(0)
|
|
|
-
|
|
|
- for fileName in files {
|
|
|
- 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)
|
|
|
-
|
|
|
+ //目录中有需要执行对照的文件
|
|
|
+ DispatchQueue.global().async {
|
|
|
+ self._status = .Process
|
|
|
+ self.reportString = NSMutableAttributedString.init(string: "\n【\(String(self.fileType())) - \(self.name())】快照比对开始!\n",
|
|
|
+ attributes:[.foregroundColor : NSColor.blue])
|
|
|
+ let files = DataModel.shared.originFilesFor(self.fileType(), type: self.type()) as [String]
|
|
|
+
|
|
|
+ let checkDirectory = self.checkFileDirectory()
|
|
|
+ let originDirectory = self.originFileDirectory()
|
|
|
+ let resultDirectory = self.resultFileDirectory()
|
|
|
+
|
|
|
+ if (files.count > 0) {
|
|
|
+ try? FileManager.default.createDirectory(atPath: checkDirectory, withIntermediateDirectories: true);
|
|
|
+ try? FileManager.default.createDirectory(atPath: resultDirectory, withIntermediateDirectories: true);
|
|
|
+ }
|
|
|
+
|
|
|
+ var tDegree = Double(0);
|
|
|
+ var tCount = Int(0)
|
|
|
+
|
|
|
+ // 用 Block 递归调用形式,确保转档单任务执行
|
|
|
+ var convertFileBlock = { (files:[String], fileIndex:Int) in }
|
|
|
+ convertFileBlock = { (files:[String], fileIndex:Int) in
|
|
|
+ if (fileIndex >= files.count) {
|
|
|
+ //所有任务已经执行完成
|
|
|
+ TestDegreeManager.shared().set(((tCount != 0) ? tDegree/Double(tCount) : 0.0),
|
|
|
+ fileType: self.fileType(),
|
|
|
+ type: self.type())
|
|
|
+
|
|
|
+ self._status = .Finished
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ complention(self, self.reportString);
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- 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)
|
|
|
+ //
|
|
|
+ let fileName = files[fileIndex];
|
|
|
+ autoreleasepool {
|
|
|
+ let fName = NSString(string: fileName).deletingPathExtension
|
|
|
+ let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
|
|
|
+ let resultPath = NSString(string: resultDirectory).appendingPathComponent(fName+"."+self.extention())
|
|
|
+ // let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention)
|
|
|
+
|
|
|
+
|
|
|
+ self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】开始转换文件 \"\(fName)\"\n",
|
|
|
+ attributes:[.foregroundColor : NSColor.blue]))
|
|
|
+ // ...
|
|
|
+ // 执行异步转换过程
|
|
|
+ self.process(originPath, resultPath: resultPath) { status in
|
|
|
+ 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: [self.extention()]).contains(ext)) {
|
|
|
+ let fileName = NSString(string: fName+"."+self.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")
|
|
|
+ var subDegree = Double(0);
|
|
|
+ var subCount = Int(0)
|
|
|
|
|
|
+ self.compareImageQueue.maxConcurrentOperationCount = 1;
|
|
|
|
|
|
- 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))
|
|
|
-
|
|
|
- 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)
|
|
|
+ var processCount = Int(0);
|
|
|
+ for item in items {
|
|
|
+ self.compareImageQueue.addOperation {
|
|
|
+ DispatchQueue.global().async {
|
|
|
+ autoreleasepool {
|
|
|
+ let subFileName = item as! String
|
|
|
+ let subResultPath = NSString(string: resultDirectory).appendingPathComponent(subFileName+"."+self.extention())
|
|
|
|
|
|
+ self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subFileName+".\(self.extention())")\"快照生成中\n",
|
|
|
+ attributes:[.foregroundColor : NSColor.black]))
|
|
|
+ let rComparePath = NSString(string: resultDirectory).appendingPathComponent(subFileName+".jpg")
|
|
|
+ let cComparePath = NSString(string: checkDirectory).appendingPathComponent(subFileName+".jpg")
|
|
|
|
|
|
- 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
|
|
|
+ ProcessThumbnal.process(subResultPath, desPath: rComparePath, outputSize: CGSize.init(width: 2048, height: 2048)) { processSuccess in
|
|
|
+ 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")"))
|
|
|
+
|
|
|
+ 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]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照生成失败\n",
|
|
|
+ attributes:[.foregroundColor : 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")"))
|
|
|
-
|
|
|
- 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
|
|
|
+ processCount = processCount+1
|
|
|
+
|
|
|
+ if (processCount >= items.count) {
|
|
|
+ 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
|
|
|
+
|
|
|
+ DispatchQueue.global().async {
|
|
|
+ autoreleasepool {
|
|
|
+ // 执行下一个文件转档
|
|
|
+ convertFileBlock(files, fileIndex + 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- subDegree += degree
|
|
|
- subCount += 1
|
|
|
-
|
|
|
- self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照对比完成,图像相似度 \(degree)%\n",
|
|
|
- attributes:[.foregroundColor : color]))
|
|
|
}
|
|
|
}
|
|
|
- }else {
|
|
|
- self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照生成失败\n",
|
|
|
- attributes:[.foregroundColor : NSColor.red]))
|
|
|
}
|
|
|
-
|
|
|
- processThumbSemaphore.signal()
|
|
|
}
|
|
|
- processThumbSemaphore.wait()
|
|
|
+ if (items.count != 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ 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
|
|
|
+ if (status == 0) {
|
|
|
+ self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档失败!\n",
|
|
|
+ attributes:[.foregroundColor : NSColor.red]))
|
|
|
+ }else if (status == -1 || status == -2) {
|
|
|
+ self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"文档无法打开!\n",
|
|
|
+ attributes:[.foregroundColor : NSColor.red]))
|
|
|
+ }else if (status == -3) {
|
|
|
+ self.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 {
|
|
|
- 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]))
|
|
|
+ DispatchQueue.global().async {
|
|
|
+ autoreleasepool {
|
|
|
+ // 执行下一个文件转档
|
|
|
+ convertFileBlock(files, fileIndex + 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // 启动第0号任务
|
|
|
+ convertFileBlock(files, 0);
|
|
|
}
|
|
|
|
|
|
- TestDegreeManager.shared().set(((tCount != 0) ? tDegree/Double(tCount) : 0.0),
|
|
|
- fileType: _fileType,
|
|
|
- type: _type)
|
|
|
-
|
|
|
- _status = .Finished
|
|
|
+
|
|
|
}else {
|
|
|
_status = .Normal
|
|
|
+
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ complention(self, nil)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func process(_ originPath:String, resultPath:String) -> Int {
|
|
|
- return process(originPath, resultPath: resultPath, params: self.params())
|
|
|
+ func process(_ originPath:String, resultPath:String, complention:@escaping (_ status:Int) -> ()) {
|
|
|
+ return process(originPath, resultPath: resultPath, params: self.params(), complention: complention)
|
|
|
}
|
|
|
|
|
|
- func process(_ originPath:String, resultPath:String, params:NSDictionary) -> Int {
|
|
|
- // ...
|
|
|
- // 执行转换过程
|
|
|
- let convertSemaphore = DispatchSemaphore(value: 0)
|
|
|
- var status = Int(1)
|
|
|
- let convertQueue = DispatchQueue.global()
|
|
|
- operateQueue.addOperation {
|
|
|
- autoreleasepool {
|
|
|
- status = FileConverter.shared().converter(originPath, inDesPath: resultPath, params: params)
|
|
|
-
|
|
|
- // 修复转 PNG 实际图片为 JPG 问题, 导致无法匹配问题
|
|
|
- if (NSArray(array: ["png", "PNG"]).contains(NSString(string: resultPath).pathExtension)) {
|
|
|
- let items = (FileManager.default.subpaths(atPath: resultPath) ?? []) as [String]
|
|
|
- for item in items {
|
|
|
- if NSArray(array: ["jpg", "JPG"]).contains(NSString(string:item).pathExtension) {
|
|
|
- let path = NSString(string: resultPath).appendingPathComponent(item);
|
|
|
-
|
|
|
- try? FileManager.default.moveItem(atPath: path,
|
|
|
- toPath: NSString(string: path).deletingPathExtension+".png");
|
|
|
- }
|
|
|
+ func process(_ originPath:String, resultPath:String, params:NSDictionary, complention:@escaping (_ status:Int) -> ()) {
|
|
|
+ FileConverter.shared().converter(originPath, inDesPath: resultPath, params: params) { status in
|
|
|
+ // 修复转 PNG 实际图片为 JPG 问题, 导致无法匹配问题
|
|
|
+ if (NSArray(array: ["png", "PNG"]).contains(NSString(string: resultPath).pathExtension)) {
|
|
|
+ let items = (FileManager.default.subpaths(atPath: resultPath) ?? []) as [String]
|
|
|
+ for item in items {
|
|
|
+ if NSArray(array: ["jpg", "JPG"]).contains(NSString(string:item).pathExtension) {
|
|
|
+ let path = NSString(string: resultPath).appendingPathComponent(item);
|
|
|
+
|
|
|
+ try? FileManager.default.moveItem(atPath: path,
|
|
|
+ toPath: NSString(string: path).deletingPathExtension+".png");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- convertSemaphore.signal()
|
|
|
}
|
|
|
+
|
|
|
+ complention(status)
|
|
|
}
|
|
|
- convertSemaphore.wait()
|
|
|
-
|
|
|
- return status
|
|
|
}
|
|
|
|
|
|
func testReport() -> NSAttributedString? {
|
|
@@ -381,14 +417,14 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
|
return TestDegreeManager.shared().degreeFor(self.fileType(), type: self.type())
|
|
|
}
|
|
|
|
|
|
-// func testReportOfFile(_ fileName:String) -> NSAttributedString? {
|
|
|
-//
|
|
|
-// }
|
|
|
+ // func testReportOfFile(_ fileName:String) -> NSAttributedString? {
|
|
|
+ //
|
|
|
+ // }
|
|
|
|
|
|
func degreeOfFile(_ fileName:String) -> Double {
|
|
|
return TestDegreeManager.shared().degreeFor(self.fileType(), type: self.type(), fileName: fileName)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
func degreeOfFile(_ fileName:String, refFilePath:String?) -> Double {
|
|
|
if refFilePath != nil {
|
|
|
return TestDegreeManager.shared().degreeFor(self.fileType(), type: self.type(), fileName: fileName, refFilePath: refFilePath)
|
|
@@ -402,14 +438,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)
|
|
@@ -462,13 +498,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)
|
|
@@ -512,13 +548,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)
|
|
@@ -558,7 +594,7 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
|
func compareFiles() -> NSArray? {
|
|
|
let items = NSMutableArray()
|
|
|
let files = DataModel.shared.originFilesFor(_fileType, type: _type) as [String]
|
|
|
-
|
|
|
+
|
|
|
for fileName in files {
|
|
|
let sItems = compareFiles(fileName)
|
|
|
if sItems != nil && sItems!.count != 0 {
|
|
@@ -573,13 +609,13 @@ 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
|
|
|
-// 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)
|
|
@@ -738,3 +774,4 @@ extension AutoTest {
|
|
|
NSString(string: _extention).isEqual(to: object._extention))
|
|
|
}
|
|
|
}
|
|
|
+
|