This repository was archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (41 loc) · 1.35 KB
/
Program.cs
File metadata and controls
50 lines (41 loc) · 1.35 KB
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
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace Mechvibes.CSharp
{
internal static class Program
{
private static MainForm frm_MainWindow;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
frm_MainWindow = new MainForm();
Application.Run(frm_MainWindow);
}
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs e)
{
if (e.Name.StartsWith("Mechvibes.CSharp.resources"))
return e.RequestingAssembly;
using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream($"Mechvibes.CSharp.Libraries.{e.Name.Split(',')[0]}.dll"))
{
byte[] dll = new byte[s.Length];
s.Read(dll, 0, dll.Length);
return Assembly.Load(dll);
}
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Application.Exit();
Process.Start(Application.ExecutablePath, $"--{frm_MainWindow.State}");
}
}
}