From 4dfee8cfd6b2a4862763845ed293ac41a0438425 Mon Sep 17 00:00:00 2001 From: Jon Kunkee Date: Sat, 27 Jun 2020 20:21:06 -0700 Subject: [PATCH] Add --delete operation --- NBTUtil/ConsoleOptions.cs | 2 ++ NBTUtil/ConsoleRunner.cs | 1 + NBTUtil/NBTUtil.csproj | 1 + NBTUtil/Ops/DeleteOperation.cs | 25 +++++++++++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 NBTUtil/Ops/DeleteOperation.cs diff --git a/NBTUtil/ConsoleOptions.cs b/NBTUtil/ConsoleOptions.cs index 1fdee5c..863650d 100644 --- a/NBTUtil/ConsoleOptions.cs +++ b/NBTUtil/ConsoleOptions.cs @@ -11,6 +11,7 @@ namespace NBTUtil Print, PrintTree, SetValue, + DeleteValue, SetList, Json, Help, @@ -64,6 +65,7 @@ namespace NBTUtil break; } }}, + { "delete", "Delete the NBT tag if found", v => Command = ConsoleCommand.DeleteValue }, }; } diff --git a/NBTUtil/ConsoleRunner.cs b/NBTUtil/ConsoleRunner.cs index c0f07fc..df1a465 100644 --- a/NBTUtil/ConsoleRunner.cs +++ b/NBTUtil/ConsoleRunner.cs @@ -13,6 +13,7 @@ namespace NBTUtil { private static readonly Dictionary _commandTable = new Dictionary() { { ConsoleCommand.SetValue, new EditOperation() }, + { ConsoleCommand.DeleteValue, new DeleteOperation() }, { ConsoleCommand.SetList, new SetListOperation() }, { ConsoleCommand.Print, new PrintOperation() }, { ConsoleCommand.PrintTree, new PrintTreeOperation() }, diff --git a/NBTUtil/NBTUtil.csproj b/NBTUtil/NBTUtil.csproj index 8571a2f..7b90512 100644 --- a/NBTUtil/NBTUtil.csproj +++ b/NBTUtil/NBTUtil.csproj @@ -45,6 +45,7 @@ + diff --git a/NBTUtil/Ops/DeleteOperation.cs b/NBTUtil/Ops/DeleteOperation.cs new file mode 100644 index 0000000..a3b165c --- /dev/null +++ b/NBTUtil/Ops/DeleteOperation.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.IO; +using NBTExplorer.Model; + +namespace NBTUtil.Ops +{ + class DeleteOperation : ConsoleOperation + { + public override bool OptionsValid (ConsoleOptions options) + { + return true; + } + + public override bool CanProcess (DataNode dataNode) + { + return (dataNode != null) && dataNode.CanDeleteNode && (dataNode.Root != dataNode); + } + + public override bool Process (DataNode dataNode, ConsoleOptions options) + { + return dataNode.DeleteNode(); + } + } +}