Kilka dni temu zacząłem pisać system operacyjny w Cosmosie. Dzisiaj wyskoczył oto ten problem:
Ważność Kod Opis Projekt Plik Wiersz Stan pominięcia
Błąd Exception: System.Exception: SKSOS C:\...\source\repos\SKSOS\IL2CPU 1
Wyskoczył podczas debugu projektu. Tworzyłem też inne projekt w Cosmosie dzisiaj(te domyślne) aby sprawdzić czy to nie problem z moją instalacją Cosmosa, ale te domyślne projekty działały. Zmieniałem tylko kod w Kernel.cs
Kod z Kernel.cs:
using Cosmos.System.FileSystem.VFS;
using System;
using System.Collections.Generic;
using System.IO;
using Sys = Cosmos.System;
namespace SKSOS
{
public class Kernel : Sys.Kernel
{
private static string currentDirectory;
private static string usersDirectory = "/usersfiles";
protected override void BeforeRun()
{
var fs = new Sys.FileSystem.CosmosVFS();
Sys.FileSystem.VFS.VFSManager.RegisterVFS(fs);
currentDirectory = usersDirectory;
Console.WriteLine("SKSOS [Version 1.0]");
Console.WriteLine("-------------------");
}
protected override void Run()
{
DOSManager();
}
public static void DOSManager()
{
Console.Write($"{currentDirectory}> ");
var dosinput = Console.ReadLine();
if (dosinput.StartsWith("print "))
{
string result = dosinput.Substring(6);
Console.WriteLine(result);
}
else if (dosinput.StartsWith("read "))
{
string fileName = dosinput.Substring(5);
string filePath = GetFilePath(fileName);
try
{
if (FileExists(filePath))
{
string fileContent = File.ReadAllText(filePath);
Console.WriteLine(fileContent);
}
else
{
Console.WriteLine("File not found: " + fileName);
}
}
catch (Exception ex)
{
Console.WriteLine("Error reading file: " + ex.Message);
}
}
else if (dosinput.StartsWith("write "))
{
int index = dosinput.IndexOf(' ', 6);
if (index != -1)
{
string fileName = dosinput.Substring(6, index - 6);
string filePath = GetFilePath(fileName);
string content = dosinput.Substring(index + 1);
if (CanWriteToDirectory(usersDirectory))
{
try
{
File.WriteAllText(filePath, content);
Console.WriteLine("File written successfully.");
}
catch (Exception ex)
{
Console.WriteLine("Error writing file: " + ex.Message);
}
}
else
{
Console.WriteLine("No write permissions for the directory: " + usersDirectory);
}
}
}
else if (dosinput.StartsWith("del "))
{
string fileName = dosinput.Substring(4);
string filePath = GetFilePath(fileName);
try
{
if (FileExists(filePath))
{
File.Delete(filePath);
Console.WriteLine("File deleted successfully.");
}
else
{
Console.WriteLine("File not found: " + fileName);
}
}
catch (Exception ex)
{
Console.WriteLine("Error deleting file: " + ex.Message);
}
}
else if (dosinput == "cd ..")
{
// Przejdź do nadrzędnego katalogu
int lastSlashIndex = currentDirectory.LastIndexOf('/');
if (lastSlashIndex != -1)
{
currentDirectory = currentDirectory.Substring(0, lastSlashIndex);
}
}
else if (dosinput.StartsWith("cd "))
{
string directoryPath = dosinput.Substring(3);
if (directoryPath == "..")
{
// Przejdź do nadrzędnego katalogu
int lastSlashIndex = currentDirectory.LastIndexOf('/');
if (lastSlashIndex != -1)
{
currentDirectory = currentDirectory.Substring(0, lastSlashIndex);
}
}
else
{
string newDirectory = Path.Combine(currentDirectory, directoryPath);
if (DirectoryExists(newDirectory))
{
currentDirectory = newDirectory;
}
else
{
Console.WriteLine("Directory not found: " + directoryPath);
}
}
}
else if (dosinput == "clear")
{
Console.Clear();
Console.WriteLine("SKSOS [Version 1.0]");
Console.WriteLine("-------------------");
}
else if (dosinput == "hi" || dosinput == "Hi")
{
Console.WriteLine("Hi!");
}
}
private static bool FileExists(string filePath)
{
return File.Exists(filePath);
}
private static bool DirectoryExists(string directoryPath)
{
return Directory.Exists(directoryPath);
}
private static bool CanWriteToDirectory(string directoryPath)
{
try
{
// Sprawdź atrybuty katalogu
var directoryAttributes = File.GetAttributes(directoryPath);
var isReadOnly = (directoryAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
return !isReadOnly;
}
catch
{
return false;
}
}
private static string GetFilePath(string fileName)
{
return Path.Combine(currentDirectory, fileName);
}
}
}