Files
SabreTools/RombaSharp/Features/Diffdat.cs

71 lines
2.3 KiB
C#
Raw Normal View History

2020-08-01 13:25:32 -07:00
using System.Collections.Generic;
using System.IO;
using SabreTools.DatFiles;
2020-12-07 13:57:26 -08:00
using SabreTools.Help;
2020-12-07 15:08:57 -08:00
using SabreTools.IO;
2020-08-01 13:25:32 -07:00
namespace RombaSharp.Features
{
internal class Diffdat : BaseFeature
{
public const string Value = "Diffdat";
public Diffdat()
{
Name = Value;
Flags = new List<string>() { "diffdat" };
Description = "Creates a DAT file with those entries that are in -new DAT.";
2020-12-07 13:57:26 -08:00
_featureType = ParameterType.Flag;
2020-08-01 13:25:32 -07:00
LongDescription = @"Creates a DAT file with those entries that are in -new DAT file and not
in -old DAT file. Ignores those entries in -old that are not in -new.";
this.Features = new Dictionary<string, Feature>();
AddFeature(OutStringInput);
AddFeature(OldStringInput);
AddFeature(NewStringInput);
AddFeature(NameStringInput);
AddFeature(DescriptionStringInput);
}
public override void ProcessFeatures(Dictionary<string, Feature> features)
{
base.ProcessFeatures(features);
// Get feature flags
string name = GetString(features, NameStringValue);
string description = GetString(features, DescriptionStringValue);
string newdat = GetString(features, NewStringValue);
string olddat = GetString(features, OldStringValue);
string outdat = GetString(features, OutStringValue);
// Ensure the output directory
2020-12-10 22:16:53 -08:00
outdat.Ensure(create: true);
2020-08-01 13:25:32 -07:00
// Check that all required files exist
if (!File.Exists(olddat))
{
logger.Error($"File '{olddat}' does not exist!");
2020-08-01 13:25:32 -07:00
return;
}
if (!File.Exists(newdat))
{
logger.Error($"File '{newdat}' does not exist!");
2020-08-01 13:25:32 -07:00
return;
}
// Create the encapsulating datfile
DatFile datfile = DatFile.Create();
datfile.Header.Name = name;
datfile.Header.Description = description;
2020-12-10 13:53:34 -08:00
Parser.ParseInto(datfile, olddat);
2020-08-01 13:25:32 -07:00
2020-08-27 21:40:08 -07:00
// Diff against the new datfile
2020-12-10 13:53:34 -08:00
DatFile intDat = Parser.CreateAndParse(newdat);
2020-12-10 12:11:32 -08:00
DatTool.DiffAgainst(datfile, intDat, false);
2020-12-10 14:03:07 -08:00
Writer.Write(intDat, outdat);
2020-08-01 13:25:32 -07:00
}
}
}