diff --git a/RombaSharp/Features/Archive.cs b/RombaSharp/Features/Archive.cs index c81dc061..79f49093 100644 --- a/RombaSharp/Features/Archive.cs +++ b/RombaSharp/Features/Archive.cs @@ -65,8 +65,8 @@ have a current entry in the DAT index."; DatFile df = DatFile.Create(); foreach (string dir in onlyDirs) { - DatTool.PopulateFromDir(df, dir, asFiles: TreatAsFile.NonArchive); - DatTool.PopulateFromDir(df, dir, asFiles: TreatAsFile.All); + DirFromDat.PopulateFromDir(df, dir, asFiles: TreatAsFile.NonArchive); + DirFromDat.PopulateFromDir(df, dir, asFiles: TreatAsFile.All); } // Create an empty Dat for files that need to be rebuilt diff --git a/RombaSharp/Features/Dir2Dat.cs b/RombaSharp/Features/Dir2Dat.cs index d28ecf85..6b319cc0 100644 --- a/RombaSharp/Features/Dir2Dat.cs +++ b/RombaSharp/Features/Dir2Dat.cs @@ -53,7 +53,7 @@ namespace RombaSharp.Features DatFile datfile = DatFile.Create(); datfile.Header.Name = string.IsNullOrWhiteSpace(name) ? "untitled" : name; datfile.Header.Description = description; - DatTool.PopulateFromDir(datfile, source, asFiles: TreatAsFile.NonArchive); + DirFromDat.PopulateFromDir(datfile, source, asFiles: TreatAsFile.NonArchive); DatTool.ApplyCleaning(datfile, new Cleaner() { ExcludeFields = Hash.DeepHashes.AsFields() }); DatTool.Write(datfile, outdat); } diff --git a/RombaSharp/Features/RefreshDats.cs b/RombaSharp/Features/RefreshDats.cs index 48cd454d..05f9437b 100644 --- a/RombaSharp/Features/RefreshDats.cs +++ b/RombaSharp/Features/RefreshDats.cs @@ -62,7 +62,7 @@ contents of any changed dats."; // First get a list of SHA-1's from the input DATs DatFile datroot = DatFile.Create(); datroot.Header.Type = "SuperDAT"; - DatTool.PopulateFromDir(datroot, _dats, asFiles: TreatAsFile.NonArchive); + DirFromDat.PopulateFromDir(datroot, _dats, asFiles: TreatAsFile.NonArchive); datroot.Items.BucketBy(Field.DatItem_SHA1, DedupeType.None); // Create a List of dat hashes in the database (SHA-1) diff --git a/RombaSharp/Features/RescanDepots.cs b/RombaSharp/Features/RescanDepots.cs index 9064ff56..92e5ca6c 100644 --- a/RombaSharp/Features/RescanDepots.cs +++ b/RombaSharp/Features/RescanDepots.cs @@ -64,7 +64,7 @@ namespace RombaSharp.Features // Now rescan the depot itself DatFile depot = DatFile.Create(); - DatTool.PopulateFromDir(depot, depotname, asFiles: TreatAsFile.NonArchive); + DirFromDat.PopulateFromDir(depot, depotname, asFiles: TreatAsFile.NonArchive); depot.Items.BucketBy(Field.DatItem_SHA1, DedupeType.None); // Set the base queries to use diff --git a/SabreTools.DatFiles/DatFile.cs b/SabreTools.DatFiles/DatFile.cs index 94579196..b70e43df 100644 --- a/SabreTools.DatFiles/DatFile.cs +++ b/SabreTools.DatFiles/DatFile.cs @@ -180,39 +180,6 @@ namespace SabreTools.DatFiles return datFile; } - /// - /// Add items from another DatFile to the existing DatFile - /// - /// DatFile to add from - /// If items should be deleted from the source DatFile - public void AddFromExisting(DatFile datFile, bool delete = false) - { - // Get the list of keys from the DAT - var keys = datFile.Items.Keys.ToList(); - foreach (string key in keys) - { - // Add everything from the key to the internal DAT - Items.AddRange(key, datFile.Items[key]); - - // Now remove the key from the source DAT - if (delete) - datFile.Items.Remove(key); - } - - // Now remove the file dictionary from the source DAT - if (delete) - datFile.Items = null; - } - - /// - /// Apply a DatHeader to an existing DatFile - /// - /// DatHeader to get the values from - public void ApplyDatHeader(DatHeader datHeader) - { - Header.ConditionalCopy(datHeader); - } - /// /// Fill the header values based on existing Header and path /// diff --git a/SabreTools.DatFiles/DatTool.Updating.cs b/SabreTools.DatFiles/DatTool.Updating.cs index 0e9ba6ac..7c666949 100644 --- a/SabreTools.DatFiles/DatTool.Updating.cs +++ b/SabreTools.DatFiles/DatTool.Updating.cs @@ -458,12 +458,37 @@ namespace SabreTools.DatFiles watch.Start("Populating internal DAT"); for (int i = 0; i < inputs.Count; i++) { - datFile.AddFromExisting(datFiles[i], true); + AddFromExisting(datFile, datFiles[i], true); } watch.Stop(); return datFiles.Select(d => d.Header).ToList(); } + + /// + /// Add items from another DatFile to the existing DatFile + /// + /// DatFile to add to + /// DatFile to add from + /// If items should be deleted from the source DatFile + private static void AddFromExisting(DatFile addTo, DatFile addFrom, bool delete = false) + { + // Get the list of keys from the DAT + var keys = addFrom.Items.Keys.ToList(); + foreach (string key in keys) + { + // Add everything from the key to the internal DAT + addTo.Items.AddRange(key, addFrom.Items[key]); + + // Now remove the key from the source DAT + if (delete) + addFrom.Items.Remove(key); + } + + // Now remove the file dictionary from the source DAT + if (delete) + addFrom.Items = null; + } } } \ No newline at end of file diff --git a/SabreTools.DatFiles/DatTool.DFD.cs b/SabreTools.DatFiles/DirFromDat.cs similarity index 98% rename from SabreTools.DatFiles/DatTool.DFD.cs rename to SabreTools.DatFiles/DirFromDat.cs index d114f22a..665751ff 100644 --- a/SabreTools.DatFiles/DatTool.DFD.cs +++ b/SabreTools.DatFiles/DirFromDat.cs @@ -8,15 +8,24 @@ using SabreTools.Core; using SabreTools.DatItems; using SabreTools.FileTypes; using SabreTools.IO; +using SabreTools.Logging; // This file represents all methods related to populating a DatFile // from a set of files and directories namespace SabreTools.DatFiles { // TODO: See if any of the methods can be broken up a bit more neatly - // TODO: See if any of this can be more stateful given the inputted DatFile - public partial class DatTool + public class DirFromDat { + #region Logging + + /// + /// Logging object + /// + private static readonly Logger logger = new Logger(); + + #endregion + /// /// Create a new Dat from a directory /// diff --git a/SabreTools.DatFiles/Formats/AttractMode.cs b/SabreTools.DatFiles/Formats/AttractMode.cs index 17f60a77..892f6e26 100644 --- a/SabreTools.DatFiles/Formats/AttractMode.cs +++ b/SabreTools.DatFiles/Formats/AttractMode.cs @@ -32,7 +32,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Open a file reader Encoding enc = FileExtensions.GetEncoding(filename); diff --git a/SabreTools.DatFiles/Formats/ClrMamePro.cs b/SabreTools.DatFiles/Formats/ClrMamePro.cs index 382ba735..6c0956ae 100644 --- a/SabreTools.DatFiles/Formats/ClrMamePro.cs +++ b/SabreTools.DatFiles/Formats/ClrMamePro.cs @@ -44,7 +44,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Open a file reader Encoding enc = FileExtensions.GetEncoding(filename); diff --git a/SabreTools.DatFiles/Formats/DosCenter.cs b/SabreTools.DatFiles/Formats/DosCenter.cs index c840c89d..8ce60273 100644 --- a/SabreTools.DatFiles/Formats/DosCenter.cs +++ b/SabreTools.DatFiles/Formats/DosCenter.cs @@ -34,7 +34,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Open a file reader Encoding enc = FileExtensions.GetEncoding(filename); diff --git a/SabreTools.DatFiles/Formats/EverdriveSmdb.cs b/SabreTools.DatFiles/Formats/EverdriveSmdb.cs index 2e2b1bd6..be93a2e0 100644 --- a/SabreTools.DatFiles/Formats/EverdriveSmdb.cs +++ b/SabreTools.DatFiles/Formats/EverdriveSmdb.cs @@ -32,7 +32,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Open a file reader Encoding enc = FileExtensions.GetEncoding(filename); diff --git a/SabreTools.DatFiles/Formats/Hashfile.cs b/SabreTools.DatFiles/Formats/Hashfile.cs index 9e437a79..3c1a6479 100644 --- a/SabreTools.DatFiles/Formats/Hashfile.cs +++ b/SabreTools.DatFiles/Formats/Hashfile.cs @@ -36,7 +36,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Open a file reader Encoding enc = FileExtensions.GetEncoding(filename); diff --git a/SabreTools.DatFiles/Formats/Listrom.cs b/SabreTools.DatFiles/Formats/Listrom.cs index a83c07c7..df0ef52c 100644 --- a/SabreTools.DatFiles/Formats/Listrom.cs +++ b/SabreTools.DatFiles/Formats/Listrom.cs @@ -41,7 +41,7 @@ namespace SabreTools.DatFiles.Formats /// 6331.sound-u8 32 BAD CRC(1d298cb0) SHA1(bb0bb62365402543e3154b9a77be9c75010e6abc) BAD_DUMP /// 16v8h-blue.u24 279 NO GOOD DUMP KNOWN /// - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Open a file reader Encoding enc = FileExtensions.GetEncoding(filename); diff --git a/SabreTools.DatFiles/Formats/Listxml.cs b/SabreTools.DatFiles/Formats/Listxml.cs index fd204afc..b1f170df 100644 --- a/SabreTools.DatFiles/Formats/Listxml.cs +++ b/SabreTools.DatFiles/Formats/Listxml.cs @@ -202,7 +202,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Prepare all internal variables XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings diff --git a/SabreTools.DatFiles/Formats/Logiqx.cs b/SabreTools.DatFiles/Formats/Logiqx.cs index f130c5d4..5f79e25f 100644 --- a/SabreTools.DatFiles/Formats/Logiqx.cs +++ b/SabreTools.DatFiles/Formats/Logiqx.cs @@ -144,7 +144,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Prepare all internal variables XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings diff --git a/SabreTools.DatFiles/Formats/Missfile.cs b/SabreTools.DatFiles/Formats/Missfile.cs index fa376a6d..c1da3c3d 100644 --- a/SabreTools.DatFiles/Formats/Missfile.cs +++ b/SabreTools.DatFiles/Formats/Missfile.cs @@ -28,7 +28,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // There is no consistent way to parse a missfile... throw new NotImplementedException(); diff --git a/SabreTools.DatFiles/Formats/OfflineList.cs b/SabreTools.DatFiles/Formats/OfflineList.cs index 1a7299c4..94123134 100644 --- a/SabreTools.DatFiles/Formats/OfflineList.cs +++ b/SabreTools.DatFiles/Formats/OfflineList.cs @@ -33,7 +33,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings { diff --git a/SabreTools.DatFiles/Formats/OpenMSX.cs b/SabreTools.DatFiles/Formats/OpenMSX.cs index 384f82a2..f73d7082 100644 --- a/SabreTools.DatFiles/Formats/OpenMSX.cs +++ b/SabreTools.DatFiles/Formats/OpenMSX.cs @@ -47,7 +47,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Prepare all internal variables XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings diff --git a/SabreTools.DatFiles/Formats/RomCenter.cs b/SabreTools.DatFiles/Formats/RomCenter.cs index d9c960ba..9fad6178 100644 --- a/SabreTools.DatFiles/Formats/RomCenter.cs +++ b/SabreTools.DatFiles/Formats/RomCenter.cs @@ -32,7 +32,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Prepare all intenral variables IniReader ir = new IniReader(filename) { ValidateRows = false }; diff --git a/SabreTools.DatFiles/Formats/SabreJSON.cs b/SabreTools.DatFiles/Formats/SabreJSON.cs index a731c34e..1235a236 100644 --- a/SabreTools.DatFiles/Formats/SabreJSON.cs +++ b/SabreTools.DatFiles/Formats/SabreJSON.cs @@ -34,7 +34,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Prepare all internal variables StreamReader sr = new StreamReader(File.OpenRead(filename), new UTF8Encoding(false)); diff --git a/SabreTools.DatFiles/Formats/SabreXML.cs b/SabreTools.DatFiles/Formats/SabreXML.cs index bd668750..9a6dc390 100644 --- a/SabreTools.DatFiles/Formats/SabreXML.cs +++ b/SabreTools.DatFiles/Formats/SabreXML.cs @@ -31,7 +31,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Prepare all internal variables XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings diff --git a/SabreTools.DatFiles/Formats/SeparatedValue.cs b/SabreTools.DatFiles/Formats/SeparatedValue.cs index e651906e..0f666d0f 100644 --- a/SabreTools.DatFiles/Formats/SeparatedValue.cs +++ b/SabreTools.DatFiles/Formats/SeparatedValue.cs @@ -38,7 +38,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Open a file reader Encoding enc = FileExtensions.GetEncoding(filename); diff --git a/SabreTools.DatFiles/Formats/SoftwareList.cs b/SabreTools.DatFiles/Formats/SoftwareList.cs index 6ca8d0d0..1862f359 100644 --- a/SabreTools.DatFiles/Formats/SoftwareList.cs +++ b/SabreTools.DatFiles/Formats/SoftwareList.cs @@ -102,7 +102,7 @@ namespace SabreTools.DatFiles.Formats /// Index ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if the error that is thrown should be thrown back to the caller, false otherwise - protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) + public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false) { // Prepare all internal variables XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings diff --git a/SabreTools.DatFiles/DatTool.Verifying.cs b/SabreTools.DatFiles/Verification.cs similarity index 96% rename from SabreTools.DatFiles/DatTool.Verifying.cs rename to SabreTools.DatFiles/Verification.cs index e74af521..07990b33 100644 --- a/SabreTools.DatFiles/DatTool.Verifying.cs +++ b/SabreTools.DatFiles/Verification.cs @@ -11,8 +11,17 @@ using SabreTools.Logging; // This file represents all methods related to verifying with a DatFile namespace SabreTools.DatFiles { - public partial class DatTool + public class Verification { + #region Logging + + /// + /// Logging object + /// + private static readonly Logger logger = new Logger(); + + #endregion + /// /// Verify a DatFile against a set of depots, leaving only missing files /// diff --git a/SabreTools/Features/Batch.cs b/SabreTools/Features/Batch.cs index 5066a071..27a8ca80 100644 --- a/SabreTools/Features/Batch.cs +++ b/SabreTools/Features/Batch.cs @@ -153,7 +153,7 @@ Reset the internal state: reset();"; // Assume there could be multiple foreach (string input in command.Arguments) { - DatTool.PopulateFromDir(datFile, input); + DirFromDat.PopulateFromDir(datFile, input); } // TODO: We might not want to remove higher order hashes in the future diff --git a/SabreTools/Features/DatFromDir.cs b/SabreTools/Features/DatFromDir.cs index 8f9721f3..e17fcc7c 100644 --- a/SabreTools/Features/DatFromDir.cs +++ b/SabreTools/Features/DatFromDir.cs @@ -89,7 +89,7 @@ namespace SabreTools.Features datdata.FillHeaderFromPath(basePath, noAutomaticDate); // Now populate from the path - bool success = DatTool.PopulateFromDir( + bool success = DirFromDat.PopulateFromDir( datdata, basePath, asFiles, diff --git a/SabreTools/Features/Verify.cs b/SabreTools/Features/Verify.cs index dba48051..1ccd52a4 100644 --- a/SabreTools/Features/Verify.cs +++ b/SabreTools/Features/Verify.cs @@ -76,7 +76,7 @@ namespace SabreTools.Features // If we have the depot flag, respect it if (Header.InputDepot?.IsActive ?? false) { - DatTool.VerifyDepot(datdata, Inputs); + Verification.VerifyDepot(datdata, Inputs); } else { @@ -84,10 +84,10 @@ namespace SabreTools.Features logger.User("Processing files:\n"); foreach (string input in Inputs) { - DatTool.PopulateFromDir(datdata, input, asFiles: asFiles, hashes: quickScan ? Hash.CRC : Hash.Standard); + DirFromDat.PopulateFromDir(datdata, input, asFiles: asFiles, hashes: quickScan ? Hash.CRC : Hash.Standard); } - DatTool.VerifyGeneric(datdata, hashOnly); + Verification.VerifyGeneric(datdata, hashOnly); } // Now write out if there are any items left @@ -125,7 +125,7 @@ namespace SabreTools.Features // If we have the depot flag, respect it if (Header.InputDepot?.IsActive ?? false) { - DatTool.VerifyDepot(datdata, Inputs); + Verification.VerifyDepot(datdata, Inputs); } else { @@ -133,10 +133,10 @@ namespace SabreTools.Features logger.User("Processing files:\n"); foreach (string input in Inputs) { - DatTool.PopulateFromDir(datdata, input, asFiles: asFiles, hashes: quickScan ? Hash.CRC : Hash.Standard); + DirFromDat.PopulateFromDir(datdata, input, asFiles: asFiles, hashes: quickScan ? Hash.CRC : Hash.Standard); } - DatTool.VerifyGeneric(datdata, hashOnly); + Verification.VerifyGeneric(datdata, hashOnly); } // Now write out if there are any items left