Filesystem and versioning

- Filesystem
- Proper versioning
- Replaced BasicApp with AboutApp
- Removd TerminalCancelEventArgs and everything related to it
This commit is contained in:
Anthony Foxclaw 2020-02-03 16:51:51 -05:00
parent 972948948f
commit 1edf3d660f
13 changed files with 191 additions and 82 deletions

8
Changelog.md Normal file
View file

@ -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

View file

@ -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

View file

@ -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
{
/// <summary>
/// Fennec art by Todd Vargo
/// </summary>
const string FENNEC = @" \/
internal class EasterEggs
{
/// <summary>
/// Fennec art by Todd Vargo
/// </summary>
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}";
}
}
}
}

View file

@ -0,0 +1 @@
0.1.0

View file

@ -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.");
}
}
}

View file

@ -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
{
/// <summary>
/// Name of the operating system
/// </summary>
public const string Name = "TOMAS";
}
public struct OSConsts
{
/// <summary>
/// Name of the operating system
/// </summary>
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}";
}
}

View file

@ -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();
}
}
}

View file

@ -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
{
/// <summary>
/// Basic framework for building terminal applications.
/// </summary>
public abstract class App
{
protected App(Kernel system)
{
System = system;
}
/// <summary>
/// Basic framework for building terminal applications.
/// </summary>
public abstract class App
{
protected App(Kernel system)
{
System = system;
}
Kernel System { get; set; }
Kernel System { get; set; }
/// <summary>
/// Main entry point of the program
/// </summary>
public virtual void Start()
{
System.InApp = true;
}
}
/// <summary>
/// Main entry point of the program
/// </summary>
public virtual void Start()
{
System.InApp = true;
var isCKey = sys.KeyboardManager.ReadKey().Key == sys.ConsoleKeyEx.C;
if (sys.KeyboardManager.ControlPressed && isCKey)
System.Restart();
}
}
}

View file

@ -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();
}
}
}

View file

@ -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;
}
}

View file

@ -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; }
}
}

51
src/Tomas.Kernel/TomFS.cs Normal file
View file

@ -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;
}
}
}
}

View file

@ -29,6 +29,10 @@
<PackageReference Include="Cosmos.Build" Version="0-*" NoWarn="NU1604" />
<PackageReference Include="Cosmos.Debug.Kernel" Version="0-*" NoWarn="NU1604" />
<PackageReference Include="Cosmos.System2" Version="0-*" NoWarn="NU1604" />
<PackageReference Include="GitInfo" Version="2.0.26">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>