mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
DFD and Verification to actual classes
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user