<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 Autofac;
using Avalonia;
#if !_CORERT
using Avalonia.Gtk3;
#endif
using Avalonia.Logging.Serilog;
using Core2D.UI.Avalonia.Modules;
using Core2D.Interfaces;

namespace Core2D.UI.Avalonia
{
    /// <summary>
    /// Encapsulates an Core2D avalonia program.
    /// </summary>
    internal class Program
    {
        private 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>
        [STAThread]
        private static void Main(string[] args)
        {
#if !_CORERT
            bool useGpu = true;
            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 "--software":
                        useGpu = false;
                        break;
                    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;
                }
            }
#endif
            try
            {
                var builder = new ContainerBuilder();
                builder.RegisterModule<LocatorModule>();
                builder.RegisterModule<CoreModule>();
                builder.RegisterModule<DependenciesModule>();
                builder.RegisterModule<AppModule>();
                builder.RegisterModule<ViewModule>();
                using (var container = builder.Build())
                {
                    using (var log = container.Resolve<ILog>())
                    {
                        var appBuilder = BuildAvaloniaApp();
#if !_CORERT
                        if (useDirect2D1 == true)
                        {
                            appBuilder.UseDirect2D1();
                        }
                        if (useSkia == true)
                        {
                            appBuilder.UseSkia();
                        }
                        if (useWin32 == true)
                        {
                            appBuilder.UseWin32(deferredRendering);
                        }
                        if (useGtk3 == true)
                        {
                            var options = new Gtk3PlatformOptions
                            {
                                UseDeferredRendering = deferredRendering,
                                UseGpuAcceleration = useGpu
                            };
                            appBuilder.UseGtk3(options);
                        }
                        if (useMonoMac == true)
                        {
                            appBuilder.UseMonoMac(deferredRendering);
                        }
#endif
                        appBuilder.SetupWithoutStarting();
                        var app = appBuilder.Instance as App;
                        var aboutInfo = app.CreateAboutInfo(
                            appBuilder.RuntimePlatform.GetRuntimeInfo(),
                            appBuilder.WindowingSubsystemName,
                            appBuilder.RenderingSubsystemName);
                        app.Start(container.Resolve<IServiceProvider>(), aboutInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                Print(ex);
            }
        }

        /// <summary>
        /// Builds Avalonia app.
        /// </summary>
        /// <returns>The Avalonia app builder.</returns>
        public static AppBuilder BuildAvaloniaApp()
            => AppBuilder.Configure<App>()
                         .UsePlatformDetect()
                         .LogToDebug();<commit_msg>Use explicit platforms for CoreRT<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 Autofac;
using Avalonia;
#if !_CORERT
using Avalonia.Gtk3;
#endif
using Avalonia.Logging.Serilog;
using Core2D.UI.Avalonia.Modules;
using Core2D.Interfaces;

namespace Core2D.UI.Avalonia
{
    /// <summary>
    /// Encapsulates an Core2D avalonia program.
    /// </summary>
    internal class Program
    {
        private 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>
        [STAThread]
        private static void Main(string[] args)
        {
#if !_CORERT
            bool useGpu = true;
            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 "--software":
                        useGpu = false;
                        break;
                    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;
                }
            }
#endif
            try
            {
                var builder = new ContainerBuilder();
                builder.RegisterModule<LocatorModule>();
                builder.RegisterModule<CoreModule>();
                builder.RegisterModule<DependenciesModule>();
                builder.RegisterModule<AppModule>();
                builder.RegisterModule<ViewModule>();
                using (var container = builder.Build())
                {
                    using (var log = container.Resolve<ILog>())
                    {
                        var appBuilder = BuildAvaloniaApp();
#if !_CORERT
                        if (useDirect2D1 == true)
                        {
                            appBuilder.UseDirect2D1();
                        }
                        if (useSkia == true)
                        {
                            appBuilder.UseSkia();
                        }
                        if (useWin32 == true)
                        {
                            appBuilder.UseWin32(deferredRendering);
                        }
                        if (useGtk3 == true)
                        {
                            var options = new Gtk3PlatformOptions
                            {
                                UseDeferredRendering = deferredRendering,
                                UseGpuAcceleration = useGpu
                            };
                            appBuilder.UseGtk3(options);
                        }
                        if (useMonoMac == true)
                        {
                            appBuilder.UseMonoMac(deferredRendering);
                        }
#endif
                        appBuilder.SetupWithoutStarting();
                        var app = appBuilder.Instance as App;
                        var aboutInfo = app.CreateAboutInfo(
                            appBuilder.RuntimePlatform.GetRuntimeInfo(),
                            appBuilder.WindowingSubsystemName,
                            appBuilder.RenderingSubsystemName);
                        app.Start(container.Resolve<IServiceProvider>(), aboutInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                Print(ex);
            }
        }

        /// <summary>
        /// Builds Avalonia app.
        /// </summary>
        /// <returns>The Avalonia app builder.</returns>
        public static AppBuilder BuildAvaloniaApp()
            => AppBuilder.Configure<App>()
#if !_CORERT
                         .UsePlatformDetect()
#elif _CORERT_WIN_X64
                         .UseWin32().UseSkia()
#elif _CORERT_LINUX_X64
                         .UseGtk3().UseSkia()
#elif _CORERT_OSX_X64
                         .UseMonoMac().UseSkia()
#endif
                         .LogToDebug();
{'fraction_non_alphanumeric': 0.08145338390896387, 'fraction_numerical': 0.006887602315831503, 'mean_word_length': 0.9193486590038314, 'pattern_counts': {'":': 16, '<': 41, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1666161', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2183, 'n_words': 485}