mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 19:24:51 +00:00
Add machines (games) to database.
This commit is contained in:
@@ -24,8 +24,10 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using Aaru.Checksums;
|
using Aaru.Checksums;
|
||||||
using RomRepoMgr.Core.EventArgs;
|
using RomRepoMgr.Core.EventArgs;
|
||||||
using RomRepoMgr.Core.Models;
|
using RomRepoMgr.Core.Models;
|
||||||
@@ -139,6 +141,59 @@ namespace RomRepoMgr.Core.Workers
|
|||||||
datCompress.SetProgressBounds += SetProgressBounds;
|
datCompress.SetProgressBounds += SetProgressBounds;
|
||||||
datCompress.CompressFile(_datPath, compressedDatPath);
|
datCompress.CompressFile(_datPath, compressedDatPath);
|
||||||
|
|
||||||
|
SetMessage?.Invoke(this, new MessageEventArgs
|
||||||
|
{
|
||||||
|
Message = "Getting machine (game) names..."
|
||||||
|
});
|
||||||
|
|
||||||
|
List<string> machineNames =
|
||||||
|
(from value in datFile.Items.Values from item in value select item.Machine.Name).Distinct().
|
||||||
|
ToList();
|
||||||
|
|
||||||
|
SetMessage?.Invoke(this, new MessageEventArgs
|
||||||
|
{
|
||||||
|
Message = "Adding machines (games)..."
|
||||||
|
});
|
||||||
|
|
||||||
|
SetProgressBounds?.Invoke(this, new ProgressBoundsEventArgs
|
||||||
|
{
|
||||||
|
Minimum = 0,
|
||||||
|
Maximum = machineNames.Count
|
||||||
|
});
|
||||||
|
|
||||||
|
int position = 0;
|
||||||
|
Dictionary<string, Machine> machines = new Dictionary<string, Machine>();
|
||||||
|
|
||||||
|
foreach(string name in machineNames)
|
||||||
|
{
|
||||||
|
SetProgress?.Invoke(this, new ProgressEventArgs
|
||||||
|
{
|
||||||
|
Value = position
|
||||||
|
});
|
||||||
|
|
||||||
|
var machine = new Machine
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
RomSet = romSet,
|
||||||
|
CreatedOn = DateTime.UtcNow,
|
||||||
|
UpdatedOn = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
|
||||||
|
machines[name] = machine;
|
||||||
|
|
||||||
|
Context.Singleton.Machines.Add(machine);
|
||||||
|
position++;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetMessage?.Invoke(this, new MessageEventArgs
|
||||||
|
{
|
||||||
|
Message = "Saving changes to database..."
|
||||||
|
});
|
||||||
|
|
||||||
|
SetIndeterminateProgress?.Invoke(this, System.EventArgs.Empty);
|
||||||
|
|
||||||
|
Context.Singleton.SaveChanges();
|
||||||
|
|
||||||
WorkFinished?.Invoke(this, System.EventArgs.Empty);
|
WorkFinished?.Invoke(this, System.EventArgs.Empty);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
|
|||||||
@@ -52,8 +52,9 @@ namespace RomRepoMgr.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DbSet<DbFile> Files { get; set; }
|
public DbSet<DbFile> Files { get; set; }
|
||||||
public DbSet<RomSet> RomSets { get; set; }
|
public DbSet<RomSet> RomSets { get; set; }
|
||||||
|
public DbSet<Machine> Machines { get; set; }
|
||||||
|
|
||||||
public static Context Create(string dbPath)
|
public static Context Create(string dbPath)
|
||||||
{
|
{
|
||||||
@@ -98,6 +99,13 @@ namespace RomRepoMgr.Database
|
|||||||
|
|
||||||
entity.HasIndex(e => e.Sha384);
|
entity.HasIndex(e => e.Sha384);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<Machine>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasIndex(e => e.Name);
|
||||||
|
|
||||||
|
entity.HasOne(e => e.RomSet).WithMany(e => e.Machines).OnDelete(DeleteBehavior.Cascade);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
169
RomRepoMgr.Database/Migrations/20200822130751_AddMachine.Designer.cs
generated
Normal file
169
RomRepoMgr.Database/Migrations/20200822130751_AddMachine.Designer.cs
generated
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
// <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("20200822130751_AddMachine")]
|
||||||
|
partial class AddMachine
|
||||||
|
{
|
||||||
|
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.Machine", b =>
|
||||||
|
{
|
||||||
|
b.Property<ulong>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedOn")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<long>("RomSetId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdatedOn")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Name");
|
||||||
|
|
||||||
|
b.HasIndex("RomSetId");
|
||||||
|
|
||||||
|
b.ToTable("Machines");
|
||||||
|
});
|
||||||
|
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("RomRepoMgr.Database.Models.Machine", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("RomRepoMgr.Database.Models.RomSet", "RomSet")
|
||||||
|
.WithMany("Machines")
|
||||||
|
.HasForeignKey("RomSetId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
57
RomRepoMgr.Database/Migrations/20200822130751_AddMachine.cs
Normal file
57
RomRepoMgr.Database/Migrations/20200822130751_AddMachine.cs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
// 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 AddMachine : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable("Machines", table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<ulong>(nullable: false).Annotation("Sqlite:Autoincrement", true),
|
||||||
|
CreatedOn = table.Column<DateTime>(nullable: false),
|
||||||
|
UpdatedOn = table.Column<DateTime>(nullable: false),
|
||||||
|
Name = table.Column<string>(nullable: false),
|
||||||
|
RomSetId = table.Column<long>(nullable: false)
|
||||||
|
}, constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Machines", x => x.Id);
|
||||||
|
|
||||||
|
table.ForeignKey("FK_Machines_RomSets_RomSetId", x => x.RomSetId, "RomSets", "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Machines_Name", "Machines", "Name");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex("IX_Machines_RomSetId", "Machines", "RomSetId");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder) => migrationBuilder.DropTable("Machines");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,6 +45,27 @@ namespace RomRepoMgr.Database.Migrations
|
|||||||
b.ToTable("Files");
|
b.ToTable("Files");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("RomRepoMgr.Database.Models.Machine", b =>
|
||||||
|
{
|
||||||
|
b.Property<ulong>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedOn").HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Name").IsRequired().HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<long>("RomSetId").HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdatedOn").HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Name");
|
||||||
|
|
||||||
|
b.HasIndex("RomSetId");
|
||||||
|
|
||||||
|
b.ToTable("Machines");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("RomRepoMgr.Database.Models.RomSet", b =>
|
modelBuilder.Entity("RomRepoMgr.Database.Models.RomSet", b =>
|
||||||
{
|
{
|
||||||
b.Property<long>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER");
|
b.Property<long>("Id").ValueGeneratedOnAdd().HasColumnType("INTEGER");
|
||||||
@@ -93,6 +114,12 @@ namespace RomRepoMgr.Database.Migrations
|
|||||||
|
|
||||||
b.ToTable("RomSets");
|
b.ToTable("RomSets");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("RomRepoMgr.Database.Models.Machine", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("RomRepoMgr.Database.Models.RomSet", "RomSet").WithMany("Machines").HasForeignKey("RomSetId").
|
||||||
|
OnDelete(DeleteBehavior.Cascade).IsRequired();
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37
RomRepoMgr.Database/Models/Machine.cs
Normal file
37
RomRepoMgr.Database/Models/Machine.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
// 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 Machine : BaseModel<ulong>
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; }
|
||||||
|
[Required]
|
||||||
|
public virtual RomSet RomSet { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
// Copyright © 2020 Natalia Portillo
|
// Copyright © 2020 Natalia Portillo
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace RomRepoMgr.Database.Models
|
namespace RomRepoMgr.Database.Models
|
||||||
@@ -40,5 +41,7 @@ namespace RomRepoMgr.Database.Models
|
|||||||
public string Filename { get; set; }
|
public string Filename { get; set; }
|
||||||
[Required, StringLength(96, MinimumLength = 96)]
|
[Required, StringLength(96, MinimumLength = 96)]
|
||||||
public string Sha384 { get; set; }
|
public string Sha384 { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<Machine> Machines { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user