mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-03-03 03:27:01 +00:00
软件管理器
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
@@ -70,6 +70,7 @@
|
||||
<EmbeddedResource Include="font.psf" />
|
||||
<EmbeddedResource Include="Wallpapers\wallpaper.bmp" />
|
||||
<EmbeddedResource Include="GitCommit.txt" />
|
||||
<EmbeddedResource Include="LuaApps\*.lua" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1 +1 @@
|
||||
a02aab3
|
||||
350db31
|
||||
13
LuaApps.cs
Normal file
13
LuaApps.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
3
LuaApps/helloworld.lua
Normal file
3
LuaApps/helloworld.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
print("Hello, World!")
|
||||
print("Welcome to CMLeonOS!")
|
||||
print("This is a simple Lua application.")
|
||||
7
LuaApps/testspeed.lua
Normal file
7
LuaApps/testspeed.lua
Normal file
@@ -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.")
|
||||
@@ -55,6 +55,9 @@ namespace CMLeonOS.shell
|
||||
case "matrix":
|
||||
shell.ShowMatrix();
|
||||
break;
|
||||
case "app":
|
||||
shell.ProcessApp(args);
|
||||
break;
|
||||
case "diff":
|
||||
shell.DiffFiles(args);
|
||||
break;
|
||||
|
||||
@@ -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>",
|
||||
|
||||
190
shell/Commands/Utility/AppManagerCommand.cs
Normal file
190
shell/Commands/Utility/AppManagerCommand.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user