<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.Diagnostics;
using System.Threading;
using Autofac;
using Avalonia;
using Avalonia.Logging.Serilog;
using Core2D.Avalonia.Modules;
using Core2D.Interfaces;

namespace Core2D.Avalonia
{
    /// <summary>
    /// Encapsulates an Core2D avalonia program.
    /// </summary>
    class Program
    {
        static void Print(Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.StackTrace);
            if (ex.InnerException != null)
            {
                Print(ex.InnerException);
            }
        }

        /// <summary>
        /// Program entry point.
        /// </summary>
        /// <param name="args">The program arguments.</param>
#if NET461
       [STAThread]
#endif
        static void Main(string[] args)
        {
#if !NET461
            Thread.CurrentThread.TrySetApartmentState(ApartmentState.STA);
#endif
            try
            {
                var builder = new ContainerBuilder();
                builder.RegisterModule<LocatorModule>();
                builder.RegisterModule<CoreModule>();
                builder.RegisterModule<DependenciesModule>();
                builder.RegisterModule<AppModule>();
                builder.RegisterModule<ViewModule>();
                using (IContainer container = builder.Build())
                {
                    using (ILog log = container.Resolve<ILog>())
                    {
                        var appBuilder = BuildAvaloniaApp();
                        if (args.Length > 0)
                        {
                            bool deferredRendering = true;
                            foreach (var arg in args)
                            {
                                switch (arg)
                                {
                                    case "--immediate":
                                        deferredRendering = false;
                                        break;
                                    case "--deferred":
                                        deferredRendering = true;
                                        break;
                                    case "--d2d":
                                        appBuilder.UseDirect2D1();
                                        break;
                                    case "--skia":
                                        appBuilder.UseSkia();
                                        break;
                                    case "--win32":
                                        appBuilder.UseWin32(deferredRendering);
                                        break;
                                    case "--gtk3":
                                        appBuilder.UseGtk3(deferredRendering);
                                        break;
                                    case "--mac":
                                        appBuilder.UseMonoMac(deferredRendering);
                                        break;
                                }
                            }
                        }
                        appBuilder.SetupWithoutStarting();
                        var app = appBuilder.Instance as App;
                        var aboutInfo = app.CreateAboutInfo(
                            appBuilder.RuntimePlatform.GetRuntimeInfo(),
                            appBuilder.WindowingSubsystemName,
                            appBuilder.RenderingSubsystemName);
                        Debug.Write(aboutInfo);
                        app.Start(container.Resolve<IServiceProvider>(), aboutInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                Print(ex);
            }
        }

        /// <summary>
        /// Builds Avalonia app.
        /// </summary>
        /// <returns>The Avalonia app builder.</returns><commit_msg>Refactored args parsing<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.Threading;
using Autofac;
using Avalonia;
using Avalonia.Logging.Serilog;
using Core2D.Avalonia.Modules;
using Core2D.Interfaces;

namespace Core2D.Avalonia
{
    /// <summary>
    /// Encapsulates an Core2D avalonia program.
    /// </summary>
    class Program
    {
        static void Print(Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.StackTrace);
            if (ex.InnerException != null)
            {
                Print(ex.InnerException);
            }
        }

        /// <summary>
        /// Program entry point.
        /// </summary>
        /// <param name="args">The program arguments.</param>
#if NET461
       [STAThread]
#endif
        static void Main(string[] args)
        {
#if !NET461
            Thread.CurrentThread.TrySetApartmentState(ApartmentState.STA);
#endif
            bool deferredRendering = true;
            bool useDirect2D1 = false;
            bool useSkia = false;
            bool useWin32 = false;
            bool useGtk3 = false;
            bool useMonoMac = false;

            foreach (var arg in args)
            {
                switch (arg)
                {
                    case "--immediate":
                        deferredRendering = false;
                        break;
                    case "--deferred":
                        deferredRendering = true;
                        break;
                    case "--d2d":
                        useDirect2D1 = true;
                        break;
                    case "--skia":
                        useSkia = true;
                        break;
                    case "--win32":
                        useWin32 = true;
                        break;
                    case "--gtk3":
                        useGtk3 = true;
                        break;
                    case "--mac":
                        useMonoMac = true;
                        break;
                }
            }

            try
            {
                var builder = new ContainerBuilder();
                builder.RegisterModule<LocatorModule>();
                builder.RegisterModule<CoreModule>();
                builder.RegisterModule<DependenciesModule>();
                builder.RegisterModule<AppModule>();
                builder.RegisterModule<ViewModule>();
                using (IContainer container = builder.Build())
                {
                    using (ILog log = container.Resolve<ILog>())
                    {
                        var appBuilder = BuildAvaloniaApp();
                        if (useDirect2D1 == true)
                        {
                            appBuilder.UseDirect2D1();
                        }
                        if (useSkia == true)
                        {
                            appBuilder.UseSkia();
                        }
                        if (useWin32 == true)
                        {
                            appBuilder.UseWin32(deferredRendering);
                        }
                        if (useGtk3 == true)
                        {
                            appBuilder.UseGtk3(deferredRendering);
                        }
                        if (useMonoMac == true)
                        {
                            appBuilder.UseMonoMac(deferredRendering);
                        }
                        appBuilder.SetupWithoutStarting();
                        var app = appBuilder.Instance as App;
                        var aboutInfo = app.CreateAboutInfo(
                            appBuilder.RuntimePlatform.GetRuntimeInfo(),
                            appBuilder.WindowingSubsystemName,
                            appBuilder.RenderingSubsystemName);
                        Console.WriteLine(aboutInfo);
                        app.Start(container.Resolve<IServiceProvider>(), aboutInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                Print(ex);
            }
        }

        /// <summary>
        /// Builds Avalonia app.
        /// </summary>
        /// <returns>The Avalonia app builder.</returns>
{'fraction_non_alphanumeric': 0.08176769467092047, 'fraction_numerical': 0.006380716058135413, 'mean_word_length': 0.9114724480578139, 'pattern_counts': {'":': 14, '<': 39, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2205838', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1744, 'n_words': 382}