2020-08-01 13:25:32 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
2020-12-08 13:23:59 -08:00
|
|
|
|
using SabreTools.Core;
|
2020-12-08 16:37:08 -08:00
|
|
|
|
using SabreTools.Core.Tools;
|
|
|
|
|
|
using SabreTools.DatFiles;
|
2020-12-08 13:48:57 -08:00
|
|
|
|
using SabreTools.Filtering;
|
2020-12-07 13:57:26 -08:00
|
|
|
|
using SabreTools.Help;
|
2020-12-07 15:08:57 -08:00
|
|
|
|
using SabreTools.IO;
|
2020-08-01 13:25:32 -07:00
|
|
|
|
|
|
|
|
|
|
namespace RombaSharp.Features
|
|
|
|
|
|
{
|
|
|
|
|
|
internal class Dir2Dat : BaseFeature
|
|
|
|
|
|
{
|
|
|
|
|
|
public const string Value = "Dir2Dat";
|
|
|
|
|
|
|
|
|
|
|
|
public Dir2Dat()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = Value;
|
|
|
|
|
|
Flags = new List<string>() { "dir2dat" };
|
|
|
|
|
|
Description = "Creates a DAT file for the specified input directory and saves it to the -out filename.";
|
2020-12-07 13:57:26 -08:00
|
|
|
|
_featureType = ParameterType.Flag;
|
2020-08-01 13:25:32 -07:00
|
|
|
|
LongDescription = "Creates a DAT file for the specified input directory and saves it to the -out filename.";
|
|
|
|
|
|
Features = new Dictionary<string, Feature>();
|
|
|
|
|
|
|
|
|
|
|
|
AddFeature(OutStringInput);
|
|
|
|
|
|
AddFeature(SourceStringInput);
|
|
|
|
|
|
AddFeature(NameStringInput); // Defaults to "untitled"
|
|
|
|
|
|
AddFeature(DescriptionStringInput);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void ProcessFeatures(Dictionary<string, Feature> features)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.ProcessFeatures(features);
|
|
|
|
|
|
|
|
|
|
|
|
// Get feature flags
|
|
|
|
|
|
string name = GetString(features, NameStringValue);
|
|
|
|
|
|
string description = GetString(features, DescriptionStringValue);
|
|
|
|
|
|
string source = GetString(features, SourceStringValue);
|
|
|
|
|
|
string outdat = GetString(features, OutStringValue);
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure the output directory
|
|
|
|
|
|
DirectoryExtensions.Ensure(outdat, create: true);
|
|
|
|
|
|
|
|
|
|
|
|
// Check that all required directories exist
|
|
|
|
|
|
if (!Directory.Exists(source))
|
|
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.Error($"File '{source}' does not exist!");
|
2020-08-01 13:25:32 -07:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-02 13:34:35 -07:00
|
|
|
|
// Create and write the encapsulating datfile
|
2020-08-01 13:25:32 -07:00
|
|
|
|
DatFile datfile = DatFile.Create();
|
|
|
|
|
|
datfile.Header.Name = string.IsNullOrWhiteSpace(name) ? "untitled" : name;
|
|
|
|
|
|
datfile.Header.Description = description;
|
2020-12-10 15:42:39 -08:00
|
|
|
|
DatFromDir.PopulateFromDir(datfile, source, asFiles: TreatAsFile.NonArchive);
|
2020-12-10 14:11:35 -08:00
|
|
|
|
Modification.ApplyCleaning(datfile, new Cleaner() { ExcludeFields = Hash.DeepHashes.AsFields() });
|
2020-12-10 14:03:07 -08:00
|
|
|
|
Writer.Write(datfile, outdat);
|
2020-08-01 13:25:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|