拆分代码6

This commit is contained in:
2026-02-04 21:16:55 +08:00
parent 73530c6ba3
commit 6dcd49e3c4
4 changed files with 274 additions and 237 deletions

View File

@@ -0,0 +1,50 @@
using System;
using System.IO;
namespace CMLeonOS.Commands.Script
{
public static class ComCommand
{
public static void ExecuteCommandFile(string args, CMLeonOS.FileSystem fileSystem, Shell shell, Action<string> showError, Action<string> showWarning)
{
if (string.IsNullOrEmpty(args))
{
showError("Usage: com <filename.cm>");
return;
}
string filePath = fileSystem.GetFullPath(args);
if (!File.Exists(filePath))
{
showError($"File not found: {args}");
return;
}
try
{
string[] lines = fileSystem.ReadFile(filePath).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
if (lines.Length == 0 || (lines.Length == 1 && string.IsNullOrWhiteSpace(lines[0])))
{
showWarning("Command file is empty");
return;
}
foreach (string line in lines)
{
if (string.IsNullOrWhiteSpace(line) || line.Trim().StartsWith("#"))
{
continue;
}
shell.ExecuteCommand(line);
}
}
catch (Exception ex)
{
showError($"Error executing command file: {ex.Message}");
}
}
}
}