Переглянути джерело

fix saveBytesAir with relative path

ncannasse 11 роки тому
батько
коміт
b34aaad03a
1 змінених файлів з 7 додано та 2 видалено
  1. 7 2
      hxd/File.hx

+ 7 - 2
hxd/File.hx

@@ -29,6 +29,11 @@ class File {
 	#end
 	#end
 
 
 	#if air3
 	#if air3
+
+	static function getRelPath( path : String ) {
+		return try new flash.filesystem.File(path) catch( e : Dynamic ) new flash.filesystem.File(flash.filesystem.File.applicationDirectory.nativePath + "/" + path);
+	}
+
 	static function browseAir( onSelect : BrowseSelect -> Void, options : BrowseOptions, filters ) {
 	static function browseAir( onSelect : BrowseSelect -> Void, options : BrowseOptions, filters ) {
 		var f = flash.filesystem.File.applicationDirectory;
 		var f = flash.filesystem.File.applicationDirectory;
 		if( options.defaultPath != null )
 		if( options.defaultPath != null )
@@ -138,7 +143,7 @@ class File {
 
 
 	public static function getBytes( path : String ) : haxe.io.Bytes {
 	public static function getBytes( path : String ) : haxe.io.Bytes {
 		#if air3
 		#if air3
-		var file = try new flash.filesystem.File(path) catch( e : Dynamic ) new flash.filesystem.File(flash.filesystem.File.applicationDirectory.nativePath + "/" + path);
+		var file = getRelPath(path);
 		if( !file.exists ) throw "File not found " + path;
 		if( !file.exists ) throw "File not found " + path;
 		var fs = new flash.filesystem.FileStream();
 		var fs = new flash.filesystem.FileStream();
 		fs.open(file, flash.filesystem.FileMode.READ);
 		fs.open(file, flash.filesystem.FileMode.READ);
@@ -157,7 +162,7 @@ class File {
 	#if air3
 	#if air3
 	static function saveBytesAir( path : String, data : haxe.io.Bytes ) {
 	static function saveBytesAir( path : String, data : haxe.io.Bytes ) {
 		if( path == null ) throw "NULL path";
 		if( path == null ) throw "NULL path";
-		var f = new flash.filesystem.File(path);
+		var f = getRelPath(path);
 		var o = new flash.filesystem.FileStream();
 		var o = new flash.filesystem.FileStream();
 		o.open(f, flash.filesystem.FileMode.WRITE);
 		o.open(f, flash.filesystem.FileMode.WRITE);
 		o.writeBytes(data.getData());
 		o.writeBytes(data.getData());