Add database table for iNES/NES 2.0 manually written information from headers.

This commit is contained in:
2021-12-08 20:34:36 +00:00
parent 5603159a82
commit 2d0447e269
11 changed files with 5380 additions and 1172 deletions

View File

@@ -271,6 +271,39 @@ namespace Aaru.Core
}); });
AaruConsole.WriteLine("Added {0} known devices", sync.Devices.Count); AaruConsole.WriteLine("Added {0} known devices", sync.Devices.Count);
AnsiConsole.Progress().AutoClear(true).HideCompleted(true).
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
Start(ctx =>
{
ProgressTask task = ctx.AddTask("Adding known iNES/NES 2.0 headers");
task.MaxValue = sync.NesHeaders.Count;
foreach(NesHeaderDto header in sync.NesHeaders)
{
task.Increment(1);
mctx.NesHeaders.Add(new NesHeaderInfo
{
Id = header.Id,
AddedWhen = DateTime.UtcNow,
BatteryPresent = header.BatteryPresent,
ConsoleType = header.ConsoleType,
DefaultExpansionDevice = header.DefaultExpansionDevice,
ExtendedConsoleType = header.ExtendedConsoleType,
FourScreenMode = header.FourScreenMode,
Mapper = header.Mapper,
ModifiedWhen = DateTime.UtcNow,
NametableMirroring = header.NametableMirroring,
Sha256 = header.Sha256,
Submapper = header.Submapper,
VsHardwareType = header.VsHardwareType,
VsPpuType = header.VsPpuType
});
}
});
AaruConsole.WriteLine("Added {0} known iNES/NES 2.0 headers", sync.NesHeaders.Count);
} }
else else
{ {
@@ -278,10 +311,12 @@ namespace Aaru.Core
long addedProducts = 0; long addedProducts = 0;
long addedOffsets = 0; long addedOffsets = 0;
long addedDevices = 0; long addedDevices = 0;
long addedNesHeaders = 0;
long modifiedVendors = 0; long modifiedVendors = 0;
long modifiedProducts = 0; long modifiedProducts = 0;
long modifiedOffsets = 0; long modifiedOffsets = 0;
long modifiedDevices = 0; long modifiedDevices = 0;
long modifiedNesHeaders = 0;
AnsiConsole.Progress().AutoClear(true).HideCompleted(true). AnsiConsole.Progress().AutoClear(true).HideCompleted(true).
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()). Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
@@ -431,6 +466,73 @@ namespace Aaru.Core
AaruConsole.WriteLine("Added {0} known devices", addedDevices); AaruConsole.WriteLine("Added {0} known devices", addedDevices);
AaruConsole.WriteLine("Modified {0} known devices", modifiedDevices); AaruConsole.WriteLine("Modified {0} known devices", modifiedDevices);
AnsiConsole.Progress().AutoClear(true).HideCompleted(true).
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
Start(ctx =>
{
ProgressTask task = ctx.AddTask("Updating known iNES/NES 2.0 headers");
task.MaxValue = sync.Offsets.Count;
foreach(NesHeaderDto header in sync.NesHeaders)
{
task.Increment(1);
NesHeaderInfo existing = mctx.NesHeaders.FirstOrDefault(d => d.Id == header.Id);
if(existing != null)
{
modifiedNesHeaders++;
DateTime addedDate = existing.AddedWhen;
mctx.Remove(existing);
existing = new NesHeaderInfo
{
Id = header.Id,
AddedWhen = addedDate,
BatteryPresent = header.BatteryPresent,
ConsoleType = header.ConsoleType,
DefaultExpansionDevice = header.DefaultExpansionDevice,
ExtendedConsoleType = header.ExtendedConsoleType,
FourScreenMode = header.FourScreenMode,
Mapper = header.Mapper,
ModifiedWhen = DateTime.UtcNow,
NametableMirroring = header.NametableMirroring,
Sha256 = header.Sha256,
Submapper = header.Submapper,
VsHardwareType = header.VsHardwareType,
VsPpuType = header.VsPpuType
};
mctx.NesHeaders.Add(existing);
}
else
{
addedNesHeaders++;
mctx.NesHeaders.Add(new NesHeaderInfo
{
Id = header.Id,
AddedWhen = DateTime.UtcNow,
BatteryPresent = header.BatteryPresent,
ConsoleType = header.ConsoleType,
DefaultExpansionDevice = header.DefaultExpansionDevice,
ExtendedConsoleType = header.ExtendedConsoleType,
FourScreenMode = header.FourScreenMode,
Mapper = header.Mapper,
ModifiedWhen = DateTime.UtcNow,
NametableMirroring = header.NametableMirroring,
Sha256 = header.Sha256,
Submapper = header.Submapper,
VsHardwareType = header.VsHardwareType,
VsPpuType = header.VsPpuType
});
}
}
});
AaruConsole.WriteLine("Added {0} known iNES/NES 2.0 headers", addedDevices);
AaruConsole.WriteLine("Modified {0} known iNES/NES 2.0 headers", modifiedDevices);
} }
} }
catch(Exception ex) catch(Exception ex)

View File

@@ -137,6 +137,8 @@
<Compile Include="Migrations\20200711182425_AddFieldsForF1hCommand06hSubcommand.Designer.cs" /> <Compile Include="Migrations\20200711182425_AddFieldsForF1hCommand06hSubcommand.Designer.cs" />
<Compile Include="Migrations\20200711230202_FixGdRomCapabilitiesFieldName.cs" /> <Compile Include="Migrations\20200711230202_FixGdRomCapabilitiesFieldName.cs" />
<Compile Include="Migrations\20200711230202_FixGdRomCapabilitiesFieldName.Designer.cs" /> <Compile Include="Migrations\20200711230202_FixGdRomCapabilitiesFieldName.Designer.cs" />
<Compile Include="Migrations\20211208202937_AddNesHeaders.cs" />
<Compile Include="Migrations\20211208202937_AddNesHeaders.Designer.cs" />
<Compile Include="Migrations\AaruContextModelSnapshot.cs" /> <Compile Include="Migrations\AaruContextModelSnapshot.cs" />
<Compile Include="Models\BaseModel.cs" /> <Compile Include="Models\BaseModel.cs" />
<Compile Include="Models\BaseOperatingSystem.cs" /> <Compile Include="Models\BaseOperatingSystem.cs" />
@@ -149,6 +151,7 @@
<Compile Include="Models\Media.cs" /> <Compile Include="Models\Media.cs" />
<Compile Include="Models\MediaFormat.cs" /> <Compile Include="Models\MediaFormat.cs" />
<Compile Include="Models\NameCountModel.cs" /> <Compile Include="Models\NameCountModel.cs" />
<Compile Include="Models\NesHeaderInfo.cs" />
<Compile Include="Models\OperatingSystem.cs" /> <Compile Include="Models\OperatingSystem.cs" />
<Compile Include="Models\Partition.cs" /> <Compile Include="Models\Partition.cs" />
<Compile Include="Models\RemoteApplication.cs" /> <Compile Include="Models\RemoteApplication.cs" />

View File

@@ -33,8 +33,8 @@
using Aaru.Database.Models; using Aaru.Database.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Aaru.Database namespace Aaru.Database;
{
/// <inheritdoc /> /// <inheritdoc />
/// <summary>Database context</summary> /// <summary>Database context</summary>
public sealed class AaruContext : DbContext public sealed class AaruContext : DbContext
@@ -78,6 +78,8 @@ namespace Aaru.Database
public DbSet<RemoteArchitecture> RemoteArchitectures { get; set; } public DbSet<RemoteArchitecture> RemoteArchitectures { get; set; }
/// <summary>Statistics of remote operating systems</summary> /// <summary>Statistics of remote operating systems</summary>
public DbSet<RemoteOperatingSystem> RemoteOperatingSystems { get; set; } public DbSet<RemoteOperatingSystem> RemoteOperatingSystems { get; set; }
/// <summary>Known iNES/NES 2.0 headers</summary>
public DbSet<NesHeaderInfo> NesHeaders { get; set; }
// Note: If table does not appear check that last migration has been REALLY added to the project // Note: If table does not appear check that last migration has been REALLY added to the project
@@ -106,9 +108,8 @@ namespace Aaru.Database
HasForeignKey("ScsiModeId").OnDelete(DeleteBehavior.Cascade)); HasForeignKey("ScsiModeId").OnDelete(DeleteBehavior.Cascade));
modelBuilder.Entity("Aaru.CommonTypes.Metadata.DensityCode", modelBuilder.Entity("Aaru.CommonTypes.Metadata.DensityCode",
b => b.HasOne("Aaru.CommonTypes.Metadata.SscSupportedMedia", null). b => b.HasOne("Aaru.CommonTypes.Metadata.SscSupportedMedia", null).WithMany("DensityCodes").
WithMany("DensityCodes").HasForeignKey("SscSupportedMediaId"). HasForeignKey("SscSupportedMediaId").OnDelete(DeleteBehavior.Cascade));
OnDelete(DeleteBehavior.Cascade));
modelBuilder.Entity("Aaru.CommonTypes.Metadata.Mmc", modelBuilder.Entity("Aaru.CommonTypes.Metadata.Mmc",
b => b.HasOne("Aaru.CommonTypes.Metadata.MmcFeatures", "Features").WithMany(). b => b.HasOne("Aaru.CommonTypes.Metadata.MmcFeatures", "Features").WithMany().
@@ -189,8 +190,8 @@ namespace Aaru.Database
b.HasOne("Aaru.CommonTypes.Metadata.FireWire", "FireWire").WithMany().HasForeignKey("FireWireId"). b.HasOne("Aaru.CommonTypes.Metadata.FireWire", "FireWire").WithMany().HasForeignKey("FireWireId").
OnDelete(DeleteBehavior.SetNull); OnDelete(DeleteBehavior.SetNull);
b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "MultiMediaCard").WithMany(). b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "MultiMediaCard").WithMany().HasForeignKey("MultiMediaCardId").
HasForeignKey("MultiMediaCardId").OnDelete(DeleteBehavior.SetNull); OnDelete(DeleteBehavior.SetNull);
b.HasOne("Aaru.CommonTypes.Metadata.Pcmcia", "PCMCIA").WithMany().HasForeignKey("PCMCIAId"). b.HasOne("Aaru.CommonTypes.Metadata.Pcmcia", "PCMCIA").WithMany().HasForeignKey("PCMCIAId").
OnDelete(DeleteBehavior.SetNull); OnDelete(DeleteBehavior.SetNull);
@@ -198,8 +199,8 @@ namespace Aaru.Database
b.HasOne("Aaru.CommonTypes.Metadata.Scsi", "SCSI").WithMany().HasForeignKey("SCSIId"). b.HasOne("Aaru.CommonTypes.Metadata.Scsi", "SCSI").WithMany().HasForeignKey("SCSIId").
OnDelete(DeleteBehavior.SetNull); OnDelete(DeleteBehavior.SetNull);
b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "SecureDigital").WithMany(). b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "SecureDigital").WithMany().HasForeignKey("SecureDigitalId").
HasForeignKey("SecureDigitalId").OnDelete(DeleteBehavior.SetNull); OnDelete(DeleteBehavior.SetNull);
b.HasOne("Aaru.CommonTypes.Metadata.Usb", "USB").WithMany().HasForeignKey("USBId"). b.HasOne("Aaru.CommonTypes.Metadata.Usb", "USB").WithMany().HasForeignKey("USBId").
OnDelete(DeleteBehavior.SetNull); OnDelete(DeleteBehavior.SetNull);
@@ -216,8 +217,8 @@ namespace Aaru.Database
b.HasOne("Aaru.CommonTypes.Metadata.FireWire", "FireWire").WithMany().HasForeignKey("FireWireId"). b.HasOne("Aaru.CommonTypes.Metadata.FireWire", "FireWire").WithMany().HasForeignKey("FireWireId").
OnDelete(DeleteBehavior.SetNull); OnDelete(DeleteBehavior.SetNull);
b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "MultiMediaCard").WithMany(). b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "MultiMediaCard").WithMany().HasForeignKey("MultiMediaCardId").
HasForeignKey("MultiMediaCardId").OnDelete(DeleteBehavior.SetNull); OnDelete(DeleteBehavior.SetNull);
b.HasOne("Aaru.CommonTypes.Metadata.Pcmcia", "PCMCIA").WithMany().HasForeignKey("PCMCIAId"). b.HasOne("Aaru.CommonTypes.Metadata.Pcmcia", "PCMCIA").WithMany().HasForeignKey("PCMCIAId").
OnDelete(DeleteBehavior.SetNull); OnDelete(DeleteBehavior.SetNull);
@@ -225,8 +226,8 @@ namespace Aaru.Database
b.HasOne("Aaru.CommonTypes.Metadata.Scsi", "SCSI").WithMany().HasForeignKey("SCSIId"). b.HasOne("Aaru.CommonTypes.Metadata.Scsi", "SCSI").WithMany().HasForeignKey("SCSIId").
OnDelete(DeleteBehavior.SetNull); OnDelete(DeleteBehavior.SetNull);
b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "SecureDigital").WithMany(). b.HasOne("Aaru.CommonTypes.Metadata.MmcSd", "SecureDigital").WithMany().HasForeignKey("SecureDigitalId").
HasForeignKey("SecureDigitalId").OnDelete(DeleteBehavior.SetNull); OnDelete(DeleteBehavior.SetNull);
b.HasOne("Aaru.CommonTypes.Metadata.Usb", "USB").WithMany().HasForeignKey("USBId"). b.HasOne("Aaru.CommonTypes.Metadata.Usb", "USB").WithMany().HasForeignKey("USBId").
OnDelete(DeleteBehavior.SetNull); OnDelete(DeleteBehavior.SetNull);
@@ -239,6 +240,8 @@ namespace Aaru.Database
modelBuilder.Entity<UsbProduct>().HasIndex(b => b.VendorId); modelBuilder.Entity<UsbProduct>().HasIndex(b => b.VendorId);
modelBuilder.Entity<UsbVendor>().HasIndex(b => b.ModifiedWhen); modelBuilder.Entity<UsbVendor>().HasIndex(b => b.ModifiedWhen);
}
modelBuilder.Entity<NesHeaderInfo>().HasIndex(b => b.Sha256);
modelBuilder.Entity<NesHeaderInfo>().HasIndex(b => b.ModifiedWhen);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,55 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Aaru.Database.Migrations
{
public partial class AddNesHeaders : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "NesHeaders",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Sha256 = table.Column<string>(type: "TEXT", maxLength: 32, nullable: true),
NametableMirroring = table.Column<bool>(type: "INTEGER", nullable: false),
BatteryPresent = table.Column<bool>(type: "INTEGER", nullable: false),
FourScreenMode = table.Column<bool>(type: "INTEGER", nullable: false),
Mapper = table.Column<ushort>(type: "INTEGER", nullable: false),
ConsoleType = table.Column<byte>(type: "INTEGER", nullable: false),
Submapper = table.Column<byte>(type: "INTEGER", nullable: false),
TimingMode = table.Column<byte>(type: "INTEGER", nullable: false),
VsPpuType = table.Column<byte>(type: "INTEGER", nullable: false),
VsHardwareType = table.Column<byte>(type: "INTEGER", nullable: false),
ExtendedConsoleType = table.Column<byte>(type: "INTEGER", nullable: false),
DefaultExpansionDevice = table.Column<byte>(type: "INTEGER", nullable: false),
AddedWhen = table.Column<DateTime>(type: "TEXT", nullable: false),
ModifiedWhen = table.Column<DateTime>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_NesHeaders", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_NesHeaders_ModifiedWhen",
table: "NesHeaders",
column: "ModifiedWhen");
migrationBuilder.CreateIndex(
name: "IX_NesHeaders_Sha256",
table: "NesHeaders",
column: "Sha256");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "NesHeaders");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
using System;
using System.ComponentModel.DataAnnotations;
using Aaru.CommonTypes.Enums;
namespace Aaru.Database.Models;
/// <summary>Information needed to rebuild an iNES/NES 2.0 header from a ROM hash</summary>
public class NesHeaderInfo : BaseModel
{
/// <summary>ROM hash</summary>
[StringLength(32)]
public string Sha256 { get; set; }
/// <summary>If <c>true</c> vertical mirroring is hard-wired, horizontal or mapper defined otherwise</summary>
public bool NametableMirroring { get; set; }
/// <summary>If <c>true</c> a battery is present</summary>
public bool BatteryPresent { get; set; }
/// <summary>If <c>true</c> the four player screen mode is hardwired</summary>
public bool FourScreenMode { get; set; }
/// <summary>Mapper number (NES 2.0 when in conflict)</summary>
public ushort Mapper { get; set; }
/// <summary>Console type</summary>
public NesConsoleType ConsoleType { get; set; }
/// <summary>Submapper number</summary>
public byte Submapper { get; set; }
/// <summary>Timing mode</summary>
public NesTimingMode TimingMode { get; set; }
/// <summary>Vs. PPU type</summary>
public NesVsPpuType VsPpuType { get; set; }
/// <summary>Vs. hardware type</summary>
public NesVsHardwareType VsHardwareType { get; set; }
/// <summary>Extended console type</summary>
public NesExtendedConsoleType ExtendedConsoleType { get; set; }
/// <summary>Default expansion device</summary>
public NesDefaultExpansionDevice DefaultExpansionDevice { get; set; }
/// <summary>Date when model has been added to the database</summary>
public DateTime AddedWhen { get; set; }
/// <summary>Date when model was last modified</summary>
public DateTime ModifiedWhen { get; set; }
}

View File

@@ -143,6 +143,7 @@
<Compile Include="ByteAddressable\GameBoy.cs" /> <Compile Include="ByteAddressable\GameBoy.cs" />
<Compile Include="ByteAddressable\GameBoyAdvance.cs" /> <Compile Include="ByteAddressable\GameBoyAdvance.cs" />
<Compile Include="ByteAddressable\MasterSystem.cs" /> <Compile Include="ByteAddressable\MasterSystem.cs" />
<Compile Include="ByteAddressable\NES.cs" />
<Compile Include="ByteAddressable\Nintendo64.cs" /> <Compile Include="ByteAddressable\Nintendo64.cs" />
<Compile Include="ByteAddressable\SegaMegaDrive.cs" /> <Compile Include="ByteAddressable\SegaMegaDrive.cs" />
<Compile Include="ByteAddressable\SuperNintendo.cs" /> <Compile Include="ByteAddressable\SuperNintendo.cs" />

View File

@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Schemas;
namespace Aaru.DiscImages.ByteAddressable;
public class NES :IByteAddressableImage
{
/// <inheritdoc />
public string Author { get; }
/// <inheritdoc />
public CICMMetadataType CicmMetadata { get; }
/// <inheritdoc />
public List<DumpHardwareType> DumpHardware { get; }
/// <inheritdoc />
public string Format { get; }
/// <inheritdoc />
public Guid Id { get; }
/// <inheritdoc />
public ImageInfo Info { get; }
/// <inheritdoc />
public string Name { get; }
/// <inheritdoc />
public bool Identify(IFilter imageFilter) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber Open(IFilter imageFilter) => throw new NotImplementedException();
/// <inheritdoc />
public string ErrorMessage { get; }
/// <inheritdoc />
public bool IsWriting { get; }
/// <inheritdoc />
public IEnumerable<string> KnownExtensions { get; }
/// <inheritdoc />
public IEnumerable<MediaTagType> SupportedMediaTags { get; }
/// <inheritdoc />
public IEnumerable<MediaType> SupportedMediaTypes { get; }
/// <inheritdoc />
public IEnumerable<(string name, Type type, string description, object @default)> SupportedOptions { get; }
/// <inheritdoc />
public IEnumerable<SectorTagType> SupportedSectorTags { get; }
/// <inheritdoc />
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors, uint sectorSize) => throw new NotImplementedException();
/// <inheritdoc />
public bool Close() => throw new NotImplementedException();
/// <inheritdoc />
public bool SetCicmMetadata(CICMMetadataType metadata) => throw new NotImplementedException();
/// <inheritdoc />
public bool SetDumpHardware(List<DumpHardwareType> dumpHardware) => throw new NotImplementedException();
/// <inheritdoc />
public bool SetMetadata(ImageInfo metadata) => throw new NotImplementedException();
/// <inheritdoc />
public long Position { get; set; }
/// <inheritdoc />
public ErrorNumber Create(string path, MediaType mediaType, Dictionary<string, string> options, long maximumSize) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber GetHeader(out byte[] header) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber GetMappings(out LinearMemoryMap mappings) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber ReadByte(out byte b, bool advance = true) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber ReadByteAt(long position, out byte b, bool advance = true) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber ReadBytes(byte[] buffer, int offset, int bytesToRead, out int bytesRead, bool advance = true) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber ReadBytesAt(long position, byte[] buffer, int offset, int bytesToRead, out int bytesRead,
bool advance = true) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber SetHeader(byte[] header) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber SetMappings(LinearMemoryMap mappings) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber WriteByte(byte b, bool advance = true) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber WriteByteAt(long position, byte b, bool advance = true) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber WriteBytes(byte[] buffer, int offset, int bytesToWrite, out int bytesWritten, bool advance = true) => throw new NotImplementedException();
/// <inheritdoc />
public ErrorNumber WriteBytesAt(long position, byte[] buffer, int offset, int bytesToWrite, out int bytesWritten,
bool advance = true) => throw new NotImplementedException();
}