mirror of
https://github.com/tonytins/tomas.git
synced 2025-03-21 15:21:21 +00:00
Filesystem and versioning
- Filesystem - Proper versioning - Replaced BasicApp with AboutApp - Removd TerminalCancelEventArgs and everything related to it
This commit is contained in:
parent
972948948f
commit
1edf3d660f
13 changed files with 191 additions and 82 deletions
8
Changelog.md
Normal file
8
Changelog.md
Normal 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
|
|
@ -3,13 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 16.0.29709.97
|
VisualStudioVersion = 16.0.29709.97
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
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
|
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
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{59C9B3FC-B1EE-4C23-9BD9-D33074BF1334}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{59C9B3FC-B1EE-4C23-9BD9-D33074BF1334}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
.editorconfig = .editorconfig
|
.editorconfig = .editorconfig
|
||||||
|
..\Changelog.md = ..\Changelog.md
|
||||||
|
..\README.md = ..\README.md
|
||||||
TOMAS.sln.licenseheader = TOMAS.sln.licenseheader
|
TOMAS.sln.licenseheader = TOMAS.sln.licenseheader
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
|
|
@ -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.
|
// See the LICENSE file in the project root for more information.
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Tomas.Kernel
|
namespace Tomas.Kernel
|
||||||
{
|
{
|
||||||
internal class EasterEggs
|
internal class EasterEggs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fennec art by Todd Vargo
|
/// Fennec art by Todd Vargo
|
||||||
/// </summary>
|
/// </summary>
|
||||||
const string FENNEC = @" \/
|
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
|
public static string FenSay
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var rng = new Random();
|
var rng = new Random();
|
||||||
var phrases = _fenPhrases[rng.Next(0, _fenPhrases.Length)];
|
var phrases = _fenPhrases[rng.Next(0, _fenPhrases.Length)];
|
||||||
return $"{phrases}{Environment.NewLine}{FENNEC}";
|
return $"{phrases}{Environment.NewLine}{FENNEC}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
src/Tomas.Kernel/GitInfo.txt
Normal file
1
src/Tomas.Kernel/GitInfo.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0.1.0
|
|
@ -12,17 +12,29 @@ namespace Tomas.Kernel
|
||||||
|
|
||||||
protected override void BeforeRun()
|
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()
|
protected override void Run()
|
||||||
{
|
{
|
||||||
var input = Terminal.ReadLine("1) Basic App");
|
var input = Terminal.ReadLine("1) About");
|
||||||
|
|
||||||
switch (input.ToLowerInvariant())
|
switch (input.ToLowerInvariant())
|
||||||
{
|
{
|
||||||
case "1":
|
case "1":
|
||||||
var basic = new BasicApp(this);
|
var basic = new AboutApp(this);
|
||||||
basic.Start();
|
basic.Start();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -33,7 +45,7 @@ namespace Tomas.Kernel
|
||||||
protected override void AfterRun()
|
protected override void AfterRun()
|
||||||
{
|
{
|
||||||
if (!InApp)
|
if (!InApp)
|
||||||
Console.WriteLine($"{OSConsts.Name} is shutting down.");
|
Console.WriteLine($"{OSConsts.NAME} is shutting down.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
// See the LICENSE file in the project root for more information.
|
||||||
namespace Tomas.Kernel
|
namespace Tomas.Kernel
|
||||||
{
|
{
|
||||||
public struct OSConsts
|
public struct OSConsts
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name of the operating system
|
/// Name of the operating system
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string Name = "TOMAS";
|
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}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
21
src/Tomas.Kernel/Programs/AboutApp.cs
Normal file
21
src/Tomas.Kernel/Programs/AboutApp.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
using sys = Cosmos.System;
|
||||||
|
|
||||||
namespace Tomas.Kernel.Programs
|
namespace Tomas.Kernel.Programs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Basic framework for building terminal applications.
|
/// Basic framework for building terminal applications.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class App
|
public abstract class App
|
||||||
{
|
{
|
||||||
protected App(Kernel system)
|
protected App(Kernel system)
|
||||||
{
|
{
|
||||||
System = system;
|
System = system;
|
||||||
}
|
}
|
||||||
|
|
||||||
Kernel System { get; set; }
|
Kernel System { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Main entry point of the program
|
/// Main entry point of the program
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Start()
|
public virtual void Start()
|
||||||
{
|
{
|
||||||
System.InApp = true;
|
System.InApp = true;
|
||||||
|
var isCKey = sys.KeyboardManager.ReadKey().Key == sys.ConsoleKeyEx.C;
|
||||||
}
|
if (sys.KeyboardManager.ControlPressed && isCKey)
|
||||||
|
System.Restart();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
// 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.
|
// See the LICENSE file in the project root for more information.
|
||||||
using System;
|
using System;
|
||||||
|
using Sys = Cosmos.System;
|
||||||
|
|
||||||
namespace Tomas.Kernel
|
namespace Tomas.Kernel
|
||||||
{
|
{
|
||||||
|
@ -9,8 +9,6 @@ namespace Tomas.Kernel
|
||||||
{
|
{
|
||||||
const char SYMBOL = '$';
|
const char SYMBOL = '$';
|
||||||
|
|
||||||
public static TerminalCancelEventHandler CancelKeyHandler;
|
|
||||||
|
|
||||||
static void Commands(string command)
|
static void Commands(string command)
|
||||||
{
|
{
|
||||||
switch (command)
|
switch (command)
|
||||||
|
@ -18,6 +16,39 @@ namespace Tomas.Kernel
|
||||||
case "fensay":
|
case "fensay":
|
||||||
Console.WriteLine(EasterEggs.FenSay);
|
Console.WriteLine(EasterEggs.FenSay);
|
||||||
break;
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
51
src/Tomas.Kernel/TomFS.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,10 @@
|
||||||
<PackageReference Include="Cosmos.Build" Version="0-*" NoWarn="NU1604" />
|
<PackageReference Include="Cosmos.Build" Version="0-*" NoWarn="NU1604" />
|
||||||
<PackageReference Include="Cosmos.Debug.Kernel" Version="0-*" NoWarn="NU1604" />
|
<PackageReference Include="Cosmos.Debug.Kernel" Version="0-*" NoWarn="NU1604" />
|
||||||
<PackageReference Include="Cosmos.System2" 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>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
Loading…
Add table
Reference in a new issue