Refactor main program to add support for version text.
This commit is contained in:
parent
6c2747001b
commit
1174882a75
4 changed files with 51 additions and 18 deletions
|
@ -6,38 +6,65 @@ using System.Reflection;
|
||||||
|
|
||||||
namespace SpritePacker
|
namespace SpritePacker
|
||||||
{
|
{
|
||||||
|
enum ProgramMode
|
||||||
|
{
|
||||||
|
Normal,
|
||||||
|
DisplayHelpText,
|
||||||
|
DisplayVersionText
|
||||||
|
};
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
private static ProgramMode programMode = ProgramMode.Normal;
|
||||||
|
private static string helpTextFilename = "SpritePacker.Resources.HelpText.txt";
|
||||||
|
private static string versionTextFilename = "SpritePacker.Resources.VersionText.txt";
|
||||||
|
private static List<string> values = new List<string>();
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Utilities.GetProgramBuildDate();
|
|
||||||
List<string> values = new List<string>();
|
|
||||||
for(int i = 0; i < args.Length; i++)
|
for(int i = 0; i < args.Length; i++)
|
||||||
{
|
{
|
||||||
switch(args[i])
|
switch(args[i])
|
||||||
{
|
{
|
||||||
case "--help":
|
case "--help":
|
||||||
string helpText = Utilities.GetEmbeddedResourceContent("SpritePacker.Resources.Help.txt");
|
programMode = ProgramMode.DisplayHelpText;
|
||||||
string commitHash = Utilities.GetEmbeddedResourceContent("SpritePacker.latest-commit-hash.txt").Trim();
|
break;
|
||||||
Dictionary<string, string> templateValues = new Dictionary<string, string>() {
|
|
||||||
{ "version", Utilities.GetProgramVersion().ToString() },
|
|
||||||
{ "build-time", Utilities.GetProgramBuildDate().ToString("dd/MM/yyyy h:mmtt") },
|
|
||||||
{ "commit-hash", commitHash.Substring(commitHash.Length - 7) }
|
|
||||||
};
|
|
||||||
foreach (KeyValuePair<string, string> replacePair in templateValues)
|
|
||||||
helpText = helpText.Replace(string.Format("{{{0}}}", replacePair.Key), replacePair.Value);
|
|
||||||
|
|
||||||
Console.WriteLine(helpText);
|
|
||||||
return;
|
|
||||||
case "--version":
|
case "--version":
|
||||||
Console.WriteLine("Version text coming soon!");
|
programMode = ProgramMode.DisplayVersionText;
|
||||||
return;
|
break;
|
||||||
default:
|
default:
|
||||||
values.Add(args[i]);
|
values.Add(args[i]);
|
||||||
break;
|
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);
|
||||||
|
string commitHash = Utilities.GetEmbeddedResourceContent("SpritePacker.latest-commit-hash.txt").Trim();
|
||||||
|
Dictionary<string, string> templateValues = new Dictionary<string, string>() {
|
||||||
|
{ "version", Utilities.GetProgramVersion().ToString() },
|
||||||
|
{ "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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RunNormal()
|
||||||
|
{
|
||||||
Packer spritePacker = new Packer();
|
Packer spritePacker = new Packer();
|
||||||
foreach(string filename in values)
|
foreach(string filename in values)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
SpritePacker v{version}, by Starbeamrainbowlabs
|
SpritePacker v{version}, by Starbeamrainbowlabs
|
||||||
Built at {build-time} from git commit {commit-hash}
|
Built at {build-date} from git commit {commit-hash}
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
mono ./SpritePacker.exe [flags] [filenames]
|
mono ./SpritePacker.exe [flags] [filenames]
|
5
SpritePacker/Resources/VersionText.txt
Normal file
5
SpritePacker/Resources/VersionText.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
SpritePacker v{version}, by Starbeamrainbowlabs
|
||||||
|
|
||||||
|
Built at {build-date}
|
||||||
|
Built from git commit hash {commit-hash}
|
||||||
|
Commit url: {commit-url}
|
|
@ -45,8 +45,9 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Resources\Help.txt" />
|
|
||||||
<EmbeddedResource Include="latest-commit-hash.txt" />
|
<EmbeddedResource Include="latest-commit-hash.txt" />
|
||||||
|
<EmbeddedResource Include="Resources\VersionText.txt" />
|
||||||
|
<EmbeddedResource Include="Resources\HelpText.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Resources\" />
|
<Folder Include="Resources\" />
|
||||||
|
|
Loading…
Reference in a new issue