浏览代码

minor fixes

ncannasse 9 年之前
父节点
当前提交
5fabf81eab
共有 2 个文件被更改,包括 29 次插入38 次删除
  1. 5 3
      hxd/fs/EmbedFileSystem.hx
  2. 24 35
      hxd/fs/LocalFileSystem.hx

+ 5 - 3
hxd/fs/EmbedFileSystem.hx

@@ -228,14 +228,16 @@ class EmbedFileSystem #if !macro implements FileSystem #end {
 			r = Reflect.field(r, p);
 		if( r == null )
 			throw path + " is not a directory";
-		return [for( name in Reflect.fields(r) ) get(path == "." ? name : path + "/" + name)];
+		var fields = Reflect.fields(r);
+		fields.sort(Reflect.compare);
+		return [for( name in fields ) get(path == "." ? name : path + "/" + name)];
 	}
 
 	function isDirectory( path : String ) {
-		var r = root;
+		var r : Dynamic = root;
 		for( p in splitPath(path) )
 			r = Reflect.field(r, p);
-		return r != null;
+		return r != null && r != true;
 	}
 
 	public function exists( path : String ) {

+ 24 - 35
hxd/fs/LocalFileSystem.hx

@@ -198,12 +198,13 @@ private class LocalEntry extends FileEntry {
 		#end
 	}
 
-	override function get_isDirectory() {
+	var isDirCached : Null<Bool>;
+	override function get_isDirectory() : Bool {
+		if( isDirCached != null ) return isDirCached;
 		#if air3
-		return file.isDirectory;
+		return isDirCached = file.isDirectory;
 		#else
-		throw "TODO";
-		return false;
+		return isDirCached = sys.FileSystem.isDirectory(file);
 		#end
 	}
 
@@ -259,8 +260,10 @@ private class LocalEntry extends FileEntry {
 			switch( f.name ) {
 			case ".svn", ".git" if( f.isDirectory ):
 				continue;
+			case ".tmp" if( this == fs.root ):
+				continue;
 			default:
-				arr.push(new LocalEntry(fs, f.name, relPath == null ? f.name : relPath + "/" + f.name, f));
+				arr.push(fs.open(relPath == null ? f.name : relPath + "/" + f.name,false));
 			}
 		return new hxd.impl.ArrayIterator(arr);
 		#else
@@ -269,8 +272,10 @@ private class LocalEntry extends FileEntry {
 			switch( f ) {
 			case ".svn", ".git" if( sys.FileSystem.isDirectory(file+"/"+f) ):
 				continue;
+			case ".tmp" if( this == fs.root ):
+				continue;
 			default:
-				arr.push(new LocalEntry(fs, f, relPath == null ? f : relPath + "/" + f, file+"/"+f));
+				arr.push(fs.open(relPath == null ? f : relPath + "/" + f,false));
 			}
 		}
 		return new hxd.impl.ArrayIterator(arr);
@@ -338,9 +343,7 @@ private class LocalEntry extends FileEntry {
 class LocalFileSystem implements FileSystem {
 
 	var root : FileEntry;
-	#if air3
-	var fileCache = new Map<String,{r:flash.filesystem.File}>();
-	#end
+	var fileCache = new Map<String,{r:LocalEntry}>();
 	public var baseDir(default,null) : String;
 	var createHMD : Bool = true;
 	public var createMP3 : Bool;
@@ -376,54 +379,40 @@ class LocalFileSystem implements FileSystem {
 		return root;
 	}
 
-	function open( path : String ) {
-		#if air3
+	function open( path : String, check = true ) {
 		var r = fileCache.get(path);
 		if( r != null )
 			return r.r;
+		var e = null;
+		#if air3
 		var f = new flash.filesystem.File(baseDir + path);
 		// ensure exact case / no relative path
-		f.canonicalize();
-		if( !f.exists || f.nativePath.split("\\").join("/") != baseDir + path )
-			f = null;
-		fileCache.set(path, { r:f } );
-		return f;
+		if( check ) f.canonicalize();
+		if( !check || (f.exists && f.nativePath.split("\\").join("/") == baseDir + path) )
+			e = new LocalEntry(this, path.split("/").pop(), path, f);
 		#else
 		var f = sys.FileSystem.fullPath(baseDir + path).split("\\").join("/");
-		if( f != baseDir + path )
-			return null;
-		return f;
+		if( !check || (f == baseDir + path && sys.FileSystem.exists(f)) )
+			e = new LocalEntry(this, path.split("/").pop(), path, f);
 		#end
+		fileCache.set(path, {r:e});
+		return e;
 	}
 
 	public function exists( path : String ) {
-		#if air3
 		var f = open(path);
 		return f != null;
-		#else
-		var f = open(path);
-		return f != null && sys.FileSystem.exists(f);
-		#end
 	}
 
 	public function get( path : String ) {
-		#if air3
 		var f = open(path);
-		if( f == null || !f.exists )
+		if( f == null )
 			throw new NotFound(path);
-		return new LocalEntry(this, path.split("/").pop(), path, f);
-		#else
-		var f = open(path);
-		if( f == null ||!sys.FileSystem.exists(f) )
-			throw new NotFound(path);
-		return new LocalEntry(this, path.split("/").pop(), path, f);
-		#end
+		return f;
 	}
 
 	public function dispose() {
-		#if air3
 		fileCache = new Map();
-		#end
 	}
 
 }