Parcourir la source

Fixed file loading for XNA on Windows Phone 7.

Liquidoodle il y a 12 ans
Parent
commit
b51a110c54
3 fichiers modifiés avec 31 ajouts et 10 suppressions
  1. 12 4
      spine-csharp/src/Atlas.cs
  2. 8 2
      spine-csharp/src/SkeletonJson.cs
  3. 11 4
      spine-xna/src/Util.cs

+ 12 - 4
spine-csharp/src/Atlas.cs

@@ -29,11 +29,12 @@
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *****************************************************************************/
-
+ *****************************************************************************/
+
 using System;
 using System.Collections.Generic;
 using System.IO;
+using System.Reflection;
 
 #if WINDOWS_STOREAPP
 using System.Threading.Tasks;
@@ -64,7 +65,14 @@ namespace Spine {
 		}
 #else
 		public Atlas (String path, TextureLoader textureLoader) {
-			using (StreamReader reader = new StreamReader(path)) {
+
+#if WINDOWS_PHONE
+            Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(path);
+            using (StreamReader reader = new StreamReader(stream))
+            {
+#else
+            using (StreamReader reader = new StreamReader(path)) {
+#endif
 				try {
 					Load(reader, Path.GetDirectoryName(path), textureLoader);
 				} catch (Exception ex) {
@@ -270,4 +278,4 @@ namespace Spine {
 		void Load (AtlasPage page, String path);
 		void Unload (Object texture);
 	}
-}
+}

+ 8 - 2
spine-csharp/src/SkeletonJson.cs

@@ -80,8 +80,14 @@ namespace Spine {
 		}
 #else
 		public SkeletonData ReadSkeletonData (String path) {
-			using (StreamReader reader = new StreamReader(path)) {
-				SkeletonData skeletonData = ReadSkeletonData(reader);
+#if WINDOWS_PHONE
+            Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(path);
+            using (StreamReader reader = new StreamReader(stream))
+            {
+#else
+            using (StreamReader reader = new StreamReader(path)) {
+#endif
+                SkeletonData skeletonData = ReadSkeletonData(reader);
 				skeletonData.name = Path.GetFileNameWithoutExtension(path);
 				return skeletonData;
 			}

+ 11 - 4
spine-xna/src/Util.cs

@@ -29,8 +29,8 @@
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *****************************************************************************/
-
+ *****************************************************************************/
+
 using System;
 using System.IO;
 using Microsoft.Xna.Framework;
@@ -60,7 +60,14 @@ namespace Spine {
 		}
 #else
 		static public Texture2D LoadTexture (GraphicsDevice device, String path) {
-			using (Stream input = new FileStream(path, FileMode.Open, FileAccess.Read)) {
+
+#if WINDOWS_PHONE
+            Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(path);
+            using (Stream input = stream)
+            {
+#else
+            using (Stream input = new FileStream(path, FileMode.Open, FileAccess.Read)) {
+#endif
 				try {
 					return Util.LoadTexture(device, input);
 				} catch (Exception ex) {
@@ -74,4 +81,4 @@ namespace Spine {
 			return Texture2D.FromStream(device, input);
 		}
 	}
-}
+}