From 8f67c3e525252688bd90d870768783b938347f06 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 10 Dec 2020 14:03:07 -0800 Subject: [PATCH] Writing to actual class --- RombaSharp/Features/Diffdat.cs | 2 +- RombaSharp/Features/Dir2Dat.cs | 2 +- RombaSharp/Features/EDiffdat.cs | 2 +- SabreTools.DatFiles/Splitter.cs | 2 +- .../{DatTool.Writing.cs => Writer.cs} | 12 +++++++++++- SabreTools/Features/Batch.cs | 2 +- SabreTools/Features/DatFromDir.cs | 2 +- SabreTools/Features/Sort.cs | 4 ++-- SabreTools/Features/Split.cs | 12 ++++++------ SabreTools/Features/Update.cs | 16 ++++++++-------- SabreTools/Features/Verify.cs | 4 ++-- 11 files changed, 35 insertions(+), 25 deletions(-) rename SabreTools.DatFiles/{DatTool.Writing.cs => Writer.cs} (96%) diff --git a/RombaSharp/Features/Diffdat.cs b/RombaSharp/Features/Diffdat.cs index dd8512ea..1b4f81d2 100644 --- a/RombaSharp/Features/Diffdat.cs +++ b/RombaSharp/Features/Diffdat.cs @@ -64,7 +64,7 @@ in -old DAT file. Ignores those entries in -old that are not in -new."; // Diff against the new datfile DatFile intDat = Parser.CreateAndParse(newdat); DatTool.DiffAgainst(datfile, intDat, false); - DatTool.Write(intDat, outdat); + Writer.Write(intDat, outdat); } } } diff --git a/RombaSharp/Features/Dir2Dat.cs b/RombaSharp/Features/Dir2Dat.cs index 6b319cc0..e1013624 100644 --- a/RombaSharp/Features/Dir2Dat.cs +++ b/RombaSharp/Features/Dir2Dat.cs @@ -55,7 +55,7 @@ namespace RombaSharp.Features datfile.Header.Description = description; DirFromDat.PopulateFromDir(datfile, source, asFiles: TreatAsFile.NonArchive); DatTool.ApplyCleaning(datfile, new Cleaner() { ExcludeFields = Hash.DeepHashes.AsFields() }); - DatTool.Write(datfile, outdat); + Writer.Write(datfile, outdat); } } } diff --git a/RombaSharp/Features/EDiffdat.cs b/RombaSharp/Features/EDiffdat.cs index 1fa14284..cf96aa4b 100644 --- a/RombaSharp/Features/EDiffdat.cs +++ b/RombaSharp/Features/EDiffdat.cs @@ -56,7 +56,7 @@ namespace RombaSharp.Features // Diff against the new datfile DatFile intDat = Parser.CreateAndParse(newdat); DatTool.DiffAgainst(datfile, intDat, false); - DatTool.Write(intDat, outdat); + Writer.Write(intDat, outdat); } } } diff --git a/SabreTools.DatFiles/Splitter.cs b/SabreTools.DatFiles/Splitter.cs index c80a001e..f9a19801 100644 --- a/SabreTools.DatFiles/Splitter.cs +++ b/SabreTools.DatFiles/Splitter.cs @@ -313,7 +313,7 @@ namespace SabreTools.DatFiles newDatFile.Header.Type = null; // Write out the temporary DAT to the proper directory - DatTool.Write(newDatFile, outDir); + Writer.Write(newDatFile, outDir); } /// diff --git a/SabreTools.DatFiles/DatTool.Writing.cs b/SabreTools.DatFiles/Writer.cs similarity index 96% rename from SabreTools.DatFiles/DatTool.Writing.cs rename to SabreTools.DatFiles/Writer.cs index 36f25d00..67ea78ce 100644 --- a/SabreTools.DatFiles/DatTool.Writing.cs +++ b/SabreTools.DatFiles/Writer.cs @@ -4,12 +4,22 @@ using System.Threading.Tasks; using SabreTools.Core; using SabreTools.IO; +using SabreTools.Logging; // This file represents all methods related to writing to a file namespace SabreTools.DatFiles { - public partial class DatTool + public class Writer { + #region Logging + + /// + /// Logging object + /// + private static readonly Logger logger = new Logger(); + + #endregion + /// /// Create and open an output file for writing direct from a dictionary /// diff --git a/SabreTools/Features/Batch.cs b/SabreTools/Features/Batch.cs index 5b43a2f1..974f639c 100644 --- a/SabreTools/Features/Batch.cs +++ b/SabreTools/Features/Batch.cs @@ -405,7 +405,7 @@ Reset the internal state: reset();"; } // Write out the dat with the current state - DatTool.Write(datFile, outputDirectory, overwrite: overwrite.Value); + Writer.Write(datFile, outputDirectory, overwrite: overwrite.Value); break; // Reset the internal state diff --git a/SabreTools/Features/DatFromDir.cs b/SabreTools/Features/DatFromDir.cs index e17fcc7c..efd9d40b 100644 --- a/SabreTools/Features/DatFromDir.cs +++ b/SabreTools/Features/DatFromDir.cs @@ -106,7 +106,7 @@ namespace SabreTools.Features DatTool.ApplyCleaning(datdata, Cleaner); // Write out the file - DatTool.Write(datdata, OutputDir); + Writer.Write(datdata, OutputDir); } else { diff --git a/SabreTools/Features/Sort.cs b/SabreTools/Features/Sort.cs index acd28a5d..46cd503c 100644 --- a/SabreTools/Features/Sort.cs +++ b/SabreTools/Features/Sort.cs @@ -114,7 +114,7 @@ namespace SabreTools.Features datdata.Header.Name = $"fixDAT_{Header.Name}"; datdata.Header.Description = $"fixDAT_{Header.Description}"; datdata.Items.ClearMarked(); - DatTool.Write(datdata, OutputDir); + Writer.Write(datdata, OutputDir); } } } @@ -155,7 +155,7 @@ namespace SabreTools.Features datdata.Header.Name = $"fixDAT_{Header.Name}"; datdata.Header.Description = $"fixDAT_{Header.Description}"; datdata.Items.ClearMarked(); - DatTool.Write(datdata, OutputDir); + Writer.Write(datdata, OutputDir); } } } diff --git a/SabreTools/Features/Split.cs b/SabreTools/Features/Split.cs index 972d1801..ec4e2762 100644 --- a/SabreTools/Features/Split.cs +++ b/SabreTools/Features/Split.cs @@ -68,8 +68,8 @@ namespace SabreTools.Features InternalStopwatch watch = new InternalStopwatch("Outputting extension-split DATs"); // Output both possible DatFiles - DatTool.Write(extADat, OutputDir); - DatTool.Write(extBDat, OutputDir); + Writer.Write(extADat, OutputDir); + Writer.Write(extBDat, OutputDir); watch.Stop(); } @@ -84,7 +84,7 @@ namespace SabreTools.Features // Loop through each type DatFile Parallel.ForEach(typeDats.Keys, Globals.ParallelOptions, itemType => { - DatTool.Write(typeDats[itemType], OutputDir); + Writer.Write(typeDats[itemType], OutputDir); }); watch.Stop(); @@ -109,8 +109,8 @@ namespace SabreTools.Features InternalStopwatch watch = new InternalStopwatch("Outputting size-split DATs"); // Output both possible DatFiles - DatTool.Write(lessThan, OutputDir); - DatTool.Write(greaterThan, OutputDir); + Writer.Write(lessThan, OutputDir); + Writer.Write(greaterThan, OutputDir); watch.Stop(); } @@ -125,7 +125,7 @@ namespace SabreTools.Features // Loop through each type DatFile Parallel.ForEach(typeDats.Keys, Globals.ParallelOptions, itemType => { - DatTool.Write(typeDats[itemType], OutputDir); + Writer.Write(typeDats[itemType], OutputDir); }); watch.Stop(); diff --git a/SabreTools/Features/Update.cs b/SabreTools/Features/Update.cs index 4e8e6943..73ec01ab 100644 --- a/SabreTools/Features/Update.cs +++ b/SabreTools/Features/Update.cs @@ -176,7 +176,7 @@ namespace SabreTools.Features string realOutDir = inputPath.GetOutputPath(OutputDir, GetBoolean(features, InplaceValue)); // Try to output the file, overwriting only if it's not in the current directory - DatTool.Write(datFile, realOutDir, overwrite: GetBoolean(features, InplaceValue)); + Writer.Write(datFile, realOutDir, overwrite: GetBoolean(features, InplaceValue)); }); return; @@ -216,7 +216,7 @@ namespace SabreTools.Features DatFile dupeData = DatTool.DiffDuplicates(userInputDat, inputPaths); InternalStopwatch watch = new InternalStopwatch("Outputting duplicate DAT"); - DatTool.Write(dupeData, OutputDir, overwrite: false); + Writer.Write(dupeData, OutputDir, overwrite: false); watch.Stop(); } @@ -226,7 +226,7 @@ namespace SabreTools.Features DatFile outerDiffData = DatTool.DiffNoDuplicates(userInputDat, inputPaths); InternalStopwatch watch = new InternalStopwatch("Outputting no duplicate DAT"); - DatTool.Write(outerDiffData, OutputDir, overwrite: false); + Writer.Write(outerDiffData, OutputDir, overwrite: false); watch.Stop(); } @@ -244,7 +244,7 @@ namespace SabreTools.Features string path = inputPaths[j].GetOutputPath(OutputDir, GetBoolean(features, InplaceValue)); // Try to output the file - DatTool.Write(datFiles[j], path, overwrite: GetBoolean(features, InplaceValue)); + Writer.Write(datFiles[j], path, overwrite: GetBoolean(features, InplaceValue)); }); watch.Stop(); @@ -280,7 +280,7 @@ namespace SabreTools.Features string path = inputPaths[j].GetOutputPath(OutputDir, GetBoolean(features, InplaceValue)); // Try to output the file - DatTool.Write(datFiles[j], path, overwrite: GetBoolean(features, InplaceValue)); + Writer.Write(datFiles[j], path, overwrite: GetBoolean(features, InplaceValue)); }); watch.Stop(); @@ -307,7 +307,7 @@ namespace SabreTools.Features // Finally output the diffed DatFile string interOutDir = inputPath.GetOutputPath(OutputDir, GetBoolean(features, InplaceValue)); - DatTool.Write(repDat, interOutDir, overwrite: GetBoolean(features, InplaceValue)); + Writer.Write(repDat, interOutDir, overwrite: GetBoolean(features, InplaceValue)); }); } @@ -332,7 +332,7 @@ namespace SabreTools.Features // Finally output the replaced DatFile string interOutDir = inputPath.GetOutputPath(OutputDir, GetBoolean(features, InplaceValue)); - DatTool.Write(repDat, interOutDir, overwrite: GetBoolean(features, InplaceValue)); + Writer.Write(repDat, interOutDir, overwrite: GetBoolean(features, InplaceValue)); }); } @@ -344,7 +344,7 @@ namespace SabreTools.Features if (string.Equals(userInputDat.Header.Type, "SuperDAT", StringComparison.OrdinalIgnoreCase)) DatTool.ApplySuperDAT(userInputDat, inputPaths); - DatTool.Write(userInputDat, OutputDir); + Writer.Write(userInputDat, OutputDir); } } } diff --git a/SabreTools/Features/Verify.cs b/SabreTools/Features/Verify.cs index 3012c8c2..68857b4f 100644 --- a/SabreTools/Features/Verify.cs +++ b/SabreTools/Features/Verify.cs @@ -92,7 +92,7 @@ namespace SabreTools.Features // Now write out if there are any items left datdata.WriteStatsToConsole(); - DatTool.Write(datdata, OutputDir); + Writer.Write(datdata, OutputDir); } } // Otherwise, process all DATs into the same output @@ -141,7 +141,7 @@ namespace SabreTools.Features // Now write out if there are any items left datdata.WriteStatsToConsole(); - DatTool.Write(datdata, OutputDir); + Writer.Write(datdata, OutputDir); } } }