mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
* DiscImageChef/Options.cs:
Added currently implemented and in-process of implementing options. * DiscImageChef/AssemblyInfo.cs: Completed AssemblyInfo for command line parser to build help upon it. * DiscImageChef/DiscImageChef.csproj: Add gsscoder's Command Line Parser Library 1.9.71.2. * DiscImageChef/Main.cs: Moved commands to separete functions, use command line parser
This commit is contained in:
@@ -41,12 +41,12 @@ using System.Reflection;
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("DiscImageChef")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyTitle("The Disc Image Chef")]
|
||||
[assembly: AssemblyDescription("The Disc Image Chef")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyCompany("Claunia.com")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2011-2014 Natalia Portillo")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
@@ -54,7 +54,7 @@ using System.Reflection;
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
@@ -77,6 +77,7 @@
|
||||
<Compile Include="ArrayFill.cs" />
|
||||
<Compile Include="PrintHex.cs" />
|
||||
<Compile Include="ImagePlugins\ZZZRawImage.cs" />
|
||||
<Compile Include="Options.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
||||
@@ -41,48 +41,84 @@ using System.Collections.Generic;
|
||||
using DiscImageChef.ImagePlugins;
|
||||
using DiscImageChef.PartPlugins;
|
||||
using DiscImageChef.Plugins;
|
||||
using System.Reflection;
|
||||
|
||||
namespace DiscImageChef
|
||||
{
|
||||
class MainClass
|
||||
{
|
||||
static PluginBase plugins;
|
||||
public static bool chkPartitions;
|
||||
public static bool chkFilesystems;
|
||||
public static bool isDebug;
|
||||
public static bool isVerbose;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
plugins = new PluginBase();
|
||||
|
||||
chkPartitions = true;
|
||||
chkFilesystems = true;
|
||||
// RELEASE
|
||||
isDebug = false;
|
||||
// DEBUG
|
||||
//isDebug = true;
|
||||
string invokedVerb = "";
|
||||
object invokedVerbInstance = null;
|
||||
|
||||
Console.WriteLine("Filesystem Identifier and Checker");
|
||||
Console.WriteLine("Copyright (C) 2011-2014 Natalia Portillo");
|
||||
var options = new Options();
|
||||
if (!CommandLine.Parser.Default.ParseArguments(args, options,
|
||||
(verb, subOptions) =>
|
||||
{
|
||||
// if parsing succeeds the verb name and correct instance
|
||||
// will be passed to onVerbCommand delegate (string,object)
|
||||
invokedVerb = verb;
|
||||
invokedVerbInstance = subOptions;
|
||||
}))
|
||||
{
|
||||
Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);
|
||||
}
|
||||
|
||||
// For debug
|
||||
if (isDebug)
|
||||
object[] attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
|
||||
string AssemblyTitle = ((AssemblyTitleAttribute) attributes[0]).Title;
|
||||
attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
||||
Version AssemblyVersion = typeof(MainClass).Assembly.GetName().Version;
|
||||
string AssemblyCopyright = ((AssemblyCopyrightAttribute) attributes[0]).Copyright;
|
||||
|
||||
Console.WriteLine("{0} {1}", AssemblyTitle, AssemblyVersion);
|
||||
Console.WriteLine("{0}", AssemblyCopyright);
|
||||
Console.WriteLine();
|
||||
|
||||
switch (invokedVerb)
|
||||
{
|
||||
plugins.RegisterAllPlugins();
|
||||
Runner("");
|
||||
case "analyze":
|
||||
AnalyzeSubOptions AnalyzeOptions = (AnalyzeSubOptions)invokedVerbInstance;
|
||||
isDebug = AnalyzeOptions.Debug;
|
||||
isVerbose = AnalyzeOptions.Verbose;
|
||||
Analyze(AnalyzeOptions);
|
||||
break;
|
||||
case "compare":
|
||||
CompareSubOptions CompareOptions = (CompareSubOptions)invokedVerbInstance;
|
||||
isDebug = CompareOptions.Debug;
|
||||
isVerbose = CompareOptions.Verbose;
|
||||
Compare(CompareOptions);
|
||||
break;
|
||||
case "checksum":
|
||||
ChecksumSubOptions ChecksumOptions = (ChecksumSubOptions)invokedVerbInstance;
|
||||
isDebug = ChecksumOptions.Debug;
|
||||
isVerbose = ChecksumOptions.Verbose;
|
||||
Checksum(ChecksumOptions);
|
||||
break;
|
||||
case "verify":
|
||||
VerifySubOptions VerifyOptions = (VerifySubOptions)invokedVerbInstance;
|
||||
isDebug = VerifyOptions.Debug;
|
||||
isVerbose = VerifyOptions.Verbose;
|
||||
Verify(VerifyOptions);
|
||||
break;
|
||||
case "formats":
|
||||
ListFormats();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Should never arrive here!");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
Usage();
|
||||
}
|
||||
else if (args.Length == 1)
|
||||
|
||||
static void ListFormats()
|
||||
{
|
||||
plugins.RegisterAllPlugins();
|
||||
|
||||
if (args[0] == "--formats")
|
||||
{
|
||||
Console.WriteLine("Supported images:");
|
||||
foreach (KeyValuePair<string, ImagePlugin> kvp in plugins.ImagePluginsList)
|
||||
Console.WriteLine(kvp.Value.Name);
|
||||
@@ -95,40 +131,62 @@ namespace DiscImageChef
|
||||
foreach (KeyValuePair<string, PartPlugin> kvp in plugins.PartPluginsList)
|
||||
Console.WriteLine(kvp.Value.Name);
|
||||
}
|
||||
else
|
||||
Runner(args[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < args.Length - 1; i++)
|
||||
{
|
||||
switch (args[i])
|
||||
{
|
||||
case "--filesystems":
|
||||
chkFilesystems = true;
|
||||
chkPartitions = false;
|
||||
break;
|
||||
case "--partitions":
|
||||
chkFilesystems = false;
|
||||
chkPartitions = true;
|
||||
break;
|
||||
case "--all":
|
||||
chkFilesystems = true;
|
||||
chkPartitions = true;
|
||||
break;
|
||||
case "--debug":
|
||||
isDebug = true;
|
||||
break;
|
||||
|
||||
static void Compare(CompareSubOptions options)
|
||||
{
|
||||
if (isDebug)
|
||||
{
|
||||
Console.WriteLine("--debug={0}", options.Debug);
|
||||
Console.WriteLine("--verbose={0}", options.Verbose);
|
||||
Console.WriteLine("--input1={0}", options.InputFile1);
|
||||
Console.WriteLine("--input2={0}", options.InputFile2);
|
||||
}
|
||||
throw new NotImplementedException("Comparing not yet implemented.");
|
||||
}
|
||||
|
||||
Runner(args[args.Length - 1]);
|
||||
}
|
||||
static void Checksum(ChecksumSubOptions options)
|
||||
{
|
||||
if (isDebug)
|
||||
{
|
||||
Console.WriteLine("--debug={0}", options.Debug);
|
||||
Console.WriteLine("--verbose={0}", options.Verbose);
|
||||
Console.WriteLine("--separated-tracks={0}", options.SeparatedTracks);
|
||||
Console.WriteLine("--whole-disc={0}", options.WholeDisc);
|
||||
Console.WriteLine("--input={0}", options.InputFile);
|
||||
Console.WriteLine("--crc32={0}", options.DoCRC32);
|
||||
Console.WriteLine("--md5={0}", options.DoMD5);
|
||||
Console.WriteLine("--sha1={0}", options.DoSHA1);
|
||||
Console.WriteLine("--fuzzy={0}", options.DoFuzzy);
|
||||
}
|
||||
throw new NotImplementedException("Checksumming not yet implemented.");
|
||||
}
|
||||
|
||||
static void Runner(string filename)
|
||||
static void Verify(VerifySubOptions options)
|
||||
{
|
||||
if (isDebug)
|
||||
{
|
||||
Console.WriteLine("--debug={0}", options.Debug);
|
||||
Console.WriteLine("--verbose={0}", options.Verbose);
|
||||
Console.WriteLine("--input={0}", options.InputFile);
|
||||
Console.WriteLine("--verify-disc={0}", options.VerifyDisc);
|
||||
Console.WriteLine("--verify-sectors={0}", options.VerifySectors);
|
||||
}
|
||||
throw new NotImplementedException("Verifying not yet implemented.");
|
||||
}
|
||||
|
||||
static void Analyze(AnalyzeSubOptions options)
|
||||
{
|
||||
if (isDebug)
|
||||
{
|
||||
Console.WriteLine("--debug={0}", options.Debug);
|
||||
Console.WriteLine("--verbose={0}", options.Verbose);
|
||||
Console.WriteLine("--input={0}", options.InputFile);
|
||||
Console.WriteLine("--filesystems={0}", options.SearchForFilesystems);
|
||||
Console.WriteLine("--partitions={0}", options.SearchForPartitions);
|
||||
}
|
||||
|
||||
plugins.RegisterAllPlugins();
|
||||
|
||||
List<string> id_plugins;
|
||||
Plugin _plugin;
|
||||
string information;
|
||||
@@ -144,7 +202,7 @@ namespace DiscImageChef
|
||||
{
|
||||
if(_imageplugin.PluginUUID != new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
||||
{
|
||||
if (_imageplugin.IdentifyImage(filename))
|
||||
if (_imageplugin.IdentifyImage(options.InputFile))
|
||||
{
|
||||
_imageFormat = _imageplugin;
|
||||
Console.WriteLine("Image format identified by {0}.", _imageplugin.Name);
|
||||
@@ -160,7 +218,7 @@ namespace DiscImageChef
|
||||
{
|
||||
if(_imageplugin.PluginUUID == new Guid("12345678-AAAA-BBBB-CCCC-123456789000"))
|
||||
{
|
||||
if (_imageplugin.IdentifyImage(filename))
|
||||
if (_imageplugin.IdentifyImage(options.InputFile))
|
||||
{
|
||||
_imageFormat = _imageplugin;
|
||||
Console.WriteLine("Image format identified by {0}.", _imageplugin.Name);
|
||||
@@ -179,7 +237,7 @@ namespace DiscImageChef
|
||||
|
||||
try
|
||||
{
|
||||
if (!_imageFormat.OpenImage(filename))
|
||||
if (!_imageFormat.OpenImage(options.InputFile))
|
||||
{
|
||||
Console.WriteLine("Unable to open image format");
|
||||
Console.WriteLine("No error given");
|
||||
@@ -203,7 +261,7 @@ namespace DiscImageChef
|
||||
|
||||
Console.WriteLine("Image identified as {0}.", _imageFormat.GetImageFormat());
|
||||
|
||||
if (chkPartitions)
|
||||
if (options.SearchForPartitions)
|
||||
{
|
||||
List<Partition> partitions = new List<Partition>();
|
||||
string partition_scheme = "";
|
||||
@@ -231,7 +289,7 @@ namespace DiscImageChef
|
||||
{
|
||||
if(MainClass.isDebug)
|
||||
Console.WriteLine("DEBUG: No partitions found");
|
||||
if (!chkFilesystems)
|
||||
if (!options.SearchForFilesystems)
|
||||
{
|
||||
Console.WriteLine("No partitions founds, not searching for filesystems");
|
||||
return;
|
||||
@@ -254,7 +312,7 @@ namespace DiscImageChef
|
||||
Console.WriteLine("Partition description:");
|
||||
Console.WriteLine(partitions[i].PartitionDescription);
|
||||
|
||||
if (chkFilesystems)
|
||||
if (options.SearchForFilesystems)
|
||||
{
|
||||
Console.WriteLine("Identifying filesystem on partition");
|
||||
|
||||
@@ -333,18 +391,6 @@ namespace DiscImageChef
|
||||
id_plugins.Add(_plugin.Name.ToLower());
|
||||
}
|
||||
}
|
||||
|
||||
static void Usage()
|
||||
{
|
||||
Console.WriteLine("Usage: filesystemidandchk [options] file");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(" --formats List all suported partition and filesystems");
|
||||
Console.WriteLine(" --debug Show debug information");
|
||||
Console.WriteLine(" --partitions Check only for partitions");
|
||||
Console.WriteLine(" --filesystems Check only for filesystems");
|
||||
Console.WriteLine(" --all Check for partitions and filesystems (default)");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
120
DiscImageChef/Options.cs
Normal file
120
DiscImageChef/Options.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using CommandLine;
|
||||
using CommandLine.Text;
|
||||
|
||||
namespace DiscImageChef
|
||||
{
|
||||
abstract class CommonSubOptions
|
||||
{
|
||||
[Option('v', "verbose", DefaultValue = false, HelpText = "Shows verbose output")]
|
||||
public bool Verbose { get; set; }
|
||||
|
||||
[Option('d', "debug", DefaultValue = false, HelpText = "Shows debug output from plugins")]
|
||||
public bool Debug { get; set; }
|
||||
}
|
||||
|
||||
class AnalyzeSubOptions : CommonSubOptions
|
||||
{
|
||||
[Option('p', "partitions", DefaultValue = true,
|
||||
HelpText = "Searches and interprets partitions.")]
|
||||
public bool SearchForPartitions { get; set; }
|
||||
|
||||
[Option('f', "filesystems", DefaultValue = true,
|
||||
HelpText = "Searches and interprets partitions.")]
|
||||
public bool SearchForFilesystems { get; set; }
|
||||
|
||||
[Option('i', "input", Required = true, HelpText = "Disc image.")]
|
||||
public string InputFile { get; set; }
|
||||
}
|
||||
|
||||
class CompareSubOptions : CommonSubOptions
|
||||
{
|
||||
[Option("input1", Required = true, HelpText = "First disc image.")]
|
||||
public string InputFile1 { get; set; }
|
||||
|
||||
[Option("input2", Required = true, HelpText = "Second disc image.")]
|
||||
public string InputFile2 { get; set; }
|
||||
}
|
||||
|
||||
class ChecksumSubOptions : CommonSubOptions
|
||||
{
|
||||
[Option('t', "separated-tracks", DefaultValue = true,
|
||||
HelpText = "Checksums each track separately.")]
|
||||
public bool SeparatedTracks { get; set; }
|
||||
|
||||
[Option('w', "whole-disc", DefaultValue = true,
|
||||
HelpText = "Checksums the whole disc.")]
|
||||
public bool WholeDisc { get; set; }
|
||||
|
||||
[Option('c', "crc32", DefaultValue = true,
|
||||
HelpText = "Calculates CRC32.")]
|
||||
public bool DoCRC32 { get; set; }
|
||||
|
||||
[Option('m', "md5", DefaultValue = true,
|
||||
HelpText = "Calculates MD5.")]
|
||||
public bool DoMD5 { get; set; }
|
||||
|
||||
[Option('s', "sha1", DefaultValue = true,
|
||||
HelpText = "Calculates SHA1.")]
|
||||
public bool DoSHA1 { get; set; }
|
||||
|
||||
[Option('f', "fuzzy", DefaultValue = true,
|
||||
HelpText = "Calculates fuzzy hashing (ssdeep).")]
|
||||
public bool DoFuzzy { get; set; }
|
||||
|
||||
[Option('i', "input", Required = true, HelpText = "Disc image.")]
|
||||
public string InputFile { get; set; }
|
||||
}
|
||||
|
||||
class VerifySubOptions : CommonSubOptions
|
||||
{
|
||||
[Option('w', "verify-disc", DefaultValue = true,
|
||||
HelpText = "Verify disc image if supported.")]
|
||||
public bool VerifyDisc { get; set; }
|
||||
|
||||
[Option('s', "verify-sectors", DefaultValue = true,
|
||||
HelpText = "Verify all sectors if supported.")]
|
||||
public bool VerifySectors { get; set; }
|
||||
|
||||
[Option('i', "input", Required = true, HelpText = "Disc image.")]
|
||||
public string InputFile { get; set; }
|
||||
}
|
||||
|
||||
class FormatsSubOptions
|
||||
{
|
||||
}
|
||||
|
||||
class Options
|
||||
{
|
||||
public Options()
|
||||
{
|
||||
AnalyzeVerb = new AnalyzeSubOptions();
|
||||
CompareVerb = new CompareSubOptions();
|
||||
ChecksumVerb = new ChecksumSubOptions();
|
||||
VerifyVerb = new VerifySubOptions();
|
||||
FormatsVerb = new FormatsSubOptions();
|
||||
}
|
||||
|
||||
[VerbOption("analyze", HelpText = "Analyzes a disc image and searches for partitions and/or filesystems.")]
|
||||
public AnalyzeSubOptions AnalyzeVerb { get; set; }
|
||||
|
||||
[VerbOption("compare", HelpText = "Compares two disc images.")]
|
||||
public CompareSubOptions CompareVerb { get; set; }
|
||||
|
||||
[VerbOption("checksum", HelpText = "Checksums an image.")]
|
||||
public ChecksumSubOptions ChecksumVerb { get; set; }
|
||||
|
||||
[VerbOption("verify", HelpText = "Verifies a disc image integrity, and if supported, sector integrity.")]
|
||||
public VerifySubOptions VerifyVerb { get; set; }
|
||||
|
||||
[VerbOption("formats", HelpText = "Lists all supported disc images, partition schemes and file systems.")]
|
||||
public FormatsSubOptions FormatsVerb { get; set; }
|
||||
|
||||
[HelpVerbOption]
|
||||
public string DoHelpForVerb(string verbName)
|
||||
{
|
||||
return HelpText.AutoBuild(this, verbName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user