2026-02-04 20:13:21 +08:00
|
|
|
using System;
|
2026-02-08 01:22:08 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using CMLeonOS;
|
2026-02-04 20:13:21 +08:00
|
|
|
|
|
|
|
|
namespace CMLeonOS.Commands.FileSystem
|
|
|
|
|
{
|
|
|
|
|
public static class RmCommand
|
|
|
|
|
{
|
|
|
|
|
public static void ProcessRm(CMLeonOS.FileSystem fileSystem, string args, bool fixMode, Action<string> showError)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(args))
|
|
|
|
|
{
|
2026-02-08 01:22:08 +08:00
|
|
|
var commandInfos = new List<UsageGenerator.CommandInfo>
|
|
|
|
|
{
|
|
|
|
|
new UsageGenerator.CommandInfo
|
|
|
|
|
{
|
|
|
|
|
Command = "<file>",
|
|
|
|
|
Description = "Delete file",
|
|
|
|
|
IsOptional = false
|
|
|
|
|
},
|
|
|
|
|
new UsageGenerator.CommandInfo
|
|
|
|
|
{
|
|
|
|
|
Command = "<file> -norisk",
|
|
|
|
|
Description = "Delete file in sys folder without confirmation",
|
|
|
|
|
IsOptional = false
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
showError(UsageGenerator.GenerateUsage("rm", commandInfos));
|
|
|
|
|
return;
|
2026-02-04 20:13:21 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bool isInSysFolder = (args.Contains(@"\system\") || args.Contains(@"/sys/")) && !fixMode;
|
|
|
|
|
|
|
|
|
|
if (isInSysFolder)
|
|
|
|
|
{
|
|
|
|
|
string[] parts = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
bool hasNorisk = false;
|
|
|
|
|
string filePath = args;
|
|
|
|
|
|
|
|
|
|
if (parts.Length > 1)
|
|
|
|
|
{
|
|
|
|
|
hasNorisk = Array.IndexOf(parts, "-norisk") >= 0;
|
|
|
|
|
filePath = parts[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hasNorisk)
|
|
|
|
|
{
|
|
|
|
|
showError("Cannot delete files in sys folder without -norisk parameter");
|
2026-02-08 01:22:08 +08:00
|
|
|
showError(UsageGenerator.GenerateSimpleUsage("rm", "<file> -norisk"));
|
2026-02-04 20:13:21 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fileSystem.DeleteFile(filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fileSystem.DeleteFile(args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|