From d6e23ca95e963253fb10a67e1c92bf6628ab21e9 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 4 Sep 2020 03:15:26 +0100 Subject: [PATCH] Import disks from DATs. --- .../Resources/Localization.Designer.cs | 675 +++++++----------- .../Resources/Localization.es.resx | 6 + RomRepoMgr.Core/Resources/Localization.resx | 6 + RomRepoMgr.Core/Workers/DatImporter.cs | 110 ++- 4 files changed, 382 insertions(+), 415 deletions(-) diff --git a/RomRepoMgr.Core/Resources/Localization.Designer.cs b/RomRepoMgr.Core/Resources/Localization.Designer.cs index 34a31ab..ddbac71 100644 --- a/RomRepoMgr.Core/Resources/Localization.Designer.cs +++ b/RomRepoMgr.Core/Resources/Localization.Designer.cs @@ -1,7 +1,6 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -12,46 +11,32 @@ namespace RomRepoMgr.Core.Resources { using System; - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Localization { - private static global::System.Resources.ResourceManager resourceMan; + private static System.Resources.ResourceManager resourceMan; - private static global::System.Globalization.CultureInfo resourceCulture; + private static System.Globalization.CultureInfo resourceCulture; - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Localization() { } - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RomRepoMgr.Core.Resources.Localization", typeof(Localization).Assembly); + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("RomRepoMgr.Core.Resources.Localization", typeof(Localization).Assembly); resourceMan = temp; } return resourceMan; } } - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -60,435 +45,303 @@ namespace RomRepoMgr.Core.Resources { } } - /// - /// Looks up a localized string similar to Adding DAT to database.... - /// - internal static string AddingDatToDatabase { - get { - return ResourceManager.GetString("AddingDatToDatabase", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Adding machines (games).... - /// - internal static string AddingMachines { - get { - return ResourceManager.GetString("AddingMachines", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Adding ROMs.... - /// - internal static string AddingRoms { - get { - return ResourceManager.GetString("AddingRoms", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Assertion failed. - /// - internal static string Assertion_failed { - get { - return ResourceManager.GetString("Assertion_failed", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Specified string is not valid Base32 format because character "{0}" does not exist in Base32 alphabet. - /// - internal static string Base32_Invalid_format { - get { - return ResourceManager.GetString("Base32_Invalid_format", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Specified string is not valid Base32 format because it doesn't have enough data to construct a complete byte array. - /// internal static string Base32_Not_enought_data { get { return ResourceManager.GetString("Base32_Not_enought_data", resourceCulture); } } - /// - /// Looks up a localized string similar to Cannot seek after stream end.. - /// - internal static string Cannot_seek_after_end { + internal static string Base32_Invalid_format { get { - return ResourceManager.GetString("Cannot_seek_after_end", resourceCulture); + return ResourceManager.GetString("Base32_Invalid_format", resourceCulture); } } - /// - /// Looks up a localized string similar to Cannot seek before stream start.. - /// internal static string Cannot_seek_before_start { get { return ResourceManager.GetString("Cannot_seek_before_start", resourceCulture); } } - /// - /// Looks up a localized string similar to Cannot find file with hash {0} in the repository. - /// - internal static string CannotFindHashInRepository { + internal static string Cannot_seek_after_end { get { - return ResourceManager.GetString("CannotFindHashInRepository", resourceCulture); + return ResourceManager.GetString("Cannot_seek_after_end", resourceCulture); } } - /// - /// Looks up a localized string similar to Cannot find lsar executable.. - /// - internal static string CannotFindLsAr { - get { - return ResourceManager.GetString("CannotFindLsAr", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Cannot find unar executable at {0}.. - /// - internal static string CannotFindUnArAtPath { - get { - return ResourceManager.GetString("CannotFindUnArAtPath", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Cannot find requested zip entry in hashes dictionary. - /// - internal static string CannotFindZipEntryInDictionary { - get { - return ResourceManager.GetString("CannotFindZipEntryInDictionary", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Cannot run lsar.. - /// - internal static string CannotRunLsAr { - get { - return ResourceManager.GetString("CannotRunLsAr", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Cannot run unar.. - /// - internal static string CannotRunUnAr { - get { - return ResourceManager.GetString("CannotRunUnAr", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Checking if file is an archive.... - /// - internal static string CheckingIfFIleIsAnArchive { - get { - return ResourceManager.GetString("CheckingIfFIleIsAnArchive", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Compressing {0}.... - /// - internal static string Compressing { - get { - return ResourceManager.GetString("Compressing", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Compressing DAT file.... - /// - internal static string CompressingDatFile { - get { - return ResourceManager.GetString("CompressingDatFile", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Compressing file.... - /// - internal static string CompressingFile { - get { - return ResourceManager.GetString("CompressingFile", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Could not find ROM set in database.. - /// - internal static string CouldNotFindRomSetInDatabase { - get { - return ResourceManager.GetString("CouldNotFindRomSetInDatabase", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to File exists. - /// - internal static string DatabaseFileExistsMsgBoxTitle { - get { - return ResourceManager.GetString("DatabaseFileExistsMsgBoxTitle", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to DAT file is already in database, not importing duplicates.. - /// - internal static string DatAlreadyInDatabase { - get { - return ResourceManager.GetString("DatAlreadyInDatabase", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Enumerating files.... - /// - internal static string EnumeratingFiles { - get { - return ResourceManager.GetString("EnumeratingFiles", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Error: {0}. - /// - internal static string ErrorWithMessage { - get { - return ResourceManager.GetString("ErrorWithMessage", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Exporting ROMs.... - /// - internal static string ExportingRoms { - get { - return ResourceManager.GetString("ExportingRoms", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Extracted contents. - /// - internal static string ExtractedContents { - get { - return ResourceManager.GetString("ExtractedContents", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Extracting archive contents.... - /// - internal static string ExtractingArchive { - get { - return ResourceManager.GetString("ExtractingArchive", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Finished. - /// - internal static string Finished { - get { - return ResourceManager.GetString("Finished", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Finishing.... - /// - internal static string Finishing { - get { - return ResourceManager.GetString("Finishing", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Found a ROM with an unknown machine, this should not happen.. - /// - internal static string FoundRomWithoutMachine { - get { - return ResourceManager.GetString("FoundRomWithoutMachine", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Getting machine (game) names.... - /// - internal static string GettingMachineNames { - get { - return ResourceManager.GetString("GettingMachineNames", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Hashing DAT file.... - /// - internal static string HashingDatFile { - get { - return ResourceManager.GetString("HashingDatFile", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Hashing file.... - /// - internal static string HashingFile { - get { - return ResourceManager.GetString("HashingFile", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Importing {0}.... - /// - internal static string Importing { - get { - return ResourceManager.GetString("Importing", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Not yet implemented.. - /// - internal static string Not_yet_implemented { - get { - return ResourceManager.GetString("Not_yet_implemented", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Not the correct lsar executable. - /// - internal static string NotCorrectLsAr { - get { - return ResourceManager.GetString("NotCorrectLsAr", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Not the correct unar executable. - /// - internal static string NotCorrectUnAr { - get { - return ResourceManager.GetString("NotCorrectUnAr", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to OK. - /// - internal static string OK { - get { - return ResourceManager.GetString("OK", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Parsing DAT file.... - /// - internal static string ParsinDatFile { - get { - return ResourceManager.GetString("ParsinDatFile", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Removing temporary path.... - /// - internal static string RemovingTemporaryPath { - get { - return ResourceManager.GetString("RemovingTemporaryPath", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Retrieving ROMs and disks.... - /// - internal static string RetrievingRomsAndDisks { - get { - return ResourceManager.GetString("RetrievingRomsAndDisks", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Retrieving ROM set from database.. - /// - internal static string RetrievingRomSetFromDatabase { - get { - return ResourceManager.GetString("RetrievingRomSetFromDatabase", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Saving changes to database.... - /// - internal static string SavingChangesToDatabase { - get { - return ResourceManager.GetString("SavingChangesToDatabase", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The input exceeds data types.. - /// - internal static string Spamsum_Input_exceeds_data { - get { - return ResourceManager.GetString("Spamsum_Input_exceeds_data", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to SpamSum does not have a binary representation.. - /// internal static string Spamsum_no_binary { get { return ResourceManager.GetString("Spamsum_no_binary", resourceCulture); } } - /// - /// Looks up a localized string similar to unar path is not set.. - /// + internal static string Assertion_failed { + get { + return ResourceManager.GetString("Assertion_failed", resourceCulture); + } + } + + internal static string Spamsum_Input_exceeds_data { + get { + return ResourceManager.GetString("Spamsum_Input_exceeds_data", resourceCulture); + } + } + + internal static string Not_yet_implemented { + get { + return ResourceManager.GetString("Not_yet_implemented", resourceCulture); + } + } + + internal static string DatabaseFileExistsMsgBoxTitle { + get { + return ResourceManager.GetString("DatabaseFileExistsMsgBoxTitle", resourceCulture); + } + } + internal static string UnArPathNotSet { get { return ResourceManager.GetString("UnArPathNotSet", resourceCulture); } } - /// - /// Looks up a localized string similar to Unhandled exception occurred.. - /// + internal static string CannotFindUnArAtPath { + get { + return ResourceManager.GetString("CannotFindUnArAtPath", resourceCulture); + } + } + + internal static string CannotFindLsAr { + get { + return ResourceManager.GetString("CannotFindLsAr", resourceCulture); + } + } + + internal static string CannotRunUnAr { + get { + return ResourceManager.GetString("CannotRunUnAr", resourceCulture); + } + } + + internal static string CannotRunLsAr { + get { + return ResourceManager.GetString("CannotRunLsAr", resourceCulture); + } + } + + internal static string NotCorrectUnAr { + get { + return ResourceManager.GetString("NotCorrectUnAr", resourceCulture); + } + } + + internal static string NotCorrectLsAr { + get { + return ResourceManager.GetString("NotCorrectLsAr", resourceCulture); + } + } + + internal static string ParsinDatFile { + get { + return ResourceManager.GetString("ParsinDatFile", resourceCulture); + } + } + + internal static string HashingDatFile { + get { + return ResourceManager.GetString("HashingDatFile", resourceCulture); + } + } + + internal static string DatAlreadyInDatabase { + get { + return ResourceManager.GetString("DatAlreadyInDatabase", resourceCulture); + } + } + + internal static string AddingDatToDatabase { + get { + return ResourceManager.GetString("AddingDatToDatabase", resourceCulture); + } + } + + internal static string CompressingDatFile { + get { + return ResourceManager.GetString("CompressingDatFile", resourceCulture); + } + } + + internal static string GettingMachineNames { + get { + return ResourceManager.GetString("GettingMachineNames", resourceCulture); + } + } + + internal static string AddingMachines { + get { + return ResourceManager.GetString("AddingMachines", resourceCulture); + } + } + + internal static string SavingChangesToDatabase { + get { + return ResourceManager.GetString("SavingChangesToDatabase", resourceCulture); + } + } + + internal static string RetrievingRomsAndDisks { + get { + return ResourceManager.GetString("RetrievingRomsAndDisks", resourceCulture); + } + } + + internal static string AddingRoms { + get { + return ResourceManager.GetString("AddingRoms", resourceCulture); + } + } + + internal static string FoundRomWithoutMachine { + get { + return ResourceManager.GetString("FoundRomWithoutMachine", resourceCulture); + } + } + internal static string UnhandledException { get { return ResourceManager.GetString("UnhandledException", resourceCulture); } } - /// - /// Looks up a localized string similar to Unhandled exception when importing file.. - /// + internal static string RetrievingRomSetFromDatabase { + get { + return ResourceManager.GetString("RetrievingRomSetFromDatabase", resourceCulture); + } + } + + internal static string CouldNotFindRomSetInDatabase { + get { + return ResourceManager.GetString("CouldNotFindRomSetInDatabase", resourceCulture); + } + } + + internal static string ExportingRoms { + get { + return ResourceManager.GetString("ExportingRoms", resourceCulture); + } + } + + internal static string Finished { + get { + return ResourceManager.GetString("Finished", resourceCulture); + } + } + + internal static string CannotFindZipEntryInDictionary { + get { + return ResourceManager.GetString("CannotFindZipEntryInDictionary", resourceCulture); + } + } + + internal static string CannotFindHashInRepository { + get { + return ResourceManager.GetString("CannotFindHashInRepository", resourceCulture); + } + } + + internal static string Compressing { + get { + return ResourceManager.GetString("Compressing", resourceCulture); + } + } + + internal static string EnumeratingFiles { + get { + return ResourceManager.GetString("EnumeratingFiles", resourceCulture); + } + } + + internal static string Importing { + get { + return ResourceManager.GetString("Importing", resourceCulture); + } + } + + internal static string CheckingIfFIleIsAnArchive { + get { + return ResourceManager.GetString("CheckingIfFIleIsAnArchive", resourceCulture); + } + } + + internal static string OK { + get { + return ResourceManager.GetString("OK", resourceCulture); + } + } + + internal static string ErrorWithMessage { + get { + return ResourceManager.GetString("ErrorWithMessage", resourceCulture); + } + } + + internal static string ExtractingArchive { + get { + return ResourceManager.GetString("ExtractingArchive", resourceCulture); + } + } + + internal static string RemovingTemporaryPath { + get { + return ResourceManager.GetString("RemovingTemporaryPath", resourceCulture); + } + } + + internal static string ExtractedContents { + get { + return ResourceManager.GetString("ExtractedContents", resourceCulture); + } + } + + internal static string HashingFile { + get { + return ResourceManager.GetString("HashingFile", resourceCulture); + } + } + + internal static string UnknownFile { + get { + return ResourceManager.GetString("UnknownFile", resourceCulture); + } + } + + internal static string CompressingFile { + get { + return ResourceManager.GetString("CompressingFile", resourceCulture); + } + } + + internal static string Finishing { + get { + return ResourceManager.GetString("Finishing", resourceCulture); + } + } + internal static string UnhandledExceptionWhenImporting { get { return ResourceManager.GetString("UnhandledExceptionWhenImporting", resourceCulture); } } - /// - /// Looks up a localized string similar to Unknown file.. - /// - internal static string UnknownFile { + internal static string AddingDisks { get { - return ResourceManager.GetString("UnknownFile", resourceCulture); + return ResourceManager.GetString("AddingDisks", resourceCulture); + } + } + + internal static string FoundDiskWithoutMachine { + get { + return ResourceManager.GetString("FoundDiskWithoutMachine", resourceCulture); } } } diff --git a/RomRepoMgr.Core/Resources/Localization.es.resx b/RomRepoMgr.Core/Resources/Localization.es.resx index 4dd91a2..e02ede4 100644 --- a/RomRepoMgr.Core/Resources/Localization.es.resx +++ b/RomRepoMgr.Core/Resources/Localization.es.resx @@ -155,4 +155,10 @@ Archivo desconocido. + + Añadiendo discos... + + + Se encontró un disco sin máquina, esto no debería pasar. + \ No newline at end of file diff --git a/RomRepoMgr.Core/Resources/Localization.resx b/RomRepoMgr.Core/Resources/Localization.resx index 8d2a2bd..4067815 100644 --- a/RomRepoMgr.Core/Resources/Localization.resx +++ b/RomRepoMgr.Core/Resources/Localization.resx @@ -160,4 +160,10 @@ Unhandled exception when importing file. + + Adding disks... + + + Found a disk with an unknown machine, this should not happen. + \ No newline at end of file diff --git a/RomRepoMgr.Core/Workers/DatImporter.cs b/RomRepoMgr.Core/Workers/DatImporter.cs index 1921d90..f70b502 100644 --- a/RomRepoMgr.Core/Workers/DatImporter.cs +++ b/RomRepoMgr.Core/Workers/DatImporter.cs @@ -354,8 +354,6 @@ namespace RomRepoMgr.Core.Workers }; newFiles.Add(file); - - //Context.Singleton.Files.Add(file); } if(string.IsNullOrEmpty(file.Crc32) && @@ -453,12 +451,116 @@ namespace RomRepoMgr.Core.Workers Maximum = disks.Count }); - // TODO: Support CHDs SetMessage?.Invoke(this, new MessageEventArgs { - Message = "Adding disks..." + Message = Localization.AddingDisks }); + position = 0; + + Dictionary pendingDisksBySha1 = new Dictionary(); + Dictionary pendingDisksByMd5 = new Dictionary(); + List newDisks = new List(); + List newDisksByMachine = new List(); + + foreach(Disk disk in disks) + { + SetProgress?.Invoke(this, new ProgressEventArgs + { + Value = position + }); + + if(!machines.TryGetValue(disk.Machine.Name, out Machine machine)) + { + ErrorOccurred?.Invoke(this, new ErrorEventArgs + { + Message = Localization.FoundDiskWithoutMachine + }); + + return; + } + + if(disk.MD5 == null && + disk.SHA1 == null) + { + position++; + + continue; + } + + DbDisk dbDisk = null; + + if(disk.SHA1 != null && + dbDisk == null) + pendingDisksBySha1.TryGetValue(disk.SHA1, out dbDisk); + + if(disk.MD5 != null && + dbDisk == null) + pendingDisksByMd5.TryGetValue(disk.MD5, out dbDisk); + + dbDisk ??= Context.Singleton.Disks.FirstOrDefault(f => (disk.SHA1 != null && f.Sha1 == disk.SHA1) || + (disk.MD5 != null && f.Md5 == disk.MD5)); + + if(dbDisk == null) + { + dbDisk = new DbDisk + { + CreatedOn = DateTime.UtcNow, + Md5 = disk.MD5, + Sha1 = disk.SHA1, + UpdatedOn = DateTime.UtcNow + }; + + newDisks.Add(dbDisk); + } + + if(string.IsNullOrEmpty(dbDisk.Md5) && + !string.IsNullOrEmpty(disk.MD5)) + { + dbDisk.Md5 = disk.MD5; + dbDisk.UpdatedOn = DateTime.UtcNow; + } + + if(string.IsNullOrEmpty(dbDisk.Sha1) && + !string.IsNullOrEmpty(disk.SHA1)) + { + dbDisk.Sha1 = disk.SHA1; + dbDisk.UpdatedOn = DateTime.UtcNow; + } + + newDisksByMachine.Add(new DiskByMachine + { + Disk = dbDisk, + Machine = machine, + Name = disk.Name + }); + + if(dbDisk.Sha1 != null) + pendingDisksBySha1[dbDisk.Sha1] = dbDisk; + + if(dbDisk.Md5 != null) + pendingDisksByMd5[dbDisk.Md5] = dbDisk; + + position++; + } + + SetMessage?.Invoke(this, new MessageEventArgs + { + Message = Localization.SavingChangesToDatabase + }); + + SetIndeterminateProgress?.Invoke(this, System.EventArgs.Empty); + + Context.Singleton.Disks.AddRange(newDisks); + Context.Singleton.DisksByMachines.AddRange(newDisksByMachine); + + Context.Singleton.SaveChanges(); + + pendingDisksBySha1.Clear(); + pendingDisksByMd5.Clear(); + newDisks.Clear(); + newDisksByMachine.Clear(); + WorkFinished?.Invoke(this, System.EventArgs.Empty); romSet = Context.Singleton.RomSets.Find(romSet.Id);