-
Notifications
You must be signed in to change notification settings - Fork 85
/
App.xaml.cs
73 lines (62 loc) · 2.85 KB
/
App.xaml.cs
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
using Galaxy_Swapper_v2.Workspace;
using Galaxy_Swapper_v2.Workspace.ClientSettings;
using Galaxy_Swapper_v2.Workspace.Properties;
using Galaxy_Swapper_v2.Workspace.Utilities;
using Serilog;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Threading;
namespace Galaxy_Swapper_v2
{
public partial class App : Application
{
public static readonly string Config = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\Galaxy-Swapper-v2-Config";
public static readonly string[] SubDirectories = { $"{Config}\\DLLS", $"{Config}\\Plugins", $"{Config}\\LOGS", $"{Config}\\Binaries" };
protected override void OnStartup(StartupEventArgs e)
{
Process[] currentprocess = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
if (currentprocess.Length > 1)
{
Win32.SetProcessHigher(currentprocess);
Message.DisplaySTA("Info", "It has been detected that Galaxy Swapper is already running. The process will be brought to the front.\nIf there is an issue, please end the 'Galaxy Swapper v2' process in Task Manager and restart the application.");
Environment.Exit(0);
}
if (File.Exists($"{Config}\\Key.config")) //Remove old config folder
{
Directory.Delete(Config, true);
}
if (!Directory.Exists(Config)) //Create config folder
{
Directory.CreateDirectory(Config);
}
foreach (string sub in SubDirectories)
{
Directory.CreateDirectory(sub);
}
Output.Initialize(); //Serilog logger
Log.Information("Version {0}", Global.Version);
Log.Information("API-Version {0}", Global.ApiVersion);
Log.Information("Runtime {0}", RuntimeInformation.FrameworkDescription);
Log.Information("Config-Path: {0}", Config);
Settings.Initialize();
SwapLogs.Initialize();
UEFN.Initialize();
Binaries.Initialize();
base.OnStartup(e);
}
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
Log.Fatal("Application caught a unexpected error and can not recover");
Log.Fatal(e.Exception.ToString());
Message.DisplaySTA("Error", $"Application caught a unexpected error and can not recover.\n{e.Exception}", discord: true);
}
private void App_Exit(object sender, ExitEventArgs e)
{
Log.Information("Shutting down application..");
Log.CloseAndFlush();
}
}
}