<commit_before>// Copyright (c) <NAME>. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using SkiaSharp;
using Svg;

namespace Svg.Skia.Converter
{
    public class Program
    {
        public static void Error(Exception ex)
        {
            Console.WriteLine($"{ex.Message}", ConsoleColor.Yellow);
            Console.WriteLine($"{ex.StackTrace}", ConsoleColor.Black);
            if (ex.InnerException != null)
            {
                Error(ex.InnerException);
            }
        }

        public static void Execute(string file, string directory, string output, string pattern, string format, int quality, float scaleX, float scaleY, bool debug)
        {
            try
            {
                var paths = new List<string>();

                if (file != null)
                {
                    paths.Add(file);
                }

                if (directory != null)
                {
                    var files = Directory.EnumerateFiles(directory, pattern);
                    if (files != null)
                    {
                        paths.AddRange(files);
                    }
                }

                if (!string.IsNullOrEmpty(output))
                {
                    if (!Directory.Exists(output))
                    {
                        Directory.CreateDirectory(output);
                    }    
                }

                var sw = Stopwatch.StartNew();

                int success = 0;

                for (int i = 0; i < paths.Count; i++)
                {
                    var path = paths[i];
                    try
                    {
                        Console.ForegroundColor = ConsoleColor.Black;
                        Console.WriteLine($"[{i}] File: {path}");

                        var extension = Path.GetExtension(path);
                        string imagePath = path.Remove(path.Length - extension.Length) + "." + format.ToLower();
                        if (!string.IsNullOrEmpty(output))
                        {
                            imagePath = Path.Combine(output, Path.GetFileName(imagePath));
                        }

                        var svg = new Svg();
                        var picture = svg.Load(path);
                        if (picture != null)
                        {
                            if (debug == true && svg.Document != null)
                            {
                                string ymlPath = path.Remove(path.Length - extension.Length) + ".yml";
                                if (!string.IsNullOrEmpty(output))
                                {
                                    ymlPath = Path.Combine(output, Path.GetFileName(ymlPath));
                                }
                                SvgDebug.Print(svg.Document, ymlPath);
                            }

                            if (Enum.TryParse<SKEncodedImageFormat>(format, true, out var skEncodedImageFormat))
                            {
                                svg.Save(imagePath, skEncodedImageFormat, quality, scaleX, scaleY);
                            }
                            else
                            {
                                throw new ArgumentException($"Invalid output image format.", nameof(format));
                            }
                        }

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine($"[{i}] Succes: {imagePath}");
                        success++;
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"[{i}] Error: {path}");
                        Error(ex);
                    }
                }

                sw.Stop();

                if (paths.Count > 0)
                {
                    Console.ForegroundColor = ConsoleColor.Black;
                    Console.WriteLine($"Done: {sw.Elapsed} ({success}/{paths.Count})");
                    Console.ResetColor();
                }
            }
            catch (Exception ex)
            {
                Console.ResetColor();
                Error(ex);
            }
        }

        public static async Task<int> Main(string[] args)
        {
            var optionFile = new Option(new [] { "--file", "-f" }, "The relative or absolute path to the input file")
            {
                Argument = new Argument<string>(defaultValue: () => null)
            };

            var optionDirectory = new Option(new [] { "--directory", "-d" }, "The relative or absolute path to the input directory")
            {
                Argument = new Argument<string>(defaultValue: () => null)
            };

            var optionOutput = new Option(new [] { "--output", "-o" }, "The relative or absolute path to the output directory")
            {
                Argument = new Argument<string>(defaultValue: () => null)
            };

            var optionPattern = new Option(new [] { "--pattern", "-p" }, "The search string to match against the names of files in the input path")
            {
                Argument = new Argument<string>(defaultValue: () => "*.svg")
            };

            var optionFormat = new Option(new [] { "--format" }, "The output image format")
            {
                Argument = new Argument<string>(defaultValue: () => "png")
            };

            var optionQuality = new Option(new [] { "--quality" }, "The output image quality")
            {
                Argument = new Argument<int>(defaultValue: () => 100)
            };

            var optionScaleX = new Option(new [] { "--scaleX" }, "The output image horizontal scaling factor")
            {
                Argument = new Argument<float>(defaultValue: () => 1f)
            };

            var optionScaleY = new Option(new [] { "--scaleY" }, "The output image vertical scaling factor")
            {
                Argument = new Argument<float>(defaultValue: () => 1f)
            };

            var optionDebug = new Option(new [] { "--debug" }, "The flag indicating whether to produce debug output to a file")
            {
                Argument = new Argument<bool>()
            };<commit_msg>Update Program.cs<commit_after>// Copyright (c) <NAME>. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using SkiaSharp;
using Svg;

namespace Svg.Skia.Converter
{
    public class Program
    {
        public static void Error(Exception ex)
        {
            Console.WriteLine($"{ex.Message}", ConsoleColor.Yellow);
            Console.WriteLine($"{ex.StackTrace}", ConsoleColor.Black);
            if (ex.InnerException != null)
            {
                Error(ex.InnerException);
            }
        }

        public static void Execute(string file, string directory, string output, string pattern, string format, int quality, float scaleX, float scaleY, bool debug)
        {
            try
            {
                var paths = new List<string>();

                if (file != null)
                {
                    paths.Add(file);
                }

                if (directory != null)
                {
                    var files = Directory.EnumerateFiles(directory, pattern);
                    if (files != null)
                    {
                        paths.AddRange(files);
                    }
                }

                if (!string.IsNullOrEmpty(output))
                {
                    if (!Directory.Exists(output))
                    {
                        Directory.CreateDirectory(output);
                    }
                }

                var sw = Stopwatch.StartNew();

                int success = 0;

                for (int i = 0; i < paths.Count; i++)
                {
                    var path = paths[i];
                    try
                    {
                        Console.ForegroundColor = ConsoleColor.Black;
                        Console.WriteLine($"[{i}] File: {path}");

                        var extension = Path.GetExtension(path);
                        string imagePath = path.Remove(path.Length - extension.Length) + "." + format.ToLower();
                        if (!string.IsNullOrEmpty(output))
                        {
                            imagePath = Path.Combine(output, Path.GetFileName(imagePath));
                        }

                        var svg = new Svg();
                        var picture = svg.Load(path);
                        if (picture != null)
                        {
                            if (debug == true && svg.Document != null)
                            {
                                string ymlPath = path.Remove(path.Length - extension.Length) + ".yml";
                                if (!string.IsNullOrEmpty(output))
                                {
                                    ymlPath = Path.Combine(output, Path.GetFileName(ymlPath));
                                }
                                SvgDebug.Print(svg.Document, ymlPath);
                            }

                            if (Enum.TryParse<SKEncodedImageFormat>(format, true, out var skEncodedImageFormat))
                            {
                                svg.Save(imagePath, skEncodedImageFormat, quality, scaleX, scaleY);
                            }
                            else
                            {
                                throw new ArgumentException($"Invalid output image format.", nameof(format));
                            }
                        }

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine($"[{i}] Succes: {imagePath}");
                        success++;
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"[{i}] Error: {path}");
                        Error(ex);
                    }
                }

                sw.Stop();

                if (paths.Count > 0)
                {
                    Console.ForegroundColor = ConsoleColor.Black;
                    Console.WriteLine($"Done: {sw.Elapsed} ({success}/{paths.Count})");
                    Console.ResetColor();
                }
            }
            catch (Exception ex)
            {
                Console.ResetColor();
                Error(ex);
            }
        }

        public static async Task<int> Main(string[] args)
        {
            var optionFile = new Option(new[] { "--file", "-f" }, "The relative or absolute path to the input file")
            {
                Argument = new Argument<string>(defaultValue: () => null)
            };

            var optionDirectory = new Option(new[] { "--directory", "-d" }, "The relative or absolute path to the input directory")
            {
                Argument = new Argument<string>(defaultValue: () => null)
            };

            var optionOutput = new Option(new[] { "--output", "-o" }, "The relative or absolute path to the output directory")
            {
                Argument = new Argument<string>(defaultValue: () => null)
            };

            var optionPattern = new Option(new[] { "--pattern", "-p" }, "The search string to match against the names of files in the input path")
            {
                Argument = new Argument<string>(defaultValue: () => "*.svg")
            };

            var optionFormat = new Option(new[] { "--format" }, "The output image format")
            {
                Argument = new Argument<string>(defaultValue: () => "png")
            };

            var optionQuality = new Option(new[] { "--quality" }, "The output image quality")
            {
                Argument = new Argument<int>(defaultValue: () => 100)
            };

            var optionScaleX = new Option(new[] { "--scaleX" }, "The output image horizontal scaling factor")
            {
                Argument = new Argument<float>(defaultValue: () => 1f)
            };

            var optionScaleY = new Option(new[] { "--scaleY" }, "The output image vertical scaling factor")
            {
                Argument = new Argument<float>(defaultValue: () => 1f)
            };

            var optionDebug = new Option(new[] { "--debug" }, "The flag indicating whether to produce debug output to a file")
            {
                Argument = new Argument<bool>()
            };
{'fraction_non_alphanumeric': 0.1035660091047041, 'fraction_numerical': 0.0012139605462822458, 'mean_word_length': 1.152, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '227009', 'n_tokens_mistral': 3079, 'n_tokens_neox': 2850, 'n_words': 759}