Decouple last diffs from writes

This commit is contained in:
Matt Nadareski
2020-08-27 22:27:23 -07:00
parent 0d1e5858b2
commit 0c2104b243
2 changed files with 43 additions and 38 deletions

View File

@@ -427,19 +427,17 @@ namespace SabreTools.Library.DatFiles
/// Output duplicate item diff /// Output duplicate item diff
/// </summary> /// </summary>
/// <param name="inputs">List of inputs to write out from</param> /// <param name="inputs">List of inputs to write out from</param>
/// <param name="outDir">Output directory to write the DATs to</param> public DatFile DiffDuplicates(List<string> inputs)
public void DiffDuplicates(List<string> inputs, string outDir)
{ {
List<ParentablePath> paths = inputs.Select(i => new ParentablePath(i)).ToList(); List<ParentablePath> paths = inputs.Select(i => new ParentablePath(i)).ToList();
DiffDuplicates(paths, outDir); return DiffDuplicates(paths);
} }
/// <summary> /// <summary>
/// Output duplicate item diff /// Output duplicate item diff
/// </summary> /// </summary>
/// <param name="inputs">List of inputs to write out from</param> /// <param name="inputs">List of inputs to write out from</param>
/// <param name="outDir">Output directory to write the DATs to</param> public DatFile DiffDuplicates(List<ParentablePath> inputs)
public void DiffDuplicates(List<ParentablePath> inputs, string outDir)
{ {
InternalStopwatch watch = new InternalStopwatch("Initializing duplicate DAT"); InternalStopwatch watch = new InternalStopwatch("Initializing duplicate DAT");
@@ -488,29 +486,24 @@ namespace SabreTools.Library.DatFiles
watch.Stop(); watch.Stop();
// Finally, loop through and output each of the DATs return dupeData;
watch.Start("Outputting duplicate DAT");
dupeData.Write(outDir, overwrite: false);
watch.Stop();
} }
/// <summary> /// <summary>
/// Output non-cascading diffs /// Output non-cascading diffs
/// </summary> /// </summary>
/// <param name="inputs">List of inputs to write out from</param> /// <param name="inputs">List of inputs to write out from</param>
/// <param name="outDir">Output directory to write the DATs to</param> public List<DatFile> DiffIndividuals(List<string> inputs)
public void DiffIndividuals(List<string> inputs, string outDir)
{ {
List<ParentablePath> paths = inputs.Select(i => new ParentablePath(i)).ToList(); List<ParentablePath> paths = inputs.Select(i => new ParentablePath(i)).ToList();
DiffIndividuals(paths, outDir); return DiffIndividuals(paths);
} }
/// <summary> /// <summary>
/// Output non-cascading diffs /// Output non-cascading diffs
/// </summary> /// </summary>
/// <param name="inputs">List of inputs to write out from</param> /// <param name="inputs">List of inputs to write out from</param>
/// <param name="outDir">Output directory to write the DATs to</param> public List<DatFile> DiffIndividuals(List<ParentablePath> inputs)
public void DiffIndividuals(List<ParentablePath> inputs, string outDir)
{ {
InternalStopwatch watch = new InternalStopwatch("Initializing all individual DATs"); InternalStopwatch watch = new InternalStopwatch("Initializing all individual DATs");
@@ -564,37 +557,24 @@ namespace SabreTools.Library.DatFiles
watch.Stop(); watch.Stop();
// Finally, loop through and output each of the DATs return outDats.ToList();
watch.Start("Outputting all individual DATs");
Parallel.For(0, inputs.Count, Globals.ParallelOptions, j =>
{
string path = inputs[j].GetOutputPath(outDir, false /* inplace */);
// Try to output the file
outDats[j].Write(path, overwrite: false);
});
watch.Stop();
} }
/// <summary> /// <summary>
/// Output non-duplicate item diff /// Output non-duplicate item diff
/// </summary> /// </summary>
/// <param name="inputs">List of inputs to write out from</param> /// <param name="inputs">List of inputs to write out from</param>
/// <param name="outDir">Output directory to write the DATs to</param> public DatFile DiffNoDuplicates(List<string> inputs)
public void DiffNoDuplicates(List<string> inputs, string outDir)
{ {
List<ParentablePath> paths = inputs.Select(i => new ParentablePath(i)).ToList(); List<ParentablePath> paths = inputs.Select(i => new ParentablePath(i)).ToList();
DiffNoDuplicates(paths, outDir); return DiffNoDuplicates(paths);
} }
/// <summary> /// <summary>
/// Output non-duplicate item diff /// Output non-duplicate item diff
/// </summary> /// </summary>
/// <param name="inputs">List of inputs to write out from</param> /// <param name="inputs">List of inputs to write out from</param>
/// <param name="outDir">Output directory to write the DATs to</param> public DatFile DiffNoDuplicates(List<ParentablePath> inputs)
public void DiffNoDuplicates(List<ParentablePath> inputs, string outDir)
{ {
InternalStopwatch watch = new InternalStopwatch("Initializing no duplicate DAT"); InternalStopwatch watch = new InternalStopwatch("Initializing no duplicate DAT");
@@ -642,10 +622,7 @@ namespace SabreTools.Library.DatFiles
watch.Stop(); watch.Stop();
// Finally, loop through and output each of the DATs return outerDiffData;
watch.Start("Outputting no duplicate DAT");
outerDiffData.Write(outDir, overwrite: false);
watch.Stop();
} }
/// <summary> /// <summary>

View File

@@ -206,15 +206,43 @@ namespace SabreTools.Features
// Output only DatItems that are duplicated across inputs // Output only DatItems that are duplicated across inputs
if (updateMode.HasFlag(UpdateMode.DiffDupesOnly)) if (updateMode.HasFlag(UpdateMode.DiffDupesOnly))
userInputDat.DiffDuplicates(inputPaths, OutputDir); {
DatFile dupeData = userInputDat.DiffDuplicates(inputPaths);
InternalStopwatch watch = new InternalStopwatch("Outputting duplicate DAT");
dupeData.Write(OutputDir, overwrite: false);
watch.Stop();
}
// Output only DatItems that are not duplicated across inputs // Output only DatItems that are not duplicated across inputs
if (updateMode.HasFlag(UpdateMode.DiffNoDupesOnly)) if (updateMode.HasFlag(UpdateMode.DiffNoDupesOnly))
userInputDat.DiffNoDuplicates(inputPaths, OutputDir); {
DatFile outerDiffData = userInputDat.DiffNoDuplicates(inputPaths);
InternalStopwatch watch = new InternalStopwatch("Outputting no duplicate DAT");
outerDiffData.Write(OutputDir, overwrite: false);
watch.Stop();
}
// Output only DatItems that are unique to each input // Output only DatItems that are unique to each input
if (updateMode.HasFlag(UpdateMode.DiffIndividualsOnly)) if (updateMode.HasFlag(UpdateMode.DiffIndividualsOnly))
userInputDat.DiffIndividuals(inputPaths, OutputDir); {
// Get all of the output DatFiles
List<DatFile> datFiles = userInputDat.DiffIndividuals(inputPaths);
// Loop through and output the new DatFiles
InternalStopwatch watch = new InternalStopwatch("Outputting all individual DATs");
Parallel.For(0, inputPaths.Count, Globals.ParallelOptions, j =>
{
string path = inputPaths[j].GetOutputPath(OutputDir, GetBoolean(features, InplaceValue));
// Try to output the file
datFiles[j].Write(path, overwrite: GetBoolean(features, InplaceValue));
});
watch.Stop();
}
// Output cascaded diffs // Output cascaded diffs
if (updateMode.HasFlag(UpdateMode.DiffCascade)) if (updateMode.HasFlag(UpdateMode.DiffCascade))