I get this error:
Error
Exception: System.Exception: Error compiling method 'SystemStringDudoOSCommandsFileExecuteSystemStringarray': System.ArgumentNullException: Value cannot be null. (Parameter 'aType') DudoOS C:\Users\k\source\repos\DudoOS\DudoOS\IL2CPU 1
And I do not know how to fix it.
using DudoOS.Commands;
using System;
using Sys = Cosmos.System;
using Cosmos.System.FileSystem;
using Cosmos.System.FileSystem.VFS;
namespace DudoOS
{
public class Kernel : Sys.Kernel
{
private CommandManager commandManager;
private CosmosVFS vfs;
protected override void BeforeRun()
{
this.vfs = new CosmosVFS();
VFSManager.RegisterVFS(this.vfs);
this.commandManager = new CommandManager();
}
protected override void Run()
{
Console.ForegroundColor = ConsoleColor.White;
while (true)
{
Console.Write("Dudo caka na tvoje prikazi \n>> ");
string input = Console.ReadLine();
string response = this.commandManager.ProcessInput(input);
Console.WriteLine(response);
}
}
}
}
using System;
using System.IO;
using Sys = Cosmos.System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cosmos.System.FileSystem.VFS;
namespace DudoOS.Commands
{
public class File : Command
{
public File(string name) : base(name) { }
public override string Execute(string[] args)
{
string response = " ";
switch (args[0])
{
case "create":
try
{
Sys.FileSystem.VFS.VFSManager.CreateFile(args[1]);
response = $"Dudo vyvoril subor: {args[1]}, neuveris vytvoril sa! :D";
}
catch (Exception e)
{
response = $"Dudo nezvladol vytvorit subor: {args[1]} Code: {e.ToString}";
break;
}
break;
case "delete":
try
{
Sys.FileSystem.VFS.VFSManager.DeleteFile(args[1]);
response = $"Dudo omylom zmazal subor: {args[1]}";
}
catch (Exception e)
{
response = $"Dudo zabudol ako sa maze subor: {args[1]} Code: {e.ToString}";
break;
}
break;
case "createdir":
try
{
Sys.FileSystem.VFS.VFSManager.CreateDirectory(args[1]);
response = $"Dudovi pomohola sova vytvorit adresar: {args[1]}";
}
catch (Exception e)
{
response = $"Dudovi nikto nepomohol vytvorit adresar: {args[1]} code: {e.ToString}";
break;
}
break;
case "removedir":
try
{
Sys.FileSystem.VFS.VFSManager.DeleteDirectory(args[1], true);
response = $"Dudo: Co sa stalo? kde je adresar: {args[1]}?";
}
catch (Exception e)
{
response = $"Dudo: kto mi pomoze zmazat adresar: {args[1]}? code: {e.ToString}";
break;
}
break;
case "writestr":
try
{
FileStream fs = (FileStream)Sys.FileSystem.VFS.VFSManager.GetFile(args[1]).GetFileStream();
if (fs.CanWrite)
{
byte[] data = Encoding.ASCII.GetBytes(args[2]);
fs.Write(data, 0, data.Length);
fs.Close();
}
else
{
response = "Dudo nemoze zapisovat do tohoto suboru";
break;
}
}
catch (Exception e)
{
response = e.ToString();
break;
}
break;
case "readstr":
try
{
FileStream fs = (FileStream)Sys.FileSystem.VFS.VFSManager.GetFile(args[1]).GetFileStream();
if (fs.CanRead)
{
byte[] data = new byte[256];
fs.Read(data, 0, data.Length);
response = Encoding.ASCII.GetString(data);
}
else
{
response = "Dudo nemoze precitat tento subor, proste stratil okuliare...";
break;
}
}
catch (Exception e)
{
response = e.ToString();
break;
}
break;
default:
response = "Dudo nevie aky prikaz mas na mysli";
break;
}
return response;
}
}
}
I tried to fix it, but vfs does not showing as registered
You must create a VFS using C#'s
new.Put this before and outside the
BeforeRunfunction.On another note, remove:
In your namespace
DudoOS.Commands, you do not need to create another vfs, as one is created before that code runs. You can just useFile,Directory,StreamWriter,StreamReader, etc.