SpritePacker/SpritePacker/Utilities.cs

49 rader
1.3 KiB
C#

using System;
using System.Dynamic;
using System.Reflection;
using System.IO;
namespace SpritePacker
{
public class Utilities
{
public static string[] GetEmbeddedResourceList()
{
return System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();
}
public static void PrintEnbeddedResourceList()
{
string[] resFiles = GetEmbeddedResourceList();
foreach (string str in resFiles)
Console.WriteLine("[{0}]", str);
}
public static string GetEmbeddedResourceContent(string resourceName)
{
Assembly asm = Assembly.GetCallingAssembly();
Stream stream = asm.GetManifestResourceStream(resourceName);
if(stream == null)
throw new FileNotFoundException($"Error: The embedded resource with the name {resourceName} does not appear to exist.");
StreamReader source = new StreamReader(stream);
string fileContent = source.ReadToEnd();
source.Dispose();
stream.Dispose();
return fileContent;
}
public static DateTime GetProgramBuildDate()
{
Version asmVersion = GetProgramVersion();
return new DateTime(2000, 1, 1).Add(new TimeSpan(
TimeSpan.TicksPerDay * asmVersion.Build +
TimeSpan.TicksPerSecond * asmVersion.Revision * 2
));
}
public static Version GetProgramVersion()
{
return Assembly.GetEntryAssembly().GetName().Version;
}
}
}