2020-08-01 13:25:32 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2020-12-08 16:37:08 -08:00
|
|
|
|
using SabreTools.DatFiles;
|
2020-12-10 23:24:09 -08:00
|
|
|
|
using SabreTools.DatTools;
|
2020-12-07 13:57:26 -08:00
|
|
|
|
using SabreTools.Help;
|
2024-04-24 13:45:38 -04:00
|
|
|
|
using SabreTools.IO.Extensions;
|
2020-08-01 13:25:32 -07:00
|
|
|
|
|
|
|
|
|
|
namespace RombaSharp.Features
|
|
|
|
|
|
{
|
|
|
|
|
|
internal class Diffdat : BaseFeature
|
|
|
|
|
|
{
|
|
|
|
|
|
public const string Value = "Diffdat";
|
|
|
|
|
|
|
|
|
|
|
|
public Diffdat()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = Value;
|
2024-07-18 01:06:40 -04:00
|
|
|
|
Flags.AddRange(["diffdat"]);
|
2020-08-01 13:25:32 -07:00
|
|
|
|
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.";
|
|
|
|
|
|
|
2021-02-03 11:10:19 -08:00
|
|
|
|
// Common Features
|
|
|
|
|
|
AddCommonFeatures();
|
|
|
|
|
|
|
2020-08-01 13:25:32 -07:00
|
|
|
|
AddFeature(OutStringInput);
|
|
|
|
|
|
AddFeature(OldStringInput);
|
|
|
|
|
|
AddFeature(NewStringInput);
|
|
|
|
|
|
AddFeature(NameStringInput);
|
|
|
|
|
|
AddFeature(DescriptionStringInput);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-05 20:26:38 -05:00
|
|
|
|
public override bool ProcessFeatures(Dictionary<string, Feature?> features)
|
2020-08-01 13:25:32 -07:00
|
|
|
|
{
|
2021-03-19 20:52:11 -07:00
|
|
|
|
// If the base fails, just fail out
|
|
|
|
|
|
if (!base.ProcessFeatures(features))
|
|
|
|
|
|
return false;
|
2020-08-01 13:25:32 -07:00
|
|
|
|
|
|
|
|
|
|
// Get feature flags
|
2024-03-05 20:26:38 -05:00
|
|
|
|
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);
|
2020-08-01 13:25:32 -07:00
|
|
|
|
|
|
|
|
|
|
// Ensure the output directory
|
2024-03-12 16:47:21 -04:00
|
|
|
|
outdat = outdat.Ensure(create: true);
|
2020-08-01 13:25:32 -07:00
|
|
|
|
|
|
|
|
|
|
// Check that all required files exist
|
2024-10-19 12:23:43 -04:00
|
|
|
|
if (olddat == null || !File.Exists(olddat))
|
2020-08-01 13:25:32 -07:00
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Error($"File '{olddat}' does not exist!");
|
2021-03-19 20:52:11 -07:00
|
|
|
|
return false;
|
2020-08-01 13:25:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-19 12:23:43 -04:00
|
|
|
|
if (newdat == null || !File.Exists(newdat))
|
2020-08-01 13:25:32 -07:00
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Error($"File '{newdat}' does not exist!");
|
2021-03-19 20:52:11 -07:00
|
|
|
|
return false;
|
2020-08-01 13:25:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create the encapsulating datfile
|
|
|
|
|
|
DatFile datfile = DatFile.Create();
|
2024-03-10 04:10:37 -04:00
|
|
|
|
datfile.Header.SetFieldValue<string?>(SabreTools.Models.Metadata.Header.NameKey, name);
|
|
|
|
|
|
datfile.Header.SetFieldValue<string?>(SabreTools.Models.Metadata.Header.DescriptionKey, 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-13 23:09:24 -08:00
|
|
|
|
DatFileTool.DiffAgainst(datfile, intDat, false);
|
2024-03-05 20:26:38 -05:00
|
|
|
|
Writer.Write(intDat, outdat!);
|
2021-03-19 20:52:11 -07:00
|
|
|
|
return true;
|
2020-08-01 13:25:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|