Browse Source

[php] use new resource encoding (unescaping does not work)

Simon Krajewski 10 years ago
parent
commit
85fdf858fc
2 changed files with 14 additions and 3 deletions
  1. 1 1
      genphp.ml
  2. 13 2
      std/php/_std/haxe/Resource.hx

+ 1 - 1
genphp.ml

@@ -335,7 +335,7 @@ let write_resource dir name data =
 	let rdir = dir ^ "/res" in
 	if not (Sys.file_exists dir) then Unix.mkdir dir 0o755;
 	if not (Sys.file_exists rdir) then Unix.mkdir rdir 0o755;
-	let name = Base64.str_encode name in
+	let name = Codegen.escape_res_name name false in
 	let ch = open_out_bin (rdir ^ "/" ^ name) in
 	output_string ch data;
 	close_out ch

+ 13 - 2
std/php/_std/haxe/Resource.hx

@@ -35,15 +35,26 @@ class Resource {
 		return untyped __call__('dirname', __php__('__FILE__'))+"/../../res";
 	}
 
+	private static function unescapeName( name : String ) : String
+	{
+		var regex = ~/-x([0-9]+)/g;
+		return regex.map(name, function(regex) return String.fromCharCode(Std.parseInt(regex.matched(1))));
+	}
+
+	private static function escapeName( name : String ) : String {
+		var regex = ~/[^A-Za-z0-9_]/g;
+		return regex.map(name, function(v) return '-x' + v.matched(0).charCodeAt(0));
+	}
+
 	static function getPath(name : String) : String {
-		return getDir()+'/'+Base64.encode(Bytes.ofString(name));
+		return getDir()+'/'+escapeName(name);
 	}
 
 	public static function listNames() : Array<String> {
 		var a = sys.FileSystem.readDirectory(getDir());
 		if(a[0] == '.') a.shift();
 		if(a[0] == '..') a.shift();
-		return a.map(function(s) return Base64.decode(s).toString());
+		return a.map(function(s) return unescapeName(s));
 	}
 
 	public static function getString( name : String ) : String {