Selaa lähdekoodia

Add version for converts (#722)

Pavel Alexandrov 5 vuotta sitten
vanhempi
commit
2230a87988
2 muutettua tiedostoa jossa 12 lisäystä ja 4 poistoa
  1. 6 0
      hxd/fs/Convert.hx
  2. 6 4
      hxd/fs/FileConverter.hx

+ 6 - 0
hxd/fs/Convert.hx

@@ -6,6 +6,11 @@ class Convert {
 	public var sourceExt(default,null) : String;
 	public var destExt(default,null) : String;
 
+	/**
+		Major version of the Convert.
+		When incremented, all files processed by this Convert would be rebuilt. **/
+	public var version(default, null) : Int;
+
 	public var params : Dynamic;
 
 	public var srcPath : String;
@@ -16,6 +21,7 @@ class Convert {
 	public function new( sourceExt, destExt ) {
 		this.sourceExt = sourceExt;
 		this.destExt = destExt;
+		this.version = 0;
 	}
 
 	public function convert() {

+ 6 - 4
hxd/fs/FileConverter.hx

@@ -30,7 +30,7 @@ class FileConverter {
 	var tmpDir : String;
 	var configs : Map<String,ConvertConfig> = new Map();
 	var defaultConfig : ConvertConfig;
-	var cache : Map<String,Array<{ out : String, time : Int, hash : String  }>>;
+	var cache : Map<String,Array<{ out : String, time : Int, hash : String, ver : Null<Int> }>>;
 
 	public function new(baseDir,configuration) {
 		this.baseDir = baseDir;
@@ -218,6 +218,7 @@ class FileConverter {
 		for( e in entry ) {
 			if( e.out == outFile ) {
 				match = e;
+				if (match.ver == null) match.ver = 0;
 				break;
 			}
 		}
@@ -226,6 +227,7 @@ class FileConverter {
 				out : outFile,
 				time : 0,
 				hash : "",
+				ver: conv.version,
 			};
 			entry.push(match);
 		}
@@ -235,14 +237,14 @@ class FileConverter {
 		if( !sys.FileSystem.exists(fullPath) ) throw "Missing "+fullPath;
 
 		var time = std.Math.floor(getFileTime(fullPath) / 1000);
-		var alreadyGen = sys.FileSystem.exists(fullOutPath);
+		var alreadyGen = sys.FileSystem.exists(fullOutPath) && match.ver == conv.version #if disable_res_cache && false #end;
 
-		if( match.time == time && alreadyGen )
+		if( alreadyGen && match.time == time )
 			return; // not changed (time stamp)
 
 		var content = hxd.File.getBytes(fullPath);
 		var hash = haxe.crypto.Sha1.make(content).toHex();
-		if( match.hash == hash && alreadyGen ) {
+		if( alreadyGen && match.hash == hash ) {
 			match.time = time;
 			saveCache();
 			return; // not changed (hash)