diff --git a/CMLeonOS.csproj b/CMLeonOS.csproj index ba40c12..fde6c18 100644 --- a/CMLeonOS.csproj +++ b/CMLeonOS.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -70,6 +70,7 @@ + diff --git a/GitCommit.txt b/GitCommit.txt index 5ec3745..f832675 100644 --- a/GitCommit.txt +++ b/GitCommit.txt @@ -1 +1 @@ -a02aab3 \ No newline at end of file +350db31 \ No newline at end of file diff --git a/LuaApps.cs b/LuaApps.cs new file mode 100644 index 0000000..8c05051 --- /dev/null +++ b/LuaApps.cs @@ -0,0 +1,13 @@ +using IL2CPU.API.Attribs; + +namespace CMLeonOS +{ + public static class LuaApps + { + [ManifestResourceStream(ResourceName = "CMLeonOS.LuaApps.helloworld.lua")] + public static readonly byte[] helloworld; + + [ManifestResourceStream(ResourceName = "CMLeonOS.LuaApps.testspeed.lua")] + public static readonly byte[] testspeed; + } +} \ No newline at end of file diff --git a/LuaApps/helloworld.lua b/LuaApps/helloworld.lua new file mode 100644 index 0000000..9534211 --- /dev/null +++ b/LuaApps/helloworld.lua @@ -0,0 +1,3 @@ +print("Hello, World!") +print("Welcome to CMLeonOS!") +print("This is a simple Lua application.") \ No newline at end of file diff --git a/LuaApps/testspeed.lua b/LuaApps/testspeed.lua new file mode 100644 index 0000000..549fc93 --- /dev/null +++ b/LuaApps/testspeed.lua @@ -0,0 +1,7 @@ +local loop = 100000000 +os.timerstart() +for i = 1, loop do + -- Nothing +end +cost = os.timerstop() +print("Loop " .. loop .. ", cost " .. cost .. "s.") \ No newline at end of file diff --git a/shell/CommandList.cs b/shell/CommandList.cs index f707506..d1a0283 100644 --- a/shell/CommandList.cs +++ b/shell/CommandList.cs @@ -55,6 +55,9 @@ namespace CMLeonOS.shell case "matrix": shell.ShowMatrix(); break; + case "app": + shell.ProcessApp(args); + break; case "diff": shell.DiffFiles(args); break; diff --git a/shell/Commands/Help/Help.cs b/shell/Commands/Help/Help.cs index 78e9e0f..37bc7a9 100644 --- a/shell/Commands/Help/Help.cs +++ b/shell/Commands/Help/Help.cs @@ -260,6 +260,12 @@ namespace CMLeonOS.Commands Description = "Show Matrix effect (The Matrix movie)" }, new CommandInfo + { + Command = "app", + Parameters = "", + Description = "Application manager" + }, + new CommandInfo { Command = "branswe", Parameters = "", diff --git a/shell/Commands/Utility/AppManagerCommand.cs b/shell/Commands/Utility/AppManagerCommand.cs new file mode 100644 index 0000000..3adfe95 --- /dev/null +++ b/shell/Commands/Utility/AppManagerCommand.cs @@ -0,0 +1,190 @@ +using System; +using System.Collections.Generic; +using System.IO; +using CMLeonOS; + +namespace CMLeonOS.Commands.Utility +{ + public static class AppManagerCommand + { + private static readonly Dictionary embeddedApps = new Dictionary(); + + public static void InitializeApps() + { + LoadEmbeddedApps(); + } + + private static void LoadEmbeddedApps() + { + embeddedApps.Clear(); + + try + { + if (LuaApps.helloworld != null && LuaApps.helloworld.Length > 0) + { + embeddedApps["helloworld.lua"] = LuaApps.helloworld; + } + + if (LuaApps.testspeed != null && LuaApps.testspeed.Length > 0) + { + embeddedApps["testspeed.lua"] = LuaApps.testspeed; + } + } + catch (Exception ex) + { + Console.WriteLine($"Error loading embedded apps: {ex.Message}"); + } + } + + public static void ListApps() + { + Console.WriteLine("Available Applications:"); + Console.WriteLine("======================"); + + if (embeddedApps.Count == 0) + { + Console.WriteLine("No applications available."); + return; + } + + foreach (var app in embeddedApps) + { + Console.WriteLine($" - {app.Key}"); + } + + Console.WriteLine(); + Console.WriteLine($"Total: {embeddedApps.Count} application(s)"); + } + + public static void InstallApp(string appName, CMLeonOS.FileSystem fileSystem, Action showError) + { + if (string.IsNullOrWhiteSpace(appName)) + { + showError("Error: Application name is required."); + Console.WriteLine("Usage: app install "); + Console.WriteLine("Use 'app list' to see available applications."); + return; + } + + if (!embeddedApps.ContainsKey(appName)) + { + showError($"Error: Application '{appName}' not found."); + Console.WriteLine("Use 'app list' to see available applications."); + return; + } + + try + { + string appsDir = "0:\\apps"; + + if (!Directory.Exists(appsDir)) + { + Directory.CreateDirectory(appsDir); + Console.WriteLine($"Created directory: {appsDir}"); + } + + string filePath = Path.Combine(appsDir, appName); + + if (File.Exists(filePath)) + { + Console.WriteLine($"Warning: File already exists: {filePath}"); + Console.Write("Overwrite? (y/n): "); + string response = Console.ReadLine()?.ToLower(); + + if (response != "y" && response != "yes") + { + Console.WriteLine("Installation cancelled."); + return; + } + } + + File.WriteAllBytes(filePath, embeddedApps[appName]); + Console.WriteLine($"Successfully installed: {appName}"); + Console.WriteLine($"Location: {filePath}"); + } + catch (Exception ex) + { + showError($"Error installing application: {ex.Message}"); + } + } + + public static void UninstallApp(string appName, CMLeonOS.FileSystem fileSystem, Action showError) + { + if (string.IsNullOrWhiteSpace(appName)) + { + showError("Error: Application name is required."); + Console.WriteLine("Usage: app uninstall "); + return; + } + + string appsDir = "0:\\apps"; + string filePath = Path.Combine(appsDir, appName); + + if (!File.Exists(filePath)) + { + showError($"Error: Application '{appName}' not installed."); + return; + } + + try + { + File.Delete(filePath); + Console.WriteLine($"Successfully uninstalled: {appName}"); + } + catch (Exception ex) + { + showError($"Error uninstalling application: {ex.Message}"); + } + } + + public static void ShowInstalledApps(CMLeonOS.FileSystem fileSystem) + { + string appsDir = "0:\\apps"; + + if (!Directory.Exists(appsDir)) + { + Console.WriteLine("No applications installed."); + return; + } + + Console.WriteLine("Installed Applications:"); + Console.WriteLine("======================="); + + var files = Directory.GetFiles(appsDir); + + if (files.Length == 0) + { + Console.WriteLine("No applications installed."); + return; + } + + foreach (var file in files) + { + string fileName = Path.GetFileName(file); + Console.WriteLine($" - {fileName}"); + } + + Console.WriteLine(); + Console.WriteLine($"Total: {files.Length} application(s)"); + } + + public static void ShowHelp() + { + Console.WriteLine("Application Manager"); + Console.WriteLine("==================="); + Console.WriteLine(); + Console.WriteLine("Commands:"); + Console.WriteLine(" app list - List available applications"); + Console.WriteLine(" app install - Install an application"); + Console.WriteLine(" app uninstall - Uninstall an application"); + Console.WriteLine(" app installed - List installed applications"); + Console.WriteLine(" app help - Show this help message"); + Console.WriteLine(); + Console.WriteLine("Examples:"); + Console.WriteLine(" app list"); + Console.WriteLine(" app install helloworld.lua"); + Console.WriteLine(" app uninstall helloworld.lua"); + Console.WriteLine(" app installed"); + } + } +} \ No newline at end of file diff --git a/shell/Shell.cs b/shell/Shell.cs index cdfd28f..1214e7d 100644 --- a/shell/Shell.cs +++ b/shell/Shell.cs @@ -571,6 +571,45 @@ namespace CMLeonOS Commands.Utility.MatrixCommand.ShowMatrix(); } + public void ProcessApp(string args) + { + Commands.Utility.AppManagerCommand.InitializeApps(); + + string[] parts = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + if (parts.Length == 0) + { + Commands.Utility.AppManagerCommand.ShowHelp(); + return; + } + + string subCommand = parts[0].ToLower(); + string subArgs = parts.Length > 1 ? parts[1] : ""; + + switch (subCommand) + { + case "list": + Commands.Utility.AppManagerCommand.ListApps(); + break; + case "install": + Commands.Utility.AppManagerCommand.InstallApp(subArgs, fileSystem, ShowError); + break; + case "uninstall": + Commands.Utility.AppManagerCommand.UninstallApp(subArgs, fileSystem, ShowError); + break; + case "installed": + Commands.Utility.AppManagerCommand.ShowInstalledApps(fileSystem); + break; + case "help": + Commands.Utility.AppManagerCommand.ShowHelp(); + break; + default: + ShowError($"Unknown app command: {subCommand}"); + Commands.Utility.AppManagerCommand.ShowHelp(); + break; + } + } + public void ShowHistory() { Commands.Utility.HistoryCommand.ShowHistory(commandHistory);