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 string IdString => $"{Type}:{Name}"; public string HashString => $"{Hash:0X} ({Hash})"; 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; Name = id ?? throw new NotSupportedException(); 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); } } }