예제 #1
0
        public void Run()
        {
            // Clean the previous failure log
            if (File.Exists("failures.log"))
            {
                File.Delete("failures.log");
            }

            Config config;

            // Load config from the file
            try
            {
                config = ConfigLoader.LoadConfig(ConfigLoader.DefaultFilename);
            }
            catch (FileNotFoundException)
            {
                Console.Error.WriteLine($"Configuration file \"{ConfigLoader.DefaultFilename}\" not found.");
                Console.ReadLine();
                return;
            }

            // Check validity of the config
            var configValidationResult = ConfigValidator.CheckValidity(config);
            var configProblems         = configValidationResult.ReportProblems();

            if (configProblems.Any())
            {
                Console.Error.WriteLine($"{configProblems.Count} problem(s) detected in the configuration file.");
                configProblems.ForEach(it =>
                {
                    Console.Error.WriteLine($"- {it}");
                });
                Console.ReadLine();
                return;
            }

            // Initiate a progress bar
            var pb = new ProgressBar(configValidationResult.TtfFiles.Count(), configValidationResult.TtcFiles.Count());

            // Process TTF fonts
            var failedTtfFonts = ProcessTtfFonts(config, configValidationResult.TtfFiles.ToList(), pb);

            // Process TTC fonts
            var failedTtcFonts = ProcessTtcFonts(config, configValidationResult.TtcFiles.ToList(), pb);

            // Done processing
            pb.MarkDone();
            pb.Dispose();

            if (failedTtfFonts.Any() || failedTtcFonts.Any())
            {
                // Write the failures to "failures.log"
                File.WriteAllLines("failures.log", failedTtfFonts.Concat(failedTtcFonts).Select(it => it.Name));

                // Report
                Console.WriteLine($"Completed with the following {failedTtfFonts.Count + failedTtcFonts.Count} failures. They have been written in \"failures.log\".");
                foreach (var failure in failedTtfFonts.Concat(failedTtcFonts))
                {
                    Console.WriteLine($"- {failure.Name}");
                }
            }
            Console.ReadLine();
        }