mlaumcherb/Mlaumcherb.Client.Avalonia/зримое/LauncherApp.axaml.cs

75 lines
2.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Mlaumcherb.Client.Avalonia.классы;
using Mlaumcherb.Client.Avalonia.сеть.Update;
using Mlaumcherb.Client.Avalonia.холопы;
namespace Mlaumcherb.Client.Avalonia.зримое;
public class LauncherApp : Application
{
public static LauncherLogger Logger = new();
public static Config Config = null!;
public static InstalledVersionCatalog InstalledVersionCatalog = null!;
public override void Initialize()
{
Logger.LogInfo(nameof(LauncherApp), "приложение запущено");
Config = Config.LoadFromFile();
Logger.DebugLogEnabled = Config.debug;
AvaloniaXamlLoader.Load(this);
try
{
SelfUpdateAsync();
// some file required by forge installer
if (!File.Exists("launcher_profiles.json"))
{
File.WriteAllText("launcher_profiles.json", "{}");
}
InstalledVersionCatalog = InstalledVersionCatalog.Load();
}
catch (Exception e)
{
ErrorHelper.ShowMessageBox(nameof(LauncherApp), e);
}
}
private async void SelfUpdateAsync()
{
try
{
Logger.LogInfo(nameof(LauncherApp), "checking for updates...");
var upd = new UpdateHelper(Config.gitea);
upd.DeleteBackupFiles();
if (await upd.IsUpdateAvailable())
{
Logger.LogInfo(nameof(LauncherApp), "downloading update...");
await upd.UpdateSelf();
Logger.LogInfo(nameof(LauncherApp), "restarting...");
upd.RestartSelf();
}
else
{
Logger.LogInfo(nameof(LauncherApp), "no updates found");
}
}
catch (Exception e)
{
ErrorHelper.ShowMessageBox(nameof(LauncherApp), e);
}
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}
base.OnFrameworkInitializationCompleted();
}
}