Files
Aaru/DiscImageChef/Main.cs

212 lines
11 KiB
C#
Raw Normal View History

/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : Main.cs
Version : 1.0
Author(s) : Natalia Portillo
Component : Main program loop.
Revision : $Revision$
Last change by : $Author$
Date : $Date$
--[ Description ] ----------------------------------------------------------
Contains the main program loop.
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2011-2014 Claunia.com
****************************************************************************/
//$Id$
using System;
using System.Collections.Generic;
using DiscImageChef.ImagePlugins;
using DiscImageChef.PartPlugins;
using DiscImageChef.Plugins;
using System.Reflection;
using DiscImageChef.Console;
namespace DiscImageChef
{
class MainClass
{
public static void Main(string[] args)
{
string invokedVerb = "";
object invokedVerbInstance = null;
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);
}
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;
DicConsole.WriteLineEvent += System.Console.WriteLine;
DicConsole.WriteEvent += System.Console.Write;
DicConsole.ErrorWriteLineEvent += System.Console.Error.WriteLine;
DicConsole.WriteLine("{0} {1}", AssemblyTitle, AssemblyVersion);
DicConsole.WriteLine("{0}", AssemblyCopyright);
DicConsole.WriteLine();
switch (invokedVerb)
{
case "analyze":
AnalyzeSubOptions AnalyzeOptions = (AnalyzeSubOptions)invokedVerbInstance;
if (AnalyzeOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (AnalyzeOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.Analyze.doAnalyze(AnalyzeOptions);
break;
case "compare":
CompareSubOptions CompareOptions = (CompareSubOptions)invokedVerbInstance;
if (CompareOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (CompareOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.Compare.doCompare(CompareOptions);
break;
case "checksum":
ChecksumSubOptions ChecksumOptions = (ChecksumSubOptions)invokedVerbInstance;
if (ChecksumOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (ChecksumOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.Checksum.doChecksum(ChecksumOptions);
break;
2015-05-19 06:04:21 +01:00
case "entropy":
EntropySubOptions entropyOptions = (EntropySubOptions)invokedVerbInstance;
if (entropyOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (entropyOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
2015-05-19 06:04:21 +01:00
Commands.Entropy.doEntropy(entropyOptions);
break;
case "verify":
VerifySubOptions VerifyOptions = (VerifySubOptions)invokedVerbInstance;
if (VerifyOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (VerifyOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.Verify.doVerify(VerifyOptions);
break;
case "printhex":
PrintHexSubOptions PrintHexOptions = (PrintHexSubOptions)invokedVerbInstance;
if (PrintHexOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (PrintHexOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.PrintHex.doPrintHex(PrintHexOptions);
break;
2014-09-01 03:44:39 +01:00
case "decode":
DecodeSubOptions DecodeOptions = (DecodeSubOptions)invokedVerbInstance;
if (DecodeOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (DecodeOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
2014-09-01 03:44:39 +01:00
Commands.Decode.doDecode(DecodeOptions);
break;
case "formats":
2014-06-16 01:50:49 +01:00
FormatsSubOptions FormatsOptions = (FormatsSubOptions)invokedVerbInstance;
if (FormatsOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (FormatsOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.Formats.ListFormats(FormatsOptions);
break;
case "device-info":
DeviceInfoSubOptions DeviceInfoOptions = (DeviceInfoSubOptions)invokedVerbInstance;
if (DeviceInfoOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (DeviceInfoOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.DeviceInfo.doDeviceInfo(DeviceInfoOptions);
break;
case "media-info":
MediaInfoSubOptions MediaInfoOptions = (MediaInfoSubOptions)invokedVerbInstance;
if (MediaInfoOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (MediaInfoOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.MediaInfo.doMediaInfo(MediaInfoOptions);
break;
case "benchmark":
BenchmarkSubOptions BenchmarkOptions = (BenchmarkSubOptions)invokedVerbInstance;
if (BenchmarkOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (BenchmarkOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.Benchmark.doBenchmark(BenchmarkOptions);
break;
* DiscImageChef.Metadata/DiskType.cs: * DiscImageChef.Metadata/DiscImageChef.Metadata.csproj: Added method to convert DiskType to disk type and subtype strings. * DiscImageChef.DiscImages/CDRWin.cs: Added extra track information. Corrected ReadLong for CD+G, subchannel should never come along main channel on reading. * DiscImageChef.DiscImages/ImagePlugin.cs: Added extra track information. Added audio media type. * DiscImageChef.DiscImages/Nero.cs: Added extra track information. * DiscImageChef.DiscImages/ZZZRawImage.cs: Added support for ReadLong and a single track and session for optical discs. * DiscImageChef.Filesystems/FFS.cs: * DiscImageChef.Filesystems/BFS.cs: * DiscImageChef.Filesystems/ODS.cs: * DiscImageChef.Filesystems/SysV.cs: * DiscImageChef.Filesystems/extFS.cs: * DiscImageChef.Filesystems/ProDOS.cs: * DiscImageChef.Filesystems/ext2FS.cs: * DiscImageChef.Filesystems/LisaFS.cs: * DiscImageChef.Filesystems/MinixFS.cs: * DiscImageChef.Filesystems/UNIXBFS.cs: * DiscImageChef.Filesystems/AppleMFS.cs: * DiscImageChef.Filesystems/PCEngine.cs: * DiscImageChef.Filesystems/AppleHFS.cs: * DiscImageChef.Filesystems/AmigaDOS.cs: * DiscImageChef.Filesystems/AppleHFSPlus.cs: Completed XML information. * DiscImageChef.Filesystems/ISO9660.cs: Corrected fail in Sega CD IP.BIN decoding. Corrected IP.BIN date decoding. Trim spaces at end of Volume Descriptor string fields. Completed XML information. * DiscImageChef/Commands/Checksum.cs: Checking memory usage on each step makes checksum calculation abismally slower. Removed. * DiscImageChef/Main.cs: * DiscImageChef/Options.cs: * DiscImageChef/DiscImageChef.csproj: * DiscImageChef/Commands/CreateSidecar.cs: Added method for creating CICM Metadata XML sidecar.
2015-12-06 05:09:31 +00:00
case "create-sidecar":
CreateSidecarSubOptions CreateSidecarOptions = (CreateSidecarSubOptions)invokedVerbInstance;
if (CreateSidecarOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (CreateSidecarOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.CreateSidecar.doSidecar(CreateSidecarOptions);
break;
case "media-scan":
MediaScanSubOptions MediaScanOptions = (MediaScanSubOptions)invokedVerbInstance;
if (MediaScanOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (MediaScanOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.MediaScan.doMediaScan(MediaScanOptions);
break;
* DiscImageChef.CommonTypes/MediaTypeFromSCSI.cs: * DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj: Added method to calculate MediaType from SCSI parameters (mode, density, medium type, device type, etc). * DiscImageChef.Metadata/DeviceReport.cs: Added command to guess drive and media parameters and output an XML report of them. * DiscImageChef/Commands/DeviceReport.cs: * DiscImageChef.Metadata/DiscImageChef.Metadata.csproj: Added command to guess drive and media parameters and output an XML report of them. * DiscImageChef/Commands/DumpMedia.cs: Added preliminary command to dump media. Only SCSI for now. CDs and tapes are not supported. Errors are blalanty ignored. Options are incomplete. Not yet usable. * DiscImageChef/Core/Checksum.cs: * DiscImageChef/Commands/CreateSidecar.cs: Moved checksum generation to a separate class. * CICMMetadata: Added support for ADIP. * DiscImageChef.CommonTypes/MediaType.cs: Added parameters of UDO media. Moved DataPlay outside of Iomega, as it's not from that manufacturer. Added missing Exatape media and corrected 160m XL one. Added SyJet media. Added all ECMA defined magneto-optical (sectors calculated from specifications, unchecked). Added PD media. Added Imation 320Gb RDX. Added generic USB flash drives. * DiscImageChef.Decoders/SCSI/Enums.cs: Make enumerations public. * DiscImageChef.Decoders/SCSI/Inquiry.cs: * DiscImageChef.Devices/Device/Constructor.cs: Trim space padded strings on SCSI INQUIRY. * DiscImageChef.Devices/Device/ScsiCommands/MMC.cs: Added PREVENT ALLOW MEDIUM REMOVAL. Added START STOP UNIT. * DiscImageChef.Devices/Device/ScsiCommands/NEC.cs: Rename NEC methods. * DiscImageChef.Devices/Device/ScsiCommands/Pioneer.cs: Corrected Pioneer transfer length calculation. * DiscImageChef.Devices/Device/ScsiCommands/Plextor.cs: Renamed Plextor methods. * DiscImageChef.Devices/Device/ScsiCommands/SPC.cs: Renamed SSC PREVENT ALLOW MEDIUM REMOVAL to uncollide with MMC same name but different command. * DiscImageChef.Devices/DiscImageChef.Devices.csproj: Set platform target to x86 (does it really matter?). * DiscImageChef.Devices/Linux/Command.cs: Reduced allocation for readlink() to current kernel MAX_PATH. * DiscImageChef.Devices/Linux/Enums.cs: Modified Linux ioctl to 32-bit. Works on 64-bit also. Solves commands not working on 32-bit environments. * DiscImageChef.DiscImages/ZZZRawImage.cs: Changed ECMA-184 and ECMA-183 enums. * DiscImageChef.Metadata/Dimensions.cs: Added all ECMA defined magneto-opticals. Added PD media. Added 320Gb RDX. Corrected Exatape 160m XL. Added Exatape 22m and 28m. * DiscImageChef.Metadata/MediaType.cs: Added 356mm magneto-optical media. Changed ECMA-184 and ECMA-183 enums. Added USB generic flash drive. * DiscImageChef/Commands/DeviceInfo.cs: Corrected SCSI INQUIRY naming. Corrected SCSI MODE SENSE (6) parameters. Reduced SCSI MODE SENSE timeout, some devices just get stuck with unsupported MODE SENSE commanda and must be left to timeout. Changed FUJITSU vendor string comparison. * DiscImageChef/Commands/MediaInfo.cs: Added method to calculate MediaType from SCSI parameters (mode, density, medium type, device type, etc). Changed some error WriteLine() to debug ones. Too much verbosity. Added DVD media type decoding from PFI. Found a drive that dumps ADIP, enabling it again (not decoded). * DiscImageChef/Commands/MediaScan.cs: Added option to generate ImgBurn compatible log to media-scan command. * DiscImageChef/DiscImageChef.csproj: Moved checksum generation to a separate class. Added command to guess drive and media parameters and output an XML report of them. Added preliminary command to dump media. Only SCSI for now. CDs and tapes are not supported. Errors are blalanty ignored. Options are incomplete. Not yet usable. * DiscImageChef/Main.cs: Added command to guess drive and media parameters and output an XML report of them. Added preliminary command to dump media. Only SCSI for now. CDs and tapes are not supported. Errors are blalanty ignored. Options are incomplete. Not yet usable. * DiscImageChef/Options.cs: Added command to guess drive and media parameters and output an XML report of them. Added preliminary command to dump media. Only SCSI for now. CDs and tapes are not supported. Errors are blalanty ignored. Options are incomplete. Not yet usable. Added option to generate ImgBurn compatible log to media-scan command.
2016-01-31 08:05:56 +00:00
case "dump-media":
DumpMediaSubOptions DumpMediaOptions = (DumpMediaSubOptions)invokedVerbInstance;
if (DumpMediaOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (DumpMediaOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.DumpMedia.doDumpMedia(DumpMediaOptions);
break;
case "device-report":
DeviceReportSubOptions DeviceReportOptions = (DeviceReportSubOptions)invokedVerbInstance;
if (DeviceReportOptions.Debug)
DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
if (DeviceReportOptions.Verbose)
DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
Commands.DeviceReport.doDeviceReport(DeviceReportOptions);
break;
default:
throw new ArgumentException("Should never arrive here!");
}
}
}
}