From ded61b9f9946eb6b90e8acdb0b46fa5ae8f6898f Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 16 Jun 2014 02:07:23 +0100 Subject: [PATCH] Moved image format detection out of "analyze" verb. --- DiscImageChef/Commands/Analyze.cs | 44 +++---------- DiscImageChef/DiscImageChef.csproj | 1 + .../ImagePlugins/DetectImageFormat.cs | 61 +++++++++++++++++++ 3 files changed, 70 insertions(+), 36 deletions(-) create mode 100644 DiscImageChef/ImagePlugins/DetectImageFormat.cs diff --git a/DiscImageChef/Commands/Analyze.cs b/DiscImageChef/Commands/Analyze.cs index 5ff9c4491..96f726f72 100644 --- a/DiscImageChef/Commands/Analyze.cs +++ b/DiscImageChef/Commands/Analyze.cs @@ -36,44 +36,18 @@ namespace DiscImageChef.Commands try { - _imageFormat = null; + _imageFormat = ImageFormat.Detect(options.InputFile); - // Check all but RAW plugin - foreach (ImagePlugin _imageplugin in plugins.ImagePluginsList.Values) + if(_imageFormat == null) { - if(_imageplugin.PluginUUID != new Guid("12345678-AAAA-BBBB-CCCC-123456789000")) - { - if (_imageplugin.IdentifyImage(options.InputFile)) - { - _imageFormat = _imageplugin; - Console.WriteLine("Image format identified by {0}.", _imageplugin.Name); - break; - } - } + Console.WriteLine("Image format not identified, not proceeding with analysis."); } - - // Check only RAW plugin - if (_imageFormat == null) + else { - foreach (ImagePlugin _imageplugin in plugins.ImagePluginsList.Values) - { - if(_imageplugin.PluginUUID == new Guid("12345678-AAAA-BBBB-CCCC-123456789000")) - { - if (_imageplugin.IdentifyImage(options.InputFile)) - { - _imageFormat = _imageplugin; - Console.WriteLine("Image format identified by {0}.", _imageplugin.Name); - break; - } - } - } - } - - // Still not recognized - if (_imageFormat == null) - { - Console.WriteLine("Image format not identified, not proceeding."); - return; + if(MainClass.isVerbose) + Console.WriteLine("Image format identified by {0} ({1}).", _imageFormat.Name, _imageFormat.PluginUUID); + else + Console.WriteLine("Image format identified by {0}.", _imageFormat.Name); } try @@ -100,8 +74,6 @@ namespace DiscImageChef.Commands return; } - Console.WriteLine("Image identified as {0}.", _imageFormat.GetImageFormat()); - if (options.SearchForPartitions) { List partitions = new List(); diff --git a/DiscImageChef/DiscImageChef.csproj b/DiscImageChef/DiscImageChef.csproj index c06cc93ee..96a62a798 100644 --- a/DiscImageChef/DiscImageChef.csproj +++ b/DiscImageChef/DiscImageChef.csproj @@ -84,6 +84,7 @@ + diff --git a/DiscImageChef/ImagePlugins/DetectImageFormat.cs b/DiscImageChef/ImagePlugins/DetectImageFormat.cs new file mode 100644 index 000000000..8c71b9d10 --- /dev/null +++ b/DiscImageChef/ImagePlugins/DetectImageFormat.cs @@ -0,0 +1,61 @@ +using System; + +namespace DiscImageChef.ImagePlugins +{ + public static class ImageFormat + { + public static ImagePlugin Detect(string imagePath) + { + try + { + ImagePlugin _imageFormat; + PluginBase plugins = new PluginBase(); + plugins.RegisterAllPlugins(); + + _imageFormat = null; + + // Check all but RAW plugin + foreach (ImagePlugin _imageplugin in plugins.ImagePluginsList.Values) + { + if(_imageplugin.PluginUUID != new Guid("12345678-AAAA-BBBB-CCCC-123456789000")) + { + if (_imageplugin.IdentifyImage(imagePath)) + { + _imageFormat = _imageplugin; + break; + } + } + } + + // Check only RAW plugin + if (_imageFormat == null) + { + foreach (ImagePlugin _imageplugin in plugins.ImagePluginsList.Values) + { + if(_imageplugin.PluginUUID == new Guid("12345678-AAAA-BBBB-CCCC-123456789000")) + { + if (_imageplugin.IdentifyImage(imagePath)) + { + _imageFormat = _imageplugin; + break; + } + } + } + } + + // Still not recognized + if (_imageFormat == null) + { + return null; + } + + return _imageFormat; + } + catch + { + return null; + } + } + } +} +