コード例 #1
0
ファイル: Main.cs プロジェクト: paulyc/Aaru
        public static int Main(string[] args)
        {
            object[] attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
            _assemblyTitle = ((AssemblyTitleAttribute)attributes[0]).Title;
            attributes     = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);

            _assemblyVersion =
                Attribute.GetCustomAttribute(typeof(MainClass).Assembly, typeof(AssemblyInformationalVersionAttribute))
                as AssemblyInformationalVersionAttribute;

            _assemblyCopyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;

            if (args.Length == 1 &&
                args[0].ToLowerInvariant() == "gui")
            {
                return(Gui.Main.Start(args));
            }

            AaruConsole.WriteLineEvent      += System.Console.WriteLine;
            AaruConsole.WriteEvent          += System.Console.Write;
            AaruConsole.ErrorWriteLineEvent += System.Console.Error.WriteLine;

            Settings.Settings.LoadSettings();

            AaruContext ctx;

            try
            {
                ctx = AaruContext.Create(Settings.Settings.LocalDbPath);
                ctx.Database.Migrate();
            }
            catch (NotSupportedException)
            {
                File.Delete(Settings.Settings.LocalDbPath);
                ctx = AaruContext.Create(Settings.Settings.LocalDbPath);
                ctx.Database.EnsureCreated();

                ctx.Database.
                ExecuteSqlRaw("CREATE TABLE IF NOT EXISTS \"__EFMigrationsHistory\" (\"MigrationId\" TEXT PRIMARY KEY, \"ProductVersion\" TEXT)");

                foreach (string migration in ctx.Database.GetPendingMigrations())
                {
                    ctx.Database.
                    ExecuteSqlRaw($"INSERT INTO \"__EFMigrationsHistory\" (MigrationId, ProductVersion) VALUES ('{migration}', '0.0.0')");
                }

                ctx.SaveChanges();
            }

            // Remove duplicates
            foreach (var duplicate in ctx.SeenDevices.AsEnumerable() !.GroupBy(a => new
            {
                a.Manufacturer,
                a.Model,
                a.Revision,
                a.Bus
            }).Where(a => a.Count() > 1).Distinct().Select(a => a.Key))
            {
                ctx.RemoveRange(ctx.SeenDevices !.
                                Where(d => d.Manufacturer == duplicate.Manufacturer && d.Model == duplicate.Model &&
                                      d.Revision == duplicate.Revision && d.Bus == duplicate.Bus).Skip(1));
            }

            // Remove nulls
            ctx.RemoveRange(ctx.SeenDevices !.Where(d => d.Manufacturer == null && d.Model == null &&
                                                    d.Revision == null));

            ctx.SaveChanges();

            bool mainDbUpdate = false;

            if (!File.Exists(Settings.Settings.MainDbPath))
            {
                mainDbUpdate = true;
                UpdateCommand.DoUpdate(true);
            }

            var mainContext = AaruContext.Create(Settings.Settings.MainDbPath);

            if (mainContext.Database.GetPendingMigrations().Any())
            {
                AaruConsole.WriteLine("New database version, updating...");

                try
                {
                    File.Delete(Settings.Settings.MainDbPath);
                }
                catch (Exception)
                {
                    AaruConsole.ErrorWriteLine("Exception trying to remove old database version, cannot continue...");
                    AaruConsole.ErrorWriteLine("Please manually remove file at {0}", Settings.Settings.MainDbPath);
                }

                UpdateCommand.DoUpdate(true);
            }

            if ((args.Length < 1 || args[0].ToLowerInvariant() != "gui") &&
                Settings.Settings.Current.GdprCompliance < DicSettings.GDPR_LEVEL)
            {
                new ConfigureCommand(true, true).Invoke(args);
            }

            Statistics.LoadStats();

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            var rootCommand = new RootCommand
            {
                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)
                },
            };

            rootCommand.Description =
                $"{_assemblyTitle} {_assemblyVersion?.InformationalVersion}\n{_assemblyCopyright}";

            rootCommand.AddCommand(new DatabaseFamily(mainDbUpdate));
            rootCommand.AddCommand(new DeviceFamily());
            rootCommand.AddCommand(new FilesystemFamily());
            rootCommand.AddCommand(new ImageFamily());
            rootCommand.AddCommand(new MediaFamily());

            rootCommand.AddCommand(new ConfigureCommand(false, false));
            rootCommand.AddCommand(new FormatsCommand());
            rootCommand.AddCommand(new ListEncodingsCommand());
            rootCommand.AddCommand(new ListNamespacesCommand());
            rootCommand.AddCommand(new RemoteCommand());

            int ret = rootCommand.Invoke(args);

            Statistics.SaveStats();

            return(ret);
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: colombod/DiscImageChef
        public static int Main(string[] args)
        {
            object[] attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
            _assemblyTitle = ((AssemblyTitleAttribute)attributes[0]).Title;
            attributes     = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);

            _assemblyVersion =
                Attribute.GetCustomAttribute(typeof(MainClass).Assembly, typeof(AssemblyInformationalVersionAttribute))
                as AssemblyInformationalVersionAttribute;

            _assemblyCopyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;

            DicConsole.WriteLineEvent      += System.Console.WriteLine;
            DicConsole.WriteEvent          += System.Console.Write;
            DicConsole.ErrorWriteLineEvent += System.Console.Error.WriteLine;

            Settings.Settings.LoadSettings();

            var ctx = DicContext.Create(Settings.Settings.LocalDbPath);

            ctx.Database.Migrate();
            ctx.SaveChanges();

            bool masterDbUpdate = false;

            if (!File.Exists(Settings.Settings.MasterDbPath))
            {
                masterDbUpdate = true;
                UpdateCommand.DoUpdate(true);
            }

            var masterContext = DicContext.Create(Settings.Settings.MasterDbPath);

            if (masterContext.Database.GetPendingMigrations().Any())
            {
                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);
            }

            if ((args.Length < 1 || args[0].ToLowerInvariant() != "gui") &&
                Settings.Settings.Current.GdprCompliance < DicSettings.GdprLevel)
            {
                new ConfigureCommand(true, true).Invoke(args);
            }

            Statistics.LoadStats();

            if (Settings.Settings.Current.Stats != null &&
                Settings.Settings.Current.Stats.ShareStats)
            {
                Task.Run(Statistics.SubmitStats);
            }

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            Statistics.SaveStats();

            var rootCommand = new RootCommand
            {
                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)
                }
            };

            rootCommand.Description =
                $"{_assemblyTitle} {_assemblyVersion?.InformationalVersion}\n{_assemblyCopyright}";

            rootCommand.AddCommand(new DatabaseFamily(masterDbUpdate));
            rootCommand.AddCommand(new DeviceFamily());
            rootCommand.AddCommand(new FilesystemFamily());
            rootCommand.AddCommand(new ImageFamily());
            rootCommand.AddCommand(new MediaFamily());

            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));
        }
コード例 #3
0
        public static int Main(string[] args)
        {
            var attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);

            AssemblyTitle   = ((AssemblyTitleAttribute)attributes[0]).Title;
            attributes      = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
            AssemblyVersion =
                Attribute.GetCustomAttribute(typeof(MainClass).Assembly, typeof(AssemblyInformationalVersionAttribute))
                as AssemblyInformationalVersionAttribute;
            AssemblyCopyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;

            DicConsole.WriteLineEvent      += System.Console.WriteLine;
            DicConsole.WriteEvent          += System.Console.Write;
            DicConsole.ErrorWriteLineEvent += System.Console.Error.WriteLine;

            Settings.Settings.LoadSettings();

            var ctx = DicContext.Create(Settings.Settings.LocalDbPath);

            ctx.Database.Migrate();
            ctx.SaveChanges();

            var masterDbUpdate = false;

            if (!File.Exists(Settings.Settings.MasterDbPath))
            {
                masterDbUpdate = true;
                UpdateCommand.DoUpdate(true);
            }

            var mctx = DicContext.Create(Settings.Settings.MasterDbPath);

            mctx.Database.Migrate();
            mctx.SaveChanges();

            if ((args.Length < 1 || args[0].ToLowerInvariant() != "gui") &&
                Settings.Settings.Current.GdprCompliance < DicSettings.GdprLevel)
            {
                new ConfigureCommand(true, true).Invoke(args);
            }
            Statistics.LoadStats();
            if (Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.ShareStats)
            {
                Task.Run(() => { Statistics.SubmitStats(); });
            }

            var currentPlatform = DetectOS.GetRealPlatformID();

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            var commands = new CommandSet("DiscImageChef")
            {
                $"{AssemblyTitle} {AssemblyVersion?.InformationalVersion}",
                $"{AssemblyCopyright}",
                "",
                "usage: DiscImageChef COMMAND [OPTIONS]",
                "",
                "Global options:",
                { "verbose|v", "Shows verbose output.", b => Verbose = b != null },
                { "debug|d", "Shows debug output from plugins.", b => Debug = b != null },
                "",
                "Available commands:",
                new AnalyzeCommand(),
                new BenchmarkCommand(),
                new ChecksumCommand(),
                new CompareCommand(),
                new ConfigureCommand(false, false),
                new ConvertImageCommand(),
                new CreateSidecarCommand(),
                new DecodeCommand()
            };

            if (currentPlatform == PlatformID.FreeBSD || currentPlatform == PlatformID.Linux ||
                currentPlatform == PlatformID.Win32NT)
            {
                commands.Add(new DeviceInfoCommand());
                commands.Add(new DeviceReportCommand());
                commands.Add(new DumpMediaCommand());
            }

            commands.Add(new EntropyCommand());
            commands.Add(new ExtractFilesCommand());
            commands.Add(new FormatsCommand());
            commands.Add(new ImageInfoCommand());

            if (currentPlatform == PlatformID.FreeBSD || currentPlatform == PlatformID.Linux ||
                currentPlatform == PlatformID.Win32NT)
            {
                commands.Add(new ListDevicesCommand());
            }

            commands.Add(new ListEncodingsCommand());
            commands.Add(new ListNamespacesCommand());
            commands.Add(new ListOptionsCommand());
            commands.Add(new LsCommand());

            if (currentPlatform == PlatformID.FreeBSD || currentPlatform == PlatformID.Linux ||
                currentPlatform == PlatformID.Win32NT)
            {
                commands.Add(new MediaInfoCommand());
                commands.Add(new MediaScanCommand());
            }

            commands.Add(new PrintHexCommand());
            commands.Add(new StatisticsCommand());
            commands.Add(new UpdateCommand(masterDbUpdate));
            commands.Add(new VerifyCommand());
            commands.Add(new RemoteCommand());

            var ret = commands.Run(args);

            Statistics.SaveStats();

            return(ret);
        }