логгирование и лисик.gif

This commit is contained in:
Timerix 2024-09-01 23:45:51 +05:00
parent 6a087767a1
commit 1ecc8ccc18
14 changed files with 292 additions and 45 deletions

View File

@ -0,0 +1,13 @@
using DTLib.Filesystem;
using DTLib.Logging;
namespace Млаумчерб.Клиент;
public class LauncherLogger : FileLogger
{
public static readonly IOPath LogsDirectory = "launcher-logs";
public LauncherLogger() : base(LogsDirectory, "млаумчерб")
{
}
}

View File

@ -0,0 +1,13 @@
namespace Млаумчерб.Клиент;
public record struct NetworkTransferResult
{
public long BytesTotal;
public long BytesTransferred;
public long BytesPerSecond;
}
public class NetworkHelper
{
}

View File

@ -2,6 +2,10 @@
global using System.Collections.Generic; global using System.Collections.Generic;
global using System.IO; global using System.IO;
global using System.Text; global using System.Text;
global using DTLib.Logging;
global using DTLib.Filesystem;
global using File = DTLib.Filesystem.File;
global using Directory = DTLib.Filesystem.Directory;
using System.Globalization; using System.Globalization;
using Avalonia; using Avalonia;

View File

@ -0,0 +1,41 @@
using System.Threading.Tasks;
using DTLib.Filesystem;
using Path = DTLib.Filesystem.Path;
namespace Млаумчерб.Клиент;
public interface IGame
{
string Name { get; }
IOPath InstallationDirectory { get; }
Progress<NetworkTransferResult> BeginUpdate();
void EndUpdate();
Task Launch();
}
public class MinecraftVersion : IGame
{
public string Name { get; }
public IOPath InstallationDirectory { get; }
public MinecraftVersion(string name)
{
Name = name;
InstallationDirectory = Path.Concat("minecraft", Path.ReplaceRestrictedChars(name));
}
public Progress<NetworkTransferResult> BeginUpdate()
{
throw new NotImplementedException();
}
public void EndUpdate()
{
throw new NotImplementedException();
}
public Task Launch()
{
throw new NotImplementedException();
}
}

View File

@ -13,15 +13,17 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.3" /> <PackageReference Include="Avalonia" Version="11.*" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.3" /> <PackageReference Include="Avalonia.Desktop" Version="11.*" />
<PackageReference Include="Avalonia.Themes.Simple" Version="11.1.3" /> <PackageReference Include="Avalonia.Themes.Simple" Version="11.*" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3" /> <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.*" />
<PackageReference Include="DTLib" Version="1.3.4" /> <PackageReference Include="AvaloniaGif-Unofficial" Version="1.0.0" />
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.6" /> <PackageReference Include="DTLib" Version="1.3.*" />
<PackageReference Include="DTLib.Logging" Version="1.3.5" /> <PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.*" />
<PackageReference Include="MessageBox.Avalonia" Version="3.1.6" /> <PackageReference Include="DTLib.Logging" Version="1.3.*" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="DTLib.Network" Version="1.4.*" />
<PackageReference Include="MessageBox.Avalonia" Version="3.1.*" />
<PackageReference Include="Newtonsoft.Json" Version="13.*" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,20 +1,20 @@
using Newtonsoft.Json; using DTLib.Logging;
using Newtonsoft.Json;
namespace Млаумчерб.Клиент; namespace Млаумчерб.Клиент;
public class Настройки public record Настройки
{ {
public string имя_пользователя { get; set; } = ""; public string имя_пользователя { get; set; } = "";
public int выделенная_память_мб { get; set; } = 4096; public int выделенная_память_мб { get; set; } = 4096;
public bool открыватьаесь_экран { get; set; } public bool открыватьаесь_экран { get; set; }
public static readonly Encoding UTF8WithoutBom = new UTF8Encoding(false);
public static Настройки ЗагрузитьИзФайла(string имяайла = "млаумчерб.настройки") public static Настройки ЗагрузитьИзФайла(string имяайла = "млаумчерб.настройки")
{ {
//TODO: лог Приложение.Логгер.LogInfo(nameof(Настройки), $"попытка загрузить настройки из файла '{имя_файла}'");
if(!File.Exists(имяайла)) if(!File.Exists(имяайла))
{ {
Приложение.Логгер.LogInfo(nameof(Настройки), "файл не существует");
return new Настройки(); return new Настройки();
} }
@ -30,13 +30,15 @@ public class Настройки
$"Создан новый файл '{имя_файла}'."); $"Создан новый файл '{имя_файла}'.");
} }
Приложение.Логгер.LogInfo(nameof(Настройки), $"настройки загружены: {н}");
return н; return н;
} }
public void СохранитьВФайл(string имяайла = "млаумчерб.настройки") public void СохранитьВФайл(string имяайла = "млаумчерб.настройки")
{ {
//TODO: log Приложение.Логгер.LogInfo(nameof(Настройки), $"попытка сохранить настройки в файл '{имя_файла}'");
var текст = JsonConvert.SerializeObject(this, Formatting.Indented); var текст = JsonConvert.SerializeObject(this, Formatting.Indented);
File.WriteAllText(имяайла, текст, UTF8WithoutBom); File.WriteAllText(имяайла, текст);
Приложение.Логгер.LogInfo(nameof(Настройки), $"настройки сохранены: {текст}");
} }
} }

View File

@ -1,5 +1,7 @@
<Window xmlns="https://github.com/avaloniaui" <Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gif="clr-namespace:Avalonia.Gif;assembly=Avalonia.Gif"
xmlns:local="clr-namespace:Млаумчерб"
x:Class="Млаумчерб.Клиент.Окне" x:Class="Млаумчерб.Клиент.Окне"
Name="window" Name="window"
Title="млаумчерб" Title="млаумчерб"
@ -9,29 +11,39 @@
Width="800" Height="500" Width="800" Height="500"
WindowStartupLocation="CenterScreen"> WindowStartupLocation="CenterScreen">
<Grid> <Grid>
<Grid.RowDefinitions>30 * 30</Grid.RowDefinitions> <Grid.RowDefinitions>* 30</Grid.RowDefinitions>
<Image Grid.RowSpan="3" Stretch="UniformToFill" <Image Grid.RowSpan="2" Stretch="UniformToFill"
Source="avares://млаумчерб/капитал/фоне.png"></Image> Source="avares://млаумчерб/капитал/фоне.png"/>
<!-- <Border Grid.Row="0" Background="#7000b0"></Border> -->
<Grid Grid.Row="1"> <Grid Grid.Row="0" Margin="10">
<Grid.ColumnDefinitions>* 300 *</Grid.ColumnDefinitions> <Grid.ColumnDefinitions>* 300 *</Grid.ColumnDefinitions>
<Border Grid.Column="0" <Border Grid.Column="0"
Classes="dark_box white_border" Classes="dark_tr_bg white_border">
Margin="10 5 ">
<Grid> <Grid>
<Grid.RowDefinitions>30 *</Grid.RowDefinitions> <Grid.RowDefinitions>30 *</Grid.RowDefinitions>
<Grid.ColumnDefinitions>30</Grid.ColumnDefinitions> <Border Classes="white_border" Margin="-1" Padding="4">
<Button></Button> <TextBlock FontWeight="Bold"
HorizontalAlignment="Center"
VerticalAlignment="Center">
News
</TextBlock>
</Border>
</Grid> </Grid>
</Border> </Border>
<Border Grid.Column="1" <Border Grid.Column="1"
Classes="dark_box white_border" Classes="dark_tr_bg white_border"
Margin="5 5"> Margin="10 0">
<Grid> <Grid>
<Grid.RowDefinitions>* 60</Grid.RowDefinitions> <Grid.RowDefinitions>* 60</Grid.RowDefinitions>
<StackPanel Orientation="Vertical" Margin="10" Spacing="10"> <StackPanel Orientation="Vertical" Margin="10" Spacing="10">
<TextBlock>Version:</TextBlock>
<ComboBox Name="VersionComboBox">
</ComboBox>
<TextBlock>Username:</TextBlock> <TextBlock>Username:</TextBlock>
<TextBox Text="{Binding #window.Username}"></TextBox> <TextBox Text="{Binding #window.Username}"></TextBox>
<TextBlock> <TextBlock>
<Run>Memory limit:</Run> <Run>Memory limit:</Run>
<TextBox Background="Transparent" Padding="0" <TextBox Background="Transparent" Padding="0"
@ -42,18 +54,19 @@
<Run>Mb</Run> <Run>Mb</Run>
</TextBlock> </TextBlock>
<Slider Minimum="2048" Maximum="8192" <Slider Minimum="2048" Maximum="8192"
Foreground="Blue"
Value="{Binding #window.MemoryLimit}"> Value="{Binding #window.MemoryLimit}">
</Slider> </Slider>
<CheckBox IsChecked="{Binding #window.Fullscreen}"> <CheckBox IsChecked="{Binding #window.Fullscreen}">
Fullscreen Fullscreen
</CheckBox> </CheckBox>
<CheckBox IsChecked="{Binding #window.UpdateGameFiles}"> <CheckBox IsChecked="{Binding #window.UpdateGameFiles}">
Update game files Update game files
</CheckBox> </CheckBox>
</StackPanel> </StackPanel>
<Button Grid.Row="1" Margin="10" Padding="0 0 0 5" <Button Grid.Row="1" Margin="10" Padding="0 0 0 4"
BorderThickness="2" BorderBrush="Transparent" Classes="button_no_border"
Background="#BBFF5900" Background="#BBFF5900"
Click="LaunchButtonHandler"> Click="LaunchButtonHandler">
Launch Launch
@ -61,11 +74,33 @@
</Grid> </Grid>
</Border> </Border>
<Border Grid.Column="2" <Border Grid.Column="2" Classes="dark_tr_bg white_border">
Classes="dark_box white_border" <Grid>
Margin="10 5"> <Grid.RowDefinitions>30 *</Grid.RowDefinitions>
<Border Classes="white_border" Margin="-1" Padding="4">
<TextBlock FontWeight="Bold"
HorizontalAlignment="Center"
VerticalAlignment="Center">
Downloads
</TextBlock>
</Border>
</Grid>
</Border> </Border>
</Grid> </Grid>
<Border Grid.Row="1" Background="#6f4808B0">
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Button Classes="menu_button button_no_border" Click="OpenLogsDirectory">logs directory</Button>
<Border Classes="menu_separator"></Border>
<Button Classes="menu_button button_no_border" Click="OpenLogFile">log file</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Classes="menu_button button_no_border" Click="OpenSourceRepository">source code</Button>
<gif:GifImage
Width="30" Height="30" Stretch="Uniform"
SourceUri="avares://млаумчерб/капитал/лисик.gif"/>
</StackPanel>
</Grid>
</Border>
</Grid> </Grid>
</Window> </Window>

View File

@ -1,8 +1,8 @@
using System.ComponentModel.DataAnnotations;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
namespace Млаумчерб.Клиент; namespace Млаумчерб.Клиент;
@ -79,4 +79,19 @@ public partial class Окне : Window
Ошибки.ПоказатьСообщение(ex); Ошибки.ПоказатьСообщение(ex);
} }
} }
private void OpenLogsDirectory(object? s, RoutedEventArgs e)
{
Launcher.LaunchDirectoryInfoAsync(new DirectoryInfo(LauncherLogger.LogsDirectory.ToString()));
}
private void OpenLogFile(object? sender, RoutedEventArgs e)
{
Launcher.LaunchFileInfoAsync(new FileInfo(Приложение.Логгер.LogfileName.ToString()));
}
private void OpenSourceRepository(object? sender, RoutedEventArgs e)
{
Launcher.LaunchUriAsync(new Uri("https://timerix.ddns.net:3322/Timerix/mlaumcherb"));
}
} }

View File

@ -1,7 +1,9 @@
using Avalonia.Controls; using Avalonia.Controls;
using DTLib.Ben.Demystifier; using DTLib.Ben.Demystifier;
using DTLib.Logging;
using MsBox.Avalonia; using MsBox.Avalonia;
using MsBox.Avalonia.Dto; using MsBox.Avalonia.Dto;
using MsBox.Avalonia.Enums;
using MsBox.Avalonia.Models; using MsBox.Avalonia.Models;
namespace Млаумчерб.Клиент; namespace Млаумчерб.Клиент;
@ -13,12 +15,13 @@ public static class Ошибки
internal static async void ПоказатьСообщение(string err) internal static async void ПоказатьСообщение(string err)
{ {
Приложение.Логгер.LogError(nameof(Ошибки), err);
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
{ {
ButtonDefinitions = new List<ButtonDefinition> { new() { Name = "пон" } }, ButtonDefinitions = new List<ButtonDefinition> { new() { Name = "пон" } },
ContentTitle = "ОШИБКА", ContentTitle = "ОШИБКА",
ContentMessage = err, ContentMessage = err,
Icon = MsBox.Avalonia.Enums.Icon.Error, Icon = Icon.Error,
WindowStartupLocation = WindowStartupLocation.CenterOwner, WindowStartupLocation = WindowStartupLocation.CenterOwner,
CanResize = true, CanResize = true,
MaxWidth = 1000, MaxWidth = 1000,
@ -28,7 +31,6 @@ public static class Ошибки
Topmost = true Topmost = true
} }
); );
//TODO: write to log
await box.ShowAsync().ConfigureAwait(false); await box.ShowAsync().ConfigureAwait(false);
} }
} }

View File

@ -5,18 +5,31 @@
<Application.Styles> <Application.Styles>
<SimpleTheme /> <SimpleTheme />
<Style Selector="Control.center"> <Style Selector="Border.dark_tr_bg">
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style Selector="Border.dark_box">
<Setter Property="Background" Value="#b7303040"/> <Setter Property="Background" Value="#b7303040"/>
</Style> </Style>
<Style Selector="Control.white_border">
<Style Selector="Border.white_border">
<Setter Property="BorderThickness" Value="1"/> <Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="White"/> <Setter Property="BorderBrush" Value="White"/>
</Style> </Style>
<Style Selector="Button.button_no_border">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="Transparent"/>
</Style>
<Style Selector="Button.menu_button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Padding" Value="4 0"/>
<Setter Property="MinWidth" Value="50"/>
</Style>
<Style Selector="Border.menu_separator">
<Setter Property="Background" Value="#ff505050"/>
<Setter Property="Width" Value="1"/>
<Setter Property="Margin" Value="4"/>
</Style>
</Application.Styles> </Application.Styles>
<Application.Resources> <Application.Resources>

View File

@ -4,10 +4,13 @@ using Avalonia.Markup.Xaml;
namespace Млаумчерб.Клиент; namespace Млаумчерб.Клиент;
public partial class Приложение : Application public class Приложение : Application
{ {
public static readonly LauncherLogger Логгер = new();
public override void Initialize() public override void Initialize()
{ {
Логгер.LogInfo(nameof(Приложение), "приложение запущено");
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View File

@ -0,0 +1,98 @@
using Newtonsoft.Json;
namespace Млаумчерб.Клиент.классы;
public class Artifact
{
[JsonRequired] public string url { get; set; } = "";
[JsonRequired] public string sha1 { get; set; } = "";
[JsonRequired] public int size { get; set; }
}
public class Os
{
[JsonRequired] public string name { get; set; } = "";
}
public class Rule
{
[JsonRequired] public string action { get; set; } = "";
[JsonRequired] public Os os { get; set; } = null!;
}
public class Classifiers
{
[JsonProperty("natives-linux")]
public Artifact? nativeslinux { get; set; }
[JsonProperty("natives-osx")]
public Artifact? nativesosx { get; set; }
[JsonProperty("natives-windows")]
public Artifact? nativeswindows { get; set; }
}
public class LibraryDownloads
{
public Artifact? artifact { get; set; }
public Classifiers? classifiers { get; set; }
}
public class Extract
{
public List<string>? exclude { get; set; }
}
public class Natives
{
public string? linux { get; set; }
public string? osx { get; set; }
public string? windows { get; set; }
}
public class Library
{
[JsonRequired] public string name { get; set; } = "";
public List<Rule>? rules { get; set; }
public Natives? natives { get; set; }
public Extract? extract { get; set; }
[JsonRequired] public LibraryDownloads downloads { get; set; } = null!;
}
public class AssetIndex
{
[JsonRequired] public string id { get; set; } = "";
[JsonRequired] public int totalSize { get; set; }
[JsonRequired] public bool known { get; set; }
[JsonRequired] public string url { get; set; } = "";
[JsonRequired] public string sha1 { get; set; } = "";
[JsonRequired] public int size { get; set; }
}
public class Downloads
{
[JsonRequired] public Artifact client { get; set; } = null!;
}
public class JavaVersion
{
[JsonRequired] public string component { get; set; } = "";
[JsonRequired] public int majorVersion { get; set; }
}
public class MinecraftVersionDescriptor
{
[JsonRequired] public string id { get; set; } = "";
[JsonRequired] public string jar { get; set; } = "";
[JsonRequired] public string family { get; set; } = "";
[JsonRequired] public DateTime time { get; set; }
[JsonRequired] public DateTime releaseTime { get; set; }
[JsonRequired] public string type { get; set; } = "";
[JsonRequired] public string mainClass { get; set; } = "";
[JsonRequired] public Downloads downloads { get; set; } = null!;
[JsonRequired] public JavaVersion javaVersion { get; set; } = null!;
[JsonRequired] public List<Library> libraries { get; set; } = null!;
[JsonRequired] public AssetIndex assetIndex { get; set; } = null!;
[JsonRequired] public string assets { get; set; } = "";
// public string minecraftArguments { get; set; }
}

View File

@ -0,0 +1,6 @@
namespace Млаумчерб.Клиент.классы;
public class Пролетариат
{
}