Compare commits
No commits in common. "631f5c9126072c8caa987dcd49a9c7583393959e" and "1f663902e267250435871f74cb30f49e24fede9a" have entirely different histories.
631f5c9126
...
1f663902e2
@ -1,12 +1,10 @@
|
|||||||
using Mlaumcherb.Client.Avalonia.зримое;
|
using Mlaumcherb.Client.Avalonia.зримое;
|
||||||
using Mlaumcherb.Client.Avalonia.классы;
|
|
||||||
using Mlaumcherb.Client.Avalonia.холопы;
|
using Mlaumcherb.Client.Avalonia.холопы;
|
||||||
|
|
||||||
namespace Mlaumcherb.Client.Avalonia;
|
namespace Mlaumcherb.Client.Avalonia;
|
||||||
|
|
||||||
public record Config
|
public record Config
|
||||||
{
|
{
|
||||||
[JsonRequired] public string config_version { get; set; } = "1.0.0";
|
|
||||||
public bool debug { get; set; } =
|
public bool debug { get; set; } =
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
true;
|
true;
|
||||||
@ -17,16 +15,10 @@ public record Config
|
|||||||
public int max_memory { get; set; } = 4096;
|
public int max_memory { get; set; } = 4096;
|
||||||
public string minecraft_dir { get; set; } = ".";
|
public string minecraft_dir { get; set; } = ".";
|
||||||
public bool download_java { get; set; } = true;
|
public bool download_java { get; set; } = true;
|
||||||
public bool redirect_game_output { get; set; } = false;
|
|
||||||
public string? last_launched_version { get; set; }
|
public string? last_launched_version { get; set; }
|
||||||
public int max_parallel_downloads { get; set; } = 16;
|
public int max_parallel_downloads { get; set; } = 16;
|
||||||
public VersionCatalogProps[] version_catalogs { get; set; } =
|
|
||||||
[
|
|
||||||
new() { Name = "Mojang", Url = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json" }
|
|
||||||
];
|
|
||||||
|
|
||||||
|
[JsonIgnore] static IOPath _filePath = "config.json";
|
||||||
[JsonIgnore] private static IOPath _filePath = "config.json";
|
|
||||||
|
|
||||||
public static Config LoadFromFile()
|
public static Config LoadFromFile()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,6 @@ using Mlaumcherb.Client.Avalonia.классы;
|
|||||||
using Mlaumcherb.Client.Avalonia.сеть;
|
using Mlaumcherb.Client.Avalonia.сеть;
|
||||||
using Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
using Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
||||||
using Mlaumcherb.Client.Avalonia.холопы;
|
using Mlaumcherb.Client.Avalonia.холопы;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using static Mlaumcherb.Client.Avalonia.холопы.PathHelper;
|
using static Mlaumcherb.Client.Avalonia.холопы.PathHelper;
|
||||||
|
|
||||||
namespace Mlaumcherb.Client.Avalonia;
|
namespace Mlaumcherb.Client.Avalonia;
|
||||||
@ -27,9 +26,9 @@ public class GameVersion
|
|||||||
private CancellationTokenSource? _gameCts;
|
private CancellationTokenSource? _gameCts;
|
||||||
private CommandTask<CommandResult>? _commandTask;
|
private CommandTask<CommandResult>? _commandTask;
|
||||||
|
|
||||||
public static Task<List<GameVersionProps>> GetAllVersionsAsync()
|
public static async Task<List<GameVersionProps>> GetAllVersionsAsync()
|
||||||
{
|
{
|
||||||
var propsList = new List<GameVersionProps>();
|
var propsSet = new HashSet<GameVersionProps>();
|
||||||
|
|
||||||
// local descriptors
|
// local descriptors
|
||||||
Directory.Create(GetVersionsDir());
|
Directory.Create(GetVersionsDir());
|
||||||
@ -39,12 +38,19 @@ public class GameVersion
|
|||||||
var d = new GameVersionProps(name, null);
|
var d = new GameVersionProps(name, null);
|
||||||
if(!File.Exists(d.LocalDescriptorPath))
|
if(!File.Exists(d.LocalDescriptorPath))
|
||||||
throw new Exception("Can't find version descriptor file in directory '{subdir}'. Rename it as directory name.");
|
throw new Exception("Can't find version descriptor file in directory '{subdir}'. Rename it as directory name.");
|
||||||
propsList.Add(d);
|
propsSet.Add(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remote non-duplicating versions
|
||||||
|
foreach (var removeVersion in await Сеть.GetDownloadableVersions())
|
||||||
|
{
|
||||||
|
propsSet.Add(removeVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
// reverse sort
|
// reverse sort
|
||||||
|
var propsList = propsSet.ToList();
|
||||||
propsList.Sort((a, b) => b.CompareTo(a));
|
propsList.Sort((a, b) => b.CompareTo(a));
|
||||||
return Task.FromResult(propsList);
|
return propsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<GameVersion> CreateFromPropsAsync(GameVersionProps props)
|
public static async Task<GameVersion> CreateFromPropsAsync(GameVersionProps props)
|
||||||
@ -54,7 +60,7 @@ public class GameVersion
|
|||||||
if (props.RemoteDescriptorUrl is null)
|
if (props.RemoteDescriptorUrl is null)
|
||||||
throw new NullReferenceException("can't download game version descriptor '"
|
throw new NullReferenceException("can't download game version descriptor '"
|
||||||
+ props.Name + "', because RemoteDescriptorUrl is null");
|
+ props.Name + "', because RemoteDescriptorUrl is null");
|
||||||
await NetworkHelper.DownloadFile(props.RemoteDescriptorUrl, props.LocalDescriptorPath);
|
await Сеть.DownloadFile(props.RemoteDescriptorUrl, props.LocalDescriptorPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new GameVersion(props);
|
return new GameVersion(props);
|
||||||
@ -63,31 +69,8 @@ public class GameVersion
|
|||||||
private GameVersion(GameVersionProps props)
|
private GameVersion(GameVersionProps props)
|
||||||
{
|
{
|
||||||
_props = props;
|
_props = props;
|
||||||
|
|
||||||
string descriptorText = File.ReadAllText(props.LocalDescriptorPath);
|
string descriptorText = File.ReadAllText(props.LocalDescriptorPath);
|
||||||
JObject descriptorRaw = JObject.Parse(descriptorText);
|
_descriptor = JsonConvert.DeserializeObject<GameVersionDescriptor>(descriptorText)
|
||||||
|
|
||||||
// Descriptors can inherit from other descriptors.
|
|
||||||
// For example, 1.12.2-forge-14.23.5.2860 inherits from 1.12.2
|
|
||||||
if (descriptorRaw.TryGetValue("inheritsFrom", out var v))
|
|
||||||
{
|
|
||||||
string parentDescriptorId = v.Value<string>()
|
|
||||||
?? throw new Exception("inheritsFrom is null");
|
|
||||||
LauncherApp.Logger.LogInfo(Name, $"merging descriptor '{parentDescriptorId}' with '{Name}'");
|
|
||||||
IOPath parentDescriptorPath = GetVersionDescriptorPath(parentDescriptorId);
|
|
||||||
if (!File.Exists(parentDescriptorPath))
|
|
||||||
throw new Exception($"Версия '{Name} требует установить версию '{parentDescriptorId}'");
|
|
||||||
string parentDescriptorText = File.ReadAllText(parentDescriptorPath);
|
|
||||||
JObject parentDescriptorRaw = JObject.Parse(parentDescriptorText);
|
|
||||||
parentDescriptorRaw.Merge(descriptorRaw,
|
|
||||||
new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Concat });
|
|
||||||
descriptorRaw = parentDescriptorRaw;
|
|
||||||
// removing dependency
|
|
||||||
descriptorRaw.Remove("inheritsFrom");
|
|
||||||
File.WriteAllText(props.LocalDescriptorPath, descriptorRaw.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
_descriptor = descriptorRaw.ToObject<GameVersionDescriptor>()
|
|
||||||
?? throw new Exception($"can't parse descriptor file '{props.LocalDescriptorPath}'");
|
?? throw new Exception($"can't parse descriptor file '{props.LocalDescriptorPath}'");
|
||||||
_javaArgs = new JavaArguments(_descriptor);
|
_javaArgs = new JavaArguments(_descriptor);
|
||||||
_gameArgs = new GameArguments(_descriptor);
|
_gameArgs = new GameArguments(_descriptor);
|
||||||
@ -214,13 +197,9 @@ public class GameVersion
|
|||||||
var command = Cli.Wrap(JavaExecutableFilePath.ToString())
|
var command = Cli.Wrap(JavaExecutableFilePath.ToString())
|
||||||
.WithWorkingDirectory(WorkingDirectory.ToString())
|
.WithWorkingDirectory(WorkingDirectory.ToString())
|
||||||
.WithArguments(argsList)
|
.WithArguments(argsList)
|
||||||
.WithValidation(CommandResultValidation.None);
|
|
||||||
if (LauncherApp.Config.redirect_game_output)
|
|
||||||
{
|
|
||||||
command = command
|
|
||||||
.WithStandardOutputPipe(PipeTarget.ToDelegate(LogGameOut))
|
.WithStandardOutputPipe(PipeTarget.ToDelegate(LogGameOut))
|
||||||
.WithStandardErrorPipe(PipeTarget.ToDelegate(LogGameError));
|
.WithStandardErrorPipe(PipeTarget.ToDelegate(LogGameError))
|
||||||
}
|
.WithValidation(CommandResultValidation.None);
|
||||||
LauncherApp.Logger.LogInfo(Name, "launching the game");
|
LauncherApp.Logger.LogInfo(Name, "launching the game");
|
||||||
LauncherApp.Logger.LogDebug(Name, "java: " + command.TargetFilePath);
|
LauncherApp.Logger.LogDebug(Name, "java: " + command.TargetFilePath);
|
||||||
LauncherApp.Logger.LogDebug(Name, "working_dir: " + command.WorkingDirPath);
|
LauncherApp.Logger.LogDebug(Name, "working_dir: " + command.WorkingDirPath);
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
namespace Mlaumcherb.Client.Avalonia;
|
using Mlaumcherb.Client.Avalonia.зримое;
|
||||||
|
|
||||||
|
namespace Mlaumcherb.Client.Avalonia;
|
||||||
|
|
||||||
public class LauncherLogger : ILogger
|
public class LauncherLogger : ILogger
|
||||||
{
|
{
|
||||||
|
|||||||
@ -15,12 +15,6 @@ public class LauncherApp : Application
|
|||||||
Config = Config.LoadFromFile();
|
Config = Config.LoadFromFile();
|
||||||
Logger.DebugLogEnabled = Config.debug;
|
Logger.DebugLogEnabled = Config.debug;
|
||||||
AvaloniaXamlLoader.Load(this);
|
AvaloniaXamlLoader.Load(this);
|
||||||
|
|
||||||
// some file required by forge installer
|
|
||||||
if (!File.Exists("launcher_profiles.json"))
|
|
||||||
{
|
|
||||||
File.WriteAllText("launcher_profiles.json", "{}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnFrameworkInitializationCompleted()
|
public override void OnFrameworkInitializationCompleted()
|
||||||
|
|||||||
@ -7,65 +7,26 @@
|
|||||||
Title="млаумчерб"
|
Title="млаумчерб"
|
||||||
Icon="avares://млаумчерб/капитал/кубе.ico"
|
Icon="avares://млаумчерб/капитал/кубе.ico"
|
||||||
FontFamily="{StaticResource MonospaceFont}" FontSize="18"
|
FontFamily="{StaticResource MonospaceFont}" FontSize="18"
|
||||||
MinWidth="800" MinHeight="400"
|
MinWidth="1200" MinHeight="700"
|
||||||
Width="800" Height="600"
|
Width="800" Height="500"
|
||||||
WindowStartupLocation="CenterScreen">
|
WindowStartupLocation="CenterScreen">
|
||||||
<Grid RowDefinitions="* 30">
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>* 30</Grid.RowDefinitions>
|
||||||
<Image Grid.RowSpan="2" Stretch="UniformToFill"
|
<Image Grid.RowSpan="2" Stretch="UniformToFill"
|
||||||
Source="avares://млаумчерб/капитал/фоне.png"/>
|
Source="avares://млаумчерб/капитал/фоне.png"/>
|
||||||
|
|
||||||
<Grid Grid.Row="0" Margin="10">
|
<Grid Grid.Row="0" Margin="10">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>* 300 *</Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition MinWidth="150"/>
|
|
||||||
<ColumnDefinition Width="2" />
|
|
||||||
<ColumnDefinition MinWidth="300"/>
|
|
||||||
<ColumnDefinition Width="2" />
|
|
||||||
<ColumnDefinition MinWidth="150"/>
|
|
||||||
</Grid.ColumnDefinitions>
|
|
||||||
|
|
||||||
<GridSplitter Grid.Column="1" Background="Transparent" ResizeDirection="Columns" />
|
|
||||||
<GridSplitter Grid.Column="3" Background="Transparent" ResizeDirection="Columns"/>
|
|
||||||
|
|
||||||
<!-- Central panel -->
|
<!-- Central panel -->
|
||||||
<Border Grid.Column="2"
|
<Border Grid.Column="1"
|
||||||
Classes="dark_tr_bg white_border">
|
Classes="dark_tr_bg white_border"
|
||||||
|
Margin="10 0">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>* 60</Grid.RowDefinitions>
|
<Grid.RowDefinitions>* 60</Grid.RowDefinitions>
|
||||||
<ScrollViewer Grid.Row="0"
|
<StackPanel Orientation="Vertical" Margin="10" Spacing="10">
|
||||||
HorizontalScrollBarVisibility="Disabled"
|
|
||||||
VerticalScrollBarVisibility="Auto">
|
|
||||||
<StackPanel Margin="10" Spacing="10">
|
|
||||||
<TextBlock>Версия:</TextBlock>
|
<TextBlock>Версия:</TextBlock>
|
||||||
<ComboBox Name="InstalledVersionComboBox"/>
|
<ComboBox Name="VersionComboBox"/>
|
||||||
<Button Name="DeleteVersionButton"
|
|
||||||
Click="DeleteVersionButton_OnClick">
|
|
||||||
Удалить версию
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Expander Header="Добавление версий"
|
|
||||||
BorderThickness="1" BorderBrush="Gray"
|
|
||||||
Padding="4">
|
|
||||||
<StackPanel>
|
|
||||||
<TextBlock>Источник:</TextBlock>
|
|
||||||
<ComboBox Name="VersionCatalogComboBox"/>
|
|
||||||
<WrapPanel>
|
|
||||||
<CheckBox Name="ReleaseVersionTypeCheckBox" IsChecked="True">релиз</CheckBox>
|
|
||||||
<CheckBox Name="SnapshotVersionTypeCheckBox">снапшот</CheckBox>
|
|
||||||
<CheckBox Name="OldVersionTypeCheckBox">старое</CheckBox>
|
|
||||||
<CheckBox Name="OtherVersionTypeAlphaCheckBox">другое</CheckBox>
|
|
||||||
</WrapPanel>
|
|
||||||
<Button Name="SearchVersionsButton"
|
|
||||||
Click="SearchVersionsButton_OnClick">
|
|
||||||
Поиск
|
|
||||||
</Button>
|
|
||||||
<TextBlock>Доступные версии:</TextBlock>
|
|
||||||
<ComboBox Name="VersionCatalogItemsComboBox"/>
|
|
||||||
<Button Name="AddVersionButton" IsEnabled="False"
|
|
||||||
Click="AddVersionButton_OnClick">
|
|
||||||
Добавить
|
|
||||||
</Button>
|
|
||||||
</StackPanel>
|
|
||||||
</Expander>
|
|
||||||
|
|
||||||
<TextBlock>Ник:</TextBlock>
|
<TextBlock>Ник:</TextBlock>
|
||||||
<TextBox Background="Transparent"
|
<TextBox Background="Transparent"
|
||||||
@ -90,13 +51,9 @@
|
|||||||
<CheckBox IsChecked="{Binding #window.EnableJavaDownload}">
|
<CheckBox IsChecked="{Binding #window.EnableJavaDownload}">
|
||||||
Скачивать джаву
|
Скачивать джаву
|
||||||
</CheckBox>
|
</CheckBox>
|
||||||
<CheckBox IsChecked="{Binding #window.RedirectGameOutput}">
|
|
||||||
Выводить лог игры в лаунчер
|
|
||||||
</CheckBox>
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</ScrollViewer>
|
|
||||||
<Button Name="LaunchButton" Grid.Row="1"
|
<Button Name="LaunchButton" Grid.Row="1"
|
||||||
Margin="10" Padding="4"
|
Margin="10" Padding="0 0 0 4"
|
||||||
Classes="button_no_border"
|
Classes="button_no_border"
|
||||||
Background="#BBfd7300"
|
Background="#BBfd7300"
|
||||||
Click="Запуск">
|
Click="Запуск">
|
||||||
@ -108,7 +65,8 @@
|
|||||||
<!-- Left panel -->
|
<!-- Left panel -->
|
||||||
<Border Grid.Column="0"
|
<Border Grid.Column="0"
|
||||||
Classes="dark_tr_bg white_border">
|
Classes="dark_tr_bg white_border">
|
||||||
<Grid RowDefinitions="36 *">
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>36 *</Grid.RowDefinitions>
|
||||||
<Border Classes="white_border" Margin="-1" Padding="4">
|
<Border Classes="white_border" Margin="-1" Padding="4">
|
||||||
<DockPanel>
|
<DockPanel>
|
||||||
<TextBlock FontWeight="Bold"
|
<TextBlock FontWeight="Bold"
|
||||||
@ -134,9 +92,9 @@
|
|||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<!-- Right panel -->
|
<!-- Right panel -->
|
||||||
<Border Grid.Column="4"
|
<Border Grid.Column="2" Classes="dark_tr_bg white_border">
|
||||||
Classes="dark_tr_bg white_border">
|
<Grid>
|
||||||
<Grid RowDefinitions="36 *">
|
<Grid.RowDefinitions>36 *</Grid.RowDefinitions>
|
||||||
<Border Classes="white_border" Margin="-1" Padding="4">
|
<Border Classes="white_border" Margin="-1" Padding="4">
|
||||||
<DockPanel>
|
<DockPanel>
|
||||||
<TextBlock FontWeight="Bold"
|
<TextBlock FontWeight="Bold"
|
||||||
|
|||||||
@ -6,9 +6,6 @@ using Avalonia.Platform.Storage;
|
|||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using Mlaumcherb.Client.Avalonia.классы;
|
using Mlaumcherb.Client.Avalonia.классы;
|
||||||
using Mlaumcherb.Client.Avalonia.холопы;
|
using Mlaumcherb.Client.Avalonia.холопы;
|
||||||
using MsBox.Avalonia;
|
|
||||||
using MsBox.Avalonia.Dto;
|
|
||||||
using MsBox.Avalonia.Models;
|
|
||||||
|
|
||||||
namespace Mlaumcherb.Client.Avalonia.зримое;
|
namespace Mlaumcherb.Client.Avalonia.зримое;
|
||||||
|
|
||||||
@ -51,15 +48,6 @@ public partial class MainWindow : Window
|
|||||||
set => SetValue(EnableJavaDownloadProperty, value);
|
set => SetValue(EnableJavaDownloadProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly StyledProperty<bool> RedirectGameOutputProperty =
|
|
||||||
AvaloniaProperty.Register<MainWindow, bool>(nameof(RedirectGameOutput),
|
|
||||||
defaultBindingMode: BindingMode.TwoWay, defaultValue: false);
|
|
||||||
public bool RedirectGameOutput
|
|
||||||
{
|
|
||||||
get => GetValue(RedirectGameOutputProperty);
|
|
||||||
set => SetValue(RedirectGameOutputProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -74,28 +62,20 @@ public partial class MainWindow : Window
|
|||||||
PlayerName = LauncherApp.Config.player_name;
|
PlayerName = LauncherApp.Config.player_name;
|
||||||
MemoryLimit = LauncherApp.Config.max_memory;
|
MemoryLimit = LauncherApp.Config.max_memory;
|
||||||
EnableJavaDownload = LauncherApp.Config.download_java;
|
EnableJavaDownload = LauncherApp.Config.download_java;
|
||||||
RedirectGameOutput = LauncherApp.Config.redirect_game_output;
|
|
||||||
|
|
||||||
InstalledVersionComboBox.SelectedIndex = 0;
|
VersionComboBox.SelectedIndex = 0;
|
||||||
InstalledVersionComboBox.IsEnabled = false;
|
VersionComboBox.IsEnabled = false;
|
||||||
var versions = await GameVersion.GetAllVersionsAsync();
|
var versions = await GameVersion.GetAllVersionsAsync();
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
foreach (var p in versions)
|
foreach (var p in versions)
|
||||||
{
|
{
|
||||||
InstalledVersionComboBox.Items.Add(new VersionItemView(p));
|
VersionComboBox.Items.Add(new VersionItemView(p));
|
||||||
// select last played version
|
|
||||||
if (LauncherApp.Config.last_launched_version != null &&
|
if (LauncherApp.Config.last_launched_version != null &&
|
||||||
p.Name == LauncherApp.Config.last_launched_version)
|
p.Name == LauncherApp.Config.last_launched_version)
|
||||||
InstalledVersionComboBox.SelectedIndex = InstalledVersionComboBox.Items.Count - 1;
|
VersionComboBox.SelectedIndex = VersionComboBox.Items.Count - 1;
|
||||||
}
|
}
|
||||||
InstalledVersionComboBox.IsEnabled = true;
|
VersionComboBox.IsEnabled = true;
|
||||||
|
|
||||||
foreach (var vc in LauncherApp.Config.version_catalogs)
|
|
||||||
{
|
|
||||||
VersionCatalogComboBox.Items.Add(vc);
|
|
||||||
}
|
|
||||||
VersionCatalogComboBox.SelectedIndex = 0;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -123,13 +103,12 @@ public partial class MainWindow : Window
|
|||||||
{
|
{
|
||||||
Dispatcher.UIThread.Invoke(() => LaunchButton.IsEnabled = false);
|
Dispatcher.UIThread.Invoke(() => LaunchButton.IsEnabled = false);
|
||||||
|
|
||||||
var selectedVersionView = (VersionItemView?)InstalledVersionComboBox.SelectedItem;
|
var selectedVersionView = (VersionItemView?)VersionComboBox.SelectedItem;
|
||||||
var selectedVersion = selectedVersionView?.Props;
|
var selectedVersion = selectedVersionView?.Props;
|
||||||
LauncherApp.Config.last_launched_version = selectedVersion?.Name;
|
LauncherApp.Config.last_launched_version = selectedVersion?.Name;
|
||||||
LauncherApp.Config.player_name = PlayerName;
|
LauncherApp.Config.player_name = PlayerName;
|
||||||
LauncherApp.Config.max_memory = MemoryLimit;
|
LauncherApp.Config.max_memory = MemoryLimit;
|
||||||
LauncherApp.Config.download_java = EnableJavaDownload;
|
LauncherApp.Config.download_java = EnableJavaDownload;
|
||||||
LauncherApp.Config.redirect_game_output = RedirectGameOutput;
|
|
||||||
LauncherApp.Config.SaveToFile();
|
LauncherApp.Config.SaveToFile();
|
||||||
if (selectedVersion == null)
|
if (selectedVersion == null)
|
||||||
return;
|
return;
|
||||||
@ -217,94 +196,4 @@ public partial class MainWindow : Window
|
|||||||
}
|
}
|
||||||
DownloadsPanel.Children.Clear();
|
DownloadsPanel.Children.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void DeleteVersionButton_OnClick(object? sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
VersionItemView? sel = InstalledVersionComboBox.SelectedItem as VersionItemView;
|
|
||||||
if(sel is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
|
|
||||||
{
|
|
||||||
ButtonDefinitions = new List<ButtonDefinition> { new() { Name = "Да" }, new() { Name = "Нет" } },
|
|
||||||
ContentTitle = $"Удаление версии {sel.Props.Name}",
|
|
||||||
ContentMessage = $"Вы уверены, что хотите удалить версию {sel.Props.Name}? Все файлы, включая сохранения, будут удалены!",
|
|
||||||
Icon = MsBox.Avalonia.Enums.Icon.Question,
|
|
||||||
WindowStartupLocation = WindowStartupLocation.CenterOwner,
|
|
||||||
SizeToContent = SizeToContent.WidthAndHeight,
|
|
||||||
ShowInCenter = true,
|
|
||||||
Topmost = true
|
|
||||||
}
|
|
||||||
);
|
|
||||||
var result = await box.ShowAsync().ConfigureAwait(false);
|
|
||||||
if (result != "Да")
|
|
||||||
return;
|
|
||||||
|
|
||||||
sel.Props.DeleteFiles();
|
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
|
||||||
{
|
|
||||||
InstalledVersionComboBox.Items.Remove(sel);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void SearchVersionsButton_OnClick(object? sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var catalogProps = VersionCatalogComboBox.SelectedItem as VersionCatalogProps;
|
|
||||||
if(catalogProps is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var catalog = await catalogProps.GetVersionCatalogAsync();
|
|
||||||
var searchParams = new VersionSearchParams();
|
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
|
||||||
{
|
|
||||||
searchParams.ReleaseTypeAllowed = ReleaseVersionTypeCheckBox.IsChecked ?? false;
|
|
||||||
searchParams.SnapshotTypeAllowed = SnapshotVersionTypeCheckBox.IsChecked ?? false;
|
|
||||||
searchParams.OldTypeAllowed = OldVersionTypeCheckBox.IsChecked ?? false;
|
|
||||||
searchParams.OtherTypeAllowed = OtherVersionTypeAlphaCheckBox.IsChecked ?? false;
|
|
||||||
});
|
|
||||||
var versions = catalog.GetDownloadableVersions(searchParams);
|
|
||||||
|
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
|
||||||
{
|
|
||||||
VersionCatalogItemsComboBox.IsEnabled = false;
|
|
||||||
VersionCatalogItemsComboBox.Items.Clear();
|
|
||||||
foreach (var p in versions)
|
|
||||||
{
|
|
||||||
VersionCatalogItemsComboBox.Items.Add(new VersionItemView(p));
|
|
||||||
}
|
|
||||||
VersionCatalogItemsComboBox.IsEnabled = true;
|
|
||||||
AddVersionButton.IsEnabled = versions.Count > 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddVersionButton_OnClick(object? sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var selectedVersionView = VersionCatalogItemsComboBox.SelectedItem as VersionItemView;
|
|
||||||
if(selectedVersionView is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
InstalledVersionComboBox.Items.Insert(0, new VersionItemView(selectedVersionView.Props));
|
|
||||||
InstalledVersionComboBox.SelectedIndex = 0;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -4,7 +4,6 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:Mlaumcherb.Client.Avalonia"
|
xmlns:local="clr-namespace:Mlaumcherb.Client.Avalonia"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Mlaumcherb.Client.Avalonia.зримое.VersionItemView"
|
x:Class="Mlaumcherb.Client.Avalonia.зримое.VersionItemView">
|
||||||
Padding="2">
|
|
||||||
<TextBlock Name="text" Background="Transparent"/>
|
<TextBlock Name="text" Background="Transparent"/>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using Avalonia.Threading;
|
|
||||||
using Mlaumcherb.Client.Avalonia.классы;
|
using Mlaumcherb.Client.Avalonia.классы;
|
||||||
|
|
||||||
namespace Mlaumcherb.Client.Avalonia.зримое;
|
namespace Mlaumcherb.Client.Avalonia.зримое;
|
||||||
@ -21,14 +20,12 @@ public partial class VersionItemView : ListBoxItem
|
|||||||
Props = props;
|
Props = props;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
text.Text = props.Name;
|
text.Text = props.Name;
|
||||||
props.StatusChanged += UpdateBackground;
|
props.OnDownloadCompleted += UpdateBackground;
|
||||||
UpdateBackground(props.IsDownloaded);
|
UpdateBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateBackground(bool isDownloaded)
|
private void UpdateBackground()
|
||||||
{
|
{
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Background = Props.IsDownloaded ? _avaliableColor : _unavaliableColor;
|
||||||
Background = isDownloaded ? _avaliableColor : _unavaliableColor
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,35 +1,8 @@
|
|||||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
namespace Mlaumcherb.Client.Avalonia.классы;
|
||||||
|
|
||||||
public record VersionSearchParams
|
|
||||||
{
|
|
||||||
public bool ReleaseTypeAllowed;
|
|
||||||
public bool SnapshotTypeAllowed;
|
|
||||||
public bool OldTypeAllowed;
|
|
||||||
public bool OtherTypeAllowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GameVersionCatalog
|
public class GameVersionCatalog
|
||||||
{
|
{
|
||||||
[JsonRequired] public List<RemoteVersionDescriptorProps> versions { get; set; } = null!;
|
[JsonRequired] public List<RemoteVersionDescriptorProps> versions { get; set; } = null!;
|
||||||
|
|
||||||
/// <returns>empty list if couldn't find any remote versions</returns>
|
|
||||||
public List<GameVersionProps> GetDownloadableVersions(VersionSearchParams p)
|
|
||||||
{
|
|
||||||
var _versionPropsList = new List<GameVersionProps>();
|
|
||||||
foreach (var r in versions)
|
|
||||||
{
|
|
||||||
bool match = r.type switch
|
|
||||||
{
|
|
||||||
"release" => p.ReleaseTypeAllowed,
|
|
||||||
"snapshot" => p.SnapshotTypeAllowed,
|
|
||||||
"old_alpha" or "old_beta" => p.OldTypeAllowed,
|
|
||||||
_ => p.OtherTypeAllowed
|
|
||||||
};
|
|
||||||
if(match)
|
|
||||||
_versionPropsList.Add(new GameVersionProps(r.id, r.url));
|
|
||||||
}
|
|
||||||
return _versionPropsList;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AssetProperties
|
public class AssetProperties
|
||||||
@ -46,9 +19,9 @@ public class AssetIndex
|
|||||||
public class RemoteVersionDescriptorProps
|
public class RemoteVersionDescriptorProps
|
||||||
{
|
{
|
||||||
[JsonRequired] public string id { get; set; } = "";
|
[JsonRequired] public string id { get; set; } = "";
|
||||||
[JsonRequired] public string url { get; set; } = "";
|
|
||||||
[JsonRequired] public string type { get; set; } = "";
|
[JsonRequired] public string type { get; set; } = "";
|
||||||
public string sha1 { get; set; } = "";
|
[JsonRequired] public string url { get; set; } = "";
|
||||||
public DateTime time { get; set; }
|
[JsonRequired] public string sha1 { get; set; } = "";
|
||||||
public DateTime releaseTime { get; set; }
|
[JsonRequired] public DateTime time { get; set; }
|
||||||
|
[JsonRequired] public DateTime releaseTime { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,10 +10,10 @@ public class GameVersionDescriptor
|
|||||||
[JsonRequired] public DateTime releaseTime { get; set; }
|
[JsonRequired] public DateTime releaseTime { get; set; }
|
||||||
[JsonRequired] public string type { get; set; } = "";
|
[JsonRequired] public string type { get; set; } = "";
|
||||||
[JsonRequired] public string mainClass { get; set; } = "";
|
[JsonRequired] public string mainClass { get; set; } = "";
|
||||||
|
[JsonRequired] public Downloads downloads { get; set; } = null!;
|
||||||
[JsonRequired] public List<Library> libraries { get; set; } = null!;
|
[JsonRequired] public List<Library> libraries { get; set; } = null!;
|
||||||
[JsonRequired] public AssetIndexProperties assetIndex { get; set; } = null!;
|
[JsonRequired] public AssetIndexProperties assetIndex { get; set; } = null!;
|
||||||
[JsonRequired] public string assets { get; set; } = "";
|
[JsonRequired] public string assets { get; set; } = "";
|
||||||
public Downloads? downloads { get; set; } = null;
|
|
||||||
public JavaVersion javaVersion { get; set; } = new() { component = "jre-legacy", majorVersion = 8 };
|
public JavaVersion javaVersion { get; set; } = new() { component = "jre-legacy", majorVersion = 8 };
|
||||||
public string? minecraftArguments { get; set; }
|
public string? minecraftArguments { get; set; }
|
||||||
public ArgumentsNew? arguments { get; set; }
|
public ArgumentsNew? arguments { get; set; }
|
||||||
@ -21,7 +21,6 @@ public class GameVersionDescriptor
|
|||||||
|
|
||||||
public class Artifact
|
public class Artifact
|
||||||
{
|
{
|
||||||
public string? path = null;
|
|
||||||
[JsonRequired] public string url { get; set; } = "";
|
[JsonRequired] public string url { get; set; } = "";
|
||||||
[JsonRequired] public string sha1 { get; set; } = "";
|
[JsonRequired] public string sha1 { get; set; } = "";
|
||||||
[JsonRequired] public int size { get; set; }
|
[JsonRequired] public int size { get; set; }
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using Mlaumcherb.Client.Avalonia.зримое;
|
using Mlaumcherb.Client.Avalonia.холопы;
|
||||||
using Mlaumcherb.Client.Avalonia.холопы;
|
|
||||||
|
|
||||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
namespace Mlaumcherb.Client.Avalonia.классы;
|
||||||
|
|
||||||
@ -14,14 +13,13 @@ public class GameVersionProps : IComparable<GameVersionProps>, IEquatable<GameVe
|
|||||||
get => _isDownloaded;
|
get => _isDownloaded;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if(_isDownloaded != value)
|
bool downloadCompleted = value && !_isDownloaded;
|
||||||
{
|
|
||||||
_isDownloaded = value;
|
_isDownloaded = value;
|
||||||
StatusChanged?.Invoke(value);
|
if(downloadCompleted)
|
||||||
|
OnDownloadCompleted?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
public event Action? OnDownloadCompleted;
|
||||||
public event Action<bool>? StatusChanged;
|
|
||||||
|
|
||||||
public GameVersionProps(string name, string? url)
|
public GameVersionProps(string name, string? url)
|
||||||
{
|
{
|
||||||
@ -31,16 +29,6 @@ public class GameVersionProps : IComparable<GameVersionProps>, IEquatable<GameVe
|
|||||||
IsDownloaded = File.Exists(PathHelper.GetVersionJarFilePath(name));
|
IsDownloaded = File.Exists(PathHelper.GetVersionJarFilePath(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteFiles()
|
|
||||||
{
|
|
||||||
IsDownloaded = false;
|
|
||||||
LauncherApp.Logger.LogInfo(Name, "Deleting files...");
|
|
||||||
var verdir = PathHelper.GetVersionDir(Name);
|
|
||||||
if(Directory.Exists(verdir))
|
|
||||||
Directory.Delete(verdir);
|
|
||||||
LauncherApp.Logger.LogInfo(Name, "Files deleted");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString() => Name;
|
public override string ToString() => Name;
|
||||||
|
|
||||||
public override int GetHashCode() => Name.GetHashCode();
|
public override int GetHashCode() => Name.GetHashCode();
|
||||||
|
|||||||
@ -13,18 +13,6 @@ public class Libraries
|
|||||||
|
|
||||||
public IReadOnlyCollection<JarLib> Libs { get; }
|
public IReadOnlyCollection<JarLib> Libs { get; }
|
||||||
|
|
||||||
private IOPath GetJarFilePath(Artifact artifact)
|
|
||||||
{
|
|
||||||
string relativePath;
|
|
||||||
if (!string.IsNullOrEmpty(artifact.path))
|
|
||||||
relativePath = artifact.path;
|
|
||||||
else if (!string.IsNullOrEmpty(artifact.url))
|
|
||||||
relativePath = artifact.url.AsSpan().After("://").After('/').ToString();
|
|
||||||
else throw new ArgumentException("Artifact must have a path or url");
|
|
||||||
|
|
||||||
return Path.Concat(PathHelper.GetLibrariesDir(), relativePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Libraries(GameVersionDescriptor descriptor)
|
public Libraries(GameVersionDescriptor descriptor)
|
||||||
{
|
{
|
||||||
List<JarLib> libs = new();
|
List<JarLib> libs = new();
|
||||||
@ -67,7 +55,9 @@ public class Libraries
|
|||||||
if(!libHashes.Add(artifact.sha1))
|
if(!libHashes.Add(artifact.sha1))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
libs.Add(new NativeLib(l.name, GetJarFilePath(artifact), artifact, l.extract));
|
string urlTail = artifact.url.AsSpan().After("://").After('/').ToString();
|
||||||
|
IOPath jarFilePath = Path.Concat(PathHelper.GetLibrariesDir(), urlTail);
|
||||||
|
libs.Add(new NativeLib(l.name, jarFilePath, artifact, l.extract));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -79,7 +69,9 @@ public class Libraries
|
|||||||
if(!libHashes.Add(artifact.sha1))
|
if(!libHashes.Add(artifact.sha1))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
libs.Add(new JarLib(l.name, GetJarFilePath(artifact), artifact));
|
string urlTail = artifact.url.AsSpan().After("://").After('/').ToString();
|
||||||
|
IOPath jarFilePath = Path.Concat(PathHelper.GetLibrariesDir(), urlTail);
|
||||||
|
libs.Add(new JarLib(l.name, jarFilePath, artifact));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +0,0 @@
|
|||||||
using Mlaumcherb.Client.Avalonia.сеть;
|
|
||||||
|
|
||||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
|
||||||
|
|
||||||
|
|
||||||
public class VersionCatalogProps
|
|
||||||
{
|
|
||||||
[JsonRequired] public required string Name { get; init; }
|
|
||||||
[JsonRequired] public required string Url { get; init; }
|
|
||||||
|
|
||||||
public override string ToString() => Name;
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<GameVersionCatalog> GetVersionCatalogAsync()
|
|
||||||
{
|
|
||||||
return await NetworkHelper.DownloadStringAndDeserialize<GameVersionCatalog>(Url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,7 +5,7 @@ using DTLib.Extensions;
|
|||||||
using Mlaumcherb.Client.Avalonia.зримое;
|
using Mlaumcherb.Client.Avalonia.зримое;
|
||||||
using Mlaumcherb.Client.Avalonia.классы;
|
using Mlaumcherb.Client.Avalonia.классы;
|
||||||
using Mlaumcherb.Client.Avalonia.холопы;
|
using Mlaumcherb.Client.Avalonia.холопы;
|
||||||
using static Mlaumcherb.Client.Avalonia.сеть.NetworkHelper;
|
using static Mlaumcherb.Client.Avalonia.сеть.Сеть;
|
||||||
|
|
||||||
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
||||||
|
|
||||||
@ -39,9 +39,9 @@ public class AssetsDownloadTaskFactory : INetworkTaskFactory
|
|||||||
{
|
{
|
||||||
if(!File.Exists(_indexFilePath))
|
if(!File.Exists(_indexFilePath))
|
||||||
{
|
{
|
||||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading asset index to '{_indexFilePath}'");
|
LauncherApp.Logger.LogInfo(nameof(Сеть), $"started downloading asset index to '{_indexFilePath}'");
|
||||||
await DownloadFile(_descriptor.assetIndex.url, _indexFilePath);
|
await DownloadFile(_descriptor.assetIndex.url, _indexFilePath);
|
||||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), "finished downloading asset index");
|
LauncherApp.Logger.LogInfo(nameof(Сеть), "finished downloading asset index");
|
||||||
}
|
}
|
||||||
|
|
||||||
string indexFileText = File.ReadAllText(_indexFilePath);
|
string indexFileText = File.ReadAllText(_indexFilePath);
|
||||||
@ -102,7 +102,7 @@ public class AssetsDownloadTaskFactory : INetworkTaskFactory
|
|||||||
|
|
||||||
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
|
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
|
||||||
{
|
{
|
||||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading assets '{_descriptor.assetIndex.id}'");
|
LauncherApp.Logger.LogInfo(nameof(Сеть), $"started downloading assets '{_descriptor.assetIndex.id}'");
|
||||||
ParallelOptions opt = new()
|
ParallelOptions opt = new()
|
||||||
{
|
{
|
||||||
MaxDegreeOfParallelism = LauncherApp.Config.max_parallel_downloads,
|
MaxDegreeOfParallelism = LauncherApp.Config.max_parallel_downloads,
|
||||||
@ -114,7 +114,7 @@ public class AssetsDownloadTaskFactory : INetworkTaskFactory
|
|||||||
bool completed = false;
|
bool completed = false;
|
||||||
while(!completed)
|
while(!completed)
|
||||||
{
|
{
|
||||||
LauncherApp.Logger.LogDebug(nameof(NetworkHelper), $"downloading asset '{a.name}' {a.hash}");
|
LauncherApp.Logger.LogDebug(nameof(Сеть), $"downloading asset '{a.name}' {a.hash}");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await DownloadFile(a.url, a.filePath, _ct, pr.AddBytesCount);
|
await DownloadFile(a.url, a.filePath, _ct, pr.AddBytesCount);
|
||||||
@ -125,13 +125,13 @@ public class AssetsDownloadTaskFactory : INetworkTaskFactory
|
|||||||
// wait on rate limit
|
// wait on rate limit
|
||||||
if(httpException.StatusCode == HttpStatusCode.TooManyRequests)
|
if(httpException.StatusCode == HttpStatusCode.TooManyRequests)
|
||||||
{
|
{
|
||||||
LauncherApp.Logger.LogDebug(nameof(NetworkHelper), "rate limit hit");
|
LauncherApp.Logger.LogDebug(nameof(Сеть), "rate limit hit");
|
||||||
await Task.Delay(1000, _ct);
|
await Task.Delay(1000, _ct);
|
||||||
}
|
}
|
||||||
else throw;
|
else throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"finished downloading assets '{_descriptor.assetIndex.id}'");
|
LauncherApp.Logger.LogInfo(nameof(Сеть), $"finished downloading assets '{_descriptor.assetIndex.id}'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,7 +3,7 @@ using DTLib.Extensions;
|
|||||||
using Mlaumcherb.Client.Avalonia.зримое;
|
using Mlaumcherb.Client.Avalonia.зримое;
|
||||||
using Mlaumcherb.Client.Avalonia.классы;
|
using Mlaumcherb.Client.Avalonia.классы;
|
||||||
using Mlaumcherb.Client.Avalonia.холопы;
|
using Mlaumcherb.Client.Avalonia.холопы;
|
||||||
using static Mlaumcherb.Client.Avalonia.сеть.NetworkHelper;
|
using static Mlaumcherb.Client.Avalonia.сеть.Сеть;
|
||||||
|
|
||||||
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ public class JavaDownloadTaskFactory : INetworkTaskFactory
|
|||||||
|
|
||||||
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
|
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
|
||||||
{
|
{
|
||||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), "started downloading java runtime " +
|
LauncherApp.Logger.LogInfo(nameof(Сеть), "started downloading java runtime " +
|
||||||
$"{_descriptor.javaVersion.majorVersion} '{_descriptor.javaVersion.component}'");
|
$"{_descriptor.javaVersion.majorVersion} '{_descriptor.javaVersion.component}'");
|
||||||
|
|
||||||
ParallelOptions opt = new()
|
ParallelOptions opt = new()
|
||||||
@ -96,7 +96,7 @@ public class JavaDownloadTaskFactory : INetworkTaskFactory
|
|||||||
{
|
{
|
||||||
if (f.props.downloads!.lzma != null)
|
if (f.props.downloads!.lzma != null)
|
||||||
{
|
{
|
||||||
LauncherApp.Logger.LogDebug(nameof(NetworkHelper), $"downloading lzma-compressed file '{f.path}'");
|
LauncherApp.Logger.LogDebug(nameof(Сеть), $"downloading lzma-compressed file '{f.path}'");
|
||||||
await using var pipe = new TransformStream(await GetStream(f.props.downloads.lzma.url, _ct));
|
await using var pipe = new TransformStream(await GetStream(f.props.downloads.lzma.url, _ct));
|
||||||
pipe.AddTransform(pr.AddBytesCount);
|
pipe.AddTransform(pr.AddBytesCount);
|
||||||
await using var fs = File.OpenWrite(f.path);
|
await using var fs = File.OpenWrite(f.path);
|
||||||
@ -104,18 +104,18 @@ public class JavaDownloadTaskFactory : INetworkTaskFactory
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LauncherApp.Logger.LogDebug(nameof(NetworkHelper), $"downloading raw file '{f.path}'");
|
LauncherApp.Logger.LogDebug(nameof(Сеть), $"downloading raw file '{f.path}'");
|
||||||
await DownloadFile(f.props.downloads.raw.url, f.path, _ct, pr.AddBytesCount);
|
await DownloadFile(f.props.downloads.raw.url, f.path, _ct, pr.AddBytesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!OperatingSystem.IsWindows() && f.props.executable is true)
|
if(!OperatingSystem.IsWindows() && f.props.executable is true)
|
||||||
{
|
{
|
||||||
LauncherApp.Logger.LogDebug(nameof(NetworkHelper), $"adding execute rights to file '{f.path}'");
|
LauncherApp.Logger.LogDebug(nameof(Сеть), $"adding execute rights to file '{f.path}'");
|
||||||
System.IO.File.SetUnixFileMode(f.path.ToString(), UnixFileMode.UserExecute);
|
System.IO.File.SetUnixFileMode(f.path.ToString(), UnixFileMode.UserExecute);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), "finished downloading java runtime " +
|
LauncherApp.Logger.LogInfo(nameof(Сеть), "finished downloading java runtime " +
|
||||||
$"{_descriptor.javaVersion.majorVersion} '{_descriptor.javaVersion.component}'");
|
$"{_descriptor.javaVersion.majorVersion} '{_descriptor.javaVersion.component}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ using DTLib.Extensions;
|
|||||||
using Mlaumcherb.Client.Avalonia.зримое;
|
using Mlaumcherb.Client.Avalonia.зримое;
|
||||||
using Mlaumcherb.Client.Avalonia.классы;
|
using Mlaumcherb.Client.Avalonia.классы;
|
||||||
using Mlaumcherb.Client.Avalonia.холопы;
|
using Mlaumcherb.Client.Avalonia.холопы;
|
||||||
using static Mlaumcherb.Client.Avalonia.сеть.NetworkHelper;
|
using static Mlaumcherb.Client.Avalonia.сеть.Сеть;
|
||||||
|
|
||||||
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory
|
|||||||
|
|
||||||
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
|
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
|
||||||
{
|
{
|
||||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading libraries '{_descriptor.id}'");
|
LauncherApp.Logger.LogInfo(nameof(Сеть), $"started downloading libraries '{_descriptor.id}'");
|
||||||
|
|
||||||
ParallelOptions opt = new()
|
ParallelOptions opt = new()
|
||||||
{
|
{
|
||||||
@ -82,9 +82,7 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory
|
|||||||
};
|
};
|
||||||
await Parallel.ForEachAsync(_libsToDownload, opt, async (l, _ct) =>
|
await Parallel.ForEachAsync(_libsToDownload, opt, async (l, _ct) =>
|
||||||
{
|
{
|
||||||
LauncherApp.Logger.LogDebug(nameof(NetworkHelper), $"downloading library '{l.name}' to '{l.jarFilePath}'");
|
LauncherApp.Logger.LogDebug(nameof(Сеть), $"downloading library '{l.name}' to '{l.jarFilePath}'");
|
||||||
if(string.IsNullOrEmpty(l.artifact.url))
|
|
||||||
throw new Exception($"library '{l.name}' doesn't have a url to download");
|
|
||||||
await DownloadFile(l.artifact.url, l.jarFilePath, _ct, pr.AddBytesCount);
|
await DownloadFile(l.artifact.url, l.jarFilePath, _ct, pr.AddBytesCount);
|
||||||
if (l is Libraries.NativeLib n)
|
if (l is Libraries.NativeLib n)
|
||||||
{
|
{
|
||||||
@ -104,6 +102,6 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"finished downloading libraries '{_descriptor.id}'");
|
LauncherApp.Logger.LogInfo(nameof(Сеть), $"finished downloading libraries '{_descriptor.id}'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,7 +3,7 @@ using DTLib.Extensions;
|
|||||||
using Mlaumcherb.Client.Avalonia.зримое;
|
using Mlaumcherb.Client.Avalonia.зримое;
|
||||||
using Mlaumcherb.Client.Avalonia.классы;
|
using Mlaumcherb.Client.Avalonia.классы;
|
||||||
using Mlaumcherb.Client.Avalonia.холопы;
|
using Mlaumcherb.Client.Avalonia.холопы;
|
||||||
using static Mlaumcherb.Client.Avalonia.сеть.NetworkHelper;
|
using static Mlaumcherb.Client.Avalonia.сеть.Сеть;
|
||||||
|
|
||||||
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
||||||
|
|
||||||
@ -36,13 +36,8 @@ public class VersionFileDownloadTaskFactory : INetworkTaskFactory
|
|||||||
{
|
{
|
||||||
if (!File.Exists(_filePath))
|
if (!File.Exists(_filePath))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!checkHashes)
|
if (!checkHashes)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (_descriptor.downloads is null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
using var fs = File.OpenRead(_filePath);
|
using var fs = File.OpenRead(_filePath);
|
||||||
string hash = _hasher.ComputeHash(fs).HashToString();
|
string hash = _hasher.ComputeHash(fs).HashToString();
|
||||||
return hash == _descriptor.downloads.client.sha1;
|
return hash == _descriptor.downloads.client.sha1;
|
||||||
@ -50,18 +45,13 @@ public class VersionFileDownloadTaskFactory : INetworkTaskFactory
|
|||||||
|
|
||||||
private long GetTotalSize()
|
private long GetTotalSize()
|
||||||
{
|
{
|
||||||
if(_descriptor.downloads is null)
|
|
||||||
return 0;
|
|
||||||
return _descriptor.downloads.client.size;
|
return _descriptor.downloads.client.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
|
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
|
||||||
{
|
{
|
||||||
if (_descriptor.downloads is null)
|
LauncherApp.Logger.LogInfo(nameof(Сеть), $"started downloading version file '{_descriptor.id}'");
|
||||||
throw new Exception($"can't download version file '{_descriptor.id}' because it has no download url");
|
|
||||||
|
|
||||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading version file '{_descriptor.id}'");
|
|
||||||
await DownloadFile(_descriptor.downloads.client.url, _filePath, ct, pr.AddBytesCount);
|
await DownloadFile(_descriptor.downloads.client.url, _filePath, ct, pr.AddBytesCount);
|
||||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"finished downloading version file '{_descriptor.id}'");
|
LauncherApp.Logger.LogInfo(nameof(Сеть), $"finished downloading version file '{_descriptor.id}'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,11 +4,11 @@ using Mlaumcherb.Client.Avalonia.классы;
|
|||||||
|
|
||||||
namespace Mlaumcherb.Client.Avalonia.сеть;
|
namespace Mlaumcherb.Client.Avalonia.сеть;
|
||||||
|
|
||||||
public static class NetworkHelper
|
public static class Сеть
|
||||||
{
|
{
|
||||||
private static HttpClient _http = new();
|
private static HttpClient _http = new();
|
||||||
|
|
||||||
static NetworkHelper()
|
static Сеть()
|
||||||
{
|
{
|
||||||
// thanks for Sashok :3
|
// thanks for Sashok :3
|
||||||
// https://github.com/new-sashok724/Launcher/blob/23485c3f7de6620d2c6b7b2dd9339c3beb6a0366/Launcher/source/helper/IOHelper.java#L259
|
// https://github.com/new-sashok724/Launcher/blob/23485c3f7de6620d2c6b7b2dd9339c3beb6a0366/Launcher/source/helper/IOHelper.java#L259
|
||||||
@ -36,9 +36,52 @@ public static class NetworkHelper
|
|||||||
|
|
||||||
public static async Task<T> DownloadStringAndDeserialize<T>(string url)
|
public static async Task<T> DownloadStringAndDeserialize<T>(string url)
|
||||||
{
|
{
|
||||||
var text = await GetString(url);
|
var text = await _http.GetStringAsync(url);
|
||||||
var result = JsonConvert.DeserializeObject<T>(text)
|
var result = JsonConvert.DeserializeObject<T>(text)
|
||||||
?? throw new Exception($"can't deserialize {typeof(T).Name}");
|
?? throw new Exception($"can't deserialize {typeof(T).Name}");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly string[] VERSION_MANIFEST_URLS =
|
||||||
|
{
|
||||||
|
"https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"
|
||||||
|
};
|
||||||
|
|
||||||
|
private static async Task<List<RemoteVersionDescriptorProps>> GetRemoteVersionDescriptorsAsync()
|
||||||
|
{
|
||||||
|
List<RemoteVersionDescriptorProps> descriptors = new();
|
||||||
|
foreach (var url in VERSION_MANIFEST_URLS)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var catalog = await DownloadStringAndDeserialize<GameVersionCatalog>(url);
|
||||||
|
descriptors.AddRange(catalog.versions);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LauncherApp.Logger.LogWarn(nameof(Сеть), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return descriptors;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<GameVersionProps>? _versionPropsList;
|
||||||
|
|
||||||
|
/// <returns>empty list if couldn't find any remote versions</returns>
|
||||||
|
public static async Task<IReadOnlyList<GameVersionProps>> GetDownloadableVersions()
|
||||||
|
{
|
||||||
|
if (_versionPropsList == null)
|
||||||
|
{
|
||||||
|
_versionPropsList = new();
|
||||||
|
var rvdlist = await GetRemoteVersionDescriptorsAsync();
|
||||||
|
foreach (var r in rvdlist)
|
||||||
|
{
|
||||||
|
if (r.type == "release")
|
||||||
|
_versionPropsList.Add(new GameVersionProps(r.id, r.url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _versionPropsList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user