From 372f9f68ac3ea2d76f4e70a357a6aeae9e0a9a12 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 5 Jan 2019 19:50:56 +0000 Subject: [PATCH] Return specific error codes from command execution. --- .../DiscImageChef.CommonTypes.csproj | 1 + .../Enums/ErrorNumber.cs | 115 ++++++++++++++++++ DiscImageChef/Commands/Analyze.cs | 28 +++-- DiscImageChef/Commands/Benchmark.cs | 7 +- DiscImageChef/Commands/Checksum.cs | 13 +- DiscImageChef/Commands/Compare.cs | 16 +-- DiscImageChef/Commands/Configure.cs | 13 +- DiscImageChef/Commands/ConvertImage.cs | 54 ++++---- DiscImageChef/Commands/CreateSidecar.cs | 24 ++-- DiscImageChef/Commands/Decode.cs | 12 +- DiscImageChef/Commands/DeviceInfo.cs | 10 +- DiscImageChef/Commands/DeviceReport.cs | 16 ++- DiscImageChef/Commands/DumpMedia.cs | 48 ++++---- DiscImageChef/Commands/Entropy.cs | 15 +-- DiscImageChef/Commands/ExtractFiles.cs | 22 ++-- DiscImageChef/Commands/Formats.cs | 7 +- DiscImageChef/Commands/Gui.cs | 7 +- DiscImageChef/Commands/ImageInfo.cs | 17 +-- DiscImageChef/Commands/ListDevices.cs | 7 +- DiscImageChef/Commands/ListEncodings.cs | 7 +- DiscImageChef/Commands/ListOptions.cs | 7 +- DiscImageChef/Commands/Ls.cs | 20 +-- DiscImageChef/Commands/MediaInfo.cs | 10 +- DiscImageChef/Commands/MediaScan.cs | 10 +- DiscImageChef/Commands/PrintHex.cs | 15 +-- DiscImageChef/Commands/Statistics.cs | 9 +- DiscImageChef/Commands/Update.cs | 9 +- DiscImageChef/Commands/Verify.cs | 36 ++++-- 28 files changed, 351 insertions(+), 204 deletions(-) create mode 100644 DiscImageChef.CommonTypes/Enums/ErrorNumber.cs diff --git a/DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj b/DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj index f31665625..089cf06cc 100644 --- a/DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj +++ b/DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj @@ -50,6 +50,7 @@ Metadata/cicm.cs + diff --git a/DiscImageChef.CommonTypes/Enums/ErrorNumber.cs b/DiscImageChef.CommonTypes/Enums/ErrorNumber.cs new file mode 100644 index 000000000..29d8d0016 --- /dev/null +++ b/DiscImageChef.CommonTypes/Enums/ErrorNumber.cs @@ -0,0 +1,115 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : ErrorNumber.cs +// Author(s) : Natalia Portillo +// +// 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 +{ + /// + /// Enumerates error codes. Positive for warnings or informative codes, negative for errors. + /// + public enum ErrorNumber + { + /// No error + NoError = 0, + /// User requested help to be shown + HelpRequested = 1, + /// Command found nothing + NothingFound = 2, + /// Media has been already dumped completely + AlreadyDumped = 3, + /// Image and its sectors cannot be verified + NotVerificable = 4, + /// There are bad sectors and image cannot be verified + BadSectorsImageNotVerified = 5, + /// All sectors are good and image cannot be verified + CorrectSectorsImageNotVerified = 6, + /// Image is bad and sectors cannot be verified + BadImageSectorsNotVerified = 7, + /// Image is bad and there are bad sectors + BadImageBadSectors = 8, + /// All sectors are good and image is bad + CorrectSectorsBadImage = 9, + /// Image is good and sectors cannot be verified + CorrectImageSectorsNotVerified = 10, + /// Image is good and there are bad sectors + CorrectImageBadSectors = 11, + /// Exception has been raised + UnexpectedException = -1, + /// The number of arguments is not as expected + UnexpectedArgumentCount = -2, + /// A required argument is not present + MissingArgument = -3, + /// A specified argument contains an invalid value + InvalidArgument = -4, + /// The specified file cannot be found + FileNotFound = -5, + /// The specified file cannot be opened + CannotOpenFile = -6, + /// The specified encoding cannot be found + EncodingUnknown = -7, + /// The image format has not been recognized + UnrecognizedFormat = -8, + /// The image format failed to open + CannotOpenFormat = -9, + /// The specified metadata sidecar does not have the correct format + InvalidSidecar = -10, + /// The specified resume map does not have the correct format + InvalidResume = -11, + /// The specified destination file/folder already exists + DestinationExists = -12, + /// The specified image format cannot be found + FormatNotFound = -13, + /// More than one format found for the specified search criteria + TooManyFormats = -14, + /// The specified format does not support the specified media + UnsupportedMedia = -15, + /// Data will be lost writing the specified format + DataWillBeLost = -16, + /// Cannot create destination format + CannotCreateFormat = -17, + /// Error writing data + WriteError = -18, + /// Argument expected a directory, but found a file + ExpectedDirectory = -19, + /// Argument expected a file, but found a directory + ExpectedFile = -20, + /// Cannot open device + CannotOpenDevice = -21, + /// The specified operation requires administrative privileges + NotEnoughPermissions = -22 + } +} \ No newline at end of file diff --git a/DiscImageChef/Commands/Analyze.cs b/DiscImageChef/Commands/Analyze.cs index 2e9a8a557..9b9cd9105 100644 --- a/DiscImageChef/Commands/Analyze.cs +++ b/DiscImageChef/Commands/Analyze.cs @@ -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 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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/Benchmark.cs b/DiscImageChef/Commands/Benchmark.cs index fd2363dc0..a2df9d927 100644 --- a/DiscImageChef/Commands/Benchmark.cs +++ b/DiscImageChef/Commands/Benchmark.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/Checksum.cs b/DiscImageChef/Commands/Checksum.cs index c60301a0c..52f9bf0ac 100644 --- a/DiscImageChef/Commands/Checksum.cs +++ b/DiscImageChef/Commands/Checksum.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/Compare.cs b/DiscImageChef/Commands/Compare.cs index 1a9a61de4..ad0cd7bda 100644 --- a/DiscImageChef/Commands/Compare.cs +++ b/DiscImageChef/Commands/Compare.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/Configure.cs b/DiscImageChef/Commands/Configure.cs index 79a36b910..bf0a3b8e9 100644 --- a/DiscImageChef/Commands/Configure.cs +++ b/DiscImageChef/Commands/Configure.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/ConvertImage.cs b/DiscImageChef/Commands/ConvertImage.cs index 585b54f6f..d6cae6151 100644 --- a/DiscImageChef/Commands/ConvertImage.cs +++ b/DiscImageChef/Commands/ConvertImage.cs @@ -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 candidates = new List(); @@ -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; diff --git a/DiscImageChef/Commands/CreateSidecar.cs b/DiscImageChef/Commands/CreateSidecar.cs index cdb84bcd5..53d9ee73a 100644 --- a/DiscImageChef/Commands/CreateSidecar.cs +++ b/DiscImageChef/Commands/CreateSidecar.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/Decode.cs b/DiscImageChef/Commands/Decode.cs index 79e432755..b6e7ffe1c 100644 --- a/DiscImageChef/Commands/Decode.cs +++ b/DiscImageChef/Commands/Decode.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/DeviceInfo.cs b/DiscImageChef/Commands/DeviceInfo.cs index c16fd63da..65152044b 100644 --- a/DiscImageChef/Commands/DeviceInfo.cs +++ b/DiscImageChef/Commands/DeviceInfo.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/DeviceReport.cs b/DiscImageChef/Commands/DeviceReport.cs index 5ca26cc28..ca805ea70 100644 --- a/DiscImageChef/Commands/DeviceReport.cs +++ b/DiscImageChef/Commands/DeviceReport.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/DumpMedia.cs b/DiscImageChef/Commands/DumpMedia.cs index 6d8efb1b9..e02ef2faa 100644 --- a/DiscImageChef/Commands/DumpMedia.cs +++ b/DiscImageChef/Commands/DumpMedia.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/Entropy.cs b/DiscImageChef/Commands/Entropy.cs index df2199cc4..2f2888128 100644 --- a/DiscImageChef/Commands/Entropy.cs +++ b/DiscImageChef/Commands/Entropy.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/ExtractFiles.cs b/DiscImageChef/Commands/ExtractFiles.cs index ebe454e3d..502035d88 100644 --- a/DiscImageChef/Commands/ExtractFiles.cs +++ b/DiscImageChef/Commands/ExtractFiles.cs @@ -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 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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/Formats.cs b/DiscImageChef/Commands/Formats.cs index c23e2e2f9..ec4f5ca37 100644 --- a/DiscImageChef/Commands/Formats.cs +++ b/DiscImageChef/Commands/Formats.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/Gui.cs b/DiscImageChef/Commands/Gui.cs index d22b99646..a95b9b0be 100644 --- a/DiscImageChef/Commands/Gui.cs +++ b/DiscImageChef/Commands/Gui.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/ImageInfo.cs b/DiscImageChef/Commands/ImageInfo.cs index 649704954..4ea59388a 100644 --- a/DiscImageChef/Commands/ImageInfo.cs +++ b/DiscImageChef/Commands/ImageInfo.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/ListDevices.cs b/DiscImageChef/Commands/ListDevices.cs index 3bfa29dda..cf1e085a0 100644 --- a/DiscImageChef/Commands/ListDevices.cs +++ b/DiscImageChef/Commands/ListDevices.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/ListEncodings.cs b/DiscImageChef/Commands/ListEncodings.cs index deb205bd5..6739f89f7 100644 --- a/DiscImageChef/Commands/ListEncodings.cs +++ b/DiscImageChef/Commands/ListEncodings.cs @@ -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 diff --git a/DiscImageChef/Commands/ListOptions.cs b/DiscImageChef/Commands/ListOptions.cs index 9c1c8ed25..67d5add1e 100644 --- a/DiscImageChef/Commands/ListOptions.cs +++ b/DiscImageChef/Commands/ListOptions.cs @@ -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) diff --git a/DiscImageChef/Commands/Ls.cs b/DiscImageChef/Commands/Ls.cs index 931034931..d536d27dc 100644 --- a/DiscImageChef/Commands/Ls.cs +++ b/DiscImageChef/Commands/Ls.cs @@ -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 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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/MediaInfo.cs b/DiscImageChef/Commands/MediaInfo.cs index 9de055a29..4c2cb9471 100644 --- a/DiscImageChef/Commands/MediaInfo.cs +++ b/DiscImageChef/Commands/MediaInfo.cs @@ -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() diff --git a/DiscImageChef/Commands/MediaScan.cs b/DiscImageChef/Commands/MediaScan.cs index 4bcdff841..7c5bc30d0 100644 --- a/DiscImageChef/Commands/MediaScan.cs +++ b/DiscImageChef/Commands/MediaScan.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/PrintHex.cs b/DiscImageChef/Commands/PrintHex.cs index 5a636b6bc..0a45b808b 100644 --- a/DiscImageChef/Commands/PrintHex.cs +++ b/DiscImageChef/Commands/PrintHex.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/Statistics.cs b/DiscImageChef/Commands/Statistics.cs index 4a1166614..a4b0146e8 100644 --- a/DiscImageChef/Commands/Statistics.cs +++ b/DiscImageChef/Commands/Statistics.cs @@ -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; } } } \ No newline at end of file diff --git a/DiscImageChef/Commands/Update.cs b/DiscImageChef/Commands/Update.cs index 64189251f..b344da9cb 100644 --- a/DiscImageChef/Commands/Update.cs +++ b/DiscImageChef/Commands/Update.cs @@ -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 arguments) { - if(masterDbUpdate) return 0; + if(masterDbUpdate) return (int)ErrorNumber.NoError; List 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) diff --git a/DiscImageChef/Commands/Verify.cs b/DiscImageChef/Commands/Verify.cs index b97dc4785..e1c41a7e2 100644 --- a/DiscImageChef/Commands/Verify.cs +++ b/DiscImageChef/Commands/Verify.cs @@ -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; } } } \ No newline at end of file