mirror of
https://github.com/jaquadro/NBTExplorer.git
synced 2025-01-10 01:46:24 +00:00
Split find and act operations to allow deletion
This change splits CanProcess into a separate loop from Process so that Process can perform actions like deletion that cause NbtPathEnumerator to throw an exception. It also caches targetNode.Root before Process because Process can cause targetNode to be invalid.
This commit is contained in:
parent
15b1b2891f
commit
f28f96c27f
1 changed files with 17 additions and 4 deletions
|
@ -45,17 +45,30 @@ namespace NBTUtil
|
|||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
|
||||
foreach (var targetNode in new NbtPathEnumerator(_options.Path)) {
|
||||
if (!op.CanProcess(targetNode)) {
|
||||
Console.WriteLine(targetNode.NodePath + ": ERROR (invalid command)");
|
||||
var nodesToProcess = new List<DataNode>();
|
||||
|
||||
foreach (var node in new NbtPathEnumerator(_options.Path))
|
||||
{
|
||||
if (op.CanProcess(node))
|
||||
{
|
||||
nodesToProcess.Add(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(node.NodePath + ": ERROR (invalid command)");
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var targetNode in nodesToProcess) {
|
||||
var root = targetNode.Root;
|
||||
|
||||
if (!op.Process(targetNode, _options)) {
|
||||
Console.WriteLine(targetNode.NodePath + ": ERROR (apply)");
|
||||
failCount++;
|
||||
}
|
||||
|
||||
targetNode.Root.Save();
|
||||
root.Save();
|
||||
|
||||
Console.WriteLine(targetNode.NodePath + ": OK");
|
||||
successCount++;
|
||||
|
|
Loading…
Reference in a new issue