#region usings using System.Collections.Generic; using System.IO; using System.Reflection; #endregion namespace SM.OGL.Shaders { /// /// Holder for shader extensions /// public class ShaderExtensions { /// /// Holds the extensions. /// public static Dictionary Extensions { get; private set; } = new Dictionary(); /// /// Adds extensions from the calling assembly /// /// Prefix for the added extensions. /// Path, where the extensions are located. public static void AddAssemblyExtensions(string prefix, string path) { AddAssemblyExtensions(prefix, Assembly.GetCallingAssembly(), path); } /// /// Adds extensions from the specific assembly /// /// Prefix for the added extensions. /// The specific assembly /// Path, where the extensions are located. public static void AddAssemblyExtensions(string prefix, Assembly assembly, string path) { var paths = assembly.GetManifestResourceNames(); for (var i = 0; i < paths.Length; i++) { var filePath = paths[i]; if (!filePath.StartsWith(path)) continue; using (var reader = new StreamReader(assembly.GetManifestResourceStream(filePath))) { var name = $"{prefix}{Path.GetFileNameWithoutExtension(filePath.Substring(path.Length)).Replace('.', '_')}"; if (Extensions.ContainsKey(name)) continue; Extensions.Add(name, new ShaderFile(reader.ReadToEnd())); } } } } }