Closed OOFMAN29803 closed 10 months ago
you are switching to GUI mode just fine, its just that the VGA console doesn't work in GUI which is why it doesnt work. Also your tags are incorrect.
try this instead;
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Sys = Cosmos.System;
using Cosmos.System.FileSystem;
using Cosmos.System.FileSystem.VFS;
using Cosmos.System.Graphics;
using System.IO;
namespace CosmosKernel5
{
public class Kernel : Sys.Kernel
{
private Canvas canvas;
private bool _guiEnabled = false;
protected override void BeforeRun()
{
var fs = new Sys.FileSystem.CosmosVFS();
Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
Console.WriteLine("Code: 1, Fatal Error. Code: 2, Success. Code: 3, Non System Fatal Error. Code 4. Partial Success.");
System.Threading.Thread.Sleep(5000);
Console.Clear();
try
{
fs.CreateDirectory(@"0:\System");
fs.CreateDirectory(@"0:\UserFiles");
Console.WriteLine("Code 2");
}
catch (Exception e)
{
Console.WriteLine("Error Creating Directory. Error: 1");
Console.WriteLine("Error for helpfulness: " + e.Message);
System.Threading.Thread.Sleep(7000);
Sys.Power.Shutdown();
}
}
protected override void Run()
{
if (!_guiEnabled) MainCommands();
else
{
canvas.Clear(Color.Black);
canvas.Display();
DrawUI();
}
}
public void MainCommands()
{
Console.WriteLine("Command: ");
var open = Console.ReadLine();
if (open == "Key-2309308475148")
{
var mode = new Mode(800, 600, ColorDepth.ColorDepth32);
canvas = FullScreenCanvas.GetFullScreenCanvas(mode);
return;
}
else if (open == "legal")
{
Console.WriteLine($"Leaking this build or releasing without permission, will terminate you and your work, or get you suspended indefinitely. \n");
}
else if (open == "build")
{
Console.WriteLine($"Build 4.19DKNU. Testing purposes only. Type: 'legal' to get more information about this build. Type 'build/? to understand the Letter on the Version Letter. \n");
}
else if (open == "calculator")
{
while (true)
{
Console.WriteLine("Enter Number 1: ");
int num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Number 2: ");
int num2 = int.Parse(Console.ReadLine());
Console.WriteLine("Operation: ");
var operation = Console.ReadLine();
if (operation == "+")
{
Console.WriteLine(num1 + num2);
break;
}
else if (operation == "-")
{
Console.WriteLine(num1 - num2);
break;
}
else if (operation == "*")
{
Console.WriteLine(num1 * num2);
break;
}
else if (operation == "/")
{
Console.WriteLine(num1 / num2);
break;
}
else
{
Console.WriteLine("Invalid Calculation");
}
}
}
else if (open == "build/?")
{
Console.Write($"MU = Modified for User, not a inside development build. MD = Modified for Demo. Modified for showing off, or a demo build. DB = Development Build, An inside Development Build. DKNU = Development Key Needed to Unlock. \n");
}
else if (open == "developer")
{
Console.WriteLine("Development Key");
var key = Console.ReadLine();
if (key == "3940387384")
{
Console.WriteLine($"Development Key for UI. Put in Command: 'Key-2309308475148' \n");
}
else
{
Console.WriteLine("Shutting Down.");
System.Threading.Thread.Sleep(5000);
Sys.Power.Shutdown();
}
}
else if (open == "shutdown")
{
Console.WriteLine("Shutting Down.");
System.Threading.Thread.Sleep(5000);
Sys.Power.Shutdown();
}
else if (open == "dir")
{
Console.WriteLine(@"Drive:
0:\
Folders:
UserFiles
SystemFiles");
}
else if (open == "restart")
{
Console.WriteLine("Restarting...");
System.Threading.Thread.Sleep(3000);
Sys.Power.Reboot();
}
else if (open == "cd")
{
Console.WriteLine("Activating File System Mode");
Console.WriteLine(" ");
Console.WriteLine(@"0:\ ");
var cd = Console.ReadLine();
if (cd == "UserFiles")
{
Console.WriteLine(@"0:\UserFiles");
CommandKey();
}
else if (cd == "SystemFiles")
{
Console.WriteLine(@"0:\SystemFiles: ");
var systemfiles = Console.ReadLine();
if (systemfiles == "cd..")
{
MainCommands();
}
}
}
else if (open == "create file")
{
CreateFile();
}
else if (open == "readfile")
{
Console.WriteLine("Enter directory");
var directory_list = Directory.GetFiles(@"0:\");
foreach (var file in directory_list)
{
Console.Write(Path.GetFileName(file));
}
var fileName = Console.ReadLine();
Console.WriteLine(directory_list);
ReadTheFile(fileName);
}
else
{
Console.WriteLine($"Invalid Command \n");
}
}
private void DrawUI()
{
canvas.DrawFilledRectangle(new Pen(Color.LightBlue), 0, 100, 800, 100);
canvas.DrawFilledRectangle(new Pen (Color.Gray), 0, 550, 800, 550);
canvas.Display();
}
private void CommandKey()
{
}
private void CreateFile()
{
try
{
Console.WriteLine("Contents: ");
var Contents = Console.ReadLine();
Console.WriteLine("Filename:");
var fileName = Console.ReadLine();
CreateTextFile(@"0:\UserFiles", Contents);
System.Threading.Thread.Sleep(2000);
Console.WriteLine(@"Saved at 0:\UserFiles ");
}
catch (Exception ex)
{
Console.Write($"An error occurred: {ex.Message}");
}
}
private void CreateTextFile(string path, string contents)
{
if (Directory.Exists(path))
{
path = Path.Combine(path, "file.txt");
}
var directory = Path.GetDirectoryName(path);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
File.WriteAllText(path, contents);
Console.WriteLine("Success");
System.Threading.Thread.Sleep(2000);
Console.Clear();
MainCommands();
}
private void ReadTheFile(string fileName)
{
string fullPath = Path.Combine(@"0:\UserFiles\", fileName);
if (File.Exists(fullPath))
{
string contents = File.ReadAllText(fullPath);
Console.WriteLine(contents);
}
else
{
Console.WriteLine("File Not Found");
}
}
}
}
@zarlo can you move this to a discussion, since this isnt a cosmos bug
so this is my code
but adding
breaks everything, but the other UI things are fine