From 5ef78954b0fa8626259a227b458c59d00737ba25 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 26 May 2019 00:44:51 +0100 Subject: [PATCH] Select only distinct density codes when creating device report. --- .../Metadata/DeviceReportV2.cs | 23 ++++++++++++++++++- DiscImageChef.Core/Devices/Report/SSC.cs | 8 +++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/DiscImageChef.CommonTypes/Metadata/DeviceReportV2.cs b/DiscImageChef.CommonTypes/Metadata/DeviceReportV2.cs index ed517cc80..320c5fffe 100644 --- a/DiscImageChef.CommonTypes/Metadata/DeviceReportV2.cs +++ b/DiscImageChef.CommonTypes/Metadata/DeviceReportV2.cs @@ -1683,9 +1683,30 @@ namespace DiscImageChef.CommonTypes.Metadata } } - public class DensityCode + public class DensityCode : IEquatable { + [JsonIgnore] [Key] + public int Id { get; set; } + public int Code { get; set; } + + public bool Equals(DensityCode other) + { + if(ReferenceEquals(null, other)) return false; + if(ReferenceEquals(this, other)) return true; + + return Code == other.Code; + } + + public override bool Equals(object obj) + { + if(ReferenceEquals(null, obj)) return false; + if(ReferenceEquals(this, obj)) return true; + + return obj.GetType() == GetType() && Equals((DensityCode)obj); + } + + public override int GetHashCode() => Code; } } \ No newline at end of file diff --git a/DiscImageChef.Core/Devices/Report/SSC.cs b/DiscImageChef.Core/Devices/Report/SSC.cs index 0bf1505ea..a18fecef5 100644 --- a/DiscImageChef.Core/Devices/Report/SSC.cs +++ b/DiscImageChef.Core/Devices/Report/SSC.cs @@ -110,9 +110,9 @@ namespace DiscImageChef.Core.Devices.Report if(mtsh.Value.descriptors[i].densityCodes == null) continue; DensityCode[] array3 = new DensityCode[mtsh.Value.descriptors[i].densityCodes.Length]; - for(int j = 0; j < mtsh.Value.descriptors.Length; j++) + for(int j = 0; j < mtsh.Value.descriptors[i].densityCodes.Length; j++) array3[j] = new DensityCode {Code = mtsh.Value.descriptors[i].densityCodes[j]}; - array2[i].DensityCodes = array3.ToList(); + array2[i].DensityCodes = array3.Distinct().ToList(); } report.SupportedMediaTypes = array2.ToList(); @@ -201,9 +201,9 @@ namespace DiscImageChef.Core.Devices.Report if(mtsh.Value.descriptors[i].densityCodes == null) continue; DensityCode[] array2 = new DensityCode[mtsh.Value.descriptors[i].densityCodes.Length]; - for(int j = 0; j < mtsh.Value.descriptors.Length; j++) + for(int j = 0; j < mtsh.Value.descriptors[i].densityCodes.Length; j++) array2[j] = new DensityCode {Code = mtsh.Value.descriptors[i].densityCodes[j]}; - array[i].DensityCodes = array2.ToList(); + array[i].DensityCodes = array2.Distinct().ToList(); } seqTest.SupportedMediaTypes = array.ToList();