using System.Collections.Generic; using System.Linq; using Vision.Core.Collections; namespace Vision.Core.IO.SHN { public class SHNHashHelper { private const int HashChunkLength = 32; public static List SeparateBigHash(string bigHash) { if (bigHash.Length % HashChunkLength == 0) { return Enumerable.Range(0, bigHash.Length / HashChunkLength) .Select(i => bigHash.Substring(i * HashChunkLength, HashChunkLength)).ToList(); } return Enumerable.Empty().ToList(); } public static Dictionary GetHashedSHNs(string bigHash, SHNManager shnManager) { var bigHashSplit = SeparateBigHash(bigHash); var hashedSHNs = new FastDictionary(); var matchedSHNHashes = new FastDictionary(); foreach (var shnType in SHNTypeExtensions.NAHashOrder) { if (shnManager.Load(shnType, out var shnFile)) { hashedSHNs.Add(shnType, shnFile.MD5Hash); } } foreach (var (shnType, hash) in bigHashSplit.Where(shnHash => hashedSHNs.ContainsValue(shnHash)).Select(hash => hashedSHNs.First(w => w.Value.Equals(hash)))) { matchedSHNHashes.Add(shnType, hash); } return matchedSHNHashes; } } }