-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathApp.xaml.cs
83 lines (74 loc) · 3.33 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
74
75
76
77
78
79
80
81
82
83
using Microsoft.UI.Xaml;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Markup.Localizer;
using Windows.Storage;
using WinDurango.UI.Settings;
using WinDurango.UI.Utils;
using WinUI3Localizer;
namespace WinDurango.UI
{
public partial class App : Application
{
// constants
public static readonly string DataDir = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WinDurango"), "UI");
public static readonly string AppDir = AppContext.BaseDirectory;
private static readonly FileVersionInfo Fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
// versioning
public static readonly uint Major = (uint)Fvi.ProductMajorPart;
public static readonly uint Minor = (uint)Fvi.ProductMinorPart;
public static readonly uint Patch = (uint)Fvi.ProductBuildPart;
public static readonly string Hash = Fvi.ProductVersion.Contains("+")
? Fvi.ProductVersion.Split("+")[1][..7]
: "HASHFAIL";
public static readonly uint VerPacked = (Major << 22) | (Minor << 12) | Patch;
public static readonly string Version = $"{Fvi.ProductMajorPart}.{Fvi.ProductMinorPart}.{Fvi.ProductBuildPart}_{Hash}"; // 1.0 will be when bugs are squashed and everything works correctly.
// other
public static readonly WdSettings Settings = new();
public static readonly MainWindow MainWindow = new();
public static (uint major, uint minor, uint patch) UnpackVersion(uint verPacked)
{
uint major = (verPacked >> 22) & 0x3FF;
uint minor = (verPacked >> 12) & 0x3FF;
uint patch = verPacked & 0xFFF;
return (major, minor, patch);
}
private static async Task InitializeLocalizer()
{
string StringsFolderPath = Path.Combine(AppContext.BaseDirectory, "Strings");
Logger.WriteDebug(AppContext.BaseDirectory);
StorageFolder stringsFolder = await StorageFolder.GetFolderFromPathAsync(StringsFolderPath);
ILocalizer localizer = await new LocalizerBuilder()
.AddStringResourcesFolderForLanguageDictionaries(StringsFolderPath)
.SetOptions(options =>
{
options.DefaultLanguage = "en-US";
})
.Build();
// await localizer.SetLanguage(Settings.Settings.Language);
Logger.WriteDebug($"Using language {localizer.GetCurrentLanguage()}");
}
private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
Logger.WriteException($"{e.Exception.GetType().FullName}: {e.Exception.Message}");
}
public App()
{
this.UnhandledException += App_UnhandledException;
InitializeComponent();
}
public static void OnClosed(object sender, WindowEventArgs args)
{
Logger.WriteInformation("Exiting");
}
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
await InitializeLocalizer();
Logger.WriteDebug("Showing MainWindow");
MainWindow.Activate();
}
}
}