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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -79,7 +79,7 @@ namespace DiscImageChef.Commands
if(showHelp) if(showHelp)
{ {
Options.WriteOptionDescriptions(CommandSet.Out); Options.WriteOptionDescriptions(CommandSet.Out);
return 0; return (int)ErrorNumber.HelpRequested;
} }
MainClass.PrintCopyright(); MainClass.PrintCopyright();
@@ -89,13 +89,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 1) if(extra.Count > 1)
{ {
DicConsole.ErrorWriteLine("Too many arguments."); DicConsole.ErrorWriteLine("Too many arguments.");
return 1; return (int)ErrorNumber.UnexpectedArgumentCount;
} }
if(extra.Count == 0) if(extra.Count == 0)
{ {
DicConsole.ErrorWriteLine("Missing device path."); DicConsole.ErrorWriteLine("Missing device path.");
return 1; return (int)ErrorNumber.MissingArgument;
} }
devicePath = extra[0]; devicePath = extra[0];
@@ -109,7 +109,7 @@ namespace DiscImageChef.Commands
DicConsole DicConsole
.ErrorWriteLine("Because of the commands sent to a device, device report must be run with administrative privileges."); .ErrorWriteLine("Because of the commands sent to a device, device report must be run with administrative privileges.");
DicConsole.ErrorWriteLine("Not continuing."); DicConsole.ErrorWriteLine("Not continuing.");
return 1; return (int)ErrorNumber.NotEnoughPermissions;
} }
if(devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0])) if(devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
@@ -120,7 +120,7 @@ namespace DiscImageChef.Commands
if(dev.Error) if(dev.Error)
{ {
DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError); DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
return 2; return (int)ErrorNumber.CannotOpenDevice;
} }
Statistics.AddDevice(dev); Statistics.AddDevice(dev);
@@ -295,9 +295,7 @@ namespace DiscImageChef.Commands
dev.AtapiIdentify(out buffer, out _, dev.Timeout, out _); dev.AtapiIdentify(out buffer, out _, dev.Timeout, out _);
if(!Identify.Decode(buffer).HasValue) return 3; if(Identify.Decode(buffer).HasValue) report.ATAPI = new Ata {Identify = buffer};
report.ATAPI = new Ata {Identify = buffer};
goto case DeviceType.SCSI; goto case DeviceType.SCSI;
case DeviceType.SCSI: case DeviceType.SCSI:
@@ -989,7 +987,7 @@ namespace DiscImageChef.Commands
// TODO: // TODO:
if(Settings.Settings.Current.ShareReports) Remote.SubmitReport(report); 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) if(showHelp)
{ {
Options.WriteOptionDescriptions(CommandSet.Out); Options.WriteOptionDescriptions(CommandSet.Out);
return 0; return (int)ErrorNumber.HelpRequested;
} }
MainClass.PrintCopyright(); MainClass.PrintCopyright();
@@ -138,13 +138,13 @@ namespace DiscImageChef.Commands
if(extra.Count > 2) if(extra.Count > 2)
{ {
DicConsole.ErrorWriteLine("Too many arguments."); DicConsole.ErrorWriteLine("Too many arguments.");
return 1; return (int)ErrorNumber.UnexpectedArgumentCount;
} }
if(extra.Count <= 1) if(extra.Count <= 1)
{ {
DicConsole.ErrorWriteLine("Missing paths."); DicConsole.ErrorWriteLine("Missing paths.");
return 1; return (int)ErrorNumber.MissingArgument;
} }
devicePath = extra[0]; devicePath = extra[0];
@@ -159,18 +159,18 @@ namespace DiscImageChef.Commands
Sidecar.EndProgressEvent2 += Progress.EndProgress2; Sidecar.EndProgressEvent2 += Progress.EndProgress2;
Sidecar.UpdateStatusEvent += Progress.UpdateStatus; Sidecar.UpdateStatusEvent += Progress.UpdateStatus;
DicConsole.DebugWriteLine("Dump-Media command", "--cicm-xml={0}", cicmXml); DicConsole.DebugWriteLine("Dump-Media command", "--cicm-xml={0}", cicmXml);
DicConsole.DebugWriteLine("Dump-Media command", "--debug={0}", MainClass.Debug); DicConsole.DebugWriteLine("Dump-Media command", "--debug={0}", MainClass.Debug);
DicConsole.DebugWriteLine("Dump-Media command", "--device={0}", devicePath); DicConsole.DebugWriteLine("Dump-Media command", "--device={0}", devicePath);
DicConsole.DebugWriteLine("Dump-Media command", "--encoding={0}", encodingName); DicConsole.DebugWriteLine("Dump-Media command", "--encoding={0}", encodingName);
DicConsole.DebugWriteLine("Dump-Media command", "--first-pregap={0}", firstTrackPregap); 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", "--force={0}", force); DicConsole.DebugWriteLine("Dump-Media command", "--force={0}", force);
DicConsole.DebugWriteLine("Dump-Media command", "--format={0}", wanteOutputFormat); DicConsole.DebugWriteLine("Dump-Media command", "--format={0}", wanteOutputFormat);
DicConsole.DebugWriteLine("Dump-Media command", "--no-metadata={0}", noMetadata); DicConsole.DebugWriteLine("Dump-Media command", "--no-metadata={0}", noMetadata);
DicConsole.DebugWriteLine("Dump-Media command", "--options={0}", Options); DicConsole.DebugWriteLine("Dump-Media command", "--options={0}", Options);
DicConsole.DebugWriteLine("Dump-Media command", "--output={0}", outputFile); DicConsole.DebugWriteLine("Dump-Media command", "--output={0}", outputFile);
DicConsole.DebugWriteLine("Dump-Media command", "--persistent={0}", persistent); DicConsole.DebugWriteLine("Dump-Media command", "--persistent={0}", persistent);
// TODO: Disabled temporarily // TODO: Disabled temporarily
//DicConsole.DebugWriteLine("Dump-Media command", "--raw={0}", raw); //DicConsole.DebugWriteLine("Dump-Media command", "--raw={0}", raw);
DicConsole.DebugWriteLine("Dump-Media command", "--resume={0}", doResume); DicConsole.DebugWriteLine("Dump-Media command", "--resume={0}", doResume);
@@ -195,7 +195,7 @@ namespace DiscImageChef.Commands
catch(ArgumentException) catch(ArgumentException)
{ {
DicConsole.ErrorWriteLine("Specified encoding is not supported."); 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])) if(devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
@@ -206,7 +206,7 @@ namespace DiscImageChef.Commands
if(dev.Error) if(dev.Error)
{ {
DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError); DicConsole.ErrorWriteLine("Error {0} opening device.", dev.LastError);
return 2; return (int)ErrorNumber.CannotOpenDevice;
} }
Statistics.AddDevice(dev); Statistics.AddDevice(dev);
@@ -226,13 +226,13 @@ namespace DiscImageChef.Commands
catch catch
{ {
DicConsole.ErrorWriteLine("Incorrect resume file, not continuing..."); DicConsole.ErrorWriteLine("Incorrect resume file, not continuing...");
return 3; return (int)ErrorNumber.InvalidResume;
} }
if(resume != null && resume.NextBlock > resume.LastBlock && resume.BadBlocks.Count == 0) if(resume != null && resume.NextBlock > resume.LastBlock && resume.BadBlocks.Count == 0)
{ {
DicConsole.WriteLine("Media already dumped correctly, not continuing..."); DicConsole.WriteLine("Media already dumped correctly, not continuing...");
return 4; return (int)ErrorNumber.AlreadyDumped;
} }
CICMMetadataType sidecar = null; CICMMetadataType sidecar = null;
@@ -248,12 +248,12 @@ namespace DiscImageChef.Commands
catch catch
{ {
DicConsole.ErrorWriteLine("Incorrect metadata sidecar file, not continuing..."); DicConsole.ErrorWriteLine("Incorrect metadata sidecar file, not continuing...");
return 5; return (int)ErrorNumber.InvalidSidecar;
} }
else else
{ {
DicConsole.ErrorWriteLine("Could not find metadata sidecar, not continuing..."); DicConsole.ErrorWriteLine("Could not find metadata sidecar, not continuing...");
return 6; return (int)ErrorNumber.FileNotFound;
} }
PluginBase plugins = GetPluginBase.Instance; PluginBase plugins = GetPluginBase.Instance;
@@ -276,13 +276,13 @@ namespace DiscImageChef.Commands
if(candidates.Count == 0) if(candidates.Count == 0)
{ {
DicConsole.WriteLine("No plugin supports requested extension."); DicConsole.WriteLine("No plugin supports requested extension.");
return 7; return (int)ErrorNumber.FormatNotFound;
} }
if(candidates.Count > 1) if(candidates.Count > 1)
{ {
DicConsole.WriteLine("More than one plugin supports requested extension."); DicConsole.WriteLine("More than one plugin supports requested extension.");
return 8; return (int)ErrorNumber.TooManyFormats;
} }
IWritableImage outputFormat = candidates[0]; IWritableImage outputFormat = candidates[0];
@@ -354,7 +354,7 @@ namespace DiscImageChef.Commands
Statistics.AddCommand("dump-media"); Statistics.AddCommand("dump-media");
dev.Close(); dev.Close();
return 0; return (int)ErrorNumber.NoError;
} }
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -32,6 +32,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.Console; using DiscImageChef.Console;
using DiscImageChef.Database; using DiscImageChef.Database;
using DiscImageChef.Database.Models; using DiscImageChef.Database.Models;
@@ -65,7 +66,7 @@ namespace DiscImageChef.Commands
if(showHelp) if(showHelp)
{ {
Options.WriteOptionDescriptions(CommandSet.Out); Options.WriteOptionDescriptions(CommandSet.Out);
return 0; return (int)ErrorNumber.HelpRequested;
} }
MainClass.PrintCopyright(); MainClass.PrintCopyright();
@@ -75,7 +76,7 @@ namespace DiscImageChef.Commands
if(extra.Count > 0) if(extra.Count > 0)
{ {
DicConsole.ErrorWriteLine("Too many arguments."); DicConsole.ErrorWriteLine("Too many arguments.");
return 1; return (int)ErrorNumber.UnexpectedArgumentCount;
} }
DicContext ctx = DicContext.Create(Settings.Settings.LocalDbPath); DicContext ctx = DicContext.Create(Settings.Settings.LocalDbPath);
@@ -84,7 +85,7 @@ namespace DiscImageChef.Commands
!ctx.Medias.Any() && !ctx.Partitions.Any() && !ctx.SeenDevices.Any()) !ctx.Medias.Any() && !ctx.Partitions.Any() && !ctx.SeenDevices.Any())
{ {
DicConsole.WriteLine("There are no statistics."); DicConsole.WriteLine("There are no statistics.");
return 1; return (int)ErrorNumber.NothingFound;
} }
bool thereAreStats = false; bool thereAreStats = false;
@@ -235,7 +236,7 @@ namespace DiscImageChef.Commands
} }
if(!thereAreStats) DicConsole.WriteLine("There are no statistics."); 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 System.Collections.Generic;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.Console; using DiscImageChef.Console;
using DiscImageChef.Core; using DiscImageChef.Core;
using Mono.Options; using Mono.Options;
@@ -59,14 +60,14 @@ namespace DiscImageChef.Commands
public override int Invoke(IEnumerable<string> arguments) public override int Invoke(IEnumerable<string> arguments)
{ {
if(masterDbUpdate) return 0; if(masterDbUpdate) return (int)ErrorNumber.NoError;
List<string> extra = Options.Parse(arguments); List<string> extra = Options.Parse(arguments);
if(showHelp) if(showHelp)
{ {
Options.WriteOptionDescriptions(CommandSet.Out); Options.WriteOptionDescriptions(CommandSet.Out);
return 0; return (int)ErrorNumber.HelpRequested;
} }
MainClass.PrintCopyright(); MainClass.PrintCopyright();
@@ -76,7 +77,7 @@ namespace DiscImageChef.Commands
if(extra.Count > 0) if(extra.Count > 0)
{ {
DicConsole.ErrorWriteLine("Too many arguments."); DicConsole.ErrorWriteLine("Too many arguments.");
return 1; return (int)ErrorNumber.UnexpectedArgumentCount;
} }
DicConsole.DebugWriteLine("Update command", "--debug={0}", MainClass.Debug); DicConsole.DebugWriteLine("Update command", "--debug={0}", MainClass.Debug);
@@ -84,7 +85,7 @@ namespace DiscImageChef.Commands
DoUpdate(false); DoUpdate(false);
return 0; return (int)ErrorNumber.NoError;
} }
internal static void DoUpdate(bool create) internal static void DoUpdate(bool create)

View File

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