2018-01-28 16:05:54 +00:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : ImageInfo.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Verbs.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Implements the 'image-info' verb.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
|
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
2018-01-28 16:05:54 +00:00
|
|
|
|
using DiscImageChef.Console;
|
|
|
|
|
|
using DiscImageChef.Core;
|
|
|
|
|
|
using DiscImageChef.Filters;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
static class ImageInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
internal static void GetImageInfo(ImageInfoOptions options)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--debug={0}", options.Debug);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--verbose={0}", options.Verbose);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Analyze command", "--input={0}", options.InputFile);
|
|
|
|
|
|
|
|
|
|
|
|
FiltersList filtersList = new FiltersList();
|
|
|
|
|
|
IFilter inputFilter = filtersList.GetFilter(options.InputFile);
|
|
|
|
|
|
|
|
|
|
|
|
if(inputFilter == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Cannot open specified file.");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
IMediaImage imageFormat = ImageFormat.Detect(inputFilter);
|
|
|
|
|
|
|
|
|
|
|
|
if(imageFormat == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.WriteLine("Image format not identified.");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLine("Image format identified by {0} ({1}).", imageFormat.Name, imageFormat.Id);
|
|
|
|
|
|
DicConsole.WriteLine();
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!imageFormat.Open(inputFilter))
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.WriteLine("Unable to open image format");
|
|
|
|
|
|
DicConsole.WriteLine("No error given");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Core.ImageInfo.PrintImageInfo(imageFormat);
|
|
|
|
|
|
|
|
|
|
|
|
Core.Statistics.AddMediaFormat(imageFormat.Format);
|
|
|
|
|
|
Core.Statistics.AddMedia(imageFormat.Info.MediaType, false);
|
|
|
|
|
|
Core.Statistics.AddFilter(inputFilter.Name);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Unable to open image format");
|
|
|
|
|
|
DicConsole.ErrorWriteLine("Error: {0}", ex.Message);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Image-info command", "Stack trace: {0}", ex.StackTrace);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
DicConsole.ErrorWriteLine($"Error reading file: {ex.Message}");
|
|
|
|
|
|
DicConsole.DebugWriteLine("Image-info command", ex.StackTrace);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Core.Statistics.AddCommand("image-info");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|