diff --git a/Changelog.md b/Changelog.md new file mode 100644 index 0000000..dc0f161 --- /dev/null +++ b/Changelog.md @@ -0,0 +1,8 @@ +# Change Log + +## 0.1.0 + +- Filesystem (based on the Cosmos Wiki [guide](https://csos-guide-to-cosmos.fandom.com/wiki/Getting_Started_-_Materials_and_Setting_Up)) +- Proper versioning (thanks to Gitinfo!) +- Replaced BasicApp with AboutApp +- Removd TerminalCancelEventArgs and everything related to it \ No newline at end of file diff --git a/src/TOMAS.sln b/src/TOMAS.sln index aca4160..94af3c0 100644 --- a/src/TOMAS.sln +++ b/src/TOMAS.sln @@ -3,13 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29709.97 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tomas.Kernel", "Tomas.Kernel\Tomas.Kernel.csproj", "{AF6338C3-342A-4A12-A25C-2D53C5568DA8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tomas.Kernel", "Tomas.Kernel\Tomas.Kernel.csproj", "{AF6338C3-342A-4A12-A25C-2D53C5568DA8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tomas.Common", "Tomas.Common\Tomas.Common.csproj", "{C50F3A6F-CFF4-4725-A1A5-21C5A2BC3321}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tomas.Common", "Tomas.Common\Tomas.Common.csproj", "{C50F3A6F-CFF4-4725-A1A5-21C5A2BC3321}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{59C9B3FC-B1EE-4C23-9BD9-D33074BF1334}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig + ..\Changelog.md = ..\Changelog.md + ..\README.md = ..\README.md TOMAS.sln.licenseheader = TOMAS.sln.licenseheader EndProjectSection EndProject diff --git a/src/Tomas.Kernel/EasterEggs.cs b/src/Tomas.Kernel/EasterEggs.cs index 16bcf2a..11200ca 100644 --- a/src/Tomas.Kernel/EasterEggs.cs +++ b/src/Tomas.Kernel/EasterEggs.cs @@ -1,15 +1,15 @@ -// TOMAS is licensed under the MPL 2.0 license. +// TOMAS is licensed under the MPL 2.0 license. // See the LICENSE file in the project root for more information. using System; namespace Tomas.Kernel { - internal class EasterEggs - { - /// - /// Fennec art by Todd Vargo - /// - const string FENNEC = @" \/ + internal class EasterEggs + { + /// + /// Fennec art by Todd Vargo + /// + const string FENNEC = @" \/ /\ /\ //\\_//\\ ____ \_ _/ / / @@ -20,16 +20,16 @@ namespace Tomas.Kernel [ [ / \/ _/ _[ [ \ /_/"; - static readonly string[] _fenPhrases = { "Screams in fennec!", "Some people call me a coffee fox." }; + static readonly string[] _fenPhrases = { "Screams in fennec!", "Some people call me a coffee fox." }; - public static string FenSay - { - get - { - var rng = new Random(); - var phrases = _fenPhrases[rng.Next(0, _fenPhrases.Length)]; - return $"{phrases}{Environment.NewLine}{FENNEC}"; - } - } - } + public static string FenSay + { + get + { + var rng = new Random(); + var phrases = _fenPhrases[rng.Next(0, _fenPhrases.Length)]; + return $"{phrases}{Environment.NewLine}{FENNEC}"; + } + } + } } diff --git a/src/Tomas.Kernel/GitInfo.txt b/src/Tomas.Kernel/GitInfo.txt new file mode 100644 index 0000000..6c6aa7c --- /dev/null +++ b/src/Tomas.Kernel/GitInfo.txt @@ -0,0 +1 @@ +0.1.0 \ No newline at end of file diff --git a/src/Tomas.Kernel/Kernel.cs b/src/Tomas.Kernel/Kernel.cs index 2a9175d..6f92b75 100644 --- a/src/Tomas.Kernel/Kernel.cs +++ b/src/Tomas.Kernel/Kernel.cs @@ -12,17 +12,29 @@ namespace Tomas.Kernel protected override void BeforeRun() { - Console.WriteLine($"{OSConsts.Name} booted successfully. Type a line of text to get it echoed back."); + try + { + Sys.PCSpeaker.Beep(); + TomFS.Initialize(); + } + catch + { + Sys.PCSpeaker.Beep(); + Console.WriteLine("File system failed to load! Not all functions will work."); + } + + + Console.WriteLine("Booted successfully. Type a line of text to get it echoed back."); } protected override void Run() { - var input = Terminal.ReadLine("1) Basic App"); + var input = Terminal.ReadLine("1) About"); switch (input.ToLowerInvariant()) { case "1": - var basic = new BasicApp(this); + var basic = new AboutApp(this); basic.Start(); break; default: @@ -33,7 +45,7 @@ namespace Tomas.Kernel protected override void AfterRun() { if (!InApp) - Console.WriteLine($"{OSConsts.Name} is shutting down."); + Console.WriteLine($"{OSConsts.NAME} is shutting down."); } } } diff --git a/src/Tomas.Kernel/OSConsts.cs b/src/Tomas.Kernel/OSConsts.cs index 9588023..d1a1813 100644 --- a/src/Tomas.Kernel/OSConsts.cs +++ b/src/Tomas.Kernel/OSConsts.cs @@ -1,12 +1,15 @@ -// TOMAS is licensed under the MPL 2.0 license. +// TOMAS is licensed under the MPL 2.0 license. // See the LICENSE file in the project root for more information. namespace Tomas.Kernel { - public struct OSConsts - { - /// - /// Name of the operating system - /// - public const string Name = "TOMAS"; - } + public struct OSConsts + { + /// + /// Name of the operating system + /// + public const string NAME = "TOMAS"; + + public static string Version = $"{ThisAssembly.Git.SemVer.Major}.{ThisAssembly.Git.SemVer.Minor}.{ThisAssembly.Git.SemVer.Patch}"; + public static string VersionGit = $"{Version}-{ThisAssembly.Git.Commit}"; + } } diff --git a/src/Tomas.Kernel/Programs/AboutApp.cs b/src/Tomas.Kernel/Programs/AboutApp.cs new file mode 100644 index 0000000..5af60b7 --- /dev/null +++ b/src/Tomas.Kernel/Programs/AboutApp.cs @@ -0,0 +1,21 @@ +// TOMAS is licensed under the MPL 2.0 license. +// See the LICENSE file in the project root for more information. +using System; + +namespace Tomas.Kernel.Programs +{ + class AboutApp : App + { + public AboutApp(Kernel system) : base(system) + { + } + + public override void Start() + { + Console.WriteLine($"{OSConsts.NAME} v{OSConsts.VersionGit}"); + Console.WriteLine("TOMAS, an abbreviation of Tony's Managed Operating System, is a operating system written in C# using the COSMOS framework."); + + base.Start(); + } + } +} diff --git a/src/Tomas.Kernel/Programs/App.cs b/src/Tomas.Kernel/Programs/App.cs index 4b9f295..0d8e2ea 100644 --- a/src/Tomas.Kernel/Programs/App.cs +++ b/src/Tomas.Kernel/Programs/App.cs @@ -1,28 +1,30 @@ -// TOMAS is licensed under the MPL 2.0 license. +// TOMAS is licensed under the MPL 2.0 license. // See the LICENSE file in the project root for more information. +using sys = Cosmos.System; namespace Tomas.Kernel.Programs { - /// - /// Basic framework for building terminal applications. - /// - public abstract class App - { - protected App(Kernel system) - { - System = system; - } + /// + /// Basic framework for building terminal applications. + /// + public abstract class App + { + protected App(Kernel system) + { + System = system; + } - Kernel System { get; set; } + Kernel System { get; set; } - /// - /// Main entry point of the program - /// - public virtual void Start() - { - System.InApp = true; - - } - - } + /// + /// Main entry point of the program + /// + public virtual void Start() + { + System.InApp = true; + var isCKey = sys.KeyboardManager.ReadKey().Key == sys.ConsoleKeyEx.C; + if (sys.KeyboardManager.ControlPressed && isCKey) + System.Restart(); + } + } } diff --git a/src/Tomas.Kernel/Programs/BasicApp.cs b/src/Tomas.Kernel/Programs/BasicApp.cs deleted file mode 100644 index 2ef1d00..0000000 --- a/src/Tomas.Kernel/Programs/BasicApp.cs +++ /dev/null @@ -1,15 +0,0 @@ -// TOMAS is licensed under the MPL 2.0 license. -// See the LICENSE file in the project root for more information. - -namespace Tomas.Kernel.Programs -{ - public class BasicApp : App - { - public BasicApp(Kernel system) : base(system) { } - - public override void Start() - { - base.Start(); - } - } -} diff --git a/src/Tomas.Kernel/Terminal.cs b/src/Tomas.Kernel/Terminal.cs index 1ce8923..d258755 100644 --- a/src/Tomas.Kernel/Terminal.cs +++ b/src/Tomas.Kernel/Terminal.cs @@ -1,7 +1,7 @@ // TOMAS is licensed under the MPL 2.0 license. // See the LICENSE file in the project root for more information. using System; - +using Sys = Cosmos.System; namespace Tomas.Kernel { @@ -9,8 +9,6 @@ namespace Tomas.Kernel { const char SYMBOL = '$'; - public static TerminalCancelEventHandler CancelKeyHandler; - static void Commands(string command) { switch (command) @@ -18,6 +16,39 @@ namespace Tomas.Kernel case "fensay": Console.WriteLine(EasterEggs.FenSay); break; + case "version": + Console.WriteLine(OSConsts.VersionGit); + break; + case "reboot": + var rbq = ReadLine($"Are you sure you want to {command}? 1) Yes 2) No"); + switch (rbq) + { + case "1": + case "yes": + Sys.Power.Reboot(); + break; + case "2": + case "no": + break; + } + break; + case "shutdown": + var shq = ReadLine($"Are you sure you want to {command}? 1) Yes 2) No"); + switch (shq) + { + case "1": + case "yes": + Sys.Power.Shutdown(); + break; + case "2": + case "no": + break; + } + break; + case "ls": + var dirs = TomFS.ListDirectories(command.Remove(0, 2)); + Console.WriteLine(dirs); + break; } } diff --git a/src/Tomas.Kernel/TerminalCancelEventArgs.cs b/src/Tomas.Kernel/TerminalCancelEventArgs.cs deleted file mode 100644 index 26acf12..0000000 --- a/src/Tomas.Kernel/TerminalCancelEventArgs.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace Tomas.Kernel -{ - public delegate void TerminalCancelEventHandler(object sender, TerminalCancelEventArgs e); - - public sealed class TerminalCancelEventArgs : EventArgs - { - public bool Cancel { get; set; } - } -} diff --git a/src/Tomas.Kernel/TomFS.cs b/src/Tomas.Kernel/TomFS.cs new file mode 100644 index 0000000..285acdf --- /dev/null +++ b/src/Tomas.Kernel/TomFS.cs @@ -0,0 +1,51 @@ +// TOMAS is licensed under the MPL 2.0 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; + +namespace Tomas.Kernel +{ + class TomFS + { + public const string ROOT_DIR = "0:\\"; + public static string SYSTEM_DIR = $"{ROOT_DIR}\\SYSTEM\\"; + + public static void Initialize() + { + try + { + var fs = new CosmosVFS(); + VFSManager.RegisterVFS(fs); + fs.CreateDirectory(SYSTEM_DIR); + Console.WriteLine("Creating system files."); + fs.CreateFile($"{SYSTEM_DIR}sysinfo.txt"); + Console.WriteLine("Setting system preferences."); + File.WriteAllText($"{SYSTEM_DIR}sysinfo.txt", $"{OSConsts.NAME}, {OSConsts.VersionGit}"); + Console.WriteLine("File system loaded sucesfully."); + var intro = File.ReadAllText($"{SYSTEM_DIR}sysinfo.txt"); + Console.WriteLine(intro); + + } + catch + { + Console.WriteLine("File system failed to load! Not all functions will work."); + } + } + + public static string[] ListDirectories(string path) + { + try + { + var dirs = Directory.GetDirectories(path); + return dirs; + } + catch + { + Console.WriteLine("Failed to find any directories."); + throw; + } + } + } +} diff --git a/src/Tomas.Kernel/Tomas.Kernel.csproj b/src/Tomas.Kernel/Tomas.Kernel.csproj index aea39fc..3b29b72 100644 --- a/src/Tomas.Kernel/Tomas.Kernel.csproj +++ b/src/Tomas.Kernel/Tomas.Kernel.csproj @@ -29,6 +29,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +