From a029d8d4d965d1556bbad9c28307fa8f72de61f8 Mon Sep 17 00:00:00 2001 From: Tony Bark Date: Fri, 6 Jan 2023 20:39:31 -0500 Subject: [PATCH] .NET 6 quality of life changes to Tomas.Common - Split and simplified version details - Raw commit hash is now a build number based on that hash --- src/Tomas.Common/ComConsts.cs | 36 ++++++++++++++------- src/Tomas.Common/GlobalUsing.cs | 2 ++ src/Tomas.Common/Programs/Clear.cs | 19 +++++------ src/Tomas.Common/Programs/Commands.cs | 25 +++++++-------- src/Tomas.Common/Programs/FenSay.cs | 45 +++++++++++++-------------- src/Tomas.Common/Tomas.Common.csproj | 13 ++++---- src/Tomas.Kernal/GlobalUsing.cs | 1 - src/Tomas.Kernal/Kernel.cs | 1 - src/Tomas.Kernal/Programs/About.cs | 3 +- src/Tomas.Kernal/Shell.cs | 2 -- src/Tomas.Kernal/TomFS.cs | 4 +-- src/Tomas.Kernal/Tomas.Kernel.csproj | 7 +++-- src/Tomas.Terminal/Programs/About.cs | 2 +- 13 files changed, 81 insertions(+), 79 deletions(-) create mode 100644 src/Tomas.Common/GlobalUsing.cs diff --git a/src/Tomas.Common/ComConsts.cs b/src/Tomas.Common/ComConsts.cs index f156bdb..f9bdd81 100644 --- a/src/Tomas.Common/ComConsts.cs +++ b/src/Tomas.Common/ComConsts.cs @@ -1,15 +1,29 @@ // I license this project under the BSD 3-Clause license. // See the LICENSE file in the project root for more information. -namespace Tomas.Common -{ - public struct ComConsts - { - /// - /// Name of the operating system - /// - public const string NAME = "TOMAS"; +using System.Text; - public static string Version = $"{ThisAssembly.Git.SemVer.Major}.{ThisAssembly.Git.SemVer.Minor}.{ThisAssembly.Git.SemVer.Patch}"; - public static string VersionGit = $"{Version}-{ThisAssembly.Git.Commit}"; - } +namespace Tomas.Common; + +public struct ComConsts +{ + /// + /// Name of the operating system + /// + public const string NAME = "TOMAS"; + public const string VERSION = $"{ThisAssembly.Git.SemVer.Major}.{ThisAssembly.Git.SemVer.Minor}.{ThisAssembly.Git.SemVer.Patch}"; + + [SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible")] + public static string BuildNumber = $"Build {BuildFromCommit}"; + + /// + /// Generate the build number from the commit hash. + /// + static uint BuildFromCommit + { + get + { + var commit = Encoding.UTF8.GetBytes(ThisAssembly.Git.Commit); + return BitConverter.ToUInt32(commit, 0) % 1000000; + } + } } \ No newline at end of file diff --git a/src/Tomas.Common/GlobalUsing.cs b/src/Tomas.Common/GlobalUsing.cs new file mode 100644 index 0000000..c66f29a --- /dev/null +++ b/src/Tomas.Common/GlobalUsing.cs @@ -0,0 +1,2 @@ +global using System.Diagnostics.CodeAnalysis; +global using Tomas.Interface; diff --git a/src/Tomas.Common/Programs/Clear.cs b/src/Tomas.Common/Programs/Clear.cs index c9dcf53..afeec90 100644 --- a/src/Tomas.Common/Programs/Clear.cs +++ b/src/Tomas.Common/Programs/Clear.cs @@ -1,16 +1,13 @@ // I license this project under the BSD 3-Clause license. // See the LICENSE file in the project root for more information. -using System; -using Tomas.Interface; -namespace Tomas.Common.Programs +namespace Tomas.Common.Programs; + +public class Clear : IProgram { - public class Clear : IProgram - { - public bool Run(IShell shell) - { - Console.Clear(); - return true; - } - } + public bool Run(IShell shell) + { + Console.Clear(); + return true; + } } \ No newline at end of file diff --git a/src/Tomas.Common/Programs/Commands.cs b/src/Tomas.Common/Programs/Commands.cs index e70c9e7..c2590c2 100644 --- a/src/Tomas.Common/Programs/Commands.cs +++ b/src/Tomas.Common/Programs/Commands.cs @@ -1,19 +1,16 @@ // I license this project under the BSD 3-Clause license. // See the LICENSE file in the project root for more information. -using System; -using Tomas.Interface; -namespace Tomas.Common.Programs +namespace Tomas.Common.Programs; + +public class Commands : IProgram { - public class Commands : IProgram - { - public bool Run(IShell shell) - { - Console.WriteLine($"Commands:"); - var progs = shell.Programs; - foreach (var commands in progs.Keys) - Console.WriteLine(commands); - return true; - } - } + public bool Run(IShell shell) + { + Console.WriteLine($"Commands:"); + var progs = shell.Programs; + foreach (var commands in progs.Keys) + Console.WriteLine(commands); + return true; + } } \ No newline at end of file diff --git a/src/Tomas.Common/Programs/FenSay.cs b/src/Tomas.Common/Programs/FenSay.cs index 246eef6..0dd73a4 100644 --- a/src/Tomas.Common/Programs/FenSay.cs +++ b/src/Tomas.Common/Programs/FenSay.cs @@ -1,17 +1,15 @@ // I license this project under the BSD 3-Clause license. // See the LICENSE file in the project root for more information. -using System; -using Tomas.Interface; -namespace Tomas.Common.Programs +namespace Tomas.Common.Programs; + +public class FenSay : IProgram { - public class FenSay : IProgram - { - /// - /// Fennec art by Todd Vargo - /// - const string _fennec = @" \/ + /// + /// Fennec art by Todd Vargo + /// + const string _fennec = @" \/ /\ /\ //\\_//\\ ____ \_ _/ / / @@ -22,20 +20,19 @@ namespace Tomas.Common.Programs [ [ / \/ _/ _[ [ \ /_/"; - readonly string[] _phrases = - { - "[SCREAMS IN FENNEC]", - "Some people call me a coffee fox.", - "Drink Soda. It makes you see faster.", - "10/10, Wouldn't Recommend." - }; + readonly string[] _phrases = + { + "[SCREAMS IN FENNEC]", + "Some people call me a coffee fox.", + "Drink Soda. It makes you see faster.", + "10/10, Wouldn't Recommend." + }; - public bool Run(IShell shell) - { - var rng = new Random(); - var phrases = _phrases[rng.Next(_phrases.Length)]; - Console.WriteLine($"{phrases}{Environment.NewLine}{_fennec}"); - return true; - } - } + public bool Run(IShell shell) + { + var rng = new Random(); + var phrases = _phrases[rng.Next(_phrases.Length)]; + Console.WriteLine($"{phrases}{Environment.NewLine}{_fennec}"); + return true; + } } \ No newline at end of file diff --git a/src/Tomas.Common/Tomas.Common.csproj b/src/Tomas.Common/Tomas.Common.csproj index 565c39e..6a91aed 100644 --- a/src/Tomas.Common/Tomas.Common.csproj +++ b/src/Tomas.Common/Tomas.Common.csproj @@ -1,18 +1,19 @@ - netstandard2.0 + net6.0 + enable - + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/Tomas.Kernal/GlobalUsing.cs b/src/Tomas.Kernal/GlobalUsing.cs index a1606b9..9d9efd3 100644 --- a/src/Tomas.Kernal/GlobalUsing.cs +++ b/src/Tomas.Kernal/GlobalUsing.cs @@ -1,5 +1,4 @@ global using Tomas.Common.Programs; global using Tomas.Interface; -global using Tomas.Kernel; global using Tomas.Kernel.Programs; global using Os = Cosmos.System; \ No newline at end of file diff --git a/src/Tomas.Kernal/Kernel.cs b/src/Tomas.Kernal/Kernel.cs index bd5113c..1bffafd 100644 --- a/src/Tomas.Kernal/Kernel.cs +++ b/src/Tomas.Kernal/Kernel.cs @@ -1,6 +1,5 @@ // I license this project under the BSD 3-Clause license. // See the LICENSE file in the project root for more information. -using System; namespace Tomas.Kernel; diff --git a/src/Tomas.Kernal/Programs/About.cs b/src/Tomas.Kernal/Programs/About.cs index df54f76..1814a0c 100644 --- a/src/Tomas.Kernal/Programs/About.cs +++ b/src/Tomas.Kernal/Programs/About.cs @@ -1,6 +1,5 @@ // I license this project under the BSD 3-Clause license. // See the LICENSE file in the project root for more information. -using System; using Tomas.Common; namespace Tomas.Kernel.Programs; @@ -9,7 +8,7 @@ public class About : IProgram { public bool Run(IShell shell) { - Console.WriteLine($"TOMAS v{ComConsts.VersionGit} is a hobby operating system written in C# using the COSMOS framework.{Environment.NewLine}Commands:"); + Console.WriteLine($"TOMAS v{ComConsts.VERSION} ({ComConsts.BuildNumber}) is a hobby operating system written in C# using the COSMOS framework.{Environment.NewLine}Commands:"); var progs = shell.Programs; foreach (var commands in progs.Keys) Console.WriteLine(commands); diff --git a/src/Tomas.Kernal/Shell.cs b/src/Tomas.Kernal/Shell.cs index f098690..975324c 100644 --- a/src/Tomas.Kernal/Shell.cs +++ b/src/Tomas.Kernal/Shell.cs @@ -1,7 +1,5 @@ // I license this project under the BSD 3-Clause license. // See the LICENSE file in the project root for more information. -using System; -using System.Collections.Generic; namespace Tomas.Kernel; diff --git a/src/Tomas.Kernal/TomFS.cs b/src/Tomas.Kernal/TomFS.cs index 48223e0..0854c4e 100644 --- a/src/Tomas.Kernal/TomFS.cs +++ b/src/Tomas.Kernal/TomFS.cs @@ -1,7 +1,5 @@ // I license this project under the BSD 3-Clause license. // See the LICENSE file in the project root for more information. -using System; -using System.IO; using Cosmos.System.FileSystem; using Cosmos.System.FileSystem.VFS; using Tomas.Common; @@ -23,7 +21,7 @@ class TomFS Console.WriteLine("Creating system files."); fs.CreateFile($"{SYSTEM_DIR}sysinfo.txt"); Console.WriteLine("Setting system preferences."); - File.WriteAllText($"{SYSTEM_DIR}sysinfo.txt", $"{ComConsts.NAME}, {ComConsts.VersionGit}"); + File.WriteAllText($"{SYSTEM_DIR}sysinfo.txt", $"{ComConsts.NAME}, {ComConsts.BuildNumber}"); Console.WriteLine("File system loaded sucesfully."); var intro = File.ReadAllText($"{SYSTEM_DIR}sysinfo.txt"); Console.WriteLine(intro); diff --git a/src/Tomas.Kernal/Tomas.Kernel.csproj b/src/Tomas.Kernal/Tomas.Kernel.csproj index 0d4bb3c..f747da9 100644 --- a/src/Tomas.Kernal/Tomas.Kernel.csproj +++ b/src/Tomas.Kernal/Tomas.Kernel.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,6 +6,7 @@ cosmos false True + enable @@ -26,8 +27,8 @@ - - + + diff --git a/src/Tomas.Terminal/Programs/About.cs b/src/Tomas.Terminal/Programs/About.cs index f8e6fa9..e5ddf6c 100644 --- a/src/Tomas.Terminal/Programs/About.cs +++ b/src/Tomas.Terminal/Programs/About.cs @@ -8,7 +8,7 @@ public class About : IProgram { public bool Run(IShell shell) { -Console.WriteLine($"{ComConsts.NAME} Terminal Emulator v{ComConsts.VersionGit}{Environment.NewLine}" +Console.WriteLine($"{ComConsts.NAME} Terminal Emulator v{ComConsts.BuildNumber}{Environment.NewLine}" + "TOMAS (Tony's Managed Operating System) is a operating system written in C# using the COSMOS framework."); return true; }