Exemple #1
0
 private static void RunOptionsAndReturnExitCode(ConsoleOptions opts)
 {
     Run(opts).GetAwaiter().GetResult();
 }
Exemple #2
0
        private static async Task Run(ConsoleOptions opts)
        {
            // Check output path
            var outputPathInfo = new DirectoryInfo(opts.OutputPath);

            if (!outputPathInfo.Exists)
            {
                outputPathInfo.Create();
            }

            // Read configuration
            IEnumerable <string> ignoredAssemblies = opts.Excluded;

            if (File.Exists("Configuration.json"))
            {
                string            configurationFileText = File.ReadAllText("Configuration.json");
                ConfigurationFile configurationFile     = JsonConvert.DeserializeObject <ConfigurationFile>(configurationFileText);

                // Concatinate with the ignored files from the arguments
                ignoredAssemblies = ignoredAssemblies.Concat(configurationFile.IgnoredAssemblies);
            }

            // Create logger
            var logger = new ConsoleLogger(opts.Verbose, opts.Wait);

            // Create configuration
            var configuration = new Configuration(ignoredAssemblies, opts.OutputPath, opts.Async, opts.JavaArgs, opts.FlixArgs, opts.ShowFlixWindow, opts.NoStringAnalysis, opts.UpdateIgnored);

            // Registrer services
            var serviceCollection = new ServiceCollection();

            Startup.ConfigureServices(serviceCollection, configuration, logger);
            var services = serviceCollection.BuildServiceProvider();

            // Create flix executor
            using (var executor = services.GetRequiredService <IFlixExecutor>())
            {
                // Get file processor
                var fileProcessor = services.GetRequiredService <FileProcessor>();

                // Check for input file
                if (!string.IsNullOrWhiteSpace(opts.InputFile))
                {
                    // Check if path is input file
                    var fileInfo = new FileInfo(opts.InputFile);
                    if (fileInfo.Exists)
                    {
                        var files = await fileProcessor.ProcessFile(fileInfo);
                        await ProcessFlix(files, executor, opts);
                    }
                    else
                    {
                        logger.Log($"File {opts.InputFile} not found");
                    }

                    return;
                }

                // Check for input path
                if (!string.IsNullOrWhiteSpace(opts.InputPath))
                {
                    var pathInfo = new DirectoryInfo(opts.InputPath);
                    if (pathInfo.Exists)
                    {
                        var searchOption =
                            opts.Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;

                        foreach (var file in
                                 Directory.GetFiles(pathInfo.FullName, "*.apk", searchOption)
                                 .Concat(Directory.GetFiles(pathInfo.FullName, "*.exe", searchOption))
                                 .Concat(Directory.GetFiles(pathInfo.FullName, "*.dll", searchOption)))
                        {
                            try
                            {
                                var fileInfo = new FileInfo(file);
                                var files    = await fileProcessor.ProcessFile(fileInfo);
                                await ProcessFlix(files, executor, opts);
                            }
                            catch (Exception ex)
                            {
                                // Log and ignore exceptions
                                logger.Log($"[EXP]: {ex.Message}{Environment.NewLine}{ex.ToString()}{Environment.NewLine}{ex.StackTrace.ToString()}");
                            }
                        }
                    }
                    else
                    {
                        logger.Log($"Path {opts.InputPath} not found");
                    }

                    return;
                }

                logger.Log("Please select file or path");
            }
        }
Exemple #3
0
 public static async Task ProcessFlix(IEnumerable <string> generatedFiles, IFlixExecutor executor, ConsoleOptions opts)
 {
     // Execute
     if (!opts.NoFlix)
     {
         await executor.Execute(generatedFiles);
     }
 }