-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
85 lines (71 loc) · 3.03 KB
/
App.xaml.cs
File metadata and controls
85 lines (71 loc) · 3.03 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
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
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using VoicemeeterOsdProgram.Core;
using VoicemeeterOsdProgram.Factories;
using VoicemeeterOsdProgram.Helpers;
using VoicemeeterOsdProgram.Options;
using VoicemeeterOsdProgram.Updater;
using VoicemeeterOsdProgram.Updater.Types;
namespace VoicemeeterOsdProgram;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public App()
{
InitializeComponent();
Current.DispatcherUnhandledException += OnUnhandledException;
}
async void OnAppStartup(object sender, StartupEventArgs e)
{
var optionsTask = OptionsStorage.InitAsync();
OptionsStorage.Program.RenderMode = RenderOptions.ProcessRenderMode;
OptionsStorage.Program.RenderModeChanged += (_, val) => RenderOptions.ProcessRenderMode = val;
VoicemeeterApiClient.PoolingRate = OptionsStorage.Voicemeeter.ApiPollingRate;
OptionsStorage.Voicemeeter.ApiPollingRateChanged += (_, val) => VoicemeeterApiClient.PoolingRate = val;
DpiHelper.Init();
TrayIconManager.Init();
OsdWindowManager.Init();
UpdateManager.logger = Globals.Logger;
UpdateManager.DefaultOS = System.Runtime.InteropServices.OSPlatform.Windows;
await optionsTask;
var vmTask = VoicemeeterApiClient.InitAsync((int)OptionsStorage.Voicemeeter.InitializationDelay);
if (OptionsStorage.Updater.CheckOnStartup)
{
var updaterRes = await UpdateManager.TryCheckForUpdatesAsync();
if (updaterRes == UpdaterResult.NewVersionFound)
{
TrayIconManager.OpenUpdater();
}
}
await vmTask;
await ArgsHandler.HandleAsync(AppLifeManager.appArgs);
// start to recieve command-line arguments from other launched instance
AppLifeManager.StartArgsPipeServer();
Globals.Logger?.Log("Program initialized");
await CheckProgramDirectoryIOAsync();
}
private async Task CheckProgramDirectoryIOAsync()
{
const string Msg = "Unable to create files/directories in the program's directory.\n" +
"Updater and persistent config might not work.\n\n" +
"Possible solution: if program is located in 'Program Files' move it to a different folder/drive";
string path = AppDomain.CurrentDomain.BaseDirectory;
bool canCreateDirs = IOAccessCheck.TryCreateRandomDirectory(path);
bool canCreateFiles = await IOAccessCheck.TryCreateRandomFileAsync(path);
if (!canCreateDirs || !canCreateFiles)
{
var exType = IOAccessCheck.LastException.GetType();
var d = MsgBoxFactory.GetWarning();
d.ContentToDisplay.Content = $"{exType}\n{Msg}";
d.Show();
}
}
private void OnUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
Globals.Logger?.LogCritical($"Unhandled exception: {e.Exception}");
}
}