mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add comparison for SCSI INQUIRY responses.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using DiscImageChef.CommonTypes.Metadata;
|
||||
using DiscImageChef.Decoders.ATA;
|
||||
using DiscImageChef.Decoders.SCSI;
|
||||
using DiscImageChef.Server.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -150,5 +153,133 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
public IActionResult Compare(int id, int rightId)
|
||||
{
|
||||
var model = new CompareModel
|
||||
{
|
||||
LeftId = id, RightId = rightId
|
||||
};
|
||||
|
||||
CommonTypes.Metadata.Scsi left = _context.Scsi.FirstOrDefault(l => l.Id == id);
|
||||
CommonTypes.Metadata.Scsi right = _context.Scsi.FirstOrDefault(r => r.Id == rightId);
|
||||
|
||||
if(left is null)
|
||||
{
|
||||
model.ErrorMessage = $"SCSI with id {id} has not been found";
|
||||
model.HasError = true;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
if(right is null)
|
||||
{
|
||||
model.ErrorMessage = $"SCSI with id {rightId} has not been found";
|
||||
model.HasError = true;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
Inquiry.SCSIInquiry? leftNullable = left.Inquiry;
|
||||
Inquiry.SCSIInquiry? rightNullable = right.Inquiry;
|
||||
model.ValueNames = new List<string>();
|
||||
model.LeftValues = new List<string>();
|
||||
model.RightValues = new List<string>();
|
||||
|
||||
if(!leftNullable.HasValue &&
|
||||
!rightNullable.HasValue)
|
||||
{
|
||||
model.AreEqual = true;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
if(leftNullable.HasValue &&
|
||||
!rightNullable.HasValue)
|
||||
{
|
||||
model.ValueNames.Add("Decoded");
|
||||
model.LeftValues.Add("decoded");
|
||||
model.RightValues.Add("null");
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
if(!leftNullable.HasValue)
|
||||
{
|
||||
model.ValueNames.Add("Decoded");
|
||||
model.LeftValues.Add("null");
|
||||
model.RightValues.Add("decoded");
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
var leftValue = left.Inquiry.Value;
|
||||
var rightValue = right.Inquiry.Value;
|
||||
|
||||
foreach(FieldInfo fieldInfo in leftValue.GetType().GetFields())
|
||||
{
|
||||
object lv = fieldInfo.GetValue(leftValue);
|
||||
object rv = fieldInfo.GetValue(rightValue);
|
||||
|
||||
if(fieldInfo.FieldType.IsArray)
|
||||
{
|
||||
object[] la = lv as object[];
|
||||
object[] ra = rv as object[];
|
||||
|
||||
switch(la)
|
||||
{
|
||||
case null when ra is null: continue;
|
||||
case null:
|
||||
model.ValueNames.Add(fieldInfo.Name);
|
||||
model.LeftValues.Add("null");
|
||||
model.RightValues.Add("[]");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ra is null)
|
||||
{
|
||||
model.ValueNames.Add(fieldInfo.Name);
|
||||
model.LeftValues.Add("[]");
|
||||
model.RightValues.Add("null");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(la.SequenceEqual(ra))
|
||||
continue;
|
||||
|
||||
model.ValueNames.Add(fieldInfo.Name);
|
||||
model.LeftValues.Add("[]");
|
||||
model.RightValues.Add("[]");
|
||||
}
|
||||
else if(lv == null &&
|
||||
rv == null) { }
|
||||
else if(lv != null &&
|
||||
rv == null)
|
||||
{
|
||||
model.ValueNames.Add(fieldInfo.Name);
|
||||
model.LeftValues.Add($"{lv}");
|
||||
model.RightValues.Add("null");
|
||||
}
|
||||
else if(lv == null)
|
||||
{
|
||||
model.ValueNames.Add(fieldInfo.Name);
|
||||
model.LeftValues.Add("null");
|
||||
model.RightValues.Add($"{rv}");
|
||||
}
|
||||
else if(!lv.Equals(rv))
|
||||
|
||||
{
|
||||
model.ValueNames.Add(fieldInfo.Name);
|
||||
model.LeftValues.Add($"{lv}");
|
||||
model.RightValues.Add($"{rv}");
|
||||
}
|
||||
}
|
||||
|
||||
model.AreEqual = model.LeftValues.Count == 0 && model.RightValues.Count == 0;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user