116 lines
2.6 KiB
C#
116 lines
2.6 KiB
C#
using System.Text;
|
|
using MkvPropEditWrapper.Shared;
|
|
|
|
namespace MkvPropEditWrapper;
|
|
|
|
public class MkvEditCommand
|
|
{
|
|
public const string CommandName = "mkvpropedit";
|
|
|
|
public class SubCommand
|
|
{
|
|
private int? _trackNumber;
|
|
|
|
private string? _property;
|
|
private string? _value;
|
|
|
|
public SubCommand()
|
|
{
|
|
}
|
|
|
|
public SubCommand(int trackNumber, string property, string value)
|
|
{
|
|
_trackNumber = trackNumber;
|
|
_property = property;
|
|
_value = value;
|
|
}
|
|
|
|
public SubCommand WithNumber(int number)
|
|
{
|
|
_trackNumber = number;
|
|
|
|
return this;
|
|
}
|
|
|
|
public SubCommand WithProperty(string property)
|
|
{
|
|
_property = property;
|
|
|
|
return this;
|
|
}
|
|
|
|
public SubCommand WithValue(string value)
|
|
{
|
|
_value = value;
|
|
|
|
return this;
|
|
}
|
|
|
|
public void AppendSelf(StringBuilder builder)
|
|
{
|
|
builder.Append($"track:{_trackNumber} --set {_property}:{_value}");
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"track:{_trackNumber} --set {_property}:{_value}";
|
|
}
|
|
}
|
|
|
|
private string? _filePath;
|
|
private readonly IList<SubCommand> _subCommands;
|
|
|
|
public MkvEditCommand()
|
|
{
|
|
_subCommands = new List<SubCommand>();
|
|
}
|
|
|
|
public MkvEditCommand(string filePath)
|
|
{
|
|
_filePath = filePath;
|
|
|
|
_subCommands = new List<SubCommand>();
|
|
}
|
|
|
|
public MkvEditCommand WithFilePath(string filePath)
|
|
{
|
|
_filePath = filePath;
|
|
|
|
return this;
|
|
}
|
|
|
|
public MkvEditCommand AddSubCommand(SubCommand command)
|
|
{
|
|
_subCommands.Add(command);
|
|
|
|
return this;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
var builder = new StringBuilder();
|
|
|
|
builder.Append($"{CommandName} {_filePath}");
|
|
|
|
foreach (var subCommand in _subCommands)
|
|
{
|
|
builder.Append(" --edit ");
|
|
subCommand.AppendSelf(builder);
|
|
}
|
|
|
|
return builder.ToString();
|
|
}
|
|
}
|
|
|
|
public static class SubCommandExtensions
|
|
{
|
|
public static MkvEditCommand.SubCommand WithFlagDefault(this MkvEditCommand.SubCommand subCommand, bool flagDefault)
|
|
{
|
|
return subCommand.WithProperty(Flags.Default).WithValue(flagDefault.ToFlagBoolean());
|
|
}
|
|
|
|
public static MkvEditCommand.SubCommand WithFlagForced(this MkvEditCommand.SubCommand subCommand, bool flagForced)
|
|
{
|
|
return subCommand.WithProperty(Flags.Forced).WithValue(flagForced.ToFlagBoolean());
|
|
}
|
|
} |