diff --git a/RomRepoMgr.Core/Models/RomSetModel.cs b/RomRepoMgr.Core/Models/RomSetModel.cs index 527d43f..008d488 100644 --- a/RomRepoMgr.Core/Models/RomSetModel.cs +++ b/RomRepoMgr.Core/Models/RomSetModel.cs @@ -43,5 +43,6 @@ namespace RomRepoMgr.Core.Models public long HaveRoms { get; set; } public long MissRoms { get; set; } public long Id { get; set; } + public string Category { get; set; } } } \ No newline at end of file diff --git a/RomRepoMgr.Core/Workers/DatImporter.cs b/RomRepoMgr.Core/Workers/DatImporter.cs index 6996249..89c1186 100644 --- a/RomRepoMgr.Core/Workers/DatImporter.cs +++ b/RomRepoMgr.Core/Workers/DatImporter.cs @@ -43,14 +43,18 @@ namespace RomRepoMgr.Core.Workers { public sealed class DatImporter { + readonly string _category; readonly string _datFilesPath; readonly string _datPath; bool _aborted; - public DatImporter(string datPath) + public DatImporter(string datPath, string category) { _datPath = datPath; _datFilesPath = Path.Combine(Settings.Settings.Current.RepositoryPath, "datfiles"); + + if(!string.IsNullOrWhiteSpace(category)) + _category = category; } public void Import() @@ -109,7 +113,8 @@ namespace RomRepoMgr.Core.Workers Sha384 = datHash, Version = datFile.Header.Version, CreatedOn = DateTime.UtcNow, - UpdatedOn = DateTime.UtcNow + UpdatedOn = DateTime.UtcNow, + Category = _category }; Context.Singleton.RomSets.Add(romSet); @@ -747,7 +752,8 @@ namespace RomRepoMgr.Core.Workers romSet.Machines.Sum(m => m.Medias.Count(f => f.Media.IsInRepo)), MissRoms = romSet.Machines.Sum(m => m.Files.Count(f => !f.File.IsInRepo)) + romSet.Machines.Sum(m => m.Disks.Count(f => !f.Disk.IsInRepo)) + - romSet.Machines.Sum(m => m.Medias.Count(f => !f.Media.IsInRepo)) + romSet.Machines.Sum(m => m.Medias.Count(f => !f.Media.IsInRepo)), + Category = _category } }); } diff --git a/RomRepoMgr.Database/Context.cs b/RomRepoMgr.Database/Context.cs index f75c671..345f7d2 100644 --- a/RomRepoMgr.Database/Context.cs +++ b/RomRepoMgr.Database/Context.cs @@ -120,6 +120,8 @@ namespace RomRepoMgr.Database entity.HasIndex(e => e.Filename); entity.HasIndex(e => e.Sha384); + + entity.HasIndex(e => e.Category); }); modelBuilder.Entity(entity => diff --git a/RomRepoMgr.Database/Migrations/20200904212924_AddRomSetCategory.Designer.cs b/RomRepoMgr.Database/Migrations/20200904212924_AddRomSetCategory.Designer.cs new file mode 100644 index 0000000..f5048a2 --- /dev/null +++ b/RomRepoMgr.Database/Migrations/20200904212924_AddRomSetCategory.Designer.cs @@ -0,0 +1,417 @@ +// +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("20200904212924_AddRomSetCategory")] + partial class AddRomSetCategory + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.7"); + + modelBuilder.Entity("RomRepoMgr.Database.Models.DbDisk", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedOn") + .HasColumnType("TEXT"); + + b.Property("IsInRepo") + .HasColumnType("INTEGER"); + + b.Property("Md5") + .HasColumnType("TEXT") + .HasMaxLength(32); + + b.Property("OriginalFileName") + .HasColumnType("TEXT"); + + b.Property("Sha1") + .HasColumnType("TEXT") + .HasMaxLength(40); + + b.Property("Size") + .HasColumnType("INTEGER"); + + b.Property("UpdatedOn") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("IsInRepo"); + + b.HasIndex("Md5"); + + b.HasIndex("Sha1"); + + b.HasIndex("Size"); + + b.ToTable("Disks"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.DbFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Crc32") + .HasColumnType("TEXT") + .HasMaxLength(8); + + b.Property("CreatedOn") + .HasColumnType("TEXT"); + + b.Property("IsInRepo") + .HasColumnType("INTEGER"); + + b.Property("Md5") + .HasColumnType("TEXT") + .HasMaxLength(32); + + b.Property("OriginalFileName") + .HasColumnType("TEXT"); + + b.Property("Sha1") + .HasColumnType("TEXT") + .HasMaxLength(40); + + b.Property("Sha256") + .HasColumnType("TEXT") + .HasMaxLength(64); + + b.Property("Sha384") + .HasColumnType("TEXT") + .HasMaxLength(96); + + b.Property("Sha512") + .HasColumnType("TEXT") + .HasMaxLength(128); + + b.Property("Size") + .HasColumnType("INTEGER"); + + b.Property("UpdatedOn") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Crc32"); + + b.HasIndex("IsInRepo"); + + b.HasIndex("Md5"); + + b.HasIndex("Sha1"); + + b.HasIndex("Sha256"); + + b.HasIndex("Sha384"); + + b.HasIndex("Sha512"); + + b.HasIndex("Size"); + + b.ToTable("Files"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.DbMedia", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedOn") + .HasColumnType("TEXT"); + + b.Property("IsInRepo") + .HasColumnType("INTEGER"); + + b.Property("Md5") + .HasColumnType("TEXT") + .HasMaxLength(32); + + b.Property("OriginalFileName") + .HasColumnType("TEXT"); + + b.Property("Sha1") + .HasColumnType("TEXT") + .HasMaxLength(40); + + b.Property("Sha256") + .HasColumnType("TEXT") + .HasMaxLength(64); + + b.Property("Size") + .HasColumnType("INTEGER"); + + b.Property("SpamSum") + .HasColumnType("TEXT"); + + b.Property("UpdatedOn") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("IsInRepo"); + + b.HasIndex("Md5"); + + b.HasIndex("Sha1"); + + b.HasIndex("Sha256"); + + b.HasIndex("Size"); + + b.HasIndex("SpamSum"); + + b.ToTable("Medias"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.DiskByMachine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DiskId") + .HasColumnType("INTEGER"); + + b.Property("MachineId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("DiskId"); + + b.HasIndex("MachineId"); + + b.HasIndex("Name"); + + b.ToTable("DisksByMachines"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.FileByMachine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("FileId") + .HasColumnType("INTEGER"); + + b.Property("MachineId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("FileId"); + + b.HasIndex("MachineId"); + + b.HasIndex("Name"); + + b.ToTable("FilesByMachines"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.Machine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedOn") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RomSetId") + .HasColumnType("INTEGER"); + + b.Property("UpdatedOn") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name"); + + b.HasIndex("RomSetId"); + + b.ToTable("Machines"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.MediaByMachine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MachineId") + .HasColumnType("INTEGER"); + + b.Property("MediaId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("MachineId"); + + b.HasIndex("MediaId"); + + b.HasIndex("Name"); + + b.ToTable("MediasByMachines"); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.RomSet", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Author") + .HasColumnType("TEXT"); + + b.Property("Category") + .HasColumnType("TEXT"); + + b.Property("Comment") + .HasColumnType("TEXT"); + + b.Property("CreatedOn") + .HasColumnType("TEXT"); + + b.Property("Date") + .HasColumnType("TEXT"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Filename") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Homepage") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Sha384") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(96); + + b.Property("UpdatedOn") + .HasColumnType("TEXT"); + + b.Property("Version") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Author"); + + b.HasIndex("Category"); + + 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.DiskByMachine", b => + { + b.HasOne("RomRepoMgr.Database.Models.DbDisk", "Disk") + .WithMany("Machines") + .HasForeignKey("DiskId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RomRepoMgr.Database.Models.Machine", "Machine") + .WithMany("Disks") + .HasForeignKey("MachineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.FileByMachine", b => + { + b.HasOne("RomRepoMgr.Database.Models.DbFile", "File") + .WithMany("Machines") + .HasForeignKey("FileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RomRepoMgr.Database.Models.Machine", "Machine") + .WithMany("Files") + .HasForeignKey("MachineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.Machine", b => + { + b.HasOne("RomRepoMgr.Database.Models.RomSet", "RomSet") + .WithMany("Machines") + .HasForeignKey("RomSetId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("RomRepoMgr.Database.Models.MediaByMachine", b => + { + b.HasOne("RomRepoMgr.Database.Models.Machine", "Machine") + .WithMany("Medias") + .HasForeignKey("MachineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RomRepoMgr.Database.Models.DbMedia", "Media") + .WithMany("Machines") + .HasForeignKey("MediaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/RomRepoMgr.Database/Migrations/20200904212924_AddRomSetCategory.cs b/RomRepoMgr.Database/Migrations/20200904212924_AddRomSetCategory.cs new file mode 100644 index 0000000..c17f698 --- /dev/null +++ b/RomRepoMgr.Database/Migrations/20200904212924_AddRomSetCategory.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace RomRepoMgr.Database.Migrations +{ + public partial class AddRomSetCategory : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn("Category", "RomSets", nullable: true); + + migrationBuilder.CreateIndex("IX_RomSets_Category", "RomSets", "Category"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex("IX_RomSets_Category", "RomSets"); + + migrationBuilder.DropColumn("Category", "RomSets"); + } + } +} \ No newline at end of file diff --git a/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs b/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs index 85b8aa9..711b21c 100644 --- a/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs +++ b/RomRepoMgr.Database/Migrations/ContextModelSnapshot.cs @@ -221,6 +221,8 @@ namespace RomRepoMgr.Database.Migrations b.Property("Author").HasColumnType("TEXT"); + b.Property("Category").HasColumnType("TEXT"); + b.Property("Comment").HasColumnType("TEXT"); b.Property("CreatedOn").HasColumnType("TEXT"); @@ -245,6 +247,8 @@ namespace RomRepoMgr.Database.Migrations b.HasIndex("Author"); + b.HasIndex("Category"); + b.HasIndex("Comment"); b.HasIndex("Date"); diff --git a/RomRepoMgr.Database/Models/RomSet.cs b/RomRepoMgr.Database/Models/RomSet.cs index e478af2..c58cae8 100644 --- a/RomRepoMgr.Database/Models/RomSet.cs +++ b/RomRepoMgr.Database/Models/RomSet.cs @@ -40,7 +40,8 @@ namespace RomRepoMgr.Database.Models [Required] public string Filename { get; set; } [Required, StringLength(96, MinimumLength = 96)] - public string Sha384 { get; set; } + public string Sha384 { get; set; } + public string Category { get; set; } public virtual ICollection Machines { get; set; } } diff --git a/RomRepoMgr/Resources/Localization.Designer.cs b/RomRepoMgr/Resources/Localization.Designer.cs index b49fb0a..0283d64 100644 --- a/RomRepoMgr/Resources/Localization.Designer.cs +++ b/RomRepoMgr/Resources/Localization.Designer.cs @@ -704,5 +704,11 @@ namespace RomRepoMgr.Resources { return ResourceManager.GetString("FilesystemMenuUmountText", resourceCulture); } } + + internal static string RomSetCategoryLabel { + get { + return ResourceManager.GetString("RomSetCategoryLabel", resourceCulture); + } + } } } diff --git a/RomRepoMgr/Resources/Localization.resx b/RomRepoMgr/Resources/Localization.resx index 4fddc39..1603050 100644 --- a/RomRepoMgr/Resources/Localization.resx +++ b/RomRepoMgr/Resources/Localization.resx @@ -349,4 +349,7 @@ Do you want to delete the file? _Umount + + Category + \ No newline at end of file diff --git a/RomRepoMgr/ViewModels/EditDatViewModel.cs b/RomRepoMgr/ViewModels/EditDatViewModel.cs index 55747a4..9ea8835 100644 --- a/RomRepoMgr/ViewModels/EditDatViewModel.cs +++ b/RomRepoMgr/ViewModels/EditDatViewModel.cs @@ -40,6 +40,7 @@ namespace RomRepoMgr.ViewModels readonly RomSetModel _romSet; readonly EditDat _view; string _author; + string _category; string _comment; string _date; string _description; @@ -56,6 +57,7 @@ namespace RomRepoMgr.ViewModels _version = romSet.Version; _author = romSet.Author; _comment = romSet.Comment; + _category = romSet.Category; _date = romSet.Date; _description = romSet.Description; _homepage = romSet.Homepage; @@ -67,6 +69,7 @@ namespace RomRepoMgr.ViewModels public string NameLabel => Localization.RomSetNameLabel; public string VersionLabel => Localization.RomSetVersionLabel; public string AuthorLabel => Localization.RomSetAuthorLabel; + public string CategoryLabel => Localization.RomSetCategoryLabel; public string CommentLabel => Localization.RomSetCommentLabel; public string DateLabel => Localization.RomSetDateLabel; public string DescriptionLabel => Localization.RomSetDescriptionLabel; @@ -146,6 +149,18 @@ namespace RomRepoMgr.ViewModels } } + public string Category + { + get => _category; + set + { + if(value != _category) + Modified = true; + + this.RaiseAndSetIfChanged(ref _category, value); + } + } + public string Date { get => _date; @@ -195,6 +210,7 @@ namespace RomRepoMgr.ViewModels romSetDb.Author = Author; romSetDb.Comment = Comment; + romSetDb.Category = Category; romSetDb.Date = Date; romSetDb.Description = Description; romSetDb.Homepage = Homepage; @@ -210,6 +226,7 @@ namespace RomRepoMgr.ViewModels { Author = Author, Comment = Comment, + Category = Category, Date = Date, Description = Description, Homepage = Homepage, diff --git a/RomRepoMgr/ViewModels/ImportDatFolderViewModel.cs b/RomRepoMgr/ViewModels/ImportDatFolderViewModel.cs index f884f4f..4f69eb7 100644 --- a/RomRepoMgr/ViewModels/ImportDatFolderViewModel.cs +++ b/RomRepoMgr/ViewModels/ImportDatFolderViewModel.cs @@ -46,6 +46,7 @@ namespace RomRepoMgr.ViewModels bool _allFilesChecked; bool _canClose; bool _canStart; + string _category; string[] _datFiles; bool _isImporting; bool _isReady; @@ -76,6 +77,7 @@ namespace RomRepoMgr.ViewModels } public string PathLabel => Localization.PathLabel; + public string CategoryLabel => Localization.RomSetCategoryLabel; public string FolderPath { get; } public string AllFilesLabel => Localization.AllFilesLabel; public string RecursiveLabel => Localization.RecursiveLabel; @@ -184,6 +186,12 @@ namespace RomRepoMgr.ViewModels set => this.RaiseAndSetIfChanged(ref _isImporting, value); } + public string Category + { + get => _category; + set => this.RaiseAndSetIfChanged(ref _category, value); + } + [NotNull] public string Title => Localization.ImportDatFolderTitle; @@ -286,7 +294,7 @@ namespace RomRepoMgr.ViewModels StatusMessage = string.Format(Localization.ImportingItem, Path.GetFileName(_datFiles[_listPosition])); ProgressValue = _listPosition; - var _worker = new DatImporter(_datFiles[_listPosition]); + var _worker = new DatImporter(_datFiles[_listPosition], Category); _worker.ErrorOccurred += OnWorkerOnErrorOccurred; _worker.SetIndeterminateProgress += OnWorkerOnSetIndeterminateProgress; _worker.SetMessage += OnWorkerOnSetMessage; diff --git a/RomRepoMgr/ViewModels/ImportDatViewModel.cs b/RomRepoMgr/ViewModels/ImportDatViewModel.cs index 4d847bb..b2ac930 100644 --- a/RomRepoMgr/ViewModels/ImportDatViewModel.cs +++ b/RomRepoMgr/ViewModels/ImportDatViewModel.cs @@ -57,7 +57,7 @@ namespace RomRepoMgr.ViewModels IndeterminateProgress = true; ProgressVisible = false; ErrorVisible = false; - _worker = new DatImporter(datPath); + _worker = new DatImporter(datPath, null); _worker.ErrorOccurred += OnWorkerOnErrorOccurred; _worker.SetIndeterminateProgress += OnWorkerOnSetIndeterminateProgress; _worker.SetMessage += OnWorkerOnSetMessage; diff --git a/RomRepoMgr/ViewModels/MainWindowViewModel.cs b/RomRepoMgr/ViewModels/MainWindowViewModel.cs index b00ae92..d862354 100644 --- a/RomRepoMgr/ViewModels/MainWindowViewModel.cs +++ b/RomRepoMgr/ViewModels/MainWindowViewModel.cs @@ -73,6 +73,7 @@ namespace RomRepoMgr.ViewModels public string RomSetNameLabel => Localization.RomSetNameLabel; public string RomSetVersionLabel => Localization.RomSetVersionLabel; public string RomSetAuthorLabel => Localization.RomSetAuthorLabel; + public string RomSetCategoryLabel => Localization.RomSetCategoryLabel; public string RomSetDateLabel => Localization.RomSetDateLabel; public string RomSetDescriptionLabel => Localization.RomSetDescriptionLabel; public string RomSetCommentLabel => Localization.RomSetCommentLabel; diff --git a/RomRepoMgr/ViewModels/SplashWindowViewModel.cs b/RomRepoMgr/ViewModels/SplashWindowViewModel.cs index a071f85..6b9c84d 100644 --- a/RomRepoMgr/ViewModels/SplashWindowViewModel.cs +++ b/RomRepoMgr/ViewModels/SplashWindowViewModel.cs @@ -352,7 +352,8 @@ namespace RomRepoMgr.ViewModels r.Machines.Sum(m => m.Medias.Count(f => f.Media.IsInRepo)), MissRoms = r.Machines.Sum(m => m.Files.Count(f => !f.File.IsInRepo)) + r.Machines.Sum(m => m.Disks.Count(f => !f.Disk.IsInRepo)) + - r.Machines.Sum(m => m.Medias.Count(f => !f.Media.IsInRepo)) + r.Machines.Sum(m => m.Medias.Count(f => !f.Media.IsInRepo)), + Category = r.Category }).ToList() }); diff --git a/RomRepoMgr/Views/EditDat.xaml b/RomRepoMgr/Views/EditDat.xaml index d465e36..726467c 100644 --- a/RomRepoMgr/Views/EditDat.xaml +++ b/RomRepoMgr/Views/EditDat.xaml @@ -40,7 +40,7 @@ - + @@ -70,6 +70,15 @@ Text="{Binding Author}" Padding="5" /> + + + + + + + @@ -78,7 +87,7 @@ - + @@ -87,7 +96,7 @@ - + @@ -96,7 +105,7 @@ - + @@ -105,7 +114,7 @@ - + @@ -114,7 +123,7 @@ - + @@ -123,7 +132,7 @@ - + @@ -132,7 +141,7 @@ - + @@ -141,7 +150,7 @@ - + @@ -150,7 +159,7 @@ - + @@ -159,7 +168,7 @@ - +