Browse Source

Polish CLI and add Utilities class.

tags/v0.1
Starbeamrainbowlabs 3 years ago
parent
commit
a67f5bbef8
6 changed files with 71 additions and 14 deletions
  1. +3
    -0
      .gitignore
  2. +1
    -0
      SpritePacker.sln
  3. +2
    -1
      SpritePacker/Help.txt
  4. +12
    -12
      SpritePacker/Program.cs
  5. +6
    -1
      SpritePacker/SpritePacker.csproj
  6. +47
    -0
      SpritePacker/Utilities.cs

+ 3
- 0
.gitignore View File

@@ -1,3 +1,6 @@
# Custom Items
latest-commit-hash.txt

# ---> C Sharp
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/

+ 1
- 0
SpritePacker.sln View File

@@ -6,6 +6,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5C9D36DD-3962-45BF-938E-BE1E258053EC}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
.gitignore = .gitignore
EndProjectSection
EndProject
Global

+ 2
- 1
SpritePacker/Help.txt View File

@@ -1,4 +1,5 @@
SpritePacker, by Starbeamrainbowlabs
SpritePacker v{version}, by Starbeamrainbowlabs
Built at {build-time} from git commit {commit-hash}

Usage:
mono ./SpritePacker.exe [flags] [filenames]

+ 12
- 12
SpritePacker/Program.cs View File

@@ -10,24 +10,24 @@ namespace SpritePacker
{
public static void Main(string[] args)
{
Utilities.GetProgramBuildDate();
List<string> values = new List<string>();
for(int i = 0; i < args.Length; i++)
{
switch(args[i])
{
case "--help":
/*
string[] resFiles = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();
foreach (string str in resFiles)
Console.WriteLine("[{0}]", str);
*/

Assembly asm = Assembly.GetExecutingAssembly();
Stream stream = asm.GetManifestResourceStream("SpritePacker.Help.txt");
StreamReader source = new StreamReader(stream);
Console.Write(source.ReadToEnd());
source.Dispose();
stream.Dispose();
string helpText = Utilities.GetEmbeddedResourceContent("SpritePacker.Help.txt");
string commitHash = Utilities.GetEmbeddedResourceContent("SpritePacker.latest-commit-hash.txt").Trim();
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":
Console.WriteLine("Version text coming soon!");

+ 6
- 1
SpritePacker/SpritePacker.csproj View File

@@ -29,6 +29,9 @@
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent>git rev-parse HEAD &gt;../../latest-commit-hash.txt</PreBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
@@ -38,9 +41,11 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Packer.cs" />
<Compile Include="Sprite.cs" />
<Compile Include="Utilities.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<EmbeddedResource Include="Help.txt" />
<EmbeddedResource Include="latest-commit-hash.txt" />
</ItemGroup>
</Project>
</Project>

+ 47
- 0
SpritePacker/Utilities.cs View File

@@ -0,0 +1,47 @@
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.GetExecutingAssembly();
Stream stream = asm.GetManifestResourceStream(resourceName);
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;
}
}
}

Loading…
Cancel
Save