Browse Source

[cs] move haxe.Resource implementation into a target-specific folder

Dan Korostelev 11 years ago
parent
commit
7fd46b1d09
2 changed files with 65 additions and 35 deletions
  1. 62 0
      std/cs/_std/haxe/Resource.hx
  2. 3 35
      std/haxe/Resource.hx

+ 62 - 0
std/cs/_std/haxe/Resource.hx

@@ -0,0 +1,62 @@
+/*
+ * Copyright (C)2005-2014 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe;
+
+@:coreApi class Resource {
+
+	@:keep static var content : Array<String>;
+	static var paths : Map<String,String>;
+
+	@:keep static function getPaths():Map<String,String> {
+		if (paths != null)
+			return paths;
+
+		var p = new Map();
+		var all = cs.Lib.toNativeType(haxe.Resource).Assembly.GetManifestResourceNames();
+		for (i in 0...all.Length) {
+			var path = all[i];
+			var name = path.substr(path.indexOf("Resources.") + 10);
+			p.set(name, path);
+		}
+		return paths = p;
+	}
+
+	public static inline function listNames() : Array<String> {
+		return content.copy();
+	}
+
+	public static function getString( name : String ) : String {
+		var path = getPaths().get(name);
+		var str = cs.Lib.toNativeType(haxe.Resource).Assembly.GetManifestResourceStream(path);
+		if (str != null)
+			return new cs.io.NativeInput(str).readAll().toString();
+		return null;
+	}
+
+	public static function getBytes( name : String ) : haxe.io.Bytes {
+		var path = getPaths().get(name);
+		var str = cs.Lib.toNativeType(haxe.Resource).Assembly.GetManifestResourceStream(path);
+		if (str != null)
+			return new cs.io.NativeInput(str).readAll();
+		return null;
+	}
+}

+ 3 - 35
std/haxe/Resource.hx

@@ -36,7 +36,7 @@ import haxe.io.BytesData;
 **/
 class Resource {
 
-	#if (java || cs)
+	#if java
 	@:keep static var content : Array<String>;
 	#elseif python
 	static var content : python.lib.Dict<String, BytesData>;
@@ -44,33 +44,13 @@ class Resource {
 	static var content : Array<{ name : String, data : String, str : String }>;
 	#end
 
-	#if cs
-	static var paths : haxe.ds.StringMap<String>;
-
-	#if cs @:keep #end private static function getPaths():haxe.ds.StringMap<String>
-	{
-		if (paths != null)
-			return paths;
-		var p = new haxe.ds.StringMap();
-		var all = cs.Lib.toNativeType(haxe.Resource).Assembly.GetManifestResourceNames();
-		for (i in 0...all.Length)
-		{
-			var path = all[i];
-			var name = path.substr(path.indexOf("Resources.") + 10);
-			p.set(name, path);
-		}
-
-		return paths = p;
-	}
-	#end
-
 	/**
 		Lists all available resource names. The resource name is the name part
 		of the -resource file@name command line parameter.
 	**/
 	public static function listNames() : Array<String> {
 		var names = new Array();
-		#if (java || cs)
+		#if java
 		for ( x in content )
 			names.push(x);
 		#elseif python
@@ -95,12 +75,6 @@ class Resource {
 			return null;
 		var stream = new java.io.NativeInput(stream);
 		return stream.readAll().toString();
-		#elseif cs
-		var path = getPaths().get(name);
-		var str = cs.Lib.toNativeType(haxe.Resource).Assembly.GetManifestResourceStream(path);
-		if (str != null)
-			return new cs.io.NativeInput(str).readAll().toString();
-		return null;
 		#elseif python
         #if embed_resources
 		for( k in content.keys().iter() )
@@ -141,12 +115,6 @@ class Resource {
 			return null;
 		var stream = new java.io.NativeInput(stream);
 		return stream.readAll();
-		#elseif cs
-		var path = getPaths().get(name);
-		var str = cs.Lib.toNativeType(haxe.Resource).Assembly.GetManifestResourceStream(path);
-		if (str != null)
-			return new cs.io.NativeInput(str).readAll();
-		return null;
 		#elseif python
         #if embed_resources
 		for( k in content.keys().iter() )
@@ -180,7 +148,7 @@ class Resource {
 		content = null;
 		#elseif as3
 		null;
-		#elseif (java || cs)
+		#elseif java
 		//do nothing
 		#elseif python
 		content = untyped _hx_resources__();