-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (60 loc) · 1.71 KB
/
Copy pathProgram.cs
File metadata and controls
68 lines (60 loc) · 1.71 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
using System;
using System.IO;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using NullWave.Views;
using NullWave.Helpers;
using NullWave.Helpers.Logging;
using NullWave.Services;
using Serilog;
namespace NullWave;
class Program
{
private static FileStream? _singleInstanceLock;
[STAThread]
public static void Main(string[] args)
{
NullWavePaths.EnsureDirectories();
if (!TryAcquireSingleInstanceLock())
{
Console.WriteLine("NullWave is already running.");
return;
}
var prefsService = new PreferencesService();
NullWaveLogConfig.Initialize(prefsService.Current.VerboseLogging);
try
{
var appBuilder = BuildAvaloniaApp();
appBuilder.StartWithClassicDesktopLifetime(args);
}
catch (Exception ex)
{
NullActionLogger.Error("Program", ex, "Unhandled top-level exception");
throw;
}
finally
{
NullWaveLogConfig.CloseAndFlush();
}
}
private static bool TryAcquireSingleInstanceLock()
{
try
{
_singleInstanceLock = new FileStream(
Path.Combine(NullWavePaths.DataDir, "single.instance.lock"),
FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
return true;
}
catch (IOException)
{
return false;
}
}
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}