Files
SabreTools/SabreTools/Features/DatFromDir.cs

110 lines
4.1 KiB
C#
Raw Normal View History

2020-07-31 23:17:12 -07:00
using System;
using System.Collections.Generic;
using System.IO;
using SabreTools.Library.DatFiles;
using SabreTools.Library.Help;
namespace SabreTools.Features
{
internal class DatFromDir : BaseFeature
{
public const string Value = "DATFromDir";
public DatFromDir()
{
Name = Value;
Flags = new List<string>() { "-d", "--d2d", "--dfd" };
Description = "Create DAT(s) from an input directory";
_featureType = FeatureType.Flag;
LongDescription = "Create a DAT file from an input directory or set of files. By default, this will output a DAT named based on the input directory and the current date. It will also treat all archives as possible games and add all three hashes (CRC, MD5, SHA-1) for each file.";
Features = new Dictionary<string, Feature>();
// Hash Features
AddFeature(SkipMd5Flag);
#if NET_FRAMEWORK
AddFeature(SkipRipeMd160Flag);
#endif
AddFeature(SkipSha1Flag);
AddFeature(SkipSha256Flag);
AddFeature(SkipSha384Flag);
AddFeature(SkipSha512Flag);
AddFeature(NoAutomaticDateFlag);
AddFeature(AaruFormatsAsFilesFlag);
2020-07-31 23:17:12 -07:00
AddFeature(ArchivesAsFilesFlag);
AddFeature(ChdsAsFilesFlag);
2020-07-31 23:17:12 -07:00
AddFeature(OutputTypeListInput);
this[OutputTypeListInput].AddFeature(DeprecatedFlag);
AddFeature(RombaFlag);
2020-08-18 23:39:13 -07:00
this[RombaFlag].AddFeature(RombaDepthInt32Input);
2020-07-31 23:17:12 -07:00
AddFeature(SkipArchivesFlag);
AddFeature(SkipFilesFlag);
AddHeaderFeatures();
AddFeature(AddBlankFilesFlag);
AddFeature(AddDateFlag);
AddFeature(CopyFilesFlag);
AddFeature(HeaderStringInput);
2020-08-21 10:38:42 -07:00
AddFeature(ExtraIniListInput);
2020-07-31 23:17:12 -07:00
AddFilteringFeatures();
AddFeature(TempStringInput);
AddFeature(OutputDirStringInput);
AddFeature(ThreadsInt32Input);
}
public override void ProcessFeatures(Dictionary<string, Feature> features)
{
base.ProcessFeatures(features);
// Get feature flags
bool addBlankFiles = GetBoolean(features, AddBlankFilesValue);
bool addFileDates = GetBoolean(features, AddDateValue);
2020-08-02 13:23:47 -07:00
TreatAsFiles asFiles = GetTreatAsFiles(features);
2020-07-31 23:17:12 -07:00
bool copyFiles = GetBoolean(features, CopyFilesValue);
bool noAutomaticDate = GetBoolean(features, NoAutomaticDateValue);
var omitFromScan = GetOmitFromScan(features);
var skipFileType = GetSkipFileType(features);
// Create a new DATFromDir object and process the inputs
DatFile basedat = DatFile.Create(Header);
basedat.Header.Date = DateTime.Now.ToString("yyyy-MM-dd");
// For each input directory, create a DAT
foreach (string path in Inputs)
{
if (Directory.Exists(path) || File.Exists(path))
{
// Clone the base Dat for information
DatFile datdata = DatFile.Create(basedat.Header);
2020-08-27 20:56:50 -07:00
// Get the base path and fill the header, if needed
2020-07-31 23:17:12 -07:00
string basePath = Path.GetFullPath(path);
2020-08-27 20:56:50 -07:00
datdata.FillHeaderFromPath(basePath, noAutomaticDate);
// Now populate from the path
2020-07-31 23:17:12 -07:00
bool success = datdata.PopulateFromDir(
basePath,
omitFromScan,
2020-08-02 13:23:47 -07:00
asFiles,
2020-07-31 23:17:12 -07:00
skipFileType,
addBlankFiles,
addFileDates,
2020-08-27 20:56:50 -07:00
copyFiles);
2020-07-31 23:17:12 -07:00
if (success)
{
2020-08-27 20:56:50 -07:00
datdata.ApplyExtras(Extras);
datdata.ApplyFilter(Filter, false);
2020-07-31 23:17:12 -07:00
datdata.Write(OutputDir);
}
else
{
Console.WriteLine();
OutputRecursive(0);
}
}
}
}
}
}