Skip to content

Commit

Permalink
Web projects can now properly load Gum XML files with UTF8 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Jul 29, 2024
1 parent 654d85c commit d5cadbe
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions RenderingLibrary/SystemManagers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
using Microsoft.Xna.Framework;
using RenderingLibrary.Content;
using ToolsUtilities;
using System.Text;
using System.Net;
using System.Xml.Linq;

#if WEB
using nkast.Wasm.XHR;
using static System.Runtime.InteropServices.JavaScript.JSType;
#endif



Expand Down Expand Up @@ -123,6 +130,7 @@ public void Draw(List<Layer> layers)
Renderer.Draw(this, layers);
}


public void Initialize(GraphicsDevice graphicsDevice, bool fullInstantiation = false)
{
#if NET6_0_OR_GREATER
Expand All @@ -139,15 +147,48 @@ public void Initialize(GraphicsDevice graphicsDevice, bool fullInstantiation = f
fileName = FileManager.MakeRelative(fileName, FileManager.ExeLocation, preserveCase:true);
}
#if WEB
if(fileName.StartsWith("./"))
{
fileName = fileName.Substring(2);
}
#endif
XMLHttpRequest request = new XMLHttpRequest();
var suffix =
"?token=" + DateTime.Now.Ticks;
request.Open("GET", fileName + suffix, false);
request.OverrideMimeType("text/plain; charset=x-user-defined");
request.Send();
if (request.Status == 200)
{
string responseText = request.ResponseText;
var bytes =
System.Text.Encoding.UTF8.GetBytes(responseText);
return new MemoryStream(bytes);
//byte[] buffer = new byte[responseText.Length];
//for (int i = 0; i < responseText.Length; i++)
// buffer[i] = (byte)(responseText[i] & 0xff);
//Stream ms = new MemoryStream(buffer);
//return ms;
}
else
{
throw new IOException("HTTP request failed. Status:" + request.Status);
}
#else
var stream = TitleContainer.OpenStream(fileName);
return stream;
#endif
};
}

Expand All @@ -156,7 +197,7 @@ public void Initialize(GraphicsDevice graphicsDevice, bool fullInstantiation = f
#if WINDOWS_8 || UWP
mPrimaryThreadId = Environment.CurrentManagedThreadId;
#else
mPrimaryThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
mPrimaryThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
#endif

Renderer = new Renderer();
Expand Down

0 comments on commit d5cadbe

Please sign in to comment.