moved some files
This commit is contained in:
parent
c2e2785a32
commit
d24dbea501
@ -13,11 +13,16 @@ global using Directory = DTLib.Filesystem.Directory;
|
||||
global using Path = DTLib.Filesystem.Path;
|
||||
using System.Globalization;
|
||||
using Avalonia;
|
||||
using Млаумчерб.Клиент.видимое;
|
||||
|
||||
namespace Млаумчерб.Клиент;
|
||||
|
||||
public class Главне
|
||||
{
|
||||
public static readonly LauncherLogger Логгер = new();
|
||||
|
||||
public static Настройки Настройки = new();
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
@ -29,7 +34,7 @@ public class Главне
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Приложение.Логгер.LogError(nameof(Главне), ex);
|
||||
Логгер.LogError(nameof(Главне), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using CliWrap;
|
||||
using DTLib.Extensions;
|
||||
using Млаумчерб.Клиент.видимое;
|
||||
using Млаумчерб.Клиент.классы;
|
||||
using static Млаумчерб.Клиент.классы.Пролетариат;
|
||||
|
||||
@ -28,7 +29,7 @@ public class GameVersionDescriptor
|
||||
string name = GetVersionDescriptorName(f);
|
||||
propsList.Add(new GameVersionProps(name, null, f));
|
||||
}
|
||||
var remoteVersions = await Network.GetDownloadableVersions();
|
||||
var remoteVersions = await Сеть.GetDownloadableVersions();
|
||||
propsList.AddRange(remoteVersions);
|
||||
return propsList;
|
||||
}
|
||||
@ -40,7 +41,7 @@ public class GameVersionDescriptor
|
||||
if (props.RemoteDescriptorUrl is null)
|
||||
throw new NullReferenceException("can't download game version descriptor '"
|
||||
+ props.Name + "', because RemoteDescriptorUrl is null");
|
||||
await Network.DownloadFileHTTP(props.RemoteDescriptorUrl, props.LocalDescriptorPath);
|
||||
await Сеть.DownloadFileHTTP(props.RemoteDescriptorUrl, props.LocalDescriptorPath);
|
||||
}
|
||||
return new GameVersionDescriptor(props);
|
||||
}
|
||||
@ -48,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");
|
||||
}
|
||||
|
||||
@ -63,11 +64,11 @@ public class GameVersionDescriptor
|
||||
try
|
||||
{
|
||||
downloadCts = new CancellationTokenSource();
|
||||
if(Приложение.Настройки.скачать_жабу)
|
||||
await Network.DownloadJava(descriptor.javaVersion, Приложение.Настройки.путь_к_жабе, force);
|
||||
await Network.DownloadAssets(descriptor.assetIndex, downloadCts.Token, force);
|
||||
await Network.DownloadVersionFile(descriptor.downloads.client.url, GetVersionJarFilePath(Name), force);
|
||||
await Network.DownloadLibraries(descriptor.libraries, GetLibrariesDir(), 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);
|
||||
// await Network.DownloadModpack(modpack, WorkingDirectory, force);
|
||||
_props.IsDownloaded = true;
|
||||
}
|
||||
@ -90,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 +
|
||||
@ -99,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()
|
||||
|
||||
@ -30,4 +30,19 @@
|
||||
<AvaloniaResource Include="капитал\**"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="видимое\VersionItemView.axaml.cs">
|
||||
<DependentUpon>VersionItemView.axaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="видимое\Окне.axaml.cs">
|
||||
<DependentUpon>Окне.axaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="видимое\Приложение.axaml.cs">
|
||||
<DependentUpon>Приложение.axaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
namespace Млаумчерб.Клиент;
|
||||
using Млаумчерб.Клиент.видимое;
|
||||
|
||||
namespace Млаумчерб.Клиент;
|
||||
|
||||
public record Настройки
|
||||
{
|
||||
@ -12,10 +14,10 @@ public record Настройки
|
||||
|
||||
public static Настройки ЗагрузитьИзФайла(string имя_файла = "млаумчерб.настройки")
|
||||
{
|
||||
Приложение.Логгер.LogInfo(nameof(Настройки), $"попытка загрузить настройки из файла '{имя_файла}'");
|
||||
Главне.Логгер.LogInfo(nameof(Настройки), $"попытка загрузить настройки из файла '{имя_файла}'");
|
||||
if(!File.Exists(имя_файла))
|
||||
{
|
||||
Приложение.Логгер.LogInfo(nameof(Настройки), "файл не существует");
|
||||
Главне.Логгер.LogInfo(nameof(Настройки), "файл не существует");
|
||||
return new Настройки();
|
||||
}
|
||||
|
||||
@ -31,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(Настройки), $"настройки сохранены: {текст}");
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ using MsBox.Avalonia;
|
||||
using MsBox.Avalonia.Dto;
|
||||
using MsBox.Avalonia.Enums;
|
||||
using MsBox.Avalonia.Models;
|
||||
using Млаумчерб.Клиент.видимое;
|
||||
|
||||
namespace Млаумчерб.Клиент;
|
||||
|
||||
@ -14,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 = "пон" } },
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
using System.Buffers;
|
||||
using System.Net.Http;
|
||||
using Млаумчерб.Клиент.видимое;
|
||||
using Млаумчерб.Клиент.классы;
|
||||
using Timer = DTLib.Timer;
|
||||
|
||||
namespace Млаумчерб.Клиент;
|
||||
|
||||
public static class Network
|
||||
public static class Сеть
|
||||
{
|
||||
private static HttpClient http = new();
|
||||
private const string ASSET_SERVER_URL = "https://resources.download.minecraft.net/";
|
||||
@ -63,9 +64,9 @@ public static class Network
|
||||
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)
|
||||
@ -101,13 +102,13 @@ public static class Network
|
||||
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];
|
||||
@ -118,7 +119,7 @@ public static class Network
|
||||
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)
|
||||
@ -132,7 +133,7 @@ public static class Network
|
||||
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()
|
||||
@ -149,7 +150,7 @@ public static class Network
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Приложение.Логгер.LogWarn(nameof(Network), ex);
|
||||
Главне.Логгер.LogWarn(nameof(Сеть), ex);
|
||||
}
|
||||
}
|
||||
return descriptors;
|
||||
@ -4,6 +4,6 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Млаумчерб.Клиент"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Млаумчерб.Клиент.VersionItemView">
|
||||
x:Class="Млаумчерб.Клиент.видимое.VersionItemView">
|
||||
<TextBlock Name="text" Background="Transparent"/>
|
||||
</UserControl>
|
||||
@ -2,7 +2,7 @@
|
||||
using Avalonia.Media;
|
||||
using Млаумчерб.Клиент.классы;
|
||||
|
||||
namespace Млаумчерб.Клиент;
|
||||
namespace Млаумчерб.Клиент.видимое;
|
||||
|
||||
public partial class VersionItemView : ListBoxItem
|
||||
{
|
||||
@ -2,7 +2,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:gif="clr-namespace:Avalonia.Labs.Gif;assembly=Avalonia.Labs.Gif"
|
||||
xmlns:local="clr-namespace:Млаумчерб"
|
||||
x:Class="Млаумчерб.Клиент.Окне"
|
||||
x:Class="Млаумчерб.Клиент.видимое.Окне"
|
||||
Name="window"
|
||||
Title="млаумчерб"
|
||||
Icon="avares://млаумчерб/капитал/кубе.ico"
|
||||
@ -6,7 +6,7 @@ using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using Млаумчерб.Клиент.классы;
|
||||
|
||||
namespace Млаумчерб.Клиент;
|
||||
namespace Млаумчерб.Клиент.видимое;
|
||||
|
||||
public partial class Окне : Window
|
||||
{
|
||||
@ -55,10 +55,10 @@ public partial class Окне : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
Приложение.Настройки = Настройки.ЗагрузитьИзФайла();
|
||||
Username = Приложение.Настройки.имя_пользователя;
|
||||
MemoryLimit = Приложение.Настройки.выделенная_память_мб;
|
||||
Fullscreen = Приложение.Настройки.открывать_на_весь_экран;
|
||||
Главне.Настройки = Настройки.ЗагрузитьИзФайла();
|
||||
Username = Главне.Настройки.имя_пользователя;
|
||||
MemoryLimit = Главне.Настройки.выделенная_память_мб;
|
||||
Fullscreen = Главне.Настройки.открывать_на_весь_экран;
|
||||
|
||||
Directory.Create(Пролетариат.GetVersionDescriptorDir());
|
||||
VersionComboBox.SelectedIndex = 0;
|
||||
@ -69,8 +69,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;
|
||||
@ -89,11 +89,11 @@ public partial class Окне : Window
|
||||
|
||||
var selectedVersionView = (VersionItemView?)VersionComboBox.SelectedItem;
|
||||
var selectedVersion = selectedVersionView?.Props;
|
||||
Приложение.Настройки.последняя_запущенная_версия = selectedVersion?.Name;
|
||||
Приложение.Настройки.имя_пользователя = Username;
|
||||
Приложение.Настройки.выделенная_память_мб = MemoryLimit;
|
||||
Приложение.Настройки.открывать_на_весь_экран = Fullscreen;
|
||||
Приложение.Настройки.СохранитьВФайл();
|
||||
Главне.Настройки.последняя_запущенная_версия = selectedVersion?.Name;
|
||||
Главне.Настройки.имя_пользователя = Username;
|
||||
Главне.Настройки.выделенная_память_мб = MemoryLimit;
|
||||
Главне.Настройки.открывать_на_весь_экран = Fullscreen;
|
||||
Главне.Настройки.СохранитьВФайл();
|
||||
if (selectedVersion == null)
|
||||
return;
|
||||
|
||||
@ -124,7 +124,7 @@ public partial class Окне : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
Launcher.LaunchFileInfoAsync(new FileInfo(Приложение.Логгер.LogfileName.ToString()))
|
||||
Launcher.LaunchFileInfoAsync(new FileInfo(Главне.Логгер.LogfileName.ToString()))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -1,6 +1,6 @@
|
||||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="Млаумчерб.Клиент.Приложение"
|
||||
x:Class="Млаумчерб.Клиент.видимое.Приложение"
|
||||
RequestedThemeVariant="Dark">
|
||||
<Application.Styles>
|
||||
<SimpleTheme />
|
||||
@ -2,15 +2,13 @@ using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Млаумчерб.Клиент;
|
||||
namespace Млаумчерб.Клиент.видимое;
|
||||
|
||||
public class Приложение : Application
|
||||
{
|
||||
public static readonly LauncherLogger Логгер = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
Логгер.LogInfo(nameof(Приложение), "приложение запущено");
|
||||
Главне.Логгер.LogInfo(nameof(Приложение), "приложение запущено");
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
@ -23,6 +21,4 @@ public class Приложение : Application
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
public static Настройки Настройки = new();
|
||||
}
|
||||
@ -1,12 +1,14 @@
|
||||
namespace Млаумчерб.Клиент.классы;
|
||||
using Млаумчерб.Клиент.видимое;
|
||||
|
||||
namespace Млаумчерб.Клиент.классы;
|
||||
|
||||
public static class Пролетариат
|
||||
{
|
||||
public static IOPath GetAssetIndexFilePath(string id) =>
|
||||
Path.Concat(Приложение.Настройки.путь_к_кубачу, $"assets/indexes/{id}.json");
|
||||
Path.Concat(Главне.Настройки.путь_к_кубачу, $"assets/indexes/{id}.json");
|
||||
|
||||
public static IOPath GetVersionDescriptorDir() =>
|
||||
Path.Concat(Приложение.Настройки.путь_к_кубачу, "version_descriptors");
|
||||
Path.Concat(Главне.Настройки.путь_к_кубачу, "version_descriptors");
|
||||
|
||||
public static string GetVersionDescriptorName(IOPath path) =>
|
||||
path.LastName().RemoveExtension().ToString();
|
||||
@ -15,11 +17,11 @@ public static class Пролетариат
|
||||
Path.Concat(GetVersionDescriptorDir(), Path.ReplaceRestrictedChars(name) + ".json");
|
||||
|
||||
public static IOPath GetVersionDir() =>
|
||||
Path.Concat(Приложение.Настройки.путь_к_кубачу, "versions");
|
||||
Path.Concat(Главне.Настройки.путь_к_кубачу, "versions");
|
||||
|
||||
public static IOPath GetVersionJarFilePath(string name) =>
|
||||
Path.Concat(GetVersionDir(), name + ".jar");
|
||||
|
||||
public static IOPath GetLibrariesDir() =>
|
||||
Path.Concat(Приложение.Настройки.путь_к_кубачу, "libraries");
|
||||
Path.Concat(Главне.Настройки.путь_к_кубачу, "libraries");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user