Encapsulate Assembly.GetManifestResourceStream in *.ReflectionCache

This commit is contained in:
YoshiRulz 2020-09-07 22:31:38 +10:00
parent 209fbc6de0
commit e10e139f10
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
5 changed files with 14 additions and 8 deletions

View File

@ -66,20 +66,20 @@ namespace BizHawk.Client.EmuHawk
ShaderChainFrugalizers[i] = new RenderTargetFrugalizer(GL);
}
using (var xml = EmuHawk.ReflectionCache.Asm.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.courier16px.fnt"))
using (var xml = EmuHawk.ReflectionCache.EmbeddedResourceStream("Resources.courier16px.fnt"))
{
using var tex = EmuHawk.ReflectionCache.Asm.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.courier16px_0.png");
using var tex = EmuHawk.ReflectionCache.EmbeddedResourceStream("Resources.courier16px_0.png");
TheOneFont = new StringRenderer(GL, xml, tex);
}
using (var gens =
EmuHawk.ReflectionCache.Asm.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.gens.ttf"))
EmuHawk.ReflectionCache.EmbeddedResourceStream("Resources.gens.ttf"))
{
LoadCustomFont(gens);
}
using (var fceux =
EmuHawk.ReflectionCache.Asm.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.fceux.ttf"))
EmuHawk.ReflectionCache.EmbeddedResourceStream("Resources.fceux.ttf"))
{
LoadCustomFont(fceux);
}

View File

@ -7,14 +7,14 @@ namespace BizHawk.Client.EmuHawk.Properties
internal static class Resources
{
/// <param name="embedPath">Dir separator is '<c>.</c>'. Path is relative to <c>&lt;NS></c>.</param>
private static Bitmap ReadEmbeddedBitmapAt(string embedPath) => new Bitmap(EmuHawk.ReflectionCache.Asm.GetManifestResourceStream($"BizHawk.Client.EmuHawk.{embedPath}"));
private static Bitmap ReadEmbeddedBitmapAt(string embedPath) => new Bitmap(EmuHawk.ReflectionCache.EmbeddedResourceStream(embedPath));
/// <param name="filename">Dir separator is '<c>.</c>'. Filename is relative to <c>&lt;NS>/images</c> and omits <c>.png</c> extension.</param>
/// <remarks>For other file extensions or paths use <see cref="ReadEmbeddedBitmapAt"/>.</remarks>
private static Bitmap ReadEmbeddedBitmap(string filename) => ReadEmbeddedBitmapAt($"images.{filename}.png");
/// <param name="filename">Dir separator is '<c>.</c>'. Filename is relative to <c>&lt;NS>/images</c> and omits <c>.ico</c> extension.</param>
private static Icon ReadEmbeddedIcon(string filename) => new Icon(EmuHawk.ReflectionCache.Asm.GetManifestResourceStream($"BizHawk.Client.EmuHawk.images.{filename}.ico"));
private static Icon ReadEmbeddedIcon(string filename) => new Icon(EmuHawk.ReflectionCache.EmbeddedResourceStream($"images.{filename}.ico"));
internal static readonly Lazy<Bitmap> A78Joystick = new Lazy<Bitmap>(() => ReadEmbeddedBitmap("ControllerImages.A78Joystick"));
internal static readonly Lazy<Bitmap> AppleIIKeyboard = new Lazy<Bitmap>(() => ReadEmbeddedBitmap("ControllerImages.AppleIIKeyboard"));
@ -53,7 +53,7 @@ namespace BizHawk.Client.EmuHawk.Properties
internal static readonly Bitmap BackMore = ReadEmbeddedBitmap("BackMore");
internal static readonly Icon BasicBot = ReadEmbeddedIcon("basicbot");
internal static readonly Bitmap Blank = ReadEmbeddedBitmap("Blank");
internal static readonly Cursor BlankCursor = new Cursor(EmuHawk.ReflectionCache.Asm.GetManifestResourceStream("BizHawk.Client.EmuHawk.images.BlankCursor.cur"));
internal static readonly Cursor BlankCursor = new Cursor(EmuHawk.ReflectionCache.EmbeddedResourceStream("images.BlankCursor.cur"));
internal static readonly Bitmap BlueDown = ReadEmbeddedBitmap("BlueDown");
internal static readonly Bitmap BlueUp = ReadEmbeddedBitmap("BlueUp");
internal static readonly Bitmap Both = ReadEmbeddedBitmap("Both");

View File

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
@ -13,5 +14,7 @@ namespace BizHawk.Client.EmuHawk
public static readonly Assembly Asm = typeof(ReflectionCache).Assembly;
public static Type[] Types => _types.Value;
public static Stream EmbeddedResourceStream(string embedPath) => Asm.GetManifestResourceStream($"BizHawk.Client.EmuHawk.{embedPath}");
}
}

View File

@ -5,7 +5,7 @@ using BizHawk.Common.IOExtensions;
namespace BizHawk.Emulation.Cores.Properties {
internal static class Resources {
/// <param name="embedPath">Dir separator is '<c>.</c>'. Path is relative to <c>&lt;NS></c>.</param>
private static byte[] ReadEmbeddedByteArray(string embedPath) => Emulation.Cores.ReflectionCache.Asm.GetManifestResourceStream($"BizHawk.Emulation.Cores.Resources.{embedPath}").ReadAllBytes();
private static byte[] ReadEmbeddedByteArray(string embedPath) => Emulation.Cores.ReflectionCache.EmbeddedResourceStream($"Resources.{embedPath}").ReadAllBytes();
internal static readonly Lazy<byte[]> CPC_AMSDOS_0_5_ROM = new Lazy<byte[]>(() => ReadEmbeddedByteArray("CPC_AMSDOS_0.5.ROM.gz"));
internal static readonly Lazy<byte[]> CPC_BASIC_1_0_ROM = new Lazy<byte[]>(() => ReadEmbeddedByteArray("CPC_BASIC_1.0.ROM.gz"));

View File

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Reflection;
namespace BizHawk.Emulation.Cores
@ -10,5 +11,7 @@ namespace BizHawk.Emulation.Cores
public static readonly Assembly Asm = typeof(ReflectionCache).Assembly;
public static Type[] Types => _types.Value;
public static Stream EmbeddedResourceStream(string embedPath) => Asm.GetManifestResourceStream($"BizHawk.Emulation.Cores.{embedPath}");
}
}