Files
SabreTools/RombaSharp/Features/Build.cs

85 lines
3.1 KiB
C#
Raw Normal View History

2020-08-01 13:25:32 -07:00
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.DatFiles;
2020-12-10 23:24:09 -08:00
using SabreTools.DatTools;
using SabreTools.FileTypes;
2020-12-07 13:57:26 -08:00
using SabreTools.Help;
2024-04-24 13:45:38 -04:00
using SabreTools.IO.Extensions;
2020-08-01 13:25:32 -07:00
namespace RombaSharp.Features
{
internal class Build : BaseFeature
{
public const string Value = "Build";
public Build()
{
Name = Value;
2024-07-18 01:06:40 -04:00
Flags.AddRange(["build"]);
2020-08-01 13:25:32 -07:00
Description = "For each specified DAT file it creates the torrentzip files.";
2020-12-07 13:57:26 -08:00
_featureType = ParameterType.Flag;
2020-08-01 13:25:32 -07:00
LongDescription = @"For each specified DAT file it creates the torrentzip files in the specified
output dir. The files will be placed in the specified location using a folder
structure according to the original DAT master directory tree structure.";
2021-02-03 11:10:19 -08:00
// Common Features
AddCommonFeatures();
2020-08-01 13:25:32 -07:00
AddFeature(OutStringInput);
AddFeature(FixdatOnlyFlag);
AddFeature(CopyFlag);
AddFeature(WorkersInt32Input);
AddFeature(SubworkersInt32Input);
}
public override bool ProcessFeatures(Dictionary<string, Feature?> features)
2020-08-01 13:25:32 -07:00
{
2021-03-19 20:52:11 -07:00
// If the base fails, just fail out
if (!base.ProcessFeatures(features))
return false;
2020-08-01 13:25:32 -07:00
// Get feature flags
bool copy = GetBoolean(features, CopyValue);
string? outdat = GetString(features, OutStringValue);
2020-08-01 13:25:32 -07:00
// Verify the filenames
Dictionary<string, string> foundDats = GetValidDats(Inputs);
// Ensure the output directory is set
if (string.IsNullOrWhiteSpace(outdat))
outdat = "out";
// Now that we have the dictionary, we can loop through and output to a new folder for each
foreach (string key in foundDats.Keys)
{
// Get the DAT file associated with the key
DatFile datFile = Parser.CreateAndParse(Path.Combine(_dats!, foundDats[key]));
2020-08-01 13:25:32 -07:00
2020-08-20 11:23:48 -07:00
// Set the depot values
2024-03-10 22:08:08 -04:00
datFile.Header.SetFieldValue<DepotInformation?>(DatHeader.InputDepotKey, new DepotInformation(true, 4));
datFile.Header.SetFieldValue<DepotInformation?>(DatHeader.OutputDepotKey, new DepotInformation(true, 4));
2020-08-20 11:23:48 -07:00
2020-08-01 13:25:32 -07:00
// Create the new output directory if it doesn't exist
string outputFolder = Path.Combine(outdat, Path.GetFileNameWithoutExtension(foundDats[key]));
2020-12-10 22:16:53 -08:00
outputFolder.Ensure(create: true);
2020-08-01 13:25:32 -07:00
// Get all online depots
List<string> onlineDepots = _depots
.Where(d => d.Value.Item2)
.Select(d => d.Key)
.ToList();
2020-08-01 13:25:32 -07:00
// Now scan all of those depots and rebuild
2020-12-10 14:31:00 -08:00
Rebuilder.RebuildDepot(
2020-12-10 11:07:36 -08:00
datFile,
2020-08-02 13:44:45 -07:00
onlineDepots,
outDir: outputFolder,
2020-12-10 11:58:46 -08:00
outputFormat: copy ? OutputFormat.TorrentGzipRomba : OutputFormat.TorrentZip);
2020-08-01 13:25:32 -07:00
}
2021-03-19 20:52:11 -07:00
return true;
2020-08-01 13:25:32 -07:00
}
}
}