FFMpegCore/FFMpegCore/FFMpeg/Arguments/OutputArgument.cs
Malte Rosenbjerg c3b5cd997e Cleanup
Former-commit-id: 72366d573a
2020-05-09 17:53:03 +02:00

38 lines
1.1 KiB
C#

using System;
using System.IO;
using FFMpegCore.Exceptions;
namespace FFMpegCore.Arguments
{
/// <summary>
/// Represents output parameter
/// </summary>
public class OutputArgument : IOutputArgument
{
public readonly string Path;
public readonly bool Overwrite;
public OutputArgument(string path, bool overwrite = false)
{
Path = path;
Overwrite = overwrite;
}
public void Pre()
{
if (!Overwrite && File.Exists(Path))
throw new FFMpegException(FFMpegExceptionType.File, "Output file already exists and overwrite is disabled");
}
public void Post()
{
if (!File.Exists(Path))
throw new FFMpegException(FFMpegExceptionType.File, "Output file was not created");
}
public OutputArgument(FileInfo value) : this(value.FullName) { }
public OutputArgument(Uri value) : this(value.AbsolutePath) { }
public string Text => $"\"{Path}\"{(Overwrite ? " -y" : string.Empty)}";
}
}