mlaumcherb/Млаумчерб.Клиент/видимое/Окне.axaml.cs
2024-09-26 01:10:11 +05:00

148 lines
5.7 KiB
C#
Raw 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;
using Avalonia.Data;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using Млаумчерб.Клиент.классы;
namespace Млаумчерб.Клиент.видимое;
public partial class Окне : Window
{
public static readonly StyledProperty<string> UsernameProperty =
AvaloniaProperty.Register<Окне, string>(nameof(Username),
defaultBindingMode: BindingMode.TwoWay);
public string Username
{
get => GetValue(UsernameProperty);
set => SetValue(UsernameProperty, value);
}
public static readonly StyledProperty<int> MemoryLimitProperty =
AvaloniaProperty.Register<Окне, int>(nameof(MemoryLimit),
defaultBindingMode: BindingMode.TwoWay, defaultValue: 2048);
public int MemoryLimit
{
get => GetValue(MemoryLimitProperty);
set => SetValue(MemoryLimitProperty, value);
}
public static readonly StyledProperty<bool> FullscreenProperty =
AvaloniaProperty.Register<Окне, bool>(nameof(Fullscreen),
defaultBindingMode: BindingMode.TwoWay, defaultValue: false);
public bool Fullscreen
{
get => GetValue(FullscreenProperty);
set => SetValue(FullscreenProperty, value);
}
public static readonly StyledProperty<bool> ForceUpdateGameFilesProperty =
AvaloniaProperty.Register<Окне, bool>(nameof(ForceUpdateGameFiles),
defaultBindingMode: BindingMode.TwoWay, defaultValue: false);
public bool ForceUpdateGameFiles
{
get => GetValue(ForceUpdateGameFilesProperty);
set => SetValue(ForceUpdateGameFilesProperty, value);
}
public Окне()
{
InitializeComponent();
}
protected override async void OnLoaded(RoutedEventArgs e)
{
try
{
Главне.Настройки = Настройки.ЗагрузитьИзФайла();
Username = Главне.Настройки.имя_пользователя;
MemoryLimit = Главне.Настройки.выделенная_память_мб;
Fullscreen = Главне.Настройки.открыватьаесь_экран;
Directory.Create(Пролетариат.GetVersionDescriptorDir());
VersionComboBox.SelectedIndex = 0;
VersionComboBox.IsEnabled = false;
var versions = await GameVersionDescriptor.GetAllVersionsAsync();
Dispatcher.UIThread.Invoke(() =>
{
foreach (var p in versions)
{
VersionComboBox.Items.Add(new VersionItemView(p));
if (Главне.Настройки.последняяапущенная_версия != null &&
p.Name == Главне.Настройки.последняяапущенная_версия)
VersionComboBox.SelectedIndex = VersionComboBox.Items.Count - 1;
}
VersionComboBox.IsEnabled = true;
});
}
catch (Exception ex)
{
Ошибки.ПоказатьСообщение(nameof(Окне), ex);
}
}
private async void LaunchButtonHandler(object? sender, RoutedEventArgs e)
{
try
{
var selectedVersionView = (VersionItemView?)VersionComboBox.SelectedItem;
var selectedVersion = selectedVersionView?.Props;
Главне.Настройки.последняяапущенная_версия = selectedVersion?.Name;
Главне.Настройки.имя_пользователя = Username;
Главне.Настройки.выделенная_память_мб = MemoryLimit;
Главне.Настройки.открыватьаесь_экран = Fullscreen;
Главне.Настройки.СохранитьВФайл();
if (selectedVersion == null)
return;
var v = await GameVersionDescriptor.CreateFromPropsAsync(selectedVersion);
v.BeginUpdate(ForceUpdateGameFiles);
Dispatcher.UIThread.Invoke(() => ForceUpdateGameFiles = false);
}
catch (Exception ex)
{
Ошибки.ПоказатьСообщение(nameof(Окне), ex);
}
}
private void OpenLogsDirectory(object? s, RoutedEventArgs e)
{
try
{
Launcher.LaunchDirectoryInfoAsync(new DirectoryInfo(LauncherLogger.LogsDirectory.ToString()))
.ConfigureAwait(false);
}
catch (Exception ex)
{
Ошибки.ПоказатьСообщение(nameof(Окне), ex);
}
}
private void OpenLogFile(object? sender, RoutedEventArgs e)
{
try
{
Launcher.LaunchFileInfoAsync(new FileInfo(Главне.Логгер.LogfileName.ToString()))
.ConfigureAwait(false);
}
catch (Exception ex)
{
Ошибки.ПоказатьСообщение(nameof(Окне), ex);
}
}
private void OpenSourceRepository(object? sender, RoutedEventArgs e)
{
try
{
Launcher.LaunchUriAsync(new Uri("https://timerix.ddns.net:3322/Timerix/mlaumcherb"))
.ConfigureAwait(false);
}
catch (Exception ex)
{
Ошибки.ПоказатьСообщение(nameof(Окне), ex);
}
}
}