DFD and Verification to actual classes

This commit is contained in:
Matt Nadareski
2020-12-10 13:30:08 -08:00
parent b57927a4ef
commit 1269f2088b
27 changed files with 76 additions and 66 deletions

View File

@@ -180,39 +180,6 @@ namespace SabreTools.DatFiles
return datFile;
}
/// <summary>
/// Add items from another DatFile to the existing DatFile
/// </summary>
/// <param name="datFile">DatFile to add from</param>
/// <param name="delete">If items should be deleted from the source DatFile</param>
public void AddFromExisting(DatFile datFile, bool delete = false)
{
// Get the list of keys from the DAT
var keys = datFile.Items.Keys.ToList();
foreach (string key in keys)
{
// Add everything from the key to the internal DAT
Items.AddRange(key, datFile.Items[key]);
// Now remove the key from the source DAT
if (delete)
datFile.Items.Remove(key);
}
// Now remove the file dictionary from the source DAT
if (delete)
datFile.Items = null;
}
/// <summary>
/// Apply a DatHeader to an existing DatFile
/// </summary>
/// <param name="datHeader">DatHeader to get the values from</param>
public void ApplyDatHeader(DatHeader datHeader)
{
Header.ConditionalCopy(datHeader);
}
/// <summary>
/// Fill the header values based on existing Header and path
/// </summary>

View File

@@ -458,12 +458,37 @@ namespace SabreTools.DatFiles
watch.Start("Populating internal DAT");
for (int i = 0; i < inputs.Count; i++)
{
datFile.AddFromExisting(datFiles[i], true);
AddFromExisting(datFile, datFiles[i], true);
}
watch.Stop();
return datFiles.Select(d => d.Header).ToList();
}
/// <summary>
/// Add items from another DatFile to the existing DatFile
/// </summary>
/// <param name="addTo">DatFile to add to</param>
/// <param name="addFrom">DatFile to add from</param>
/// <param name="delete">If items should be deleted from the source DatFile</param>
private static void AddFromExisting(DatFile addTo, DatFile addFrom, bool delete = false)
{
// Get the list of keys from the DAT
var keys = addFrom.Items.Keys.ToList();
foreach (string key in keys)
{
// Add everything from the key to the internal DAT
addTo.Items.AddRange(key, addFrom.Items[key]);
// Now remove the key from the source DAT
if (delete)
addFrom.Items.Remove(key);
}
// Now remove the file dictionary from the source DAT
if (delete)
addFrom.Items = null;
}
}
}

View File

@@ -8,15 +8,24 @@ using SabreTools.Core;
using SabreTools.DatItems;
using SabreTools.FileTypes;
using SabreTools.IO;
using SabreTools.Logging;
// This file represents all methods related to populating a DatFile
// from a set of files and directories
namespace SabreTools.DatFiles
{
// TODO: See if any of the methods can be broken up a bit more neatly
// TODO: See if any of this can be more stateful given the inputted DatFile
public partial class DatTool
public class DirFromDat
{
#region Logging
/// <summary>
/// Logging object
/// </summary>
private static readonly Logger logger = new Logger();
#endregion
/// <summary>
/// Create a new Dat from a directory
/// </summary>

View File

@@ -32,7 +32,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);

View File

@@ -44,7 +44,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);

View File

@@ -34,7 +34,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);

View File

@@ -32,7 +32,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);

View File

@@ -36,7 +36,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);

View File

@@ -41,7 +41,7 @@ namespace SabreTools.DatFiles.Formats
/// 6331.sound-u8 32 BAD CRC(1d298cb0) SHA1(bb0bb62365402543e3154b9a77be9c75010e6abc) BAD_DUMP
/// 16v8h-blue.u24 279 NO GOOD DUMP KNOWN
/// </remarks>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);

View File

@@ -202,7 +202,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings

View File

@@ -144,7 +144,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings

View File

@@ -28,7 +28,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// There is no consistent way to parse a missfile...
throw new NotImplementedException();

View File

@@ -33,7 +33,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings
{

View File

@@ -47,7 +47,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings

View File

@@ -32,7 +32,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all intenral variables
IniReader ir = new IniReader(filename) { ValidateRows = false };

View File

@@ -34,7 +34,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all internal variables
StreamReader sr = new StreamReader(File.OpenRead(filename), new UTF8Encoding(false));

View File

@@ -31,7 +31,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings

View File

@@ -38,7 +38,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Open a file reader
Encoding enc = FileExtensions.GetEncoding(filename);

View File

@@ -102,7 +102,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="indexId">Index ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
public override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
{
// Prepare all internal variables
XmlReader xtr = XmlReader.Create(filename, new XmlReaderSettings

View File

@@ -11,8 +11,17 @@ using SabreTools.Logging;
// This file represents all methods related to verifying with a DatFile
namespace SabreTools.DatFiles
{
public partial class DatTool
public class Verification
{
#region Logging
/// <summary>
/// Logging object
/// </summary>
private static readonly Logger logger = new Logger();
#endregion
/// <summary>
/// Verify a DatFile against a set of depots, leaving only missing files
/// </summary>