using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

namespace OmicronMountMusicFixer.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();
		}
	}
}
