/*************************************************************************** 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 . ---------------------------------------------------------------------------- Copyright (C) 2011-2014 Claunia.com ****************************************************************************/ //$Id$ using System; using System.Reflection; using DiscImageChef.Console; using DiscImageChef.Settings; using CommandLine; namespace DiscImageChef { class MainClass { public static void Main(string[] args) { DicConsole.WriteLineEvent += System.Console.WriteLine; DicConsole.WriteEvent += System.Console.Write; DicConsole.ErrorWriteLineEvent += System.Console.Error.WriteLine; Settings.Settings.LoadSettings(); Core.Statistics.LoadStats(); Parser.Default.ParseArguments(args) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.Analyze.doAnalyze(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.Compare.doCompare(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.Checksum.doChecksum(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.Entropy.doEntropy(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.Verify.doVerify(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.PrintHex.doPrintHex(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.Decode.doDecode(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.DeviceInfo.doDeviceInfo(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.MediaInfo.doMediaInfo(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.MediaScan.doMediaScan(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.Formats.ListFormats(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.Benchmark.doBenchmark(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.CreateSidecar.doSidecar(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.DumpMedia.doDumpMedia(opts); }) .WithParsed(opts => { if(opts.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine; if(opts.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine; PrintCopyright(); Commands.DeviceReport.doDeviceReport(opts); }) .WithParsed(opts => { PrintCopyright(); Commands.Configure.doConfigure(); }) .WithParsed(opts => { PrintCopyright(); Commands.Statistics.showStats(); }) .WithNotParsed(errs => Environment.Exit(1)); Core.Statistics.SaveStats(); } static void PrintCopyright() { 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.WriteLine("{0} {1}", AssemblyTitle, AssemblyVersion); DicConsole.WriteLine("{0}", AssemblyCopyright); DicConsole.WriteLine(); } } }