mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 19:24:51 +00:00
Save dat file in database.
This commit is contained in:
@@ -28,6 +28,8 @@ using System.Diagnostics;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using Aaru.Checksums;
|
using Aaru.Checksums;
|
||||||
using RomRepoMgr.Core.EventArgs;
|
using RomRepoMgr.Core.EventArgs;
|
||||||
|
using RomRepoMgr.Database;
|
||||||
|
using RomRepoMgr.Database.Models;
|
||||||
using SabreTools.Library.DatFiles;
|
using SabreTools.Library.DatFiles;
|
||||||
using ErrorEventArgs = RomRepoMgr.Core.EventArgs.ErrorEventArgs;
|
using ErrorEventArgs = RomRepoMgr.Core.EventArgs.ErrorEventArgs;
|
||||||
|
|
||||||
@@ -83,6 +85,31 @@ namespace RomRepoMgr.Core.Workers
|
|||||||
return;
|
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
|
SetMessage?.Invoke(this, new MessageEventArgs
|
||||||
{
|
{
|
||||||
Message = "Compressing DAT file..."
|
Message = "Compressing DAT file..."
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ 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)
|
public static Context Create(string dbPath)
|
||||||
{
|
{
|
||||||
@@ -76,6 +77,27 @@ namespace RomRepoMgr.Database
|
|||||||
|
|
||||||
entity.HasIndex(e => e.Size);
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,6 @@ namespace RomRepoMgr.Database.Migrations
|
|||||||
.HasMaxLength(8);
|
.HasMaxLength(8);
|
||||||
|
|
||||||
b.Property<DateTime>("CreatedOn")
|
b.Property<DateTime>("CreatedOn")
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Md5")
|
b.Property<string>("Md5")
|
||||||
@@ -48,7 +47,6 @@ namespace RomRepoMgr.Database.Migrations
|
|||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<DateTime>("UpdatedOn")
|
b.Property<DateTime>("UpdatedOn")
|
||||||
.ValueGeneratedOnAddOrUpdate()
|
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|||||||
132
RomRepoMgr.Database/Migrations/20200822042211_AddRomSets.Designer.cs
generated
Normal file
132
RomRepoMgr.Database/Migrations/20200822042211_AddRomSets.Designer.cs
generated
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
75
RomRepoMgr.Database/Migrations/20200822042211_AddRomSets.cs
Normal file
75
RomRepoMgr.Database/Migrations/20200822042211_AddRomSets.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ namespace RomRepoMgr.Database.Migrations
|
|||||||
|
|
||||||
b.Property<string>("Crc32").HasColumnType("TEXT").HasMaxLength(8);
|
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);
|
b.Property<string>("Md5").HasColumnType("TEXT").HasMaxLength(32);
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ namespace RomRepoMgr.Database.Migrations
|
|||||||
|
|
||||||
b.Property<ulong>("Size").HasColumnType("INTEGER");
|
b.Property<ulong>("Size").HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<DateTime>("UpdatedOn").ValueGeneratedOnAddOrUpdate().HasColumnType("TEXT");
|
b.Property<DateTime>("UpdatedOn").HasColumnType("TEXT");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@@ -44,6 +44,55 @@ namespace RomRepoMgr.Database.Migrations
|
|||||||
|
|
||||||
b.ToTable("Files");
|
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
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace RomRepoMgr.Database.Models
|
namespace RomRepoMgr.Database.Models
|
||||||
{
|
{
|
||||||
@@ -32,9 +31,7 @@ namespace RomRepoMgr.Database.Models
|
|||||||
{
|
{
|
||||||
public TKey Id { get; set; }
|
public TKey Id { get; set; }
|
||||||
|
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
||||||
public DateTime CreatedOn { get; set; }
|
public DateTime CreatedOn { get; set; }
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
|
|
||||||
public DateTime UpdatedOn { get; set; }
|
public DateTime UpdatedOn { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
44
RomRepoMgr.Database/Models/RomSet.cs
Normal file
44
RomRepoMgr.Database/Models/RomSet.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user