catastropy averted?
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace MultiboxMutexer.dll.Resourcer;
|
||||
|
||||
[StructLayout(LayoutKind.Auto, CharSet = CharSet.Auto)]
|
||||
internal static class ResourceHelper
|
||||
{
|
||||
private static Assembly assembly;
|
||||
|
||||
static ResourceHelper()
|
||||
{
|
||||
assembly = typeof(ResourceHelper).GetTypeInfo().Assembly;
|
||||
}
|
||||
|
||||
public static Stream AsStream(string P_0)
|
||||
{
|
||||
return assembly.GetManifestResourceStream(P_0);
|
||||
}
|
||||
|
||||
public static StreamReader AsStreamReader(string P_0)
|
||||
{
|
||||
Stream manifestResourceStream = assembly.GetManifestResourceStream(P_0);
|
||||
if (manifestResourceStream == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new StreamReader(manifestResourceStream);
|
||||
}
|
||||
|
||||
public static string AsString(string P_0)
|
||||
{
|
||||
StreamReader streamReader = null;
|
||||
Stream stream = null;
|
||||
try
|
||||
{
|
||||
stream = assembly.GetManifestResourceStream(P_0);
|
||||
if (stream == null)
|
||||
{
|
||||
throw new Exception("Could not find a resource named '" + P_0 + "'.");
|
||||
}
|
||||
streamReader = new StreamReader(stream);
|
||||
return streamReader.ReadToEnd();
|
||||
}
|
||||
finally
|
||||
{
|
||||
streamReader?.Dispose();
|
||||
stream?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user