mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Diff, determination, enum cleanup
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Filtering;
|
||||
using SabreTools.Library.Help;
|
||||
using SabreTools.Library.Tools;
|
||||
@@ -10,6 +12,54 @@ namespace SabreTools.Features
|
||||
{
|
||||
internal class BaseFeature : TopLevel
|
||||
{
|
||||
#region Enums
|
||||
|
||||
/// <summary>
|
||||
/// Determines how the DAT will be split on output
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum SplittingMode
|
||||
{
|
||||
None = 0x00,
|
||||
|
||||
Extension = 1 << 0,
|
||||
Hash = 1 << 2,
|
||||
Level = 1 << 3,
|
||||
Type = 1 << 4,
|
||||
Size = 1 << 5,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines special update modes
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum UpdateMode
|
||||
{
|
||||
None = 0x00,
|
||||
|
||||
// Standard diffs
|
||||
DiffDupesOnly = 1 << 0,
|
||||
DiffNoDupesOnly = 1 << 1,
|
||||
DiffIndividualsOnly = 1 << 2,
|
||||
|
||||
// Cascaded diffs
|
||||
DiffCascade = 1 << 3,
|
||||
DiffReverseCascade = 1 << 4,
|
||||
|
||||
// Base diffs
|
||||
DiffAgainst = 1 << 5,
|
||||
|
||||
// Special update modes
|
||||
Merge = 1 << 6,
|
||||
BaseReplace = 1 << 7,
|
||||
ReverseBaseReplace = 1 << 8,
|
||||
|
||||
// Combinations
|
||||
AllDiffs = DiffDupesOnly | DiffNoDupesOnly | DiffIndividualsOnly,
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Features
|
||||
|
||||
#region Flag features
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.Help;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.Help;
|
||||
|
||||
namespace SabreTools.Features
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.Help;
|
||||
|
||||
namespace SabreTools.Features
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.Help;
|
||||
using SabreTools.Library.Skippers;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.Help;
|
||||
using SabreTools.Library.Skippers;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.Help;
|
||||
|
||||
namespace SabreTools.Features
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.Help;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
namespace SabreTools.Features
|
||||
{
|
||||
@@ -38,18 +38,55 @@ namespace SabreTools.Features
|
||||
public override void ProcessFeatures(Dictionary<string, Feature> features)
|
||||
{
|
||||
base.ProcessFeatures(features);
|
||||
SplittingMode splittingMode = GetSplittingMode(features);
|
||||
|
||||
DatFile datfile = DatFile.Create(Header.DatFormat);
|
||||
datfile.DetermineSplitType(
|
||||
Inputs,
|
||||
OutputDir,
|
||||
GetBoolean(features, InplaceValue),
|
||||
GetSplittingMode(features),
|
||||
GetList(features, ExtAListValue),
|
||||
GetList(features, ExtBListValue),
|
||||
GetBoolean(features, ShortValue),
|
||||
GetBoolean(features, BaseValue),
|
||||
GetInt64(features, RadixInt64Value));
|
||||
// If we somehow have the "none" split type, return
|
||||
if (splittingMode == SplittingMode.None)
|
||||
return;
|
||||
|
||||
// Get only files from the inputs
|
||||
List<ParentablePath> files = DirectoryExtensions.GetFilesOnly(Inputs, appendparent: true);
|
||||
|
||||
// Loop over the input files
|
||||
foreach (ParentablePath file in files)
|
||||
{
|
||||
// Create and fill the new DAT
|
||||
DatFile internalDat = DatFile.Create(Header);
|
||||
internalDat.Parse(file);
|
||||
|
||||
// Get the output directory
|
||||
OutputDir = file.GetOutputPath(OutputDir, GetBoolean(features, InplaceValue));
|
||||
|
||||
// Extension splitting
|
||||
if (splittingMode.HasFlag(SplittingMode.Extension))
|
||||
{
|
||||
internalDat.SplitByExtension(
|
||||
OutputDir,
|
||||
GetList(features, ExtAListValue),
|
||||
GetList(features, ExtBListValue));
|
||||
}
|
||||
|
||||
// Hash splitting
|
||||
if (splittingMode.HasFlag(SplittingMode.Hash))
|
||||
internalDat.SplitByHash(OutputDir);
|
||||
|
||||
// Level splitting
|
||||
if (splittingMode.HasFlag(SplittingMode.Level))
|
||||
{
|
||||
internalDat.SplitByLevel(
|
||||
OutputDir,
|
||||
GetBoolean(features, ShortValue),
|
||||
GetBoolean(features, BaseValue));
|
||||
}
|
||||
|
||||
// Size splitting
|
||||
if (splittingMode.HasFlag(SplittingMode.Size))
|
||||
internalDat.SplitBySize(OutputDir, GetInt64(features, RadixInt64Value));
|
||||
|
||||
// Type splitting
|
||||
if (splittingMode.HasFlag(SplittingMode.Type))
|
||||
internalDat.SplitByType(OutputDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.Help;
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Help;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
namespace SabreTools.Features
|
||||
{
|
||||
@@ -142,20 +143,93 @@ namespace SabreTools.Features
|
||||
if (updateFields == null || updateFields.Count == 0)
|
||||
updateFields = new List<Field>() { Field.Name };
|
||||
|
||||
// Populate the DatData object
|
||||
// Ensure we only have files in the inputs
|
||||
List<ParentablePath> inputFileNames = DirectoryExtensions.GetFilesOnly(Inputs, appendparent: true);
|
||||
List<ParentablePath> baseFileNames = DirectoryExtensions.GetFilesOnly(GetList(features, BaseDatListValue));
|
||||
|
||||
// If we're in standard update mode, run through all of the inputs
|
||||
if (updateMode == UpdateMode.None)
|
||||
{
|
||||
DatFile datFile = DatFile.Create(Header);
|
||||
datFile.Update(
|
||||
inputFileNames,
|
||||
OutputDir,
|
||||
GetBoolean(features, InplaceValue),
|
||||
Filter);
|
||||
return;
|
||||
}
|
||||
|
||||
// Reverse inputs if we're in a required mode
|
||||
if (updateMode.HasFlag(UpdateMode.DiffReverseCascade))
|
||||
{
|
||||
updateMode |= UpdateMode.DiffCascade;
|
||||
inputFileNames.Reverse();
|
||||
}
|
||||
if (updateMode.HasFlag(UpdateMode.ReverseBaseReplace))
|
||||
{
|
||||
updateMode |= UpdateMode.BaseReplace;
|
||||
baseFileNames.Reverse();
|
||||
}
|
||||
|
||||
// Create a DAT to capture inputs
|
||||
DatFile userInputDat = DatFile.Create(Header);
|
||||
|
||||
userInputDat.DetermineUpdateType(
|
||||
Inputs,
|
||||
GetList(features, BaseDatListValue),
|
||||
OutputDir,
|
||||
updateMode,
|
||||
GetBoolean(features, InplaceValue),
|
||||
GetBoolean(features, SkipFirstOutputValue),
|
||||
Filter,
|
||||
updateFields,
|
||||
GetBoolean(features, OnlySameValue),
|
||||
GetBoolean(Features, ByGameValue));
|
||||
// Populate using the correct set
|
||||
List<DatHeader> datHeaders;
|
||||
if (updateMode.HasFlag(UpdateMode.DiffAgainst) || updateMode.HasFlag(UpdateMode.BaseReplace))
|
||||
datHeaders = userInputDat.PopulateUserData(baseFileNames, Filter);
|
||||
else
|
||||
datHeaders = userInputDat.PopulateUserData(inputFileNames, Filter);
|
||||
|
||||
// Merge all input files and write
|
||||
if (updateMode.HasFlag(UpdateMode.Merge))
|
||||
userInputDat.MergeNoDiff(inputFileNames, OutputDir);
|
||||
|
||||
// Output only DatItems that are duplicated across inputs
|
||||
if (updateMode.HasFlag(UpdateMode.DiffDupesOnly))
|
||||
userInputDat.DiffDuplicates(inputFileNames, OutputDir);
|
||||
|
||||
// Output only DatItems that are not duplicated across inputs
|
||||
if (updateMode.HasFlag(UpdateMode.DiffNoDupesOnly))
|
||||
userInputDat.DiffNoDuplicates(inputFileNames, OutputDir);
|
||||
|
||||
// Output only DatItems that are unique to each input
|
||||
if (updateMode.HasFlag(UpdateMode.DiffIndividualsOnly))
|
||||
userInputDat.DiffIndividuals(inputFileNames, OutputDir);
|
||||
|
||||
// Output cascaded diffs
|
||||
if (updateMode.HasFlag(UpdateMode.DiffCascade))
|
||||
{
|
||||
userInputDat.DiffCascade(
|
||||
inputFileNames,
|
||||
datHeaders,
|
||||
OutputDir,
|
||||
GetBoolean(features, InplaceValue),
|
||||
GetBoolean(features, SkipFirstOutputValue));
|
||||
}
|
||||
|
||||
// Output differences against a base DAT
|
||||
if (updateMode.HasFlag(UpdateMode.DiffAgainst))
|
||||
{
|
||||
userInputDat.DiffAgainst(
|
||||
inputFileNames,
|
||||
OutputDir,
|
||||
GetBoolean(features, InplaceValue),
|
||||
Filter,
|
||||
GetBoolean(Features, ByGameValue));
|
||||
}
|
||||
|
||||
// Output DATs after replacing fields from a base DAT
|
||||
if (updateMode.HasFlag(UpdateMode.BaseReplace))
|
||||
{
|
||||
userInputDat.BaseReplace(
|
||||
inputFileNames,
|
||||
OutputDir,
|
||||
GetBoolean(features, InplaceValue),
|
||||
Filter,
|
||||
updateFields,
|
||||
GetBoolean(features, OnlySameValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.Filtering;
|
||||
using SabreTools.Library.Help;
|
||||
|
||||
Reference in New Issue
Block a user