using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
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);
        
        // some file required by forge installer
        if (!File.Exists("launcher_profiles.json"))
        {
            File.WriteAllText("launcher_profiles.json", "{}");
        }

        InstalledVersionCatalog = InstalledVersionCatalog.Load();
    }

    public override void OnFrameworkInitializationCompleted()
    {
        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
        {
            desktop.MainWindow = new MainWindow();
        }

        base.OnFrameworkInitializationCompleted();
    }
}