mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add ATA comparer.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DiscImageChef.Decoders.ATA;
|
||||||
using DiscImageChef.Server.Models;
|
using DiscImageChef.Server.Models;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -140,5 +142,133 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IActionResult Compare(int id, int rightId)
|
||||||
|
{
|
||||||
|
var model = new CompareModel();
|
||||||
|
|
||||||
|
model.LeftId = id;
|
||||||
|
model.RightId = rightId;
|
||||||
|
|
||||||
|
CommonTypes.Metadata.Ata left = _context.Ata.FirstOrDefault(l => l.Id == id);
|
||||||
|
CommonTypes.Metadata.Ata right = _context.Ata.FirstOrDefault(r => r.Id == rightId);
|
||||||
|
|
||||||
|
if(left is null)
|
||||||
|
{
|
||||||
|
model.ErrorMessage = $"ATA with id {id} has not been found";
|
||||||
|
model.HasError = true;
|
||||||
|
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(right is null)
|
||||||
|
{
|
||||||
|
model.ErrorMessage = $"ATA with id {rightId} has not been found";
|
||||||
|
model.HasError = true;
|
||||||
|
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
Identify.IdentifyDevice? leftNullable = left.IdentifyDevice;
|
||||||
|
Identify.IdentifyDevice? rightNullable = right.IdentifyDevice;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Identify.IdentifyDevice leftValue = left.IdentifyDevice.Value;
|
||||||
|
Identify.IdentifyDevice rightValue = right.IdentifyDevice.Value;
|
||||||
|
model.ValueNames = new List<string>();
|
||||||
|
model.LeftValues = new List<string>();
|
||||||
|
model.RightValues = new List<string>();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
82
DiscImageChef.Server/Areas/Admin/Views/Atas/Compare.cshtml
Normal file
82
DiscImageChef.Server/Areas/Admin/Views/Atas/Compare.cshtml
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
@model CompareModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
|
||||||
|
ViewBag.Title = "DiscImageChef";
|
||||||
|
}
|
||||||
|
@{
|
||||||
|
// /***************************************************************************
|
||||||
|
// The Disc Image Chef
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Filename : Details.cshtml
|
||||||
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// Component : DiscImageChef Server.
|
||||||
|
//
|
||||||
|
// --[ License ] --------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 2.1 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Copyright © 2011-2019 Natalia Portillo
|
||||||
|
// ****************************************************************************/
|
||||||
|
}
|
||||||
|
<h2>Comparing ATA IDENTIFY ID @Model.LeftId with ID @Model.RightId</h2>
|
||||||
|
@if (Model.AreEqual)
|
||||||
|
{
|
||||||
|
<p>No differences found.</p>
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (Model.HasError)
|
||||||
|
{
|
||||||
|
<p class="alert-info">@Model.ErrorMessage</p>
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Value name
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
ID: @Model.LeftId
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
ID: @Model.RightId
|
||||||
|
</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@for (var i = 0; i < Model.ValueNames.Count; i++)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Model.ValueNames[i]
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Model.LeftValues[i]
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Model.RightValues[i]
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<a asp-action="Index" class="btn btn-primary">Back to List</a>
|
||||||
|
<a asp-action="Delete" asp-route-id="@Model.LeftId" class="btn btn-danger">Delete ID @Model.LeftId</a>
|
||||||
|
<a asp-action="Delete" asp-route-id="@Model.RightId" class="btn btn-danger">Delete ID @Model.RightId</a>
|
||||||
@@ -41,5 +41,11 @@
|
|||||||
@Html.Raw(Html.EncodedMultiLineText(Identify.Prettify(Model.Identify)))
|
@Html.Raw(Html.EncodedMultiLineText(Identify.Prettify(Model.Identify)))
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
<form asp-action="Compare">
|
||||||
|
<input type="hidden" asp-for="Id" />
|
||||||
|
Compare to:
|
||||||
|
<input name="RightId" type="number" />
|
||||||
<a asp-action="Index" class="btn btn-secondary">Back to List</a>
|
<a asp-action="Index" class="btn btn-secondary">Back to List</a>
|
||||||
|
<input class="btn btn-primary" type="submit" value="Compare" />
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
16
DiscImageChef.Server/Models/CompareModel.cs
Normal file
16
DiscImageChef.Server/Models/CompareModel.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace DiscImageChef.Server.Models
|
||||||
|
{
|
||||||
|
public class CompareModel
|
||||||
|
{
|
||||||
|
public int LeftId { get; set; }
|
||||||
|
public int RightId { get; set; }
|
||||||
|
public List<string> ValueNames { get; set; }
|
||||||
|
public List<string> LeftValues { get; set; }
|
||||||
|
public List<string> RightValues { get; set; }
|
||||||
|
public bool HasError { get; set; }
|
||||||
|
public string ErrorMessage { get; set; }
|
||||||
|
public bool AreEqual { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user