فهرست منبع

fix for files starting with underscore

ncannasse 11 سال پیش
والد
کامیت
6cc577c68e
1فایلهای تغییر یافته به همراه18 افزوده شده و 16 حذف شده
  1. 18 16
      hxd/res/FileTree.hx

+ 18 - 16
hxd/res/FileTree.hx

@@ -5,7 +5,7 @@ import haxe.macro.Expr;
 private typedef FileEntry = { e : Expr, t : ComplexType };
 
 class FileTree {
-	
+
 	var path : String;
 	var currentModule : String;
 	var pos : Position;
@@ -18,7 +18,7 @@ class FileTree {
 	var isJS : Bool;
 	var isCPP : Bool;
 	var embedTypes : Array<String>;
-	
+
 	public function new(dir) {
 		this.path = resolvePath(dir);
 		currentModule = Std.string(Context.getLocalClass());
@@ -36,7 +36,7 @@ class FileTree {
 		isJS = Context.defined("js");
 		isCPP = Context.defined("cpp");
 	}
-	
+
 	public static function resolvePath( ?dir:String ) {
 		var resolve = true;
 		if( dir == null ) {
@@ -51,7 +51,7 @@ class FileTree {
 			Context.error("Resource directory does not exists '" + path + "'", pos);
 		return path;
 	}
-	
+
 	public function embed(options:EmbedOptions) {
 		if( options == null ) options = { };
 		var needTmp = options.compressSounds;
@@ -62,7 +62,7 @@ class FileTree {
 		embedTypes = [];
 		return { tree : embedRec(""), types : embedTypes };
 	}
-	
+
 	function embedRec( relPath : String ) {
 		var dir = this.path + relPath;
 		var data = { };
@@ -88,22 +88,22 @@ class FileTree {
 		}
 		return data;
 	}
-	
+
 	function embedDir( dir : String, relPath : String, fullPath : String ) {
 		var f = embedRec(relPath);
 		if( Reflect.fields(f).length == 0 )
 			return null;
 		return f;
 	}
-	
+
 	function getTime( file : String ) {
 		return try sys.FileSystem.stat(file).mtime.getTime() catch( e : Dynamic ) -1.;
 	}
-	
+
 	static var invalidChars = ~/[^A-Za-z0-9_]/g;
 	function embedFile( file : String, ext : String, relPath : String, fullPath : String ) {
 		var name = "R" + invalidChars.replace(relPath, "_");
-		
+
 		switch( ext.toLowerCase() ) {
 		case "wav" if( options.compressSounds ):
 			var tmp = options.tmpDir + name + ".mp3";
@@ -133,7 +133,7 @@ class FileTree {
 			fullPath = tmp;
 		default:
 		}
-		
+
 		if( isFlash ) {
 			switch( ext.toLowerCase() ) {
 			case "ttf":
@@ -165,7 +165,7 @@ class FileTree {
 		}
 		return true;
 	}
-	
+
 	public function scan() {
 		var fields = Context.getBuildFields();
 		var dict = new Map();
@@ -203,7 +203,7 @@ class FileTree {
 		scanRec("", fields, dict);
 		return fields;
 	}
-	
+
 	function scanRec( relPath : String, fields : Array<Field>, dict : Map<String,{path:String,field:Field,fget:Field}> ) {
 		var dir = this.path + (relPath == "" ? "" : "/" + relPath);
 		// make sure to rescan if one of the directories content has changed (file added or deleted)
@@ -244,6 +244,8 @@ class FileTree {
 			}
 			if( field != null ) {
 				var fname = invalidChars.replace(f, "_");
+				if( fname.charCodeAt(0) >= "0".code && fname.charCodeAt(0) <= "9".code )
+					fname = "_" + fname;
 				var other = dict.get(fname);
 				if( other != null ) {
 					var pe = pairedExt.get(other.path.split(".").pop().toLowerCase());
@@ -288,7 +290,7 @@ class FileTree {
 			}
 		}
 	}
-	
+
 	function handleDir( dir : String, relPath : String, fullPath : String ) : FileEntry {
 		var ofields = [];
 		var dict = new Map();
@@ -322,7 +324,7 @@ class FileTree {
 			e : { expr : ENew(tpath, [macro loader]), pos : pos },
 		};
 	}
-	
+
 	function handleFile( file : String, ext : String, relPath : String, fullPath : String ) : FileEntry {
 		var epath = { expr : EConst(CString(relPath)), pos : pos };
 		switch( ext.toLowerCase() ) {
@@ -345,9 +347,9 @@ class FileTree {
 		}
 		return null;
 	}
-	
+
 	public static function build( ?dir : String ) {
 		return new FileTree(dir).scan();
 	}
-	
+
 }