public void ReplaceFieldsDatItemTest() { var datItem = CreateDatItem(); var repDatItem = CreateDatItem(); repDatItem.SetName("bar"); var fields = new List <DatItemField> { DatItemField.Name }; Replacer.ReplaceFields(datItem, repDatItem, fields); Assert.Equal("bar", datItem.GetName()); }
public void ReplaceFieldsMachineTest() { var datItem = CreateDatItem(); var repDatItem = CreateDatItem(); repDatItem.Machine.Name = "foo"; var fields = new List <MachineField> { MachineField.Name }; Replacer.ReplaceFields(datItem.Machine, repDatItem.Machine, fields, false); Assert.Equal("foo", datItem.Machine.Name); }
/// <summary> /// Replace item values from the base set represented by the current DAT /// </summary> /// <param name="datFile">Current DatFile object to use for updating</param> /// <param name="intDat">DatFile to replace the values in</param> /// <param name="machineFields">List of MachineFields representing what should be updated</param> /// <param name="datItemFields">List of DatItemFields representing what should be updated</param> /// <param name="onlySame">True if descriptions should only be replaced if the game name is the same, false otherwise</param> public static void BaseReplace( DatFile datFile, DatFile intDat, List <MachineField> machineFields, List <DatItemField> datItemFields, bool onlySame) { InternalStopwatch watch = new InternalStopwatch($"Replacing items in '{intDat.Header.FileName}' from the base DAT"); // If we are matching based on DatItem fields of any sort if (datItemFields.Any()) { // For comparison's sake, we want to use CRC as the base bucketing datFile.Items.BucketBy(ItemKey.CRC, DedupeType.Full); intDat.Items.BucketBy(ItemKey.CRC, DedupeType.None); // Then we do a hashwise comparison against the base DAT Parallel.ForEach(intDat.Items.Keys, Globals.ParallelOptions, key => { ConcurrentList <DatItem> datItems = intDat.Items[key]; ConcurrentList <DatItem> newDatItems = new ConcurrentList <DatItem>(); foreach (DatItem datItem in datItems) { ConcurrentList <DatItem> dupes = datFile.Items.GetDuplicates(datItem, sorted: true); DatItem newDatItem = datItem.Clone() as DatItem; // Replace fields from the first duplicate, if we have one if (dupes.Count > 0) { Replacer.ReplaceFields(newDatItem, dupes.First(), datItemFields); } newDatItems.Add(newDatItem); } // Now add the new list to the key intDat.Items.Remove(key); intDat.Items.AddRange(key, newDatItems); }); } // If we are matching based on Machine fields of any sort if (machineFields.Any()) { // For comparison's sake, we want to use Machine Name as the base bucketing datFile.Items.BucketBy(ItemKey.Machine, DedupeType.Full); intDat.Items.BucketBy(ItemKey.Machine, DedupeType.None); // Then we do a namewise comparison against the base DAT Parallel.ForEach(intDat.Items.Keys, Globals.ParallelOptions, key => { ConcurrentList <DatItem> datItems = intDat.Items[key]; ConcurrentList <DatItem> newDatItems = new ConcurrentList <DatItem>(); foreach (DatItem datItem in datItems) { DatItem newDatItem = datItem.Clone() as DatItem; if (datFile.Items.ContainsKey(key) && datFile.Items[key].Count() > 0) { Replacer.ReplaceFields(newDatItem.Machine, datFile.Items[key][0].Machine, machineFields, onlySame); } newDatItems.Add(newDatItem); } // Now add the new list to the key intDat.Items.Remove(key); intDat.Items.AddRange(key, newDatItems); }); } watch.Stop(); }