2016-07-28 18:13:49 +01:00
|
|
|
// /***************************************************************************
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Main.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Main program loop.
|
|
|
|
|
//
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
// ****************************************************************************/
|
2014-04-17 19:58:14 +00:00
|
|
|
|
2011-03-03 18:34:33 +00:00
|
|
|
using System;
|
2020-01-02 04:09:39 +00:00
|
|
|
using System.CommandLine;
|
|
|
|
|
using System.CommandLine.Invocation;
|
2019-01-02 04:05:51 +00:00
|
|
|
using System.IO;
|
2019-12-07 17:34:38 +00:00
|
|
|
using System.Linq;
|
2014-06-16 00:41:47 +01:00
|
|
|
using System.Reflection;
|
2019-07-19 14:25:33 +01:00
|
|
|
using System.Text;
|
2018-11-16 00:17:52 +00:00
|
|
|
using System.Threading.Tasks;
|
2017-12-21 14:30:38 +00:00
|
|
|
using DiscImageChef.Commands;
|
2020-01-03 17:41:19 +00:00
|
|
|
using DiscImageChef.Commands.Device;
|
|
|
|
|
using DiscImageChef.Commands.Filesystem;
|
|
|
|
|
using DiscImageChef.Commands.Image;
|
|
|
|
|
using DiscImageChef.Commands.Media;
|
2017-12-19 19:33:46 +00:00
|
|
|
using DiscImageChef.Console;
|
2019-01-05 16:59:23 +00:00
|
|
|
using DiscImageChef.Core;
|
2018-12-21 03:17:35 +00:00
|
|
|
using DiscImageChef.Database;
|
2018-06-22 08:08:38 +01:00
|
|
|
using DiscImageChef.Settings;
|
2018-12-21 03:17:35 +00:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2011-03-03 18:34:33 +00:00
|
|
|
|
2014-06-15 23:39:34 +01:00
|
|
|
namespace DiscImageChef
|
2011-03-03 18:34:33 +00:00
|
|
|
{
|
2019-10-12 19:26:28 +01:00
|
|
|
internal class MainClass
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
static string _assemblyCopyright;
|
|
|
|
|
static string _assemblyTitle;
|
|
|
|
|
static AssemblyInformationalVersionAttribute _assemblyVersion;
|
2019-01-05 16:59:23 +00:00
|
|
|
|
2018-08-26 14:04:09 +01:00
|
|
|
[STAThread]
|
2019-01-05 16:59:23 +00:00
|
|
|
public static int Main(string[] args)
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
object[] attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
|
|
|
|
|
_assemblyTitle = ((AssemblyTitleAttribute)attributes[0]).Title;
|
|
|
|
|
attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
|
|
|
|
|
|
|
|
|
_assemblyVersion =
|
2019-01-05 16:59:23 +00:00
|
|
|
Attribute.GetCustomAttribute(typeof(MainClass).Assembly, typeof(AssemblyInformationalVersionAttribute))
|
|
|
|
|
as AssemblyInformationalVersionAttribute;
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
_assemblyCopyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
|
|
|
|
|
|
|
|
|
DicConsole.WriteLineEvent += System.Console.WriteLine;
|
|
|
|
|
DicConsole.WriteEvent += System.Console.Write;
|
2015-10-18 22:04:03 +01:00
|
|
|
DicConsole.ErrorWriteLineEvent += System.Console.Error.WriteLine;
|
|
|
|
|
|
2019-01-01 05:43:32 +00:00
|
|
|
Settings.Settings.LoadSettings();
|
|
|
|
|
|
2019-10-12 19:26:28 +01:00
|
|
|
var ctx = DicContext.Create(Settings.Settings.LocalDbPath);
|
2018-12-21 03:17:35 +00:00
|
|
|
ctx.Database.Migrate();
|
|
|
|
|
ctx.SaveChanges();
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
bool masterDbUpdate = false;
|
|
|
|
|
|
|
|
|
|
if(!File.Exists(Settings.Settings.MasterDbPath))
|
2019-01-02 04:05:51 +00:00
|
|
|
{
|
|
|
|
|
masterDbUpdate = true;
|
2019-01-19 15:14:54 +00:00
|
|
|
UpdateCommand.DoUpdate(true);
|
2019-01-02 04:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
var masterContext = DicContext.Create(Settings.Settings.MasterDbPath);
|
2019-12-07 17:34:38 +00:00
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
if(masterContext.Database.GetPendingMigrations().Any())
|
2019-12-07 17:34:38 +00:00
|
|
|
{
|
|
|
|
|
DicConsole.WriteLine("New database version, updating...");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.Delete(Settings.Settings.MasterDbPath);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.ErrorWriteLine("Exception trying to remove old database version, cannot continue...");
|
|
|
|
|
DicConsole.ErrorWriteLine("Please manually remove file at {0}", Settings.Settings.MasterDbPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateCommand.DoUpdate(true);
|
|
|
|
|
}
|
2019-01-02 04:05:51 +00:00
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
if((args.Length < 1 || args[0].ToLowerInvariant() != "gui") &&
|
|
|
|
|
Settings.Settings.Current.GdprCompliance < DicSettings.GdprLevel)
|
2019-01-19 15:14:54 +00:00
|
|
|
new ConfigureCommand(true, true).Invoke(args);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
Statistics.LoadStats();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
if(Settings.Settings.Current.Stats != null &&
|
|
|
|
|
Settings.Settings.Current.Stats.ShareStats)
|
|
|
|
|
Task.Run(Statistics.SubmitStats);
|
2019-01-09 12:29:19 +00:00
|
|
|
|
2019-07-19 14:25:33 +01:00
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
Statistics.SaveStats();
|
2019-01-09 12:29:19 +00:00
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
var rootCommand = new RootCommand
|
2019-01-09 12:29:19 +00:00
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
new Option(new[]
|
|
|
|
|
{
|
|
|
|
|
"--verbose", "-v"
|
|
|
|
|
}, "Shows verbose output.")
|
|
|
|
|
{
|
|
|
|
|
Argument = new Argument<bool>(() => false)
|
|
|
|
|
},
|
|
|
|
|
new Option(new[]
|
|
|
|
|
{
|
|
|
|
|
"--debug", "-d"
|
|
|
|
|
}, "Shows debug output from plugins.")
|
|
|
|
|
{
|
|
|
|
|
Argument = new Argument<bool>(() => false)
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-01-05 16:59:23 +00:00
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
rootCommand.Description =
|
|
|
|
|
$"{_assemblyTitle} {_assemblyVersion?.InformationalVersion}\n{_assemblyCopyright}";
|
|
|
|
|
|
2020-01-03 17:41:19 +00:00
|
|
|
rootCommand.AddCommand(new DatabaseFamily(masterDbUpdate));
|
|
|
|
|
rootCommand.AddCommand(new DeviceFamily());
|
|
|
|
|
rootCommand.AddCommand(new FilesystemFamily());
|
|
|
|
|
rootCommand.AddCommand(new ImageFamily());
|
|
|
|
|
rootCommand.AddCommand(new MediaFamily());
|
|
|
|
|
|
2020-01-02 04:09:39 +00:00
|
|
|
rootCommand.AddCommand(new ConfigureCommand(false, false));
|
|
|
|
|
rootCommand.AddCommand(new FormatsCommand());
|
|
|
|
|
rootCommand.AddCommand(new ListEncodingsCommand());
|
|
|
|
|
rootCommand.AddCommand(new ListNamespacesCommand());
|
|
|
|
|
rootCommand.AddCommand(new RemoteCommand());
|
|
|
|
|
|
|
|
|
|
return rootCommand.Invoke(args);
|
2014-06-16 00:41:47 +01:00
|
|
|
}
|
2016-07-19 22:28:01 +01:00
|
|
|
|
2019-01-05 16:59:23 +00:00
|
|
|
internal static void PrintCopyright()
|
2016-07-19 22:28:01 +01:00
|
|
|
{
|
2020-01-02 04:09:39 +00:00
|
|
|
DicConsole.WriteLine("{0} {1}", _assemblyTitle, _assemblyVersion?.InformationalVersion);
|
|
|
|
|
DicConsole.WriteLine("{0}", _assemblyCopyright);
|
2016-07-19 22:28:01 +01:00
|
|
|
DicConsole.WriteLine();
|
|
|
|
|
}
|
2014-04-14 02:29:13 +00:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|