логи
This commit is contained in:
parent
d24dbea501
commit
45c3f90da0
@ -1,13 +0,0 @@
|
||||
namespace Млаумчерб.Клиент;
|
||||
|
||||
public class LauncherLogger : FileLogger
|
||||
{
|
||||
public static readonly IOPath LogsDirectory = "launcher_logs";
|
||||
|
||||
public LauncherLogger() : base(LogsDirectory, "млаумчерб")
|
||||
{
|
||||
#if DEBUG
|
||||
DebugLogEnabled = true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -19,10 +19,6 @@ namespace Млаумчерб.Клиент;
|
||||
|
||||
public class Главне
|
||||
{
|
||||
public static readonly LauncherLogger Логгер = new();
|
||||
|
||||
public static Настройки Настройки = new();
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
@ -34,7 +30,7 @@ public class Главне
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Логгер.LogError(nameof(Главне), ex);
|
||||
Приложение.Логгер.LogError(nameof(Главне), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
using DTLib.Extensions;
|
||||
using Млаумчерб.Клиент.видимое;
|
||||
using Млаумчерб.Клиент.классы;
|
||||
using static Млаумчерб.Клиент.классы.Пролетариат;
|
||||
using static Млаумчерб.Клиент.классы.Пути;
|
||||
|
||||
namespace Млаумчерб.Клиент;
|
||||
|
||||
@ -49,13 +49,13 @@ public class GameVersionDescriptor
|
||||
private GameVersionDescriptor(GameVersionProps props)
|
||||
{
|
||||
_props = props;
|
||||
WorkingDirectory = Path.Concat(Главне.Настройки.путь_к_кубачу, Name);
|
||||
WorkingDirectory = Path.Concat(Приложение.Настройки.путь_к_кубачу, Name);
|
||||
string descriptorText = File.ReadAllText(props.LocalDescriptorPath);
|
||||
descriptor = JsonConvert.DeserializeObject<MinecraftVersionDescriptor>(descriptorText)
|
||||
?? throw new Exception($"can't parse descriptor file '{props.LocalDescriptorPath}'");
|
||||
javaArgs = new JavaArguments(descriptor);
|
||||
gameArgs = new GameArguments(descriptor);
|
||||
JavaExecutableFilePath = Path.Concat(Главне.Настройки.путь_к_жабе, "bin",
|
||||
JavaExecutableFilePath = Path.Concat(Приложение.Настройки.путь_к_жабе, "bin",
|
||||
OperatingSystem.IsWindows() ? "javaw.exe" : "javaw");
|
||||
}
|
||||
|
||||
@ -64,8 +64,8 @@ public class GameVersionDescriptor
|
||||
try
|
||||
{
|
||||
downloadCts = new CancellationTokenSource();
|
||||
if(Главне.Настройки.скачать_жабу)
|
||||
await Сеть.DownloadJava(descriptor.javaVersion, Главне.Настройки.путь_к_жабе, force);
|
||||
if(Приложение.Настройки.скачать_жабу)
|
||||
await Сеть.DownloadJava(descriptor.javaVersion, Приложение.Настройки.путь_к_жабе, force);
|
||||
await Сеть.DownloadAssets(descriptor.assetIndex, downloadCts.Token, force);
|
||||
await Сеть.DownloadVersionFile(descriptor.downloads.client.url, GetVersionJarFilePath(Name), force);
|
||||
await Сеть.DownloadLibraries(descriptor.libraries, GetLibrariesDir(), force);
|
||||
@ -91,7 +91,7 @@ public class GameVersionDescriptor
|
||||
.WithWorkingDirectory(WorkingDirectory.ToString())
|
||||
.WithArguments(javaArgsList)
|
||||
.WithArguments(gameArgsList);
|
||||
Главне.Логгер.LogInfo(nameof(GameVersionDescriptor),
|
||||
Приложение.Логгер.LogInfo(nameof(GameVersionDescriptor),
|
||||
$"launching the game" +
|
||||
"\njava: " + command.TargetFilePath +
|
||||
"\nworking_dir: " + command.WorkingDirPath +
|
||||
@ -100,7 +100,7 @@ public class GameVersionDescriptor
|
||||
gameCts = new();
|
||||
commandTask = command.ExecuteAsync(gameCts.Token);
|
||||
var result = await commandTask;
|
||||
Главне.Логгер.LogInfo(nameof(GameVersionDescriptor), $"game exited with code {result.ExitCode}");
|
||||
Приложение.Логгер.LogInfo(nameof(GameVersionDescriptor), $"game exited with code {result.ExitCode}");
|
||||
}
|
||||
|
||||
public void Close()
|
||||
|
||||
79
Млаумчерб.Клиент/Логи.cs
Normal file
79
Млаумчерб.Клиент/Логи.cs
Normal file
@ -0,0 +1,79 @@
|
||||
namespace Млаумчерб.Клиент;
|
||||
|
||||
public class LauncherLogger : ILogger
|
||||
{
|
||||
private CompositeLogger _compositeLogger;
|
||||
private FileLogger _fileLogger;
|
||||
public static readonly IOPath LogsDirectory = "launcher_logs";
|
||||
public IOPath LogfileName => _fileLogger.LogfileName;
|
||||
|
||||
public LauncherLogger()
|
||||
{
|
||||
_fileLogger = new FileLogger(LogsDirectory, "млаумчерб");
|
||||
ILogger[] loggers =
|
||||
[
|
||||
_fileLogger,
|
||||
#if DEBUG
|
||||
new ConsoleLogger(),
|
||||
#endif
|
||||
];
|
||||
_compositeLogger = new CompositeLogger(loggers);
|
||||
|
||||
#if DEBUG
|
||||
DebugLogEnabled = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
public delegate void LogHandler(string context, LogSeverity severity, object message, ILogFormat format);
|
||||
public event LogHandler? OnLogMessage;
|
||||
|
||||
public void Log(string context, LogSeverity severity, object message, ILogFormat format)
|
||||
{
|
||||
_compositeLogger.Log(context, severity, message, format);
|
||||
bool isEnabled = severity switch
|
||||
{
|
||||
LogSeverity.Debug => DebugLogEnabled,
|
||||
LogSeverity.Info => InfoLogEnabled,
|
||||
LogSeverity.Warn => WarnLogEnabled,
|
||||
LogSeverity.Error => ErrorLogEnabled,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(severity), severity, null)
|
||||
};
|
||||
if(isEnabled)
|
||||
OnLogMessage?.Invoke(context, severity, message, format);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_compositeLogger.Dispose();
|
||||
}
|
||||
|
||||
public ILogFormat Format
|
||||
{
|
||||
get => _compositeLogger.Format;
|
||||
set => _compositeLogger.Format = value;
|
||||
}
|
||||
|
||||
public bool DebugLogEnabled
|
||||
{
|
||||
get => _compositeLogger.DebugLogEnabled;
|
||||
set => _compositeLogger.DebugLogEnabled = value;
|
||||
}
|
||||
|
||||
public bool InfoLogEnabled
|
||||
{
|
||||
get => _compositeLogger.InfoLogEnabled;
|
||||
set => _compositeLogger.InfoLogEnabled = value;
|
||||
}
|
||||
|
||||
public bool WarnLogEnabled
|
||||
{
|
||||
get => _compositeLogger.WarnLogEnabled;
|
||||
set => _compositeLogger.WarnLogEnabled = value;
|
||||
}
|
||||
|
||||
public bool ErrorLogEnabled
|
||||
{
|
||||
get => _compositeLogger.ErrorLogEnabled;
|
||||
set => _compositeLogger.ErrorLogEnabled = value;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<OutputType Condition="'$(Configuration)' == 'Debug'">Exe</OutputType>
|
||||
<OutputType Condition="'$(Configuration)' != 'Debug'">WinExe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
@ -21,7 +22,7 @@
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.*" />
|
||||
<PackageReference Include="Avalonia.Labs.Gif" Version="11.2.999-cibuild-00051673"/>
|
||||
<PackageReference Include="CliWrap" Version="3.6.*" />
|
||||
<PackageReference Include="DTLib" Version="1.4.1" />
|
||||
<PackageReference Include="DTLib" Version="1.4.2" />
|
||||
<PackageReference Include="MessageBox.Avalonia" Version="3.1.*" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.*" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -14,10 +14,10 @@ public record Настройки
|
||||
|
||||
public static Настройки ЗагрузитьИзФайла(string имя_файла = "млаумчерб.настройки")
|
||||
{
|
||||
Главне.Логгер.LogInfo(nameof(Настройки), $"попытка загрузить настройки из файла '{имя_файла}'");
|
||||
Приложение.Логгер.LogInfo(nameof(Настройки), $"попытка загрузить настройки из файла '{имя_файла}'");
|
||||
if(!File.Exists(имя_файла))
|
||||
{
|
||||
Главне.Логгер.LogInfo(nameof(Настройки), "файл не существует");
|
||||
Приложение.Логгер.LogInfo(nameof(Настройки), "файл не существует");
|
||||
return new Настройки();
|
||||
}
|
||||
|
||||
@ -33,15 +33,15 @@ public record Настройки
|
||||
$"Создан новый файл '{имя_файла}'.");
|
||||
}
|
||||
|
||||
Главне.Логгер.LogInfo(nameof(Настройки), $"настройки загружены: {н}");
|
||||
Приложение.Логгер.LogInfo(nameof(Настройки), $"настройки загружены: {н}");
|
||||
return н;
|
||||
}
|
||||
|
||||
public void СохранитьВФайл(string имя_файла = "млаумчерб.настройки")
|
||||
{
|
||||
Главне.Логгер.LogInfo(nameof(Настройки), $"попытка сохранить настройки в файл '{имя_файла}'");
|
||||
Приложение.Логгер.LogInfo(nameof(Настройки), $"попытка сохранить настройки в файл '{имя_файла}'");
|
||||
var текст = JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
File.WriteAllText(имя_файла, текст);
|
||||
Главне.Логгер.LogInfo(nameof(Настройки), $"настройки сохранены: {текст}");
|
||||
Приложение.Логгер.LogInfo(nameof(Настройки), $"настройки сохранены: {текст}");
|
||||
}
|
||||
}
|
||||
@ -15,7 +15,7 @@ public static class Ошибки
|
||||
|
||||
internal static async void ПоказатьСообщение(string context, string err)
|
||||
{
|
||||
Главне.Логгер.LogError(nameof(Ошибки), err);
|
||||
Приложение.Логгер.LogError(nameof(Ошибки), err);
|
||||
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
|
||||
{
|
||||
ButtonDefinitions = new List<ButtonDefinition> { new() { Name = "пон" } },
|
||||
|
||||
@ -55,7 +55,7 @@ public static class Сеть
|
||||
|
||||
public static async Task DownloadAssets(AssetIndexProperties assetIndexProperties, CancellationToken ct, bool force)
|
||||
{
|
||||
IOPath indexFilePath = Пролетариат.GetAssetIndexFilePath(assetIndexProperties.id);
|
||||
IOPath indexFilePath = Пути.GetAssetIndexFilePath(assetIndexProperties.id);
|
||||
if (File.Exists(indexFilePath) && !force)
|
||||
return;
|
||||
|
||||
@ -64,9 +64,9 @@ public static class Сеть
|
||||
File.Delete(indexFilePathTmp);
|
||||
|
||||
// TODO: add something to Downloads ScrollList
|
||||
Главне.Логгер.LogInfo(nameof(DownloadAssets), $"started downloading asset index to '{indexFilePathTmp}'");
|
||||
Приложение.Логгер.LogInfo(nameof(DownloadAssets), $"started downloading asset index to '{indexFilePathTmp}'");
|
||||
await DownloadFileHTTP(assetIndexProperties.url, indexFilePathTmp, null, ct);
|
||||
Главне.Логгер.LogInfo(nameof(DownloadAssets), "finished downloading asset index");
|
||||
Приложение.Логгер.LogInfo(nameof(DownloadAssets), "finished downloading asset index");
|
||||
|
||||
string indexFileText = File.ReadAllText(indexFilePathTmp);
|
||||
AssetIndex assetIndex = JsonConvert.DeserializeObject<AssetIndex>(indexFileText)
|
||||
@ -102,13 +102,13 @@ public static class Сеть
|
||||
long bytesPerSec = (currentSize - prevSize) / (timerDelay / 1000);
|
||||
float KbytesPerSec = bytesPerSec / 1024f;
|
||||
prevSize = currentSize;
|
||||
Главне.Логгер.LogDebug(nameof(DownloadAssets),
|
||||
Приложение.Логгер.LogDebug(nameof(DownloadAssets),
|
||||
$"download progress {currentSizeM}Mb/{totalSizeM}Mb ({KbytesPerSec}Kb/s)");
|
||||
}
|
||||
using Timer timer = new Timer(true, timerDelay, ReportProgress);
|
||||
timer.Start();
|
||||
|
||||
Главне.Логгер.LogInfo(nameof(DownloadAssets), "started downloading assets");
|
||||
Приложение.Логгер.LogInfo(nameof(DownloadAssets), "started downloading assets");
|
||||
int parallelDownloads = 32;
|
||||
var tasks = new Task[parallelDownloads];
|
||||
var currentlyDownloadingFileHashes = new string[parallelDownloads];
|
||||
@ -119,7 +119,7 @@ public static class Сеть
|
||||
string hashStart = hash.Substring(0, 2);
|
||||
var assetUrl = $"{ASSET_SERVER_URL}/{hashStart}/{hash}";
|
||||
IOPath assetFilePath = Path.Concat("assets", "objects", hashStart, hash);
|
||||
Главне.Логгер.LogDebug(nameof(DownloadAssets), $"downloading asset '{a.Key}' {hash}");
|
||||
Приложение.Логгер.LogDebug(nameof(DownloadAssets), $"downloading asset '{a.Key}' {hash}");
|
||||
tasks[i] = DownloadFileHTTP(assetUrl, assetFilePath, AddBytesCountAtomic, ct);
|
||||
currentlyDownloadingFileHashes[i] = hash;
|
||||
if (++i == parallelDownloads)
|
||||
@ -133,7 +133,7 @@ public static class Сеть
|
||||
timer.Stop();
|
||||
timer.InvokeAction();
|
||||
File.Move(indexFilePathTmp, indexFilePath, true);
|
||||
Главне.Логгер.LogInfo(nameof(DownloadAssets), "finished downloading assets");
|
||||
Приложение.Логгер.LogInfo(nameof(DownloadAssets), "finished downloading assets");
|
||||
}
|
||||
|
||||
private static async Task<List<RemoteVersionDescriptorProps>> GetRemoteVersionDescriptorsAsync()
|
||||
@ -150,7 +150,7 @@ public static class Сеть
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Главне.Логгер.LogWarn(nameof(Сеть), ex);
|
||||
Приложение.Логгер.LogWarn(nameof(Сеть), ex);
|
||||
}
|
||||
}
|
||||
return descriptors;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
Name="window"
|
||||
Title="млаумчерб"
|
||||
Icon="avares://млаумчерб/капитал/кубе.ico"
|
||||
FontFamily="{StaticResource PlexMono}" FontSize="18"
|
||||
FontFamily="{StaticResource MonospaceFont}" FontSize="18"
|
||||
MinWidth="800" MinHeight="500"
|
||||
Width="800" Height="500"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
@ -25,9 +25,18 @@
|
||||
<TextBlock FontWeight="Bold"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
News
|
||||
Лог
|
||||
</TextBlock>
|
||||
</Border>
|
||||
<ScrollViewer Name="LogScrollViewer" Grid.Row="1"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
VerticalScrollBarVisibility="Visible"
|
||||
Background="Transparent">
|
||||
<TextBox Name="LogTextBox"
|
||||
FontSize="12"
|
||||
IsReadOnly="True" TextWrapping="Wrap"
|
||||
Background="Transparent" BorderThickness="0"/>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Border>
|
||||
<Border Grid.Column="1"
|
||||
@ -36,40 +45,39 @@
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>* 60</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Vertical" Margin="10" Spacing="10">
|
||||
<TextBlock>Version:</TextBlock>
|
||||
<ComboBox Name="VersionComboBox">
|
||||
|
||||
</ComboBox>
|
||||
<TextBlock>Версия:</TextBlock>
|
||||
<ComboBox Name="VersionComboBox"/>
|
||||
|
||||
<TextBlock>Username:</TextBlock>
|
||||
<TextBox Text="{Binding #window.Username}"></TextBox>
|
||||
<TextBlock>Ник:</TextBlock>
|
||||
<TextBox Background="Transparent"
|
||||
Text="{Binding #window.Username}"/>
|
||||
|
||||
<TextBlock>
|
||||
<Run>Memory limit:</Run>
|
||||
<Run>Выделенная память:</Run>
|
||||
<TextBox Background="Transparent" Padding="0"
|
||||
BorderThickness="1"
|
||||
BorderBrush="#777777"
|
||||
Text="{Binding #window.MemoryLimit}">
|
||||
</TextBox>
|
||||
<Run>Mb</Run>
|
||||
<Run>Мб</Run>
|
||||
</TextBlock>
|
||||
<Slider Minimum="2048" Maximum="8192"
|
||||
Value="{Binding #window.MemoryLimit}">
|
||||
</Slider>
|
||||
|
||||
<CheckBox IsChecked="{Binding #window.Fullscreen}">
|
||||
Fullscreen
|
||||
Запустить полноэкранное
|
||||
</CheckBox>
|
||||
|
||||
<CheckBox IsChecked="{Binding #window.ForceUpdateGameFiles}">
|
||||
Force update game files
|
||||
<CheckBox IsChecked="{Binding #window.CheckGameFiles}">
|
||||
Проверить файлы игры
|
||||
</CheckBox>
|
||||
</StackPanel>
|
||||
<Button Grid.Row="1" Margin="10" Padding="0 0 0 4"
|
||||
Classes="button_no_border"
|
||||
Background="#BBFF5900"
|
||||
Click="LaunchButtonHandler">
|
||||
Launch
|
||||
Background="#BBfd7300"
|
||||
Click="Запуск">
|
||||
Запуск
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
@ -81,21 +89,25 @@
|
||||
<TextBlock FontWeight="Bold"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
Downloads
|
||||
Загрузки
|
||||
</TextBlock>
|
||||
</Border>
|
||||
<ScrollViewer Name="DownloadsScrollViewer" Grid.Row="1"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
VerticalScrollBarVisibility="Visible"
|
||||
Background="Transparent"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
<Border Grid.Row="1" Background="#954808B0">
|
||||
<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>
|
||||
<Button Classes="menu_button button_no_border" Click="ОткрытьПапкуЛаунчера">директория лаунчера</Button>
|
||||
<Border Classes="menu_separator"/>
|
||||
<Button Classes="menu_button button_no_border" Click="ОткрытьФайлЛогов">лог-файл</Button>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Classes="menu_button button_no_border" Click="OpenSourceRepository">source code</Button>
|
||||
<Button Classes="menu_button button_no_border" Click="ОткрытьРепозиторий">исходный код</Button>
|
||||
<gif:GifImage
|
||||
Width="30" Height="30" Stretch="Uniform"
|
||||
Source="avares://млаумчерб/капитал/лисик.gif"/>
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Presenters;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using Avalonia.VisualTree;
|
||||
using Млаумчерб.Клиент.классы;
|
||||
|
||||
namespace Млаумчерб.Клиент.видимое;
|
||||
@ -37,13 +39,13 @@ public partial class Окне : Window
|
||||
set => SetValue(FullscreenProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> ForceUpdateGameFilesProperty =
|
||||
AvaloniaProperty.Register<Окне, bool>(nameof(ForceUpdateGameFiles),
|
||||
public static readonly StyledProperty<bool> CheckGameFilesProperty =
|
||||
AvaloniaProperty.Register<Окне, bool>(nameof(CheckGameFiles),
|
||||
defaultBindingMode: BindingMode.TwoWay, defaultValue: false);
|
||||
public bool ForceUpdateGameFiles
|
||||
public bool CheckGameFiles
|
||||
{
|
||||
get => GetValue(ForceUpdateGameFilesProperty);
|
||||
set => SetValue(ForceUpdateGameFilesProperty, value);
|
||||
get => GetValue(CheckGameFilesProperty);
|
||||
set => SetValue(CheckGameFilesProperty, value);
|
||||
}
|
||||
|
||||
public Окне()
|
||||
@ -55,12 +57,28 @@ public partial class Окне : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
Главне.Настройки = Настройки.ЗагрузитьИзФайла();
|
||||
Username = Главне.Настройки.имя_пользователя;
|
||||
MemoryLimit = Главне.Настройки.выделенная_память_мб;
|
||||
Fullscreen = Главне.Настройки.открывать_на_весь_экран;
|
||||
Приложение.Логгер.OnLogMessage += (context, severity, message, format) =>
|
||||
{
|
||||
StringBuilder b = new();
|
||||
b.Append(DateTime.Now.ToString("[HH:mm:ss]["));
|
||||
b.Append(severity);
|
||||
b.Append("]: ");
|
||||
b.Append(message);
|
||||
b.Append('\n');
|
||||
double offsetFromBottom = LogScrollViewer.Extent.Height
|
||||
- LogScrollViewer.Offset.Y
|
||||
- LogScrollViewer.Viewport.Height;
|
||||
bool is_scrolled_to_end = offsetFromBottom < 20.0; // scrolled less then one line up
|
||||
LogTextBox.Text += b.ToString();
|
||||
if(is_scrolled_to_end)
|
||||
LogScrollViewer.ScrollToEnd();
|
||||
};
|
||||
|
||||
Directory.Create(Пролетариат.GetVersionDescriptorDir());
|
||||
Username = Приложение.Настройки.имя_пользователя;
|
||||
MemoryLimit = Приложение.Настройки.выделенная_память_мб;
|
||||
Fullscreen = Приложение.Настройки.открывать_на_весь_экран;
|
||||
|
||||
Directory.Create(Пути.GetVersionDescriptorDir());
|
||||
VersionComboBox.SelectedIndex = 0;
|
||||
VersionComboBox.IsEnabled = false;
|
||||
var versions = await GameVersionDescriptor.GetAllVersionsAsync();
|
||||
@ -69,8 +87,8 @@ public partial class Окне : Window
|
||||
foreach (var p in versions)
|
||||
{
|
||||
VersionComboBox.Items.Add(new VersionItemView(p));
|
||||
if (Главне.Настройки.последняя_запущенная_версия != null &&
|
||||
p.Name == Главне.Настройки.последняя_запущенная_версия)
|
||||
if (Приложение.Настройки.последняя_запущенная_версия != null &&
|
||||
p.Name == Приложение.Настройки.последняя_запущенная_версия)
|
||||
VersionComboBox.SelectedIndex = VersionComboBox.Items.Count - 1;
|
||||
}
|
||||
VersionComboBox.IsEnabled = true;
|
||||
@ -82,24 +100,23 @@ public partial class Окне : Window
|
||||
}
|
||||
}
|
||||
|
||||
private async void LaunchButtonHandler(object? sender, RoutedEventArgs e)
|
||||
private async void Запуск(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var selectedVersionView = (VersionItemView?)VersionComboBox.SelectedItem;
|
||||
var selectedVersion = selectedVersionView?.Props;
|
||||
Главне.Настройки.последняя_запущенная_версия = selectedVersion?.Name;
|
||||
Главне.Настройки.имя_пользователя = Username;
|
||||
Главне.Настройки.выделенная_память_мб = MemoryLimit;
|
||||
Главне.Настройки.открывать_на_весь_экран = Fullscreen;
|
||||
Главне.Настройки.СохранитьВФайл();
|
||||
Приложение.Настройки.последняя_запущенная_версия = selectedVersion?.Name;
|
||||
Приложение.Настройки.имя_пользователя = Username;
|
||||
Приложение.Настройки.выделенная_память_мб = MemoryLimit;
|
||||
Приложение.Настройки.открывать_на_весь_экран = Fullscreen;
|
||||
Приложение.Настройки.СохранитьВФайл();
|
||||
if (selectedVersion == null)
|
||||
return;
|
||||
|
||||
var v = await GameVersionDescriptor.CreateFromPropsAsync(selectedVersion);
|
||||
v.BeginUpdate(ForceUpdateGameFiles);
|
||||
Dispatcher.UIThread.Invoke(() => ForceUpdateGameFiles = false);
|
||||
v.BeginUpdate(CheckGameFiles);
|
||||
Dispatcher.UIThread.Invoke(() => CheckGameFiles = false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -107,11 +124,11 @@ public partial class Окне : Window
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenLogsDirectory(object? s, RoutedEventArgs e)
|
||||
private void ОткрытьПапкуЛаунчера(object? s, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Launcher.LaunchDirectoryInfoAsync(new DirectoryInfo(LauncherLogger.LogsDirectory.ToString()))
|
||||
Launcher.LaunchDirectoryInfoAsync(new DirectoryInfo(Directory.GetCurrent().ToString()))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -120,11 +137,11 @@ public partial class Окне : Window
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenLogFile(object? sender, RoutedEventArgs e)
|
||||
private void ОткрытьФайлЛогов(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Launcher.LaunchFileInfoAsync(new FileInfo(Главне.Логгер.LogfileName.ToString()))
|
||||
Launcher.LaunchFileInfoAsync(new FileInfo(Приложение.Логгер.LogfileName.ToString()))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -133,7 +150,7 @@ public partial class Окне : Window
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenSourceRepository(object? sender, RoutedEventArgs e)
|
||||
private void ОткрытьРепозиторий(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@ -30,9 +30,30 @@
|
||||
<Setter Property="Width" Value="1"/>
|
||||
<Setter Property="Margin" Value="4"/>
|
||||
</Style>
|
||||
|
||||
<Style Selector="ScrollBar /template/ Border">
|
||||
<Setter Property="Width" Value="5"/>
|
||||
<Setter Property="Margin" Value="4"/>
|
||||
<Setter Property="ClipToBounds" Value="True"/>
|
||||
<Setter Property="CornerRadius" Value="0"/>
|
||||
</Style>
|
||||
<Style Selector="ScrollBar /template/ Rectangle">
|
||||
<Setter Property="Fill" Value="#d8ceb9"/>
|
||||
</Style>
|
||||
<Style Selector="ScrollBar /template/ Thumb">
|
||||
<Setter Property="Background" Value="#fd7300"/>
|
||||
<Setter Property="Cursor" Value="Hand"/>
|
||||
<Setter Property="CornerRadius" Value="0"/>
|
||||
</Style>
|
||||
<Style Selector="ScrollBar /template/ Thumb /template/ Border">
|
||||
<Setter Property="ClipToBounds" Value="True"/>
|
||||
<Setter Property="CornerRadius" Value="0"/>
|
||||
<Setter Property="Width" Value="5"/>
|
||||
</Style>
|
||||
|
||||
</Application.Styles>
|
||||
|
||||
<Application.Resources>
|
||||
<FontFamily x:Key="PlexMono">avares://млаумчерб/капитал/IBMPlexMono-Regular.ttf</FontFamily>
|
||||
<FontFamily x:Key="MonospaceFont">avares://млаумчерб/капитал/IBMPlexMono-Regular.ttf</FontFamily>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
@ -6,9 +6,13 @@ namespace Млаумчерб.Клиент.видимое;
|
||||
|
||||
public class Приложение : Application
|
||||
{
|
||||
public static LauncherLogger Логгер = new();
|
||||
public static Настройки Настройки = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
Главне.Логгер.LogInfo(nameof(Приложение), "приложение запущено");
|
||||
Логгер.LogInfo(nameof(Приложение), "приложение запущено");
|
||||
Настройки = Настройки.ЗагрузитьИзФайла();
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
|
||||
@ -22,11 +22,11 @@ public class GameVersionProps
|
||||
Name = name;
|
||||
LocalDescriptorPath = descriptorPath;
|
||||
RemoteDescriptorUrl = url;
|
||||
IsDownloaded = File.Exists(Пролетариат.GetVersionJarFilePath(name));
|
||||
IsDownloaded = File.Exists(Пути.GetVersionJarFilePath(name));
|
||||
}
|
||||
|
||||
public GameVersionProps(string name, string? url) :
|
||||
this(name, url, Пролетариат.GetVersionDescriptorPath(name)) { }
|
||||
this(name, url, Пути.GetVersionDescriptorPath(name)) { }
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
@ -1,27 +1,6 @@
|
||||
using Млаумчерб.Клиент.видимое;
|
||||
|
||||
namespace Млаумчерб.Клиент.классы;
|
||||
namespace Млаумчерб.Клиент.классы;
|
||||
|
||||
public static class Пролетариат
|
||||
{
|
||||
public static IOPath GetAssetIndexFilePath(string id) =>
|
||||
Path.Concat(Главне.Настройки.путь_к_кубачу, $"assets/indexes/{id}.json");
|
||||
|
||||
public static IOPath GetVersionDescriptorDir() =>
|
||||
Path.Concat(Главне.Настройки.путь_к_кубачу, "version_descriptors");
|
||||
|
||||
public static string GetVersionDescriptorName(IOPath path) =>
|
||||
path.LastName().RemoveExtension().ToString();
|
||||
|
||||
public static IOPath GetVersionDescriptorPath(string name) =>
|
||||
Path.Concat(GetVersionDescriptorDir(), Path.ReplaceRestrictedChars(name) + ".json");
|
||||
|
||||
public static IOPath GetVersionDir() =>
|
||||
Path.Concat(Главне.Настройки.путь_к_кубачу, "versions");
|
||||
|
||||
public static IOPath GetVersionJarFilePath(string name) =>
|
||||
Path.Concat(GetVersionDir(), name + ".jar");
|
||||
|
||||
public static IOPath GetLibrariesDir() =>
|
||||
Path.Concat(Главне.Настройки.путь_к_кубачу, "libraries");
|
||||
}
|
||||
}
|
||||
27
Млаумчерб.Клиент/классы/Пути.cs
Normal file
27
Млаумчерб.Клиент/классы/Пути.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using Млаумчерб.Клиент.видимое;
|
||||
|
||||
namespace Млаумчерб.Клиент.классы;
|
||||
|
||||
public static class Пути
|
||||
{
|
||||
public static IOPath GetAssetIndexFilePath(string id) =>
|
||||
Path.Concat(Приложение.Настройки.путь_к_кубачу, $"assets/indexes/{id}.json");
|
||||
|
||||
public static IOPath GetVersionDescriptorDir() =>
|
||||
Path.Concat(Приложение.Настройки.путь_к_кубачу, "version_descriptors");
|
||||
|
||||
public static string GetVersionDescriptorName(IOPath path) =>
|
||||
path.LastName().RemoveExtension().ToString();
|
||||
|
||||
public static IOPath GetVersionDescriptorPath(string name) =>
|
||||
Path.Concat(GetVersionDescriptorDir(), Path.ReplaceRestrictedChars(name) + ".json");
|
||||
|
||||
public static IOPath GetVersionDir() =>
|
||||
Path.Concat(Приложение.Настройки.путь_к_кубачу, "versions");
|
||||
|
||||
public static IOPath GetVersionJarFilePath(string name) =>
|
||||
Path.Concat(GetVersionDir(), name + ".jar");
|
||||
|
||||
public static IOPath GetLibrariesDir() =>
|
||||
Path.Concat(Приложение.Настройки.путь_к_кубачу, "libraries");
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user