软件管理器

This commit is contained in:
2026-02-10 01:48:04 +08:00
parent 350db3140d
commit 25c7326bb2
9 changed files with 264 additions and 2 deletions

View File

@@ -55,6 +55,9 @@ namespace CMLeonOS.shell
case "matrix":
shell.ShowMatrix();
break;
case "app":
shell.ProcessApp(args);
break;
case "diff":
shell.DiffFiles(args);
break;

View File

@@ -260,6 +260,12 @@ namespace CMLeonOS.Commands
Description = "Show Matrix effect (The Matrix movie)"
},
new CommandInfo
{
Command = "app",
Parameters = "<command>",
Description = "Application manager"
},
new CommandInfo
{
Command = "branswe",
Parameters = "<filename>",

View File

@@ -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<string, byte[]> embeddedApps = new Dictionary<string, byte[]>();
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<string> showError)
{
if (string.IsNullOrWhiteSpace(appName))
{
showError("Error: Application name is required.");
Console.WriteLine("Usage: app install <appname>");
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<string> showError)
{
if (string.IsNullOrWhiteSpace(appName))
{
showError("Error: Application name is required.");
Console.WriteLine("Usage: app uninstall <appname>");
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 <name> - Install an application");
Console.WriteLine(" app uninstall <name> - 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");
}
}
}

View File

@@ -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);