diff --git a/AssetEntry.cs b/AssetEntry.cs new file mode 100644 index 0000000..7bf75f5 --- /dev/null +++ b/AssetEntry.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Linq; + +namespace HashCalculator.GUI +{ + public class AssetEntry : IEquatable + { + public string Type { get; } + public string Name { get; } + public IEnumerable DisplayLabels { get; } + public uint Hash => SageHash.CalculateLowercaseHash(Name); + + public AssetEntry(XElement element) + { + if (element == null) + { + throw new ArgumentNullException($"{nameof(element)} is null"); + } + + if (element.Name.Namespace != ModXml.EalaAsset) + { + throw new NotSupportedException(); + } + + Type = element.Name.LocalName; + var id = element.Attribute("id")?.Value; + if (id == null) + { + throw new NotSupportedException(); + } + + Name = id; + + var labels = from name in element.Elements(ModXml.EalaAsset + "DisplayName") + select name.Value; + var transformLabels = from name in element.Elements(ModXml.EalaAsset + "DisplayNameTransformed") + select name.Value; + DisplayLabels = labels.Concat(transformLabels).ToArray(); + } + + public bool Equals(AssetEntry entry) + { + return this == entry; + } + + // override object.Equals + public override bool Equals(object obj) + { + // + // See the full list of guidelines at + // http://go.microsoft.com/fwlink/?LinkID=85237 + // and also the guidance for operator== at + // http://go.microsoft.com/fwlink/?LinkId=85238 + // + + if (!(obj is AssetEntry entry)) + { + return false; + } + + return this == entry; + } + + public static bool operator ==(AssetEntry a, AssetEntry b) + { + if (a is null || b is null) + { + return a is null == b is null; + } + + if (ReferenceEquals(a, b)) + { + return true; + } + + return a.Type == b.Type && a.Hash == b.Hash; + } + + public static bool operator !=(AssetEntry a, AssetEntry b) + { + return !(a == b); + } + + // override object.GetHashCode + public override int GetHashCode() + { + return HashCode.Combine(Type, Hash); + } + } +} diff --git a/HashCalculator.GUI.csproj b/HashCalculator.GUI.csproj index 65353e7..a26be0d 100644 --- a/HashCalculator.GUI.csproj +++ b/HashCalculator.GUI.csproj @@ -8,13 +8,16 @@ enable true AnyCPU;x86 + bf77c300-44f6-46ea-be94-f50d6993b55b + all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/MainWindow.xaml b/MainWindow.xaml index 7bc4812..9440091 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -14,7 +14,7 @@ - + @@ -31,7 +31,7 @@ HintText="Select some big file" Text="{Binding Text}" Collection="{Binding Items}" - TextChanged="OnTextChanged" + TextChanged="OnMainInputTextChanged" />