Utilise embedded git commit.
This commit is contained in:
parent
6b4a968b87
commit
d6c8ade2fc
7 changed files with 264 additions and 62 deletions
2
cscz.sln
2
cscz.sln
|
@ -27,6 +27,6 @@ Global
|
|||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
description = The C# Class Generator.
|
||||
version = 0.2
|
||||
version = 0.4
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
cscz - The C# Class Generator, v0.3
|
||||
cscz - The C# Class Generator, {version}
|
||||
By Starbeamrainbowlabs (@SBRLabs)
|
||||
Built from https://git.starbeamrainbowlabs.com/sbrl/cscz/
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ using System.Diagnostics;
|
|||
using System.Reflection;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using SBRLUtilities;
|
||||
using System.Security.Policy;
|
||||
|
||||
namespace cscz
|
||||
{
|
||||
|
@ -25,13 +27,8 @@ namespace cscz
|
|||
switch(args[i].Trim('-'))
|
||||
{
|
||||
case "help":
|
||||
Assembly asm = Assembly.GetExecutingAssembly();
|
||||
/*** Debug - Lists the names of all embedded resources ***
|
||||
foreach(string str in asm.GetManifestResourceNames())
|
||||
Console.WriteLine(str);*/
|
||||
StreamReader helpTextReader = new StreamReader(asm.GetManifestResourceStream(@"cscz.Help.md"));
|
||||
string helpText = helpTextReader.ReadToEnd();
|
||||
helpTextReader.Dispose();
|
||||
string helpText = EmbeddedFiles.ReadAllText(@"cscz.Help.md");
|
||||
helpText = helpText.Replace("{version}", Utilities.GetVersionText());
|
||||
Console.WriteLine(helpText);
|
||||
return 0;
|
||||
case "private":
|
||||
|
|
|
@ -17,7 +17,7 @@ using System.Runtime.CompilerServices;
|
|||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.4.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
|
171
cscz/SBRLUtilities/EmbeddedFiles.cs
Normal file
171
cscz/SBRLUtilities/EmbeddedFiles.cs
Normal file
|
@ -0,0 +1,171 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using System.Net.Configuration;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SBRLUtilities
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of static methods for manipulating embedded resources.
|
||||
/// </summary>
|
||||
/// <description>
|
||||
/// v0.2, by Starbeamrainbowlabs <feedback@starbeamrainbowlabs.com>
|
||||
/// Last updated 8th August 2016.
|
||||
/// Licensed under MPL-2.0.
|
||||
///
|
||||
/// Changelog:
|
||||
/// v0.1 (25th July 2016):
|
||||
/// - Initial release.
|
||||
/// v0.2 (8th August 2016):
|
||||
/// - Changed namespace.
|
||||
/// </description>
|
||||
public static class EmbeddedFiles
|
||||
{
|
||||
/// <summary>
|
||||
/// An array of the filenames of all the resources embedded in the calling assembly.
|
||||
/// </summary>
|
||||
/// <value>The resource list.</value>
|
||||
public static string[] ResourceList { get {
|
||||
return Assembly.GetCallingAssembly().GetManifestResourceNames();
|
||||
}}
|
||||
|
||||
public static string GetResourceListText()
|
||||
{
|
||||
StringWriter result = new StringWriter();
|
||||
result.WriteLine("Files embedded in {0}:", Assembly.GetCallingAssembly().GetName().Name);
|
||||
foreach (string filename in ResourceList)
|
||||
result.WriteLine(" - {0}", filename);
|
||||
return result.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// Writes a list of embedded resources to the Console's standard output.
|
||||
/// </summary>
|
||||
public static void WriteResourceList()
|
||||
{
|
||||
Console.WriteLine(GetResourceListText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a StreamReader attached to the specified embedded resource.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename of the embedded resource to a StreamReader for.</param>
|
||||
/// <returns>A StreamReader attached to the specified embedded resource.</returns>
|
||||
public static StreamReader GetReader(string filename)
|
||||
{
|
||||
return new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(filename));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified embedded resource's content as a byte array.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename of the embedded resource to get conteent of.</param>
|
||||
/// <returns>The specified embedded resource's content as a byte array.</returns>
|
||||
public static byte[] ReadAllBytes(string filename)
|
||||
{
|
||||
// Referencing the Result property will block until the async method completes
|
||||
return ReadAllBytesAsync(filename).Result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the specified embedded resource's content as a byte array asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename of the embedded resource to get conteent of.</param>
|
||||
/// <returns>The specified embedded resource's content as a byte array.</returns>
|
||||
public static async Task<byte[]> ReadAllBytesAsync(string filename)
|
||||
{
|
||||
using (Stream resourceStream = Assembly.GetCallingAssembly().GetManifestResourceStream(filename))
|
||||
using (MemoryStream temp = new MemoryStream())
|
||||
{
|
||||
await resourceStream.CopyToAsync(temp);
|
||||
return temp.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the text stored in the specified embedded resource.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename to fetch the content of.</param>
|
||||
/// <returns>All the text stored in the specified embedded resource.</returns>
|
||||
public static string ReadAllText(string filename)
|
||||
{
|
||||
using (StreamReader resourceReader = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(filename)))
|
||||
{
|
||||
return resourceReader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets all the text stored in the specified embedded resource asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename to fetch the content of.</param>
|
||||
/// <returns>All the text stored in the specified embedded resource.</returns>
|
||||
public static async Task<string> ReadAllTextAsync(string filename)
|
||||
{
|
||||
using (StreamReader resourceReader = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(filename)))
|
||||
{
|
||||
return await resourceReader.ReadToEndAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enumerates the lines of text in the specified embedded resource.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename of the embedded resource to enumerate.</param>
|
||||
/// <returns>An IEnumerator that enumerates the specified embedded resource.</returns>
|
||||
public static IEnumerator<string> EnumerateLines(string filename)
|
||||
{
|
||||
using (StreamReader resourceReader = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(filename)))
|
||||
{
|
||||
string nextLine;
|
||||
while ((nextLine = resourceReader.ReadLine()) != null)
|
||||
{
|
||||
yield return nextLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Enumerates the lines of text in the specified embedded resource asynchronously.
|
||||
/// Each successive call returns a task that, when complete, returns the next line of text stored
|
||||
/// in the embedded resource.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename of the embedded resource to enumerate.</param>
|
||||
/// <returns>An IEnumerator that enumerates the specified embedded resource.</returns>
|
||||
public static IEnumerable<Task<string>> EnumerateLinesAsync(string filename)
|
||||
{
|
||||
using (StreamReader resourceReader = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(filename)))
|
||||
{
|
||||
while (!resourceReader.EndOfStream)
|
||||
{
|
||||
yield return resourceReader.ReadLineAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the lines of text in the specified embedded resource.
|
||||
/// You might find EnumerateLines(string filename) more useful depending on your situation.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename to obtain the lines of text from.</param>
|
||||
/// <returns>A list of lines in the specified embedded resource.</returns>
|
||||
public static List<string> GetAllLines(string filename)
|
||||
{
|
||||
// Referencing the Result property will block until the async method completes
|
||||
return GetAllLinesAsync(filename).Result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets all the lines of text in the specified embedded resource asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename to obtain the lines of text from.</param>
|
||||
/// <returns>A list of lines in the specified embedded resource.</returns>
|
||||
public static async Task<List<string>> GetAllLinesAsync(string filename)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
IEnumerable<Task<string>> lineIterator = EnumerateLinesAsync(filename);
|
||||
foreach(Task<string> nextLine in lineIterator)
|
||||
{
|
||||
lines.Add(await nextLine);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
}
|
30
cscz/Utiliities.cs
Normal file
30
cscz/Utiliities.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
using SBRLUtilities;
|
||||
|
||||
namespace cscz
|
||||
{
|
||||
public static class Utilities
|
||||
{
|
||||
public static string GetFullHash()
|
||||
{
|
||||
string hash = EmbeddedFiles.ReadAllText("cscz.git-hash.txt").Trim();
|
||||
if (hash == string.Empty)
|
||||
hash = new string('?', 40);
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static string GetShortHash()
|
||||
{
|
||||
return GetFullHash().Substring(0, 7);
|
||||
}
|
||||
|
||||
public static string GetVersionText()
|
||||
{
|
||||
Version asmVersion = Assembly.GetCallingAssembly().GetName().Version;
|
||||
return $"v{asmVersion.Major}.{asmVersion.Minor}-{GetShortHash()}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
<AssemblyName>cscz</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<Description>The C# Class Generator.</Description>
|
||||
<ReleaseVersion>0.2</ReleaseVersion>
|
||||
<ReleaseVersion>0.4</ReleaseVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
@ -42,6 +42,8 @@
|
|||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ClassGenerator.cs" />
|
||||
<Compile Include="Utiliities.cs" />
|
||||
<Compile Include="SBRLUtilities\EmbeddedFiles.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
@ -51,5 +53,7 @@
|
|||
<Target Name="BeforeBuild" BeforeTargets="Build">
|
||||
<Exec Command="git rev-parse HEAD >git-hash.txt" WorkingDirectory="$(ProjectDir)" IgnoreExitCode="true" />
|
||||
</Target>
|
||||
<ItemGroup>
|
||||
<Folder Include="SBRLUtilities\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
|
|
Loading…
Reference in a new issue