From 5a104b30395e42df33ab755d76a92d4e06831c92 Mon Sep 17 00:00:00 2001 From: Haven1433 Date: Sat, 10 Sep 2022 20:48:51 -0500 Subject: [PATCH] allow TableStreamRun to match an ArrayRun if the format matches This can happen if the user gives a name to a tablestreamrun with a fixed length - it becomes an ArrayRun. Allow the StreamElementViewModel to accept pointers of both streams and arrays when judging the UsageCount. Allow --- .../Models/Runs/Factory/TableStreamRunContentStrategy.cs | 5 ++++- .../ViewModels/Tools/StreamElementViewModel.cs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/HexManiac.Core/Models/Runs/Factory/TableStreamRunContentStrategy.cs b/src/HexManiac.Core/Models/Runs/Factory/TableStreamRunContentStrategy.cs index 04d25836..ae85d2f8 100644 --- a/src/HexManiac.Core/Models/Runs/Factory/TableStreamRunContentStrategy.cs +++ b/src/HexManiac.Core/Models/Runs/Factory/TableStreamRunContentStrategy.cs @@ -30,7 +30,10 @@ namespace HavenSoft.HexManiac.Core.Models.Runs.Factory { } return false; } - public override bool Matches(IFormattedRun run) => run is TableStreamRun streamRun && streamRun.FormatString == Format; + public override bool Matches(IFormattedRun run) { + if (run == null || run.FormatString != Format) return false; + return run is ITableRun; + } public override IFormattedRun WriteNewRun(IDataModel owner, ModelDelta token, int source, int destination, string name, IReadOnlyList sourceSegments) { // don't bother checking the TryParse result: we very much expect that the data originally in the run won't fit the parse. TableStreamRun.TryParseTableStream(owner, destination, new SortedSpan(source), name, Format, sourceSegments, out var tableStream); diff --git a/src/HexManiac.Core/ViewModels/Tools/StreamElementViewModel.cs b/src/HexManiac.Core/ViewModels/Tools/StreamElementViewModel.cs index 2ce94f1c..d1b979d7 100644 --- a/src/HexManiac.Core/ViewModels/Tools/StreamElementViewModel.cs +++ b/src/HexManiac.Core/ViewModels/Tools/StreamElementViewModel.cs @@ -148,8 +148,8 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools { if (destination == Pointer.NULL) { UsageCount = 0; } else { - var run = Model.GetNextRun(destination) as IStreamRun; - UsageCount = run?.PointerSources?.Count ?? 0; + var run = Model.GetNextRun(destination); + UsageCount = run is IStreamRun || run is ITableRun ? run.PointerSources?.Count ?? 0 : 0; } }