92 строки
2.7 KiB
C#
92 строки
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Markup;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
namespace SpritePacker
|
|
{
|
|
enum ProgramMode
|
|
{
|
|
Normal,
|
|
DisplayHelpText,
|
|
DisplayVersionText
|
|
};
|
|
|
|
class Program
|
|
{
|
|
public static string Version = Utilities.GetEmbeddedResourceContent("SpritePacker.Version.txt").Trim();
|
|
|
|
private static ProgramMode programMode = ProgramMode.Normal;
|
|
private static string helpTextFilename = "SpritePacker.Resources.HelpText.txt";
|
|
private static string versionTextFilename = "SpritePacker.Resources.VersionText.txt";
|
|
private static string commitHashFilename = "SpritePacker.latest-commit-hash.txt";
|
|
private static List<string> values = new List<string>();
|
|
|
|
public static int Main(string[] args)
|
|
{
|
|
string commitHash = Utilities.GetEmbeddedResourceContent(commitHashFilename).Trim();
|
|
Version += "-" + commitHash.Substring(commitHash.Length - 7);
|
|
|
|
for(int i = 0; i < args.Length; i++)
|
|
{
|
|
switch(args[i])
|
|
{
|
|
case "--help":
|
|
programMode = ProgramMode.DisplayHelpText;
|
|
break;
|
|
case "--version":
|
|
programMode = ProgramMode.DisplayVersionText;
|
|
break;
|
|
default:
|
|
if(args[i].StartsWith("-"))
|
|
{
|
|
Console.Error.WriteLine("Error: Unrecognised flag '{0}'.", args[i]);
|
|
return 1;
|
|
}
|
|
values.Add(args[i]);
|
|
break;
|
|
}
|
|
}
|
|
|
|
switch(programMode)
|
|
{
|
|
case ProgramMode.Normal:
|
|
RunNormal();
|
|
break;
|
|
case ProgramMode.DisplayHelpText:
|
|
case ProgramMode.DisplayVersionText:
|
|
string textFileName = programMode == ProgramMode.DisplayHelpText ? helpTextFilename : versionTextFilename;
|
|
string helpText = Utilities.GetEmbeddedResourceContent(textFileName);
|
|
Dictionary<string, string> templateValues = new Dictionary<string, string>() {
|
|
{ "version", Version },
|
|
{ "build-date", Utilities.GetProgramBuildDate().ToString("dd/MM/yyyy h:mmtt") },
|
|
{ "commit-hash", commitHash.Substring(commitHash.Length - 7) },
|
|
{ "commit-url", string.Format("https://git.starbeamrainbowlabs.com/sbrl/SpritePacker/commit/{0}", commitHash) }
|
|
};
|
|
foreach (KeyValuePair<string, string> replacePair in templateValues)
|
|
helpText = helpText.Replace(string.Format("{{{0}}}", replacePair.Key), replacePair.Value);
|
|
|
|
Console.WriteLine(helpText);
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
public static void RunNormal()
|
|
{
|
|
Packer spritePacker = new Packer();
|
|
foreach(string filename in values)
|
|
{
|
|
if (File.Exists(filename))
|
|
spritePacker.Add(new Sprite(filename));
|
|
else
|
|
Console.Error.WriteLine("Warning: Ignoring non-existent file '{0}'.", filename);
|
|
}
|
|
spritePacker.Arrange();
|
|
Console.WriteLine(spritePacker.ToString());
|
|
}
|
|
}
|
|
}
|