public string FormatOutputPath(string formatString)
{
if (this.Show == null || this.Episode == null || this.InputFile == null)
{
return string.Empty;
}
// Replace the extension and folder name. (Format codes with no parameters)
formatString = formatString.Replace("{Ext}", this.InputFile.Extension);
formatString = formatString.Replace("{FName}", this.Show.FolderName);
// Identify the other format codes and their parameters.
var regExp = new Regex(@"{([a-zA-Z]+)\(([^\)}]+)\)}");
// Replace the matches with the appropriate strings.
formatString = regExp.Replace(formatString, this.ProcessMatch);
// Replace : with .
formatString = formatString.Replace(':', '.');
// Get the invalid characters for a file name, not including the DirectorySeparatorChar.
IEnumerable<char> invalidChars =
StringExtensions.InvalidFilenameChars.Where(x => !x.Equals(Path.DirectorySeparatorChar));
// Remove any characters that can't be in a filename from the formatString.
return invalidChars.Aggregate(
formatString, (current, ch) => current.Replace(ch.ToString(CultureInfo.InvariantCulture), string.Empty));
}