diff --git a/CodeResources.cs b/CodeResources.cs new file mode 100644 index 0000000..a49dc6e --- /dev/null +++ b/CodeResources.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using Serilog; + +namespace ModShardLauncher +{ + internal static class CodeResources + { + private static readonly Lazy> _scripts = new(LoadAllScripts); + public static string GetGML(string name) + { + if (_scripts.Value.TryGetValue(name, out var script)) return script; + + throw new ArgumentException($"GML script '{name}' not found"); + } + private static Dictionary LoadAllScripts() + { + Dictionary scripts = new(); + Assembly assembly = Assembly.GetExecutingAssembly(); + + // Load all .gml resources + IEnumerable resourceNames = assembly.GetManifestResourceNames() + .Where(name => name.EndsWith(".gml")); + foreach (string resourceName in resourceNames) + { + string? scriptName = Path.GetFileNameWithoutExtension(resourceName); + + using Stream? stream = + assembly.GetManifestResourceStream(resourceName) ?? + throw new FileNotFoundException($"GML script '{scriptName}' not found"); + using StreamReader reader = new(stream); + scripts[scriptName.Split('.').Last()] = reader.ReadToEnd(); + } + + return scripts; + } + } +} diff --git a/Controls/GeneralPage.xaml b/Controls/GeneralPage.xaml index 2223692..a5a220c 100644 --- a/Controls/GeneralPage.xaml +++ b/Controls/GeneralPage.xaml @@ -292,7 +292,7 @@