Skip to content

I have error like this #3229

Description

@QwertyKeypadMan

<img** width="740" height="458" alt="Image" src="https://github.com/user-attachments/assets/3936eed1-cafa-4a6d-817f-c28082a5bac6" />
using System.Drawing;
using Cosmos.System;
using Cosmos.System.Graphics;
using Cosmos.System.Graphics.Fonts;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;

namespace CosmosMiniOS.Gui
{
public static class Gui
{
public static int ScreenSizeX = 1920, ScreenSizeY = 1080;
public static SVGAIICanvas MainCanvas;
public static Bitmap Wallpaper, Cursor;

    public static void Update() {
        MainCanvas.DrawImage(Wallpaper, 0, 0);
        MainCanvas.DrawImage(Cursor, (int)MouseManager.X, (int)MouseManager.Y);
        MainCanvas.Display();
    }
    public static void StartGUI()
    { 
    MainCanvas = new SVGAIICanvas(new Mode((int)(uint)ScreenSizeX, (int)(uint)ScreenSizeY, ColorDepth.ColorDepth32));
        MouseManager.ScreenWidth = (uint)ScreenSizeX;
        MouseManager.ScreenHeight = (uint)ScreenSizeY;
        MouseManager.X = (uint)ScreenSizeX /2;
        MouseManager.Y = (uint)ScreenSizeY / 2;
    }
}

}
here is a code**

using IL2CPU.API.Attribs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;

namespace CosmosMiniOS.Resources
{
    internal class Files
    {
        [ManifestResourceStream(ResourceName = "CosmosMiniOS.Resources.w1.bmp")] public static byte[] CosmosMiniOSBackgroundRaw;
        [ManifestResourceStream(ResourceName = "CosmosMiniOS.Resources.cursor1.bmp")] public static byte[] CosmosMiniOSCursor;
    }
}
here is a resource code

using Cosmos;
using Cosmos.System.Graphics;
using System;
using Sys = Cosmos.System;

namespace CosmosMiniOS
{
    public sealed class Shell
    {
        private readonly RamFileSystem _fileSystem = new RamFileSystem();
        private readonly OpRuntime _opRuntime;

        public Shell()
        {
            _opRuntime = new OpRuntime(_fileSystem);
        }

        public void Execute(string input)
        {
            ExecuteInternal(input, 0);
        }

        private void ExecuteInternal(string input, int depth)
        {
            if (input == null)
            {
                return;
            }

            input = input.Trim();
            if (input == "")
            {
                return;
            }

            string command = input;
            string args = "";
            int spaceIndex = input.IndexOf(' ');

            if (spaceIndex >= 0)
            {
                command = ToLowerAscii(input.Substring(0, spaceIndex));
                args = input.Substring(spaceIndex + 1).Trim();
            }
            else
            {
                command = ToLowerAscii(input);
            }

            if (command == "help")
            {
                ShowHelp();
            }
            else if (command == "about" || command == "ver")
            {
                ShowAbout();
            }
            else if (command == "clear" || command == "cls")
            {
                Console.Clear();
            }
            else if (command == "echo")
            {
                Console.WriteLine(args);
            }
            else if (command == "pause")
            {
               Console.WriteLine("Devam etmek icin Enter'a bas.");
               Console.ReadLine();
            }
            else if (command == "mem")
            {
                _fileSystem.Info();
            }
            else if (command == "calc")
            {
                Calculate(args);
            }
            else if (command == "ls" || command == "dir")
            {
                _fileSystem.List();
            }
            else if (command == "touch")
            {
                _fileSystem.Touch(args);
            }
            else if (command == "write")
            {
                WriteFile(args);
            }
            else if (command == "append")
            {
                AppendFile(args);
            }
            else if (command == "cat" || command == "type")
            {
                _fileSystem.Read(args);
            }
            else if (command == "copy")
            {
                CopyFile(args);
            }
            else if (command == "ren" || command == "rename")
            {
                RenameFile(args);
            }
            else if (command == "del")
            {
                _fileSystem.Delete(args);
            }
            else if (command == "fsinfo")
            {
                _fileSystem.Info();
            }
            else if (command == "apps")
            {
                _opRuntime.ListApps();
            }
            else if (command == "run")
            {
                RunTarget(args, depth);
            }
            else if (command == "opengui")
            {
                Kernel.RunGui = true;
                Gui.Gui.Wallpaper = new Bitmap(Resources.Files.CosmosMiniOSBackgroundRaw);
                Gui.Gui.Cursor = new Bitmap(Resources.Files.CosmosMiniOSCursor);
                Gui.Gui.StartGUI();
            }
            else if (command == "reboot")
            {
                Sys.Power.Reboot();
            }
            else if (command == "shutdown")
            {
                Sys.Power.Shutdown();
            }
            else
            {
                Console.WriteLine("Bilinmeyen komut: " + command);
            }
   
            
        }

        private void RunTarget(string args, int depth)
        {
            if (EndsWithAscii(args, ".op"))
            {
                _opRuntime.Run(args);
                return;
            }

            if (EndsWithAscii(args, ".ops"))
            {
                RunScript(args, depth);
                return;
            }

           Console.WriteLine("Kullanim: run hello.op veya run start.ops");
        }

        private void RunScript(string fileName, int depth)
        {
            if (depth >= 4)
            {
                Console.WriteLine("Script ic ice calistirma siniri asildi.");
                return;
            }

            string content;
            if (!_fileSystem.TryReadText(fileName, out content))
            {
                Console.WriteLine("Script dosyasi bulunamadi.");
                return;
            }

            int start = 0;
            int index = 0;

            while (index <= content.Length)
            {
                if (index == content.Length || content[index] == ';')
                {
                    string line = content.Substring(start, index - start).Trim();
                    if (line != "")
                    {
                        ExecuteInternal(line, depth + 1);
                    }

                    start = index + 1;
                }

                index++;
            }
        }

        private static void ShowHelp()
        {
            Console.WriteLine("Komutlar:");
            Console.WriteLine("  help, ver, cls, echo, pause, mem");
            Console.WriteLine("  dir/ls, type/cat, copy, ren, del");
            Console.WriteLine("  touch, write, append, fsinfo");
            Console.WriteLine("  apps, run <app.op>, run <file.ops>");
            Console.WriteLine("  calc, reboot, shutdown");
        }

        private static void ShowAbout()
        {
           Console.WriteLine("Cosmos Mini OS 0.2");
           Console.WriteLine("Kernel: Cosmos.System.Kernel");
           Console.WriteLine("Dosya sistemi: RAM FS");
           Console.WriteLine("Uygulama tipi: .op operable");
        }

        private void WriteFile(string args)
        {
            string name;
            string text;

            if (!ReadTwoParts(args, out name, out text))
            {
                Console.WriteLine("Kullanim: write not.txt merhaba");
                return;
            }

            _fileSystem.Write(name, text);
        }

        private void AppendFile(string args)
        {
            string name;
            string text;

            if (!ReadTwoParts(args, out name, out text))
            {
                Console.WriteLine("Kullanim: append not.txt merhaba");
                return;
            }

            _fileSystem.Append(name, text);
        }

        private void CopyFile(string args)
        {
            string source;
            string target;

            if (!ReadTwoParts(args, out source, out target))
            {
                Console.WriteLine("Kullanim: copy a.txt b.txt");
                return;
            }

            _fileSystem.Copy(source, target);
        }

        private void RenameFile(string args)
        {
            string source;
            string target;

            if (!ReadTwoParts(args, out source, out target))
            {
                Console.WriteLine("Kullanim: ren eski.txt yeni.txt");
                return;
            }

            _fileSystem.Rename(source, target);
        }

        private static bool ReadTwoParts(string args, out string first, out string rest)
        {
            first = "";
            rest = "";

            if (args == null)
            {
                return false;
            }

            args = args.Trim();
            int spaceIndex = args.IndexOf(' ');
            if (spaceIndex < 0)
            {
                return false;
            }

            first = args.Substring(0, spaceIndex).Trim();
            rest = args.Substring(spaceIndex + 1).Trim();
            return first != "" && rest != "";
        }

        private static void Calculate(string args)
        {
            string leftText;
            string operation;
            string rightText;

            if (!ReadCalcParts(args, out leftText, out operation, out rightText))
            {
                Console.WriteLine("Kullanim: calc 10 + 5");
                return;
            }

            int left;
            int right;

            if (!TryParseInt(leftText, out left) || !TryParseInt(rightText, out right))
            {
                Console.WriteLine("Sadece tam sayilar destekleniyor.");
                return;
            }

            if (operation == "+")
            {
                Console.WriteLine(left + right);
            }
            else if (operation == "-")
            {
                Console.WriteLine(left - right);
            }
            else if (operation == "*")
            {
                Console.WriteLine(left * right);
            }
            else if (operation == "/")
            {
                if (right == 0)
                {
                    Console.WriteLine("Sifira bolme yapilamaz.");
                    return;
                }

                Console.WriteLine(left / right);
            }
            else
            {
                Console.WriteLine("Desteklenen islemler: + - * /");
            }
        }

        private static bool ReadCalcParts(string args, out string left, out string operation, out string right)
        {
            left = "";
            operation = "";
            right = "";

            args = args.Trim();
            int firstSpace = args.IndexOf(' ');
            if (firstSpace < 0)
            {
                return false;
            }

            left = args.Substring(0, firstSpace).Trim();
            string rest = args.Substring(firstSpace + 1).Trim();
            int secondSpace = rest.IndexOf(' ');
            if (secondSpace < 0)
            {
                return false;
            }

            operation = rest.Substring(0, secondSpace).Trim();
            right = rest.Substring(secondSpace + 1).Trim();
            return left != "" && operation != "" && right != "";
        }

        private static bool TryParseInt(string text, out int value)
        {
            value = 0;

            if (text == null || text == "")
            {
                return false;
            }

            int sign = 1;
            int index = 0;

            if (text[0] == '-')
            {
                sign = -1;
                index = 1;
            }

            if (index >= text.Length)
            {
                return false;
            }

            while (index < text.Length)
            {
                char current = text[index];
                if (current < '0' || current > '9')
                {
                    return false;
                }

                value = (value * 10) + (current - '0');
                index++;
            }

            value = value * sign;
            return true;
        }

        private static bool EndsWithAscii(string text, string suffix)
        {
            if (text == null || suffix == null)
            {
                return false;
            }

            if (text.Length < suffix.Length)
            {
                return false;
            }

            int offset = text.Length - suffix.Length;
            int index = 0;

            while (index < suffix.Length)
            {
                if (ToLowerChar(text[offset + index]) != suffix[index])
                {
                    return false;
                }

                index++;
            }

            return true;
        }

        private static string ToLowerAscii(string text)
        {
            string result = "";
            int index = 0;

            while (index < text.Length)
            {
                result = result + ToLowerChar(text[index]);
                index++;
            }

            return result;
        }

        private static char ToLowerChar(char current)
        {
            if (current >= 'A' && current <= 'Z')
            {
                return (char)(current + 32);
            }

            return current;
        }
    }
}

here is a shell. sorry for my bad english.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions