mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-29 17:55:12 +01:00
Add check if category is compatible with output type.
This commit is contained in:
1 parent
fedd6fa02d
commit
9b0777d54d
2 files changed
+44
-3
No files matched your search
@@ -115,6 +115,15 @@ namespace FileConverter.ConversionJobs
|
||||
throw new Exception("The conversion preset must be valid.");
|
||||
}
|
||||
|
||||
string extension = System.IO.Path.GetExtension(inputFilePath);
|
||||
extension = extension.Substring(1, extension.Length - 1);
|
||||
string extensionCategory = PathHelpers.GetExtensionCategory(extension);
|
||||
if (!PathHelpers.IsOutputTypeCompatibleWithCategory(this.ConversionPreset.OutputType, extensionCategory))
|
||||
{
|
||||
this.ConvertionFailed("The input file type is not compatible with the output file type.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.initialInputPath = inputFilePath;
|
||||
this.InputFilePath = inputFilePath;
|
||||
this.OutputFilePath = this.ConversionPreset.GenerateOutputFilePath(inputFilePath);
|
||||
|
||||
@@ -72,16 +72,48 @@ namespace FileConverter
|
||||
case "ogg":
|
||||
case "wav":
|
||||
case "wma":
|
||||
return "Audio";
|
||||
return InputCategoryNames.Audio;
|
||||
|
||||
case "avi":
|
||||
case "flv":
|
||||
case "mp4":
|
||||
case "mkv":
|
||||
return "Video";
|
||||
return InputCategoryNames.Video;
|
||||
}
|
||||
|
||||
return "Misc";
|
||||
return InputCategoryNames.Misc;
|
||||
}
|
||||
|
||||
public static bool IsOutputTypeCompatibleWithCategory(OutputType outputType, string category)
|
||||
{
|
||||
if (category == InputCategoryNames.Misc)
|
||||
{
|
||||
// Misc category contains unsorted input extensions, so we consider that they are compatible to be tolerant.
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (outputType)
|
||||
{
|
||||
case OutputType.Aac:
|
||||
case OutputType.Flac:
|
||||
case OutputType.Mp3:
|
||||
case OutputType.Ogg:
|
||||
case OutputType.Wav:
|
||||
return category == InputCategoryNames.Audio || category == InputCategoryNames.Video;
|
||||
|
||||
case OutputType.Mkv:
|
||||
return category == InputCategoryNames.Video;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InputCategoryNames
|
||||
{
|
||||
public const string Audio = "Audio";
|
||||
public const string Video = "Video";
|
||||
public const string Misc = "Misc";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user