Return specific error codes from command execution.

This commit is contained in:
2019-01-05 19:50:56 +00:00
parent 104bc55c5e
commit 372f9f68ac
28 changed files with 351 additions and 204 deletions

View File

@@ -50,6 +50,7 @@
<Link>Metadata/cicm.cs</Link>
</Compile>
<Compile Include="Enums\DeviceType.cs" />
<Compile Include="Enums\ErrorNumber.cs" />
<Compile Include="Enums\Images.cs" />
<Compile Include="Exceptions\Images.cs" />
<Compile Include="Extents\ExtentsByte.cs" />

View File

@@ -0,0 +1,115 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : ErrorNumber.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Common types.
//
// --[ Description ] ----------------------------------------------------------
//
// Defines enumerations of error numbers.
//
// --[ License ] --------------------------------------------------------------
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
namespace DiscImageChef.CommonTypes.Enums
{
/// <summary>
/// Enumerates error codes. Positive for warnings or informative codes, negative for errors.
/// </summary>
public enum ErrorNumber
{
/// <summary>No error</summary>
NoError = 0,
/// <summary>User requested help to be shown</summary>
HelpRequested = 1,
/// <summary>Command found nothing</summary>
NothingFound = 2,
/// <summary>Media has been already dumped completely</summary>
AlreadyDumped = 3,
/// <summary>Image and its sectors cannot be verified</summary>
NotVerificable = 4,
/// <summary>There are bad sectors and image cannot be verified</summary>
BadSectorsImageNotVerified = 5,
/// <summary>All sectors are good and image cannot be verified</summary>
CorrectSectorsImageNotVerified = 6,
/// <summary>Image is bad and sectors cannot be verified</summary>
BadImageSectorsNotVerified = 7,
/// <summary>Image is bad and there are bad sectors</summary>
BadImageBadSectors = 8,
/// <summary>All sectors are good and image is bad</summary>
CorrectSectorsBadImage = 9,
/// <summary>Image is good and sectors cannot be verified</summary>
CorrectImageSectorsNotVerified = 10,
/// <summary>Image is good and there are bad sectors</summary>
CorrectImageBadSectors = 11,
/// <summary>Exception has been raised</summary>
UnexpectedException = -1,
/// <summary>The number of arguments is not as expected</summary>
UnexpectedArgumentCount = -2,
/// <summary>A required argument is not present</summary>
MissingArgument = -3,
/// <summary>A specified argument contains an invalid value</summary>
InvalidArgument = -4,
/// <summary>The specified file cannot be found</summary>
FileNotFound = -5,
/// <summary>The specified file cannot be opened</summary>
CannotOpenFile = -6,
/// <summary>The specified encoding cannot be found</summary>
EncodingUnknown = -7,
/// <summary>The image format has not been recognized</summary>
UnrecognizedFormat = -8,
/// <summary>The image format failed to open</summary>
CannotOpenFormat = -9,
/// <summary>The specified metadata sidecar does not have the correct format</summary>
InvalidSidecar = -10,
/// <summary>The specified resume map does not have the correct format</summary>
InvalidResume = -11,
/// <summary>The specified destination file/folder already exists</summary>
DestinationExists = -12,
/// <summary>The specified image format cannot be found</summary>
FormatNotFound = -13,
/// <summary>More than one format found for the specified search criteria</summary>
TooManyFormats = -14,
/// <summary>The specified format does not support the specified media</summary>
UnsupportedMedia = -15,
/// <summary>Data will be lost writing the specified format</summary>
DataWillBeLost = -16,
/// <summary>Cannot create destination format</summary>
CannotCreateFormat = -17,
/// <summary>Error writing data</summary>
WriteError = -18,
/// <summary>Argument expected a directory, but found a file</summary>
ExpectedDirectory = -19,
/// <summary>Argument expected a file, but found a directory</summary>
ExpectedFile = -20,
/// <summary>Cannot open device</summary>
CannotOpenDevice = -21,
/// <summary>The specified operation requires administrative privileges</summary>
NotEnoughPermissions = -22
}
}

View File

@@ -34,6 +34,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using DiscImageChef.Core;
@@ -45,9 +46,9 @@ namespace DiscImageChef.Commands
{
string encodingName;
string inputFile;
bool searchForFilesystems = true;
bool searchForPartitions = true;
bool showHelp;
bool searchForFilesystems = true;
bool searchForPartitions = true;
bool showHelp;
public AnalyzeCommand() : base("analyze",
"Analyzes a disc image and searches for partitions and/or filesystems.")
@@ -74,7 +75,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -84,13 +85,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
inputFile = extra[0];
@@ -108,7 +109,7 @@ namespace DiscImageChef.Commands
if(inputFilter == null)
{
DicConsole.ErrorWriteLine("Cannot open specified file.");
return 2;
return (int)ErrorNumber.CannotOpenFile;
}
Encoding encoding = null;
@@ -122,7 +123,7 @@ namespace DiscImageChef.Commands
catch(ArgumentException)
{
DicConsole.ErrorWriteLine("Specified encoding is not supported.");
return 5;
return (int)ErrorNumber.EncodingUnknown;
}
PluginBase plugins = GetPluginBase.Instance;
@@ -136,7 +137,7 @@ namespace DiscImageChef.Commands
if(imageFormat == null)
{
DicConsole.WriteLine("Image format not identified, not proceeding with analysis.");
return 3;
return (int)ErrorNumber.UnrecognizedFormat;
}
if(MainClass.Verbose)
@@ -151,7 +152,7 @@ namespace DiscImageChef.Commands
{
DicConsole.WriteLine("Unable to open image format");
DicConsole.WriteLine("No error given");
return 4;
return (int)ErrorNumber.CannotOpenFormat;
}
if(MainClass.Verbose)
@@ -169,7 +170,7 @@ namespace DiscImageChef.Commands
DicConsole.ErrorWriteLine("Unable to open image format");
DicConsole.ErrorWriteLine("Error: {0}", ex.Message);
DicConsole.DebugWriteLine("Analyze command", "Stack trace: {0}", ex.StackTrace);
return -1;
return (int)ErrorNumber.CannotOpenFormat;
}
List<string> idPlugins;
@@ -186,7 +187,7 @@ namespace DiscImageChef.Commands
if(!searchForFilesystems)
{
DicConsole.WriteLine("No partitions founds, not searching for filesystems");
return -2;
return (int)ErrorNumber.NothingFound;
}
checkraw = true;
@@ -283,10 +284,11 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine($"Error reading file: {ex.Message}");
DicConsole.DebugWriteLine("Analyze command", ex.StackTrace);
return (int)ErrorNumber.UnexpectedException;
}
Statistics.AddCommand("analyze");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -31,6 +31,7 @@
// ****************************************************************************/
using System.Collections.Generic;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.Console;
using DiscImageChef.Core;
using Mono.Options;
@@ -66,7 +67,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -76,7 +77,7 @@ namespace DiscImageChef.Commands
if(extra.Count != 0)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
DicConsole.DebugWriteLine("Benchmark command", "--debug={0}", MainClass.Debug);
@@ -109,7 +110,7 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine("Min memory used is {0} bytes", results.MinMemory);
Statistics.AddCommand("benchmark");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -33,6 +33,7 @@
using System;
using System.Collections.Generic;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.CommonTypes.Structs;
using DiscImageChef.Console;
@@ -101,7 +102,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -111,13 +112,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
inputFile = extra[0];
@@ -147,7 +148,7 @@ namespace DiscImageChef.Commands
if(inputFilter == null)
{
DicConsole.ErrorWriteLine("Cannot open specified file.");
return 1;
return (int)ErrorNumber.CannotOpenFile;
}
IMediaImage inputFormat = ImageFormat.Detect(inputFilter);
@@ -155,7 +156,7 @@ namespace DiscImageChef.Commands
if(inputFormat == null)
{
DicConsole.ErrorWriteLine("Unable to recognize image format, not checksumming");
return 2;
return (int)ErrorNumber.UnrecognizedFormat;
}
inputFormat.Open(inputFilter);
@@ -305,7 +306,7 @@ namespace DiscImageChef.Commands
}
Statistics.AddCommand("checksum");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -71,7 +71,7 @@ namespace DiscImageChef.Commands
if(ShowHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -81,13 +81,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 2)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count <= 1)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
InputFile1 = extra[0];
@@ -106,13 +106,13 @@ namespace DiscImageChef.Commands
if(inputFilter1 == null)
{
DicConsole.ErrorWriteLine("Cannot open input file 1");
return 1;
return (int)ErrorNumber.CannotOpenFile;
}
if(inputFilter2 == null)
{
DicConsole.ErrorWriteLine("Cannot open input file 2");
return 2;
return (int)ErrorNumber.CannotOpenFile;
}
IMediaImage input1Format = ImageFormat.Detect(inputFilter1);
@@ -121,7 +121,7 @@ namespace DiscImageChef.Commands
if(input1Format == null)
{
DicConsole.ErrorWriteLine("Input file 1 format not identified, not proceeding with comparison.");
return 3;
return (int)ErrorNumber.UnrecognizedFormat;
}
if(MainClass.Verbose)
@@ -132,7 +132,7 @@ namespace DiscImageChef.Commands
if(input2Format == null)
{
DicConsole.ErrorWriteLine("Input file 2 format not identified, not proceeding with comparison.");
return 4;
return (int)ErrorNumber.UnrecognizedFormat;
}
if(MainClass.Verbose)
@@ -399,7 +399,7 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine(sb.ToString());
Statistics.AddCommand("compare");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -32,6 +32,7 @@
using System;
using System.Collections.Generic;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.Console;
using DiscImageChef.Settings;
using Mono.Options;
@@ -65,7 +66,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -75,13 +76,7 @@ namespace DiscImageChef.Commands
if(extra.Count != 0)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(gdprChange)
@@ -272,7 +267,7 @@ namespace DiscImageChef.Commands
Settings.Settings.Current.GdprCompliance = DicSettings.GdprLevel;
Settings.Settings.SaveSettings();
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -156,7 +156,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -166,13 +166,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 2)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count <= 1)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
inputFile = extra[0];
@@ -211,7 +211,7 @@ namespace DiscImageChef.Commands
if(count == 0)
{
DicConsole.ErrorWriteLine("Need to specify more than 0 sectors to copy at once");
return 1;
return (int)ErrorNumber.InvalidArgument;
}
Resume resume = null;
@@ -229,12 +229,12 @@ namespace DiscImageChef.Commands
catch
{
DicConsole.ErrorWriteLine("Incorrect metadata sidecar file, not continuing...");
return 2;
return (int)ErrorNumber.InvalidSidecar;
}
else
{
DicConsole.ErrorWriteLine("Could not find metadata sidecar, not continuing...");
return 3;
return (int)ErrorNumber.FileNotFound;
}
xs = new XmlSerializer(typeof(Resume));
@@ -249,12 +249,12 @@ namespace DiscImageChef.Commands
catch
{
DicConsole.ErrorWriteLine("Incorrect resume file, not continuing...");
return 4;
return (int)ErrorNumber.InvalidResume;
}
else
{
DicConsole.ErrorWriteLine("Could not find resume file, not continuing...");
return 5;
return (int)ErrorNumber.FileNotFound;
}
FiltersList filtersList = new FiltersList();
@@ -263,13 +263,13 @@ namespace DiscImageChef.Commands
if(inputFilter == null)
{
DicConsole.ErrorWriteLine("Cannot open specified file.");
return 6;
return (int)ErrorNumber.CannotOpenFile;
}
if(File.Exists(outputFile))
{
DicConsole.ErrorWriteLine("Output file already exists, not continuing.");
return 8;
return (int)ErrorNumber.DestinationExists;
}
PluginBase plugins = GetPluginBase.Instance;
@@ -278,7 +278,7 @@ namespace DiscImageChef.Commands
if(inputFormat == null)
{
DicConsole.WriteLine("Input image format not identified, not proceeding with conversion.");
return 7;
return (int)ErrorNumber.UnrecognizedFormat;
}
if(MainClass.Verbose)
@@ -292,7 +292,7 @@ namespace DiscImageChef.Commands
{
DicConsole.WriteLine("Unable to open image format");
DicConsole.WriteLine("No error given");
return 9;
return (int)ErrorNumber.CannotOpenFormat;
}
DicConsole.DebugWriteLine("Convert-image command", "Correctly opened image file.");
@@ -311,7 +311,7 @@ namespace DiscImageChef.Commands
DicConsole.ErrorWriteLine("Unable to open image format");
DicConsole.ErrorWriteLine("Error: {0}", ex.Message);
DicConsole.DebugWriteLine("Convert-image command", "Stack trace: {0}", ex.StackTrace);
return 10;
return (int)ErrorNumber.CannotOpenFormat;
}
List<IWritableImage> candidates = new List<IWritableImage>();
@@ -333,13 +333,13 @@ namespace DiscImageChef.Commands
if(candidates.Count == 0)
{
DicConsole.WriteLine("No plugin supports requested extension.");
return 11;
return (int)ErrorNumber.FormatNotFound;
}
if(candidates.Count > 1)
{
DicConsole.WriteLine("More than one plugin supports requested extension.");
return 12;
return (int)ErrorNumber.TooManyFormats;
}
IWritableImage outputFormat = candidates[0];
@@ -351,7 +351,7 @@ namespace DiscImageChef.Commands
if(!outputFormat.SupportedMediaTypes.Contains(inputFormat.Info.MediaType))
{
DicConsole.ErrorWriteLine("Output format does not support media type, cannot continue...");
return 13;
return (int)ErrorNumber.UnsupportedMedia;
}
foreach(MediaTagType mediaTag in inputFormat.Info.ReadableMediaTags)
@@ -360,7 +360,7 @@ namespace DiscImageChef.Commands
DicConsole.ErrorWriteLine("Converting image will lose media tag {0}, not continuing...", mediaTag);
DicConsole.ErrorWriteLine("If you don't care, use force option.");
return 14;
return (int)ErrorNumber.DataWillBeLost;
}
bool useLong = inputFormat.Info.ReadableSectorTags.Count != 0;
@@ -379,14 +379,14 @@ namespace DiscImageChef.Commands
DicConsole.ErrorWriteLine("Converting image will lose sector tag {0}, not continuing...", sectorTag);
DicConsole
.ErrorWriteLine("If you don't care, use force option. This will skip all sector tags converting only user data.");
return 15;
return (int)ErrorNumber.DataWillBeLost;
}
if(!outputFormat.Create(outputFile, inputFormat.Info.MediaType, parsedOptions, inputFormat.Info.Sectors,
inputFormat.Info.SectorSize))
{
DicConsole.ErrorWriteLine("Error {0} creating output image.", outputFormat.ErrorMessage);
return 16;
return (int)ErrorNumber.CannotCreateFormat;
}
ImageInfo metadata = new ImageInfo
@@ -415,7 +415,7 @@ namespace DiscImageChef.Commands
if(!force)
{
DicConsole.ErrorWriteLine("not continuing...");
return 17;
return (int)ErrorNumber.WriteError;
}
DicConsole.ErrorWriteLine("continuing...");
@@ -434,7 +434,7 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine("Error {0} sending tracks list to output image.",
outputFormat.ErrorMessage);
return 18;
return (int)ErrorNumber.WriteError;
}
foreach(MediaTagType mediaTag in inputFormat.Info.ReadableMediaTags)
@@ -451,7 +451,7 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine("Error {0} writing media tag, not continuing...",
outputFormat.ErrorMessage);
return 19;
return (int)ErrorNumber.WriteError;
}
}
@@ -515,7 +515,7 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, not continuing...",
outputFormat.ErrorMessage, doneSectors);
return 20;
return (int)ErrorNumber.WriteError;
}
doneSectors += sectorsToDo;
@@ -580,7 +580,7 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, not continuing...",
outputFormat.ErrorMessage, doneSectors);
return 21;
return (int)ErrorNumber.WriteError;
}
doneSectors += sectorsToDo;
@@ -648,7 +648,7 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine("Error {0} writing sector {1}, not continuing...",
outputFormat.ErrorMessage, doneSectors);
return 22;
return (int)ErrorNumber.WriteError;
}
doneSectors += sectorsToDo;
@@ -702,7 +702,7 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine("Error {0} writing tag, not continuing...",
outputFormat.ErrorMessage);
return 23;
return (int)ErrorNumber.WriteError;
}
continue;
@@ -743,7 +743,7 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine("Error {0} writing tag for sector {1}, not continuing...",
outputFormat.ErrorMessage, doneSectors);
return 24;
return (int)ErrorNumber.WriteError;
}
doneSectors += sectorsToDo;

View File

@@ -37,6 +37,7 @@ using System.Linq;
using System.Text;
using System.Xml.Serialization;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using DiscImageChef.Core;
@@ -85,7 +86,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -95,13 +96,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
inputFile = extra[0];
@@ -132,7 +133,7 @@ namespace DiscImageChef.Commands
catch(ArgumentException)
{
DicConsole.ErrorWriteLine("Specified encoding is not supported.");
return 1;
return (int)ErrorNumber.EncodingUnknown;
}
if(File.Exists(inputFile))
@@ -140,7 +141,7 @@ namespace DiscImageChef.Commands
if(tape)
{
DicConsole.ErrorWriteLine("You cannot use --tape option when input is a file.");
return 2;
return (int)ErrorNumber.ExpectedDirectory;
}
FiltersList filtersList = new FiltersList();
@@ -149,7 +150,7 @@ namespace DiscImageChef.Commands
if(inputFilter == null)
{
DicConsole.ErrorWriteLine("Cannot open specified file.");
return 3;
return (int)ErrorNumber.CannotOpenFile;
}
try
@@ -159,7 +160,7 @@ namespace DiscImageChef.Commands
if(imageFormat == null)
{
DicConsole.WriteLine("Image format not identified, not proceeding with analysis.");
return 4;
return (int)ErrorNumber.UnrecognizedFormat;
}
if(MainClass.Verbose)
@@ -173,7 +174,7 @@ namespace DiscImageChef.Commands
{
DicConsole.WriteLine("Unable to open image format");
DicConsole.WriteLine("No error given");
return 5;
return (int)ErrorNumber.CannotOpenFormat;
}
DicConsole.DebugWriteLine("Analyze command", "Correctly opened image file.");
@@ -182,7 +183,7 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine("Unable to open image format");
DicConsole.ErrorWriteLine("Error: {0}", ex.Message);
return 6;
return (int)ErrorNumber.CannotOpenFormat;
}
Statistics.AddMediaFormat(imageFormat.Format);
@@ -207,6 +208,7 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine($"Error reading file: {ex.Message}");
DicConsole.DebugWriteLine("Analyze command", ex.StackTrace);
return (int)ErrorNumber.UnexpectedException;
}
}
else if(Directory.Exists(inputFile))
@@ -214,7 +216,7 @@ namespace DiscImageChef.Commands
if(!tape)
{
DicConsole.ErrorWriteLine("Cannot create a sidecar from a directory.");
return 7;
return (int)ErrorNumber.ExpectedFile;
}
string[] contents = Directory.GetFiles(inputFile, "*", SearchOption.TopDirectoryOnly);
@@ -239,7 +241,7 @@ namespace DiscImageChef.Commands
}
else DicConsole.ErrorWriteLine("The specified input file cannot be found.");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -77,7 +77,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -87,13 +87,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
inputFile = extra[0];
@@ -112,7 +112,7 @@ namespace DiscImageChef.Commands
if(inputFilter == null)
{
DicConsole.ErrorWriteLine("Cannot open specified file.");
return 1;
return (int)ErrorNumber.CannotOpenFile;
}
IMediaImage inputFormat = ImageFormat.Detect(inputFilter);
@@ -120,7 +120,7 @@ namespace DiscImageChef.Commands
if(inputFormat == null)
{
DicConsole.ErrorWriteLine("Unable to recognize image format, not decoding");
return 2;
return (int)ErrorNumber.UnrecognizedFormat;
}
inputFormat.Open(inputFilter);
@@ -319,7 +319,7 @@ namespace DiscImageChef.Commands
}
Statistics.AddCommand("decode");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -74,7 +74,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -84,13 +84,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing device path.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
devicePath = extra[0];
@@ -108,7 +108,7 @@ namespace DiscImageChef.Commands
if(dev.Error)
{
DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
return 1;
return (int)ErrorNumber.CannotOpenDevice;
}
Statistics.AddDevice(dev);
@@ -911,7 +911,7 @@ namespace DiscImageChef.Commands
dev.Close();
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -79,7 +79,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -89,13 +89,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing device path.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
devicePath = extra[0];
@@ -109,7 +109,7 @@ namespace DiscImageChef.Commands
DicConsole
.ErrorWriteLine("Because of the commands sent to a device, device report must be run with administrative privileges.");
DicConsole.ErrorWriteLine("Not continuing.");
return 1;
return (int)ErrorNumber.NotEnoughPermissions;
}
if(devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
@@ -120,7 +120,7 @@ namespace DiscImageChef.Commands
if(dev.Error)
{
DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
return 2;
return (int)ErrorNumber.CannotOpenDevice;
}
Statistics.AddDevice(dev);
@@ -295,9 +295,7 @@ namespace DiscImageChef.Commands
dev.AtapiIdentify(out buffer, out _, dev.Timeout, out _);
if(!Identify.Decode(buffer).HasValue) return 3;
report.ATAPI = new Ata {Identify = buffer};
if(Identify.Decode(buffer).HasValue) report.ATAPI = new Ata {Identify = buffer};
goto case DeviceType.SCSI;
case DeviceType.SCSI:
@@ -989,7 +987,7 @@ namespace DiscImageChef.Commands
// TODO:
if(Settings.Settings.Current.ShareReports) Remote.SubmitReport(report);
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -128,7 +128,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -138,13 +138,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 2)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count <= 1)
{
DicConsole.ErrorWriteLine("Missing paths.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
devicePath = extra[0];
@@ -159,18 +159,18 @@ namespace DiscImageChef.Commands
Sidecar.EndProgressEvent2 += Progress.EndProgress2;
Sidecar.UpdateStatusEvent += Progress.UpdateStatus;
DicConsole.DebugWriteLine("Dump-Media command", "--cicm-xml={0}", cicmXml);
DicConsole.DebugWriteLine("Dump-Media command", "--debug={0}", MainClass.Debug);
DicConsole.DebugWriteLine("Dump-Media command", "--device={0}", devicePath);
DicConsole.DebugWriteLine("Dump-Media command", "--encoding={0}", encodingName);
DicConsole.DebugWriteLine("Dump-Media command", "--first-pregap={0}", firstTrackPregap);
DicConsole.DebugWriteLine("Dump-Media command", "--force={0}", force);
DicConsole.DebugWriteLine("Dump-Media command", "--force={0}", force);
DicConsole.DebugWriteLine("Dump-Media command", "--format={0}", wanteOutputFormat);
DicConsole.DebugWriteLine("Dump-Media command", "--no-metadata={0}", noMetadata);
DicConsole.DebugWriteLine("Dump-Media command", "--options={0}", Options);
DicConsole.DebugWriteLine("Dump-Media command", "--output={0}", outputFile);
DicConsole.DebugWriteLine("Dump-Media command", "--persistent={0}", persistent);
DicConsole.DebugWriteLine("Dump-Media command", "--cicm-xml={0}", cicmXml);
DicConsole.DebugWriteLine("Dump-Media command", "--debug={0}", MainClass.Debug);
DicConsole.DebugWriteLine("Dump-Media command", "--device={0}", devicePath);
DicConsole.DebugWriteLine("Dump-Media command", "--encoding={0}", encodingName);
DicConsole.DebugWriteLine("Dump-Media command", "--first-pregap={0}", firstTrackPregap);
DicConsole.DebugWriteLine("Dump-Media command", "--force={0}", force);
DicConsole.DebugWriteLine("Dump-Media command", "--force={0}", force);
DicConsole.DebugWriteLine("Dump-Media command", "--format={0}", wanteOutputFormat);
DicConsole.DebugWriteLine("Dump-Media command", "--no-metadata={0}", noMetadata);
DicConsole.DebugWriteLine("Dump-Media command", "--options={0}", Options);
DicConsole.DebugWriteLine("Dump-Media command", "--output={0}", outputFile);
DicConsole.DebugWriteLine("Dump-Media command", "--persistent={0}", persistent);
// TODO: Disabled temporarily
//DicConsole.DebugWriteLine("Dump-Media command", "--raw={0}", raw);
DicConsole.DebugWriteLine("Dump-Media command", "--resume={0}", doResume);
@@ -195,7 +195,7 @@ namespace DiscImageChef.Commands
catch(ArgumentException)
{
DicConsole.ErrorWriteLine("Specified encoding is not supported.");
return 1;
return (int)ErrorNumber.EncodingUnknown;
}
if(devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
@@ -206,7 +206,7 @@ namespace DiscImageChef.Commands
if(dev.Error)
{
DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
return 2;
return (int)ErrorNumber.CannotOpenDevice;
}
Statistics.AddDevice(dev);
@@ -226,13 +226,13 @@ namespace DiscImageChef.Commands
catch
{
DicConsole.ErrorWriteLine("Incorrect resume file, not continuing...");
return 3;
return (int)ErrorNumber.InvalidResume;
}
if(resume != null && resume.NextBlock > resume.LastBlock && resume.BadBlocks.Count == 0)
{
DicConsole.WriteLine("Media already dumped correctly, not continuing...");
return 4;
return (int)ErrorNumber.AlreadyDumped;
}
CICMMetadataType sidecar = null;
@@ -248,12 +248,12 @@ namespace DiscImageChef.Commands
catch
{
DicConsole.ErrorWriteLine("Incorrect metadata sidecar file, not continuing...");
return 5;
return (int)ErrorNumber.InvalidSidecar;
}
else
{
DicConsole.ErrorWriteLine("Could not find metadata sidecar, not continuing...");
return 6;
return (int)ErrorNumber.FileNotFound;
}
PluginBase plugins = GetPluginBase.Instance;
@@ -276,13 +276,13 @@ namespace DiscImageChef.Commands
if(candidates.Count == 0)
{
DicConsole.WriteLine("No plugin supports requested extension.");
return 7;
return (int)ErrorNumber.FormatNotFound;
}
if(candidates.Count > 1)
{
DicConsole.WriteLine("More than one plugin supports requested extension.");
return 8;
return (int)ErrorNumber.TooManyFormats;
}
IWritableImage outputFormat = candidates[0];
@@ -354,7 +354,7 @@ namespace DiscImageChef.Commands
Statistics.AddCommand("dump-media");
dev.Close();
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -32,6 +32,7 @@
using System.Collections.Generic;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using DiscImageChef.Core;
@@ -79,7 +80,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -89,13 +90,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
inputFile = extra[0];
@@ -113,7 +114,7 @@ namespace DiscImageChef.Commands
if(inputFilter == null)
{
DicConsole.ErrorWriteLine("Cannot open specified file.");
return 1;
return (int)ErrorNumber.CannotOpenFile;
}
IMediaImage inputFormat = ImageFormat.Detect(inputFilter);
@@ -121,7 +122,7 @@ namespace DiscImageChef.Commands
if(inputFormat == null)
{
DicConsole.ErrorWriteLine("Unable to recognize image format, not checksumming");
return 2;
return (int)ErrorNumber.UnrecognizedFormat;
}
inputFormat.Open(inputFilter);
@@ -153,7 +154,7 @@ namespace DiscImageChef.Commands
if(!wholeDisc)
{
Statistics.AddCommand("entropy");
return 0;
return (int)ErrorNumber.NoError;
}
EntropyResults entropy = entropyCalculator.CalculateMediaEntropy(duplicatedSectors);
@@ -164,7 +165,7 @@ namespace DiscImageChef.Commands
(double)entropy.UniqueSectors / (double)entropy.Sectors);
Statistics.AddCommand("entropy");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -35,6 +35,7 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.CommonTypes.Structs;
using DiscImageChef.Console;
@@ -83,7 +84,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -93,13 +94,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
inputFile = extra[0];
@@ -124,7 +125,7 @@ namespace DiscImageChef.Commands
if(inputFilter == null)
{
DicConsole.ErrorWriteLine("Cannot open specified file.");
return 0;
return (int)ErrorNumber.CannotOpenFile;
}
Encoding encoding = null;
@@ -138,7 +139,7 @@ namespace DiscImageChef.Commands
catch(ArgumentException)
{
DicConsole.ErrorWriteLine("Specified encoding is not supported.");
return 1;
return (int)ErrorNumber.EncodingUnknown;
}
PluginBase plugins = GetPluginBase.Instance;
@@ -150,7 +151,7 @@ namespace DiscImageChef.Commands
if(imageFormat == null)
{
DicConsole.WriteLine("Image format not identified, not proceeding with analysis.");
return 2;
return (int)ErrorNumber.UnrecognizedFormat;
}
if(MainClass.Verbose)
@@ -161,7 +162,7 @@ namespace DiscImageChef.Commands
if(Directory.Exists(outputDir) || File.Exists(outputDir))
{
DicConsole.ErrorWriteLine("Destination exists, aborting.");
return 3;
return (int)ErrorNumber.DestinationExists;
}
Directory.CreateDirectory(outputDir);
@@ -172,7 +173,7 @@ namespace DiscImageChef.Commands
{
DicConsole.WriteLine("Unable to open image format");
DicConsole.WriteLine("No error given");
return 4;
return (int)ErrorNumber.CannotOpenFormat;
}
DicConsole.DebugWriteLine("Extract-Files command", "Correctly opened image file.");
@@ -191,7 +192,7 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine("Unable to open image format");
DicConsole.ErrorWriteLine("Error: {0}", ex.Message);
return 5;
return (int)ErrorNumber.CannotOpenFormat;
}
List<Partition> partitions = Core.Partitions.GetAll(imageFormat);
@@ -797,10 +798,11 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine($"Error reading file: {ex.Message}");
DicConsole.DebugWriteLine("Extract-Files command", ex.StackTrace);
return (int)ErrorNumber.UnexpectedException;
}
Statistics.AddCommand("extract-files");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -33,6 +33,7 @@
using System.Collections.Generic;
using System.Linq;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using DiscImageChef.Core;
@@ -67,7 +68,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -77,7 +78,7 @@ namespace DiscImageChef.Commands
if(extra.Count > 0)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
DicConsole.DebugWriteLine("Formats command", "--debug={0}", MainClass.Debug);
@@ -153,7 +154,7 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine(kvp.Value.Name);
Statistics.AddCommand("formats");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -31,6 +31,7 @@
// ****************************************************************************/
using System.Collections.Generic;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.Console;
using DiscImageChef.Gui.Forms;
using Eto;
@@ -65,7 +66,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
if(extra.Count > 0)
@@ -73,11 +74,11 @@ namespace DiscImageChef.Commands
MainClass.PrintCopyright();
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
new Application(Platform.Detect).Run(new frmMain(MainClass.Debug, MainClass.Verbose));
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -33,6 +33,7 @@
using System;
using System.Collections.Generic;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using DiscImageChef.Core;
@@ -68,7 +69,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -78,13 +79,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
inputFile = extra[0];
@@ -99,7 +100,7 @@ namespace DiscImageChef.Commands
if(inputFilter == null)
{
DicConsole.ErrorWriteLine("Cannot open specified file.");
return 1;
return (int)ErrorNumber.CannotOpenFile;
}
try
@@ -109,7 +110,7 @@ namespace DiscImageChef.Commands
if(imageFormat == null)
{
DicConsole.WriteLine("Image format not identified.");
return 2;
return (int)ErrorNumber.UnrecognizedFormat;
}
DicConsole.WriteLine("Image format identified by {0} ({1}).", imageFormat.Name, imageFormat.Id);
@@ -121,7 +122,7 @@ namespace DiscImageChef.Commands
{
DicConsole.WriteLine("Unable to open image format");
DicConsole.WriteLine("No error given");
return 3;
return (int)ErrorNumber.CannotOpenFormat;
}
ImageInfo.PrintImageInfo(imageFormat);
@@ -135,16 +136,18 @@ namespace DiscImageChef.Commands
DicConsole.ErrorWriteLine("Unable to open image format");
DicConsole.ErrorWriteLine("Error: {0}", ex.Message);
DicConsole.DebugWriteLine("Image-info command", "Stack trace: {0}", ex.StackTrace);
return (int)ErrorNumber.CannotOpenFormat;
}
}
catch(Exception ex)
{
DicConsole.ErrorWriteLine($"Error reading file: {ex.Message}");
DicConsole.DebugWriteLine("Image-info command", ex.StackTrace);
return (int)ErrorNumber.UnexpectedException;
}
Statistics.AddCommand("image-info");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -32,6 +32,7 @@
using System.Collections.Generic;
using System.Linq;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.Console;
using DiscImageChef.Core;
using DiscImageChef.Devices;
@@ -64,7 +65,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -74,7 +75,7 @@ namespace DiscImageChef.Commands
if(extra.Count > 0)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
DicConsole.DebugWriteLine("List-Devices command", "--debug={0}", MainClass.Debug);
@@ -98,7 +99,7 @@ namespace DiscImageChef.Commands
}
Statistics.AddCommand("list-devices");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -33,6 +33,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.Console;
using DiscImageChef.Core;
using Mono.Options;
@@ -64,7 +65,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -74,7 +75,7 @@ namespace DiscImageChef.Commands
if(extra.Count > 0)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
DicConsole.DebugWriteLine("List-Encodings command", "--debug={0}", MainClass.Debug);
@@ -99,7 +100,7 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine("{0,-16} {1,-8}", info.Name, info.DisplayName);
Statistics.AddCommand("list-encodings");
return 0;
return (int)ErrorNumber.NoError;
}
struct CommonEncodingInfo

View File

@@ -34,6 +34,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using DiscImageChef.Core;
@@ -67,7 +68,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -77,7 +78,7 @@ namespace DiscImageChef.Commands
if(extra.Count > 0)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
DicConsole.DebugWriteLine("List-Options command", "--debug={0}", MainClass.Debug);
@@ -117,7 +118,7 @@ namespace DiscImageChef.Commands
DicConsole.WriteLine();
}
return 0;
return (int)ErrorNumber.NoError;
}
static string TypeToString(Type type)

View File

@@ -34,6 +34,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.CommonTypes.Structs;
using DiscImageChef.Console;
@@ -77,7 +78,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -87,13 +88,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
inputFile = extra[0];
@@ -116,7 +117,7 @@ namespace DiscImageChef.Commands
if(inputFilter == null)
{
DicConsole.ErrorWriteLine("Cannot open specified file.");
return 1;
return (int)ErrorNumber.CannotOpenFile;
}
Encoding encoding = null;
@@ -130,7 +131,7 @@ namespace DiscImageChef.Commands
catch(ArgumentException)
{
DicConsole.ErrorWriteLine("Specified encoding is not supported.");
return 2;
return (int)ErrorNumber.EncodingUnknown;
}
PluginBase plugins = GetPluginBase.Instance;
@@ -142,7 +143,7 @@ namespace DiscImageChef.Commands
if(imageFormat == null)
{
DicConsole.WriteLine("Image format not identified, not proceeding with analysis.");
return 3;
return (int)ErrorNumber.UnrecognizedFormat;
}
if(MainClass.Verbose)
@@ -156,7 +157,7 @@ namespace DiscImageChef.Commands
{
DicConsole.WriteLine("Unable to open image format");
DicConsole.WriteLine("No error given");
return 4;
return (int)ErrorNumber.CannotOpenFormat;
}
DicConsole.DebugWriteLine("Ls command", "Correctly opened image file.");
@@ -174,7 +175,7 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine("Unable to open image format");
DicConsole.ErrorWriteLine("Error: {0}", ex.Message);
return 3;
return (int)ErrorNumber.CannotOpenFormat;
}
List<Partition> partitions = Core.Partitions.GetAll(imageFormat);
@@ -350,10 +351,11 @@ namespace DiscImageChef.Commands
{
DicConsole.ErrorWriteLine($"Error reading file: {ex.Message}");
DicConsole.DebugWriteLine("Ls command", ex.StackTrace);
return (int)ErrorNumber.UnexpectedException;
}
Statistics.AddCommand("ls");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -84,7 +84,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -94,13 +94,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing device path.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
devicePath = extra[0];
@@ -118,7 +118,7 @@ namespace DiscImageChef.Commands
if(dev.Error)
{
DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
return 1;
return (int)ErrorNumber.CannotOpenDevice;
}
Statistics.AddDevice(dev);
@@ -144,7 +144,7 @@ namespace DiscImageChef.Commands
Statistics.AddCommand("media-info");
return 0;
return (int)ErrorNumber.NoError;
}
static void DoAtaMediaInfo()

View File

@@ -71,7 +71,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -81,13 +81,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing device path.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
devicePath = extra[0];
@@ -106,7 +106,7 @@ namespace DiscImageChef.Commands
if(dev.Error)
{
DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
return 1;
return (int)ErrorNumber.CannotOpenDevice;
}
Statistics.AddDevice(dev);
@@ -161,7 +161,7 @@ namespace DiscImageChef.Commands
Statistics.AddCommand("media-scan");
dev.Close();
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -32,6 +32,7 @@
using System.Collections.Generic;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using DiscImageChef.Core;
@@ -73,7 +74,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -83,19 +84,19 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
if(startSector is null)
{
DicConsole.ErrorWriteLine("Missing starting sector.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
inputFile = extra[0];
@@ -114,7 +115,7 @@ namespace DiscImageChef.Commands
if(inputFilter == null)
{
DicConsole.ErrorWriteLine("Cannot open specified file.");
return 1;
return (int)ErrorNumber.CannotOpenFile;
}
IMediaImage inputFormat = ImageFormat.Detect(inputFilter);
@@ -122,7 +123,7 @@ namespace DiscImageChef.Commands
if(inputFormat == null)
{
DicConsole.ErrorWriteLine("Unable to recognize image format, not verifying");
return 2;
return (int)ErrorNumber.UnrecognizedFormat;
}
inputFormat.Open(inputFilter);
@@ -155,7 +156,7 @@ namespace DiscImageChef.Commands
}
Statistics.AddCommand("print-hex");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -32,6 +32,7 @@
using System.Collections.Generic;
using System.Linq;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.Console;
using DiscImageChef.Database;
using DiscImageChef.Database.Models;
@@ -65,7 +66,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -75,7 +76,7 @@ namespace DiscImageChef.Commands
if(extra.Count > 0)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
DicContext ctx = DicContext.Create(Settings.Settings.LocalDbPath);
@@ -84,7 +85,7 @@ namespace DiscImageChef.Commands
!ctx.Medias.Any() && !ctx.Partitions.Any() && !ctx.SeenDevices.Any())
{
DicConsole.WriteLine("There are no statistics.");
return 1;
return (int)ErrorNumber.NothingFound;
}
bool thereAreStats = false;
@@ -235,7 +236,7 @@ namespace DiscImageChef.Commands
}
if(!thereAreStats) DicConsole.WriteLine("There are no statistics.");
return 0;
return (int)ErrorNumber.NoError;
}
}
}

View File

@@ -31,6 +31,7 @@
// ****************************************************************************/
using System.Collections.Generic;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.Console;
using DiscImageChef.Core;
using Mono.Options;
@@ -59,14 +60,14 @@ namespace DiscImageChef.Commands
public override int Invoke(IEnumerable<string> arguments)
{
if(masterDbUpdate) return 0;
if(masterDbUpdate) return (int)ErrorNumber.NoError;
List<string> extra = Options.Parse(arguments);
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -76,7 +77,7 @@ namespace DiscImageChef.Commands
if(extra.Count > 0)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
DicConsole.DebugWriteLine("Update command", "--debug={0}", MainClass.Debug);
@@ -84,7 +85,7 @@ namespace DiscImageChef.Commands
DoUpdate(false);
return 0;
return (int)ErrorNumber.NoError;
}
internal static void DoUpdate(bool create)

View File

@@ -33,6 +33,7 @@
using System;
using System.Collections.Generic;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.CommonTypes.Structs;
using DiscImageChef.Console;
@@ -71,7 +72,7 @@ namespace DiscImageChef.Commands
if(showHelp)
{
Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
return (int)ErrorNumber.HelpRequested;
}
MainClass.PrintCopyright();
@@ -81,13 +82,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1)
{
DicConsole.ErrorWriteLine("Too many arguments.");
return 1;
return (int)ErrorNumber.UnexpectedArgumentCount;
}
if(extra.Count == 0)
{
DicConsole.ErrorWriteLine("Missing input image.");
return 1;
return (int)ErrorNumber.MissingArgument;
}
inputFile = extra[0];
@@ -104,7 +105,7 @@ namespace DiscImageChef.Commands
if(inputFilter == null)
{
DicConsole.ErrorWriteLine("Cannot open specified file.");
return 1;
return (int)ErrorNumber.CannotOpenFile;
}
IMediaImage inputFormat = ImageFormat.Detect(inputFilter);
@@ -112,7 +113,7 @@ namespace DiscImageChef.Commands
if(inputFormat == null)
{
DicConsole.ErrorWriteLine("Unable to recognize image format, not verifying");
return 2;
return (int)ErrorNumber.FormatNotFound;
}
inputFormat.Open(inputFilter);
@@ -120,10 +121,10 @@ namespace DiscImageChef.Commands
Statistics.AddMedia(inputFormat.Info.MediaType, false);
Statistics.AddFilter(inputFilter.Name);
bool? correctDisc = null;
bool? correctImage = null;
long totalSectors = 0;
long errorSectors = 0;
long correctSectors = 0;
bool? correctSectors = null;
long unknownSectors = 0;
if(verifyDisc)
@@ -147,7 +148,7 @@ namespace DiscImageChef.Commands
break;
}
correctDisc = discCheckStatus;
correctImage = discCheckStatus;
DicConsole.VerboseWriteLine("Checking disc image checksums took {0} seconds", checkTime.TotalSeconds);
}
@@ -288,11 +289,26 @@ namespace DiscImageChef.Commands
totalSectors = (long)inputFormat.Info.Sectors;
errorSectors = failingLbas.Count;
unknownSectors = unknownLbas.Count;
correctSectors = totalSectors - errorSectors - unknownSectors;
if(failingLbas.Count > 0) correctSectors = false;
else if((ulong)unknownLbas.Count < inputFormat.Info.Sectors) correctSectors = true;
}
Statistics.AddCommand("verify");
return 0;
switch(correctImage)
{
case null when correctSectors is null: return (int)ErrorNumber.NotVerificable;
case null when correctSectors == false: return (int)ErrorNumber.BadSectorsImageNotVerified;
case null when correctSectors == true: return (int)ErrorNumber.CorrectSectorsImageNotVerified;
case false when correctSectors is null: return (int)ErrorNumber.BadImageSectorsNotVerified;
case false when correctSectors == false: return (int)ErrorNumber.BadImageBadSectors;
case false when correctSectors == true: return (int)ErrorNumber.CorrectSectorsBadImage;
case true when correctSectors is null: return (int)ErrorNumber.CorrectImageSectorsNotVerified;
case true when correctSectors == false: return (int)ErrorNumber.CorrectImageBadSectors;
case true when correctSectors == true: return (int)ErrorNumber.NoError;
}
return (int)ErrorNumber.NoError;
}
}
}