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:
@@ -65,8 +65,8 @@ have a current entry in the DAT index.";
|
||||
DatFile df = DatFile.Create();
|
||||
foreach (string dir in onlyDirs)
|
||||
{
|
||||
DatTool.PopulateFromDir(df, dir, asFiles: TreatAsFile.NonArchive);
|
||||
DatTool.PopulateFromDir(df, dir, asFiles: TreatAsFile.All);
|
||||
DirFromDat.PopulateFromDir(df, dir, asFiles: TreatAsFile.NonArchive);
|
||||
DirFromDat.PopulateFromDir(df, dir, asFiles: TreatAsFile.All);
|
||||
}
|
||||
|
||||
// Create an empty Dat for files that need to be rebuilt
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace RombaSharp.Features
|
||||
DatFile datfile = DatFile.Create();
|
||||
datfile.Header.Name = string.IsNullOrWhiteSpace(name) ? "untitled" : name;
|
||||
datfile.Header.Description = description;
|
||||
DatTool.PopulateFromDir(datfile, source, asFiles: TreatAsFile.NonArchive);
|
||||
DirFromDat.PopulateFromDir(datfile, source, asFiles: TreatAsFile.NonArchive);
|
||||
DatTool.ApplyCleaning(datfile, new Cleaner() { ExcludeFields = Hash.DeepHashes.AsFields() });
|
||||
DatTool.Write(datfile, outdat);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ contents of any changed dats.";
|
||||
// First get a list of SHA-1's from the input DATs
|
||||
DatFile datroot = DatFile.Create();
|
||||
datroot.Header.Type = "SuperDAT";
|
||||
DatTool.PopulateFromDir(datroot, _dats, asFiles: TreatAsFile.NonArchive);
|
||||
DirFromDat.PopulateFromDir(datroot, _dats, asFiles: TreatAsFile.NonArchive);
|
||||
datroot.Items.BucketBy(Field.DatItem_SHA1, DedupeType.None);
|
||||
|
||||
// Create a List of dat hashes in the database (SHA-1)
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace RombaSharp.Features
|
||||
|
||||
// Now rescan the depot itself
|
||||
DatFile depot = DatFile.Create();
|
||||
DatTool.PopulateFromDir(depot, depotname, asFiles: TreatAsFile.NonArchive);
|
||||
DirFromDat.PopulateFromDir(depot, depotname, asFiles: TreatAsFile.NonArchive);
|
||||
depot.Items.BucketBy(Field.DatItem_SHA1, DedupeType.None);
|
||||
|
||||
// Set the base queries to use
|
||||
|
||||
@@ -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>
|
||||
@@ -153,7 +153,7 @@ Reset the internal state: reset();";
|
||||
// Assume there could be multiple
|
||||
foreach (string input in command.Arguments)
|
||||
{
|
||||
DatTool.PopulateFromDir(datFile, input);
|
||||
DirFromDat.PopulateFromDir(datFile, input);
|
||||
}
|
||||
|
||||
// TODO: We might not want to remove higher order hashes in the future
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace SabreTools.Features
|
||||
datdata.FillHeaderFromPath(basePath, noAutomaticDate);
|
||||
|
||||
// Now populate from the path
|
||||
bool success = DatTool.PopulateFromDir(
|
||||
bool success = DirFromDat.PopulateFromDir(
|
||||
datdata,
|
||||
basePath,
|
||||
asFiles,
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace SabreTools.Features
|
||||
// If we have the depot flag, respect it
|
||||
if (Header.InputDepot?.IsActive ?? false)
|
||||
{
|
||||
DatTool.VerifyDepot(datdata, Inputs);
|
||||
Verification.VerifyDepot(datdata, Inputs);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -84,10 +84,10 @@ namespace SabreTools.Features
|
||||
logger.User("Processing files:\n");
|
||||
foreach (string input in Inputs)
|
||||
{
|
||||
DatTool.PopulateFromDir(datdata, input, asFiles: asFiles, hashes: quickScan ? Hash.CRC : Hash.Standard);
|
||||
DirFromDat.PopulateFromDir(datdata, input, asFiles: asFiles, hashes: quickScan ? Hash.CRC : Hash.Standard);
|
||||
}
|
||||
|
||||
DatTool.VerifyGeneric(datdata, hashOnly);
|
||||
Verification.VerifyGeneric(datdata, hashOnly);
|
||||
}
|
||||
|
||||
// Now write out if there are any items left
|
||||
@@ -125,7 +125,7 @@ namespace SabreTools.Features
|
||||
// If we have the depot flag, respect it
|
||||
if (Header.InputDepot?.IsActive ?? false)
|
||||
{
|
||||
DatTool.VerifyDepot(datdata, Inputs);
|
||||
Verification.VerifyDepot(datdata, Inputs);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -133,10 +133,10 @@ namespace SabreTools.Features
|
||||
logger.User("Processing files:\n");
|
||||
foreach (string input in Inputs)
|
||||
{
|
||||
DatTool.PopulateFromDir(datdata, input, asFiles: asFiles, hashes: quickScan ? Hash.CRC : Hash.Standard);
|
||||
DirFromDat.PopulateFromDir(datdata, input, asFiles: asFiles, hashes: quickScan ? Hash.CRC : Hash.Standard);
|
||||
}
|
||||
|
||||
DatTool.VerifyGeneric(datdata, hashOnly);
|
||||
Verification.VerifyGeneric(datdata, hashOnly);
|
||||
}
|
||||
|
||||
// Now write out if there are any items left
|
||||
|
||||
Reference in New Issue
Block a user