Save dat file in database.

This commit is contained in:
2020-08-22 05:40:50 +01:00
parent 25dd3f4921
commit 3b0feee452
8 changed files with 352 additions and 8 deletions

View File

@@ -28,6 +28,8 @@ using System.Diagnostics;
using System.IO;
using Aaru.Checksums;
using RomRepoMgr.Core.EventArgs;
using RomRepoMgr.Database;
using RomRepoMgr.Database.Models;
using SabreTools.Library.DatFiles;
using ErrorEventArgs = RomRepoMgr.Core.EventArgs.ErrorEventArgs;
@@ -83,6 +85,31 @@ namespace RomRepoMgr.Core.Workers
return;
}
SetMessage?.Invoke(this, new MessageEventArgs
{
Message = "Adding DAT to database..."
});
// TODO: Check if there is a has in database but not in repo
var romSet = new RomSet
{
Author = datFile.Header.Author,
Comment = datFile.Header.Comment,
Date = datFile.Header.Date,
Description = datFile.Header.Description,
Filename = Path.GetFileName(_datPath),
Homepage = datFile.Header.Homepage,
Name = datFile.Header.Name,
Sha384 = datHash,
Version = datFile.Header.Version,
CreatedOn = DateTime.UtcNow,
UpdatedOn = DateTime.UtcNow
};
Context.Singleton.RomSets.Add(romSet);
Context.Singleton.SaveChanges();
SetMessage?.Invoke(this, new MessageEventArgs
{
Message = "Compressing DAT file..."

View File

@@ -52,7 +52,8 @@ namespace RomRepoMgr.Database
}
}
public DbSet<DbFile> Files { get; set; }
public DbSet<DbFile> Files { get; set; }
public DbSet<RomSet> RomSets { get; set; }
public static Context Create(string dbPath)
{
@@ -76,6 +77,27 @@ namespace RomRepoMgr.Database
entity.HasIndex(e => e.Size);
});
modelBuilder.Entity<RomSet>(entity =>
{
entity.HasIndex(e => e.Author);
entity.HasIndex(e => e.Comment);
entity.HasIndex(e => e.Date);
entity.HasIndex(e => e.Description);
entity.HasIndex(e => e.Homepage);
entity.HasIndex(e => e.Name);
entity.HasIndex(e => e.Version);
entity.HasIndex(e => e.Filename);
entity.HasIndex(e => e.Sha384);
});
}
}
}

View File

@@ -29,7 +29,6 @@ namespace RomRepoMgr.Database.Migrations
.HasMaxLength(8);
b.Property<DateTime>("CreatedOn")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Md5")
@@ -48,7 +47,6 @@ namespace RomRepoMgr.Database.Migrations
.HasColumnType("INTEGER");
b.Property<DateTime>("UpdatedOn")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TEXT");
b.HasKey("Id");

View File

@@ -0,0 +1,132 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using RomRepoMgr.Database;
namespace RomRepoMgr.Database.Migrations
{
[DbContext(typeof(Context))]
[Migration("20200822042211_AddRomSets")]
partial class AddRomSets
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.7");
modelBuilder.Entity("RomRepoMgr.Database.Models.DbFile", b =>
{
b.Property<ulong>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Crc32")
.HasColumnType("TEXT")
.HasMaxLength(8);
b.Property<DateTime>("CreatedOn")
.HasColumnType("TEXT");
b.Property<string>("Md5")
.HasColumnType("TEXT")
.HasMaxLength(32);
b.Property<string>("Sha1")
.HasColumnType("TEXT")
.HasMaxLength(40);
b.Property<string>("Sha256")
.HasColumnType("TEXT")
.HasMaxLength(64);
b.Property<ulong>("Size")
.HasColumnType("INTEGER");
b.Property<DateTime>("UpdatedOn")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Crc32");
b.HasIndex("Sha1");
b.HasIndex("Sha256");
b.HasIndex("Size");
b.ToTable("Files");
});
modelBuilder.Entity("RomRepoMgr.Database.Models.RomSet", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Author")
.HasColumnType("TEXT");
b.Property<string>("Comment")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedOn")
.HasColumnType("TEXT");
b.Property<string>("Date")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("Filename")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Homepage")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Sha384")
.IsRequired()
.HasColumnType("TEXT")
.HasMaxLength(96);
b.Property<DateTime>("UpdatedOn")
.HasColumnType("TEXT");
b.Property<string>("Version")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Author");
b.HasIndex("Comment");
b.HasIndex("Date");
b.HasIndex("Description");
b.HasIndex("Filename");
b.HasIndex("Homepage");
b.HasIndex("Name");
b.HasIndex("Sha384");
b.HasIndex("Version");
b.ToTable("RomSets");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,75 @@
/******************************************************************************
// RomRepoMgr - ROM repository manager
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2020 Natalia Portillo
*******************************************************************************/
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace RomRepoMgr.Database.Migrations
{
public partial class AddRomSets : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable("RomSets", table => new
{
Id = table.Column<long>(nullable: false).Annotation("Sqlite:Autoincrement", true),
CreatedOn = table.Column<DateTime>(nullable: false),
UpdatedOn = table.Column<DateTime>(nullable: false),
Author = table.Column<string>(nullable: true),
Comment = table.Column<string>(nullable: true),
Date = table.Column<string>(nullable: true),
Description = table.Column<string>(nullable: true),
Homepage = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true),
Version = table.Column<string>(nullable: true),
Filename = table.Column<string>(nullable: false),
Sha384 = table.Column<string>(maxLength: 96, nullable: false)
}, constraints: table =>
{
table.PrimaryKey("PK_RomSets", x => x.Id);
});
migrationBuilder.CreateIndex("IX_RomSets_Author", "RomSets", "Author");
migrationBuilder.CreateIndex("IX_RomSets_Comment", "RomSets", "Comment");
migrationBuilder.CreateIndex("IX_RomSets_Date", "RomSets", "Date");
migrationBuilder.CreateIndex("IX_RomSets_Description", "RomSets", "Description");
migrationBuilder.CreateIndex("IX_RomSets_Filename", "RomSets", "Filename");
migrationBuilder.CreateIndex("IX_RomSets_Homepage", "RomSets", "Homepage");
migrationBuilder.CreateIndex("IX_RomSets_Name", "RomSets", "Name");
migrationBuilder.CreateIndex("IX_RomSets_Sha384", "RomSets", "Sha384");
migrationBuilder.CreateIndex("IX_RomSets_Version", "RomSets", "Version");
}
protected override void Down(MigrationBuilder migrationBuilder) => migrationBuilder.DropTable("RomSets");
}
}

View File

@@ -20,7 +20,7 @@ namespace RomRepoMgr.Database.Migrations
b.Property<string>("Crc32").HasColumnType("TEXT").HasMaxLength(8);
b.Property<DateTime>("CreatedOn").ValueGeneratedOnAdd().HasColumnType("TEXT");
b.Property<DateTime>("CreatedOn").HasColumnType("TEXT");
b.Property<string>("Md5").HasColumnType("TEXT").HasMaxLength(32);
@@ -30,7 +30,7 @@ namespace RomRepoMgr.Database.Migrations
b.Property<ulong>("Size").HasColumnType("INTEGER");
b.Property<DateTime>("UpdatedOn").ValueGeneratedOnAddOrUpdate().HasColumnType("TEXT");
b.Property<DateTime>("UpdatedOn").HasColumnType("TEXT");
b.HasKey("Id");
@@ -44,6 +44,55 @@ namespace RomRepoMgr.Database.Migrations
b.ToTable("Files");
});
modelBuilder.Entity("RomRepoMgr.Database.Models.RomSet", b =>
{
b.Property<long>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER");
b.Property<string>("Author").HasColumnType("TEXT");
b.Property<string>("Comment").HasColumnType("TEXT");
b.Property<DateTime>("CreatedOn").HasColumnType("TEXT");
b.Property<string>("Date").HasColumnType("TEXT");
b.Property<string>("Description").HasColumnType("TEXT");
b.Property<string>("Filename").IsRequired().HasColumnType("TEXT");
b.Property<string>("Homepage").HasColumnType("TEXT");
b.Property<string>("Name").HasColumnType("TEXT");
b.Property<string>("Sha384").IsRequired().HasColumnType("TEXT").HasMaxLength(96);
b.Property<DateTime>("UpdatedOn").HasColumnType("TEXT");
b.Property<string>("Version").HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Author");
b.HasIndex("Comment");
b.HasIndex("Date");
b.HasIndex("Description");
b.HasIndex("Filename");
b.HasIndex("Homepage");
b.HasIndex("Name");
b.HasIndex("Sha384");
b.HasIndex("Version");
b.ToTable("RomSets");
});
#pragma warning restore 612, 618
}
}

View File

@@ -24,7 +24,6 @@
*******************************************************************************/
using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace RomRepoMgr.Database.Models
{
@@ -32,9 +31,7 @@ namespace RomRepoMgr.Database.Models
{
public TKey Id { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public DateTime CreatedOn { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime UpdatedOn { get; set; }
}
}

View File

@@ -0,0 +1,44 @@
/******************************************************************************
// RomRepoMgr - ROM repository manager
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2020 Natalia Portillo
*******************************************************************************/
using System.ComponentModel.DataAnnotations;
namespace RomRepoMgr.Database.Models
{
public class RomSet : BaseModel<long>
{
public string Author { get; set; }
public string Comment { get; set; }
public string Date { get; set; }
public string Description { get; set; }
public string Homepage { get; set; }
public string Name { get; set; }
public string Version { get; set; }
[Required]
public string Filename { get; set; }
[Required, StringLength(96, MinimumLength = 96)]
public string Sha384 { get; set; }
}
}