resgen.swift/Sources/ToolCore/GeneratorChecker.swift
Thibaut Schmitt efd04299a8
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
Mise à jour des headers des fichiers générés
2022-07-25 09:56:54 +02:00

41 lines
1.5 KiB
Swift

//
// GeneratorChecker.swift
//
//
// Created by Thibaut Schmitt on 22/12/2021.
//
import Foundation
public class GeneratorChecker {
/// Return `true` if inputFile is newer than extensionFile, otherwise `false`
public static func shouldGenerate(force: Bool, inputFilePath: String, extensionFilePath: String) -> Bool {
guard force == false else {
return true
}
// If inputFile is newer that generated extension -> Regenerate
let extensionFileURL = URL(fileURLWithPath: extensionFilePath)
let inputFileURL = URL(fileURLWithPath: inputFilePath)
let extensionRessourceValues = try? extensionFileURL.resourceValues(forKeys: [URLResourceKey.contentModificationDateKey])
let inputFileRessourceValues = try? inputFileURL.resourceValues(forKeys: [URLResourceKey.contentModificationDateKey])
if let extensionModificationDate = extensionRessourceValues?.contentModificationDate,
let inputFileModificationDate = inputFileRessourceValues?.contentModificationDate {
if inputFileModificationDate >= extensionModificationDate {
print("Input file is newer that generated extension.")
return true
} else {
return false
}
}
// ModificationDate not available for both file
print("⚠️ Could not compare file modication date. ⚠️")
return true
}
}