private void AddEntries(Dictionary <byte[], TradDictEntry> dictionary) { foreach (var alteredEntry in Command.AddedEntries) { byte[] hash = null; if (alteredEntry.Key != null) { hash = MiscUtilities.HexByteStringToByteArray(alteredEntry.Key); } else { do { hash = GenerateEntryHash(); }while (dictionary.ContainsKey(hash)); } //Alter if exists otherwise add a new one. TradDictEntry entry; if (dictionary.TryGetValue(hash, out entry)) { entry.Content = alteredEntry.Value; } else { entry = new TradDictEntry(); entry.Content = alteredEntry.Value; entry.ContentLength = (uint)alteredEntry.Value.Length; entry.Hash = hash; dictionary.Add(hash, entry); } } }
/// <remarks> /// Credits go to enohka for this code. /// See more at: https://github.com/enohka/moddingSuite/blob/master/moddingSuite/BL/TradManager.cs /// </remarks> protected virtual IEnumerable <TradDictEntry> ReadEntries(MemoryStream ms, uint entriesCount) { var entries = new List <TradDictEntry>(); var buffer = new byte[4]; for (int i = 0; i < entriesCount; i++) { var entry = new TradDictEntry(); entry.OffsetDictionary = (uint)ms.Position; var hashBuffer = new byte[8]; ms.Read(hashBuffer, 0, hashBuffer.Length); entry.Hash = hashBuffer; ms.Read(buffer, 0, buffer.Length); entry.OffsetContent = BitConverter.ToUInt32(buffer, 0); ms.Read(buffer, 0, buffer.Length); entry.ContentLength = BitConverter.ToUInt32(buffer, 0); entries.Add(entry); } return(entries); }