Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Program.cs « UVtools.WPF - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b3ee62da11596020cf3c16068b4c57211ec1621b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Diagnostics;
using System.Runtime.ExceptionServices;
using Avalonia;
using UVtools.WPF.Extensions;

namespace UVtools.WPF
{
    public static class Program
    {
        public static string[] Args;

        public static Stopwatch ProgramStartupTime;
        // Initialization code. Don't use any Avalonia, third-party APIs or any
        // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
        // yet and stuff might break.
        [STAThread]
        public static void Main(string[] args)
        {
            ProgramStartupTime = Stopwatch.StartNew();
            Args = args;

            try
            {
                if (ConsoleArguments.ParseArgs(args)) return;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return;
            }
            
            /*Slicer slicer = new(Size.Empty, SizeF.Empty, "D:\\Cube100x100x100.stl");
            var slices = slicer.SliceModel(0.05f);
            
            foreach (var slice in slices)
            {
                using var mat = EmguExtensions.InitMat(new Size(1000, 1000));
                var contour = slice.Value.ToContour();
                using var vec = new VectorOfPoint(contour);
                CvInvoke.FillPoly(mat, vec, EmguExtensions.WhiteColor, LineType.AntiAlias);
                mat.Save(@$"D:\SLICE\{slice.Key}.png");
            }*/

            // Add the event handler for handling non-UI thread exceptions to the event.
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
            //AppDomain.CurrentDomain.FirstChanceException += CurrentDomainOnFirstChanceException;
            BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
        }

        private static void CurrentDomainOnFirstChanceException(object? sender, FirstChanceExceptionEventArgs e)
        {
            ErrorLog.AppendLine("First chance exception", e.Exception.ToString());
        }


        private static async void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = (Exception)e.ExceptionObject;
            ErrorLog.AppendLine("Fatal Non-UI Error", ex.ToString());

            try
            {
                string errorMsg = "An application error occurred. Please contact the administrator with the following information:\n\n" +
                                  $"{ex}";

                await App.MainWindow.MessageBoxError(errorMsg, "Fatal Non-UI Error");
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
            }
        }

        // Avalonia configuration, don't remove; also used by visual designer.
        public static AppBuilder BuildAvaloniaApp()
            => AppBuilder.Configure<App>()
                .UsePlatformDetect()
                .With(new Win32PlatformOptions { AllowEglInitialization = true/*, UseWgl = true*/})
                .With(new X11PlatformOptions { UseGpu = true/*, UseEGL = true*/ })
                .With(new MacOSPlatformOptions { ShowInDock = true })
                .With(new AvaloniaNativePlatformOptions { UseGpu = true })
                .UseSkia()
                .LogToTrace();
    }
}