Compare commits
No commits in common. "main" and "0.2.0" have entirely different histories.
@ -1,6 +1,5 @@
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
using Mlaumcherb.Client.Avalonia.сеть.Update;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia;
|
||||
@ -21,28 +20,21 @@ public record Config
|
||||
public bool redirect_game_output { get; set; } = false;
|
||||
public string? last_launched_version { get; set; }
|
||||
public int max_parallel_downloads { get; set; } = 16;
|
||||
public GameVersionCatalogProps[] version_catalogs { get; set; } =
|
||||
public VersionCatalogProps[] version_catalogs { get; set; } =
|
||||
[
|
||||
new() { name = "Тимериховое", url = "https://timerix.ddns.net/minecraft/catalog.json" },
|
||||
new() { name = "Mojang", url = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json" },
|
||||
new() { name = "Тимериховое", url = "https://timerix.ddns.net/minecraft/catalog.json" }
|
||||
];
|
||||
|
||||
public UpdateHelper.GiteaConfig gitea { get; set; } = new()
|
||||
{
|
||||
serverUrl = "https://timerix.ddns.net/git/",
|
||||
user = "Timerix",
|
||||
repo = "mlaumcherb",
|
||||
};
|
||||
|
||||
|
||||
[JsonIgnore] private static IOPath _filePath = "млаумчерб.json";
|
||||
|
||||
public static Config LoadFromFile()
|
||||
{
|
||||
LauncherApp.Logger.LogDebug(nameof(Config), $"loading config from file '{_filePath}'");
|
||||
LauncherApp.Logger.LogInfo(nameof(Config), $"loading config from file '{_filePath}'");
|
||||
if(!File.Exists(_filePath))
|
||||
{
|
||||
LauncherApp.Logger.LogDebug(nameof(Config), "file doesn't exist");
|
||||
LauncherApp.Logger.LogInfo(nameof(Config), "file doesn't exist");
|
||||
return new Config();
|
||||
}
|
||||
|
||||
@ -75,7 +67,7 @@ public record Config
|
||||
|
||||
public void SaveToFile()
|
||||
{
|
||||
LauncherApp.Logger.LogDebug(nameof(Config), $"saving config to file '{_filePath}'");
|
||||
LauncherApp.Logger.LogInfo(nameof(Config), $"saving config to file '{_filePath}'");
|
||||
var text = JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
File.WriteAllText(_filePath, text);
|
||||
LauncherApp.Logger.LogDebug(nameof(Config), $"config has been saved: {text}");
|
||||
|
||||
@ -7,14 +7,15 @@ using Mlaumcherb.Client.Avalonia.классы;
|
||||
using Mlaumcherb.Client.Avalonia.сеть;
|
||||
using Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using static Mlaumcherb.Client.Avalonia.холопы.PathHelper;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia;
|
||||
|
||||
public class GameVersion
|
||||
{
|
||||
private readonly InstalledGameVersionProps _props;
|
||||
public string Id => _props.Id;
|
||||
private readonly GameVersionProps _props;
|
||||
public string Name => _props.Name;
|
||||
public IOPath WorkingDirectory { get; }
|
||||
|
||||
private IOPath JavaExecutableFilePath;
|
||||
@ -26,32 +27,94 @@ public class GameVersion
|
||||
private CancellationTokenSource? _gameCts;
|
||||
private CommandTask<CommandResult>? _commandTask;
|
||||
|
||||
internal GameVersion(InstalledGameVersionProps props, GameVersionDescriptor descriptor)
|
||||
public static Task<List<GameVersionProps>> GetAllVersionsAsync()
|
||||
{
|
||||
var propsList = new List<GameVersionProps>();
|
||||
|
||||
// local descriptors
|
||||
Directory.Create(GetVersionsDir());
|
||||
foreach (IOPath subdir in Directory.GetDirectories(GetVersionsDir()))
|
||||
{
|
||||
string name = subdir.LastName().ToString();
|
||||
var d = new GameVersionProps(name);
|
||||
if(!File.Exists(d.LocalDescriptorPath))
|
||||
throw new Exception("Can't find version descriptor file in directory '{subdir}'. Rename it as directory name.");
|
||||
propsList.Add(d);
|
||||
}
|
||||
|
||||
// reverse sort
|
||||
propsList.Sort((a, b) => b.CompareTo(a));
|
||||
return Task.FromResult(propsList);
|
||||
}
|
||||
|
||||
public static async Task<GameVersion> CreateFromPropsAsync(GameVersionProps props, bool checkHash)
|
||||
{
|
||||
//TODO: refresh version descriptor from server
|
||||
if (!File.Exists(props.LocalDescriptorPath))
|
||||
{
|
||||
if (props.RemoteProps is null)
|
||||
throw new NullReferenceException("can't download game version descriptor '"
|
||||
+ props.Name + "', because RemoteDescriptorUrl is null");
|
||||
await NetworkHelper.DownloadFile(props.RemoteProps.url, props.LocalDescriptorPath);
|
||||
}
|
||||
|
||||
return new GameVersion(props);
|
||||
}
|
||||
|
||||
private GameVersion(GameVersionProps props)
|
||||
{
|
||||
_props = props;
|
||||
_descriptor = descriptor;
|
||||
|
||||
string descriptorText = File.ReadAllText(props.LocalDescriptorPath);
|
||||
JObject descriptorRaw = JObject.Parse(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}'");
|
||||
_javaArgs = new JavaArguments(_descriptor);
|
||||
_gameArgs = new GameArguments(_descriptor);
|
||||
_libraries = new Libraries(_descriptor);
|
||||
WorkingDirectory = GetVersionDir(_descriptor.id);
|
||||
JavaExecutableFilePath = GetJavaExecutablePath(
|
||||
_descriptor.javaVersion.component, LauncherApp.Config.redirect_game_output);
|
||||
JavaExecutableFilePath = GetJavaExecutablePath(_descriptor.javaVersion.component, LauncherApp.Config.debug);
|
||||
}
|
||||
|
||||
public async Task Download(bool checkHashes, Action<NetworkTask> networkTaskCreatedCallback)
|
||||
public async Task UpdateFiles(bool checkHashes, Action<NetworkTask> networkTaskCreatedCallback)
|
||||
{
|
||||
LauncherApp.Logger.LogInfo(Id, $"started updating version {Id}");
|
||||
LauncherApp.Logger.LogInfo(Name, $"started updating version {Name}");
|
||||
|
||||
List<INetworkTaskFactory> taskFactories =
|
||||
[
|
||||
new AssetsDownloadTaskFactory(_descriptor),
|
||||
new LibrariesDownloadTaskFactory(_descriptor, _libraries),
|
||||
];
|
||||
if (LauncherApp.Config.download_java && (!File.Exists(JavaExecutableFilePath) || checkHashes))
|
||||
if (LauncherApp.Config.download_java)
|
||||
{
|
||||
taskFactories.Add(new JavaDownloadTaskFactory(_descriptor));
|
||||
}
|
||||
if (_descriptor.modpack != null)
|
||||
{
|
||||
taskFactories.Add(new ModpackDownloadTaskFactory(_descriptor));
|
||||
// has to be downloaded last because it is used to check if version is installed
|
||||
}
|
||||
// has to be downloaded last because it is used by GameVersionProps to check if version is installed
|
||||
taskFactories.Add(new VersionJarDownloadTaskFactory(_descriptor));
|
||||
|
||||
var networkTasks = new List<NetworkTask>();
|
||||
@ -79,8 +142,8 @@ public class GameVersion
|
||||
await res.CopyToAsync(file);
|
||||
}
|
||||
|
||||
_props.IsInstalled = true;
|
||||
LauncherApp.Logger.LogInfo(Id, $"finished updating version {Id}");
|
||||
_props.IsDownloaded = true;
|
||||
LauncherApp.Logger.LogInfo(Name, $"finished updating version {Name}");
|
||||
}
|
||||
|
||||
//minecraft player uuid explanation
|
||||
@ -109,7 +172,6 @@ public class GameVersion
|
||||
if (string.IsNullOrWhiteSpace(LauncherApp.Config.player_name))
|
||||
throw new Exception("invalid player name");
|
||||
|
||||
string classSeparator = PlatformHelper.GetOs() == "windows" ? ";" : ":";
|
||||
Directory.Create(WorkingDirectory);
|
||||
string uuid = GetPlayerUUID(LauncherApp.Config.player_name);
|
||||
Dictionary<string, string> placeholder_values = new() {
|
||||
@ -129,14 +191,14 @@ public class GameVersion
|
||||
{ "launcher_version", "1.6.84-j" },
|
||||
{ "classpath", _libraries.Libs.Select(l => l.jarFilePath)
|
||||
.Append(GetVersionJarFilePath(_descriptor.id))
|
||||
.MergeToString(classSeparator) },
|
||||
.MergeToString(';') },
|
||||
{ "assets_index_name", _descriptor.assets },
|
||||
{ "assets_root", GetAssetsDir().ToString() },
|
||||
{ "game_assets", GetAssetsDir().ToString() },
|
||||
{ "game_directory", WorkingDirectory.ToString() },
|
||||
{ "natives_directory", GetNativeLibrariesDir(_descriptor.id).ToString() },
|
||||
{ "library_directory", GetLibrariesDir().ToString() },
|
||||
{ "classpath_separator", classSeparator},
|
||||
{ "classpath_separator", ";"},
|
||||
{ "path", GetLog4jConfigFilePath().ToString() },
|
||||
{ "version_name", _descriptor.id },
|
||||
{ "version_type", _descriptor.type },
|
||||
@ -162,23 +224,23 @@ public class GameVersion
|
||||
.WithStandardOutputPipe(PipeTarget.ToDelegate(LogGameOut))
|
||||
.WithStandardErrorPipe(PipeTarget.ToDelegate(LogGameError));
|
||||
}
|
||||
LauncherApp.Logger.LogInfo(Id, "launching the game");
|
||||
LauncherApp.Logger.LogDebug(Id, "java: " + command.TargetFilePath);
|
||||
LauncherApp.Logger.LogDebug(Id, "working_dir: " + command.WorkingDirPath);
|
||||
LauncherApp.Logger.LogDebug(Id, "arguments: \n\t" + argsList.MergeToString("\n\t"));
|
||||
LauncherApp.Logger.LogInfo(Name, "launching the game");
|
||||
LauncherApp.Logger.LogDebug(Name, "java: " + command.TargetFilePath);
|
||||
LauncherApp.Logger.LogDebug(Name, "working_dir: " + command.WorkingDirPath);
|
||||
LauncherApp.Logger.LogDebug(Name, "arguments: \n\t" + argsList.MergeToString("\n\t"));
|
||||
_gameCts = new();
|
||||
_commandTask = command.ExecuteAsync(_gameCts.Token);
|
||||
var result = await _commandTask;
|
||||
LauncherApp.Logger.LogInfo(Id, $"game exited with code {result.ExitCode}");
|
||||
LauncherApp.Logger.LogInfo(Name, $"game exited with code {result.ExitCode}");
|
||||
}
|
||||
|
||||
private void LogGameOut(string line)
|
||||
{
|
||||
LauncherApp.Logger.LogInfo(Id, line);
|
||||
LauncherApp.Logger.LogInfo(Name, line);
|
||||
}
|
||||
private void LogGameError(string line)
|
||||
{
|
||||
LauncherApp.Logger.LogWarn(Id, line);
|
||||
LauncherApp.Logger.LogWarn(Name, line);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
@ -187,5 +249,5 @@ public class GameVersion
|
||||
}
|
||||
|
||||
|
||||
public override string ToString() => Id;
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
@ -5,12 +5,11 @@ public class LauncherLogger : ILogger
|
||||
private CompositeLogger _compositeLogger;
|
||||
private FileLogger _fileLogger;
|
||||
public static readonly IOPath LogsDirectory = "launcher_logs";
|
||||
public IOPath LogFilePath => _fileLogger.LogfileName;
|
||||
public IOPath LogfileName => _fileLogger.LogfileName;
|
||||
|
||||
public LauncherLogger()
|
||||
{
|
||||
_fileLogger = new FileLogger(LogsDirectory, "млаумчерб");
|
||||
_fileLogger.DebugLogEnabled = true;
|
||||
ILogger[] loggers =
|
||||
[
|
||||
_fileLogger,
|
||||
@ -55,11 +54,7 @@ public class LauncherLogger : ILogger
|
||||
public bool DebugLogEnabled
|
||||
{
|
||||
get => _compositeLogger.DebugLogEnabled;
|
||||
set
|
||||
{
|
||||
_compositeLogger.DebugLogEnabled = value;
|
||||
_fileLogger.DebugLogEnabled = true;
|
||||
}
|
||||
set => _compositeLogger.DebugLogEnabled = value;
|
||||
}
|
||||
|
||||
public bool InfoLogEnabled
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Version>1.1.2</Version>
|
||||
<OutputType Condition="'$(Configuration)' == 'Debug'">Exe</OutputType>
|
||||
<OutputType Condition="'$(Configuration)' != 'Debug'">WinExe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
@ -12,19 +11,18 @@
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
<ApplicationIcon>капитал\кубе.ico</ApplicationIcon>
|
||||
<AssemblyName>млаумчерб</AssemblyName>
|
||||
<Configurations>Release;Debug</Configurations>
|
||||
<Platforms>x64</Platforms>
|
||||
<!-- AXAML resource has no public constructor -->
|
||||
<NoWarn>AVLN3001</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.2.*" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.2.*" />
|
||||
<PackageReference Include="Avalonia.Themes.Simple" Version="11.2.*" />
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.*" />
|
||||
<PackageReference Include="Avalonia.Labs.Gif" Version="11.2.*" />
|
||||
<PackageReference Include="CliWrap" Version="3.7.0" />
|
||||
<PackageReference Include="DTLib" Version="1.7.3" />
|
||||
<PackageReference Include="Avalonia" Version="11.2.0" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.2.0" />
|
||||
<PackageReference Include="Avalonia.Themes.Simple" Version="11.2.0" />
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.0" />
|
||||
<PackageReference Include="Avalonia.Labs.Gif" Version="11.2.0" />
|
||||
<PackageReference Include="CliWrap" Version="3.6.7" />
|
||||
<PackageReference Include="DTLib" Version="1.6.1" />
|
||||
<PackageReference Include="LZMA-SDK" Version="22.1.1" />
|
||||
<PackageReference Include="MessageBox.Avalonia" Version="3.2.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.*" />
|
||||
|
||||
@ -1,48 +0,0 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.зримое;
|
||||
|
||||
public abstract partial class GameVersionItemView : ListBoxItem
|
||||
{
|
||||
private static readonly SolidColorBrush _avaliableColor = new(Color.FromRgb(30, 130, 40));
|
||||
private static readonly SolidColorBrush _unavaliableColor = new(Color.FromRgb(170, 70, 70));
|
||||
|
||||
protected GameVersionItemView(string name, bool initialStatus)
|
||||
{
|
||||
InitializeComponent();
|
||||
text.Text = name;
|
||||
UpdateBackground(initialStatus);
|
||||
}
|
||||
|
||||
protected void UpdateBackground(bool isInstalled)
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() => Background = isInstalled ? _avaliableColor : _unavaliableColor);
|
||||
}
|
||||
}
|
||||
|
||||
// Background changes when props status changes
|
||||
public class InstalledGameVersionItemView : GameVersionItemView
|
||||
{
|
||||
public readonly InstalledGameVersionProps Props;
|
||||
|
||||
public InstalledGameVersionItemView(InstalledGameVersionProps props) : base(props.Id, props.IsInstalled)
|
||||
{
|
||||
Props = props;
|
||||
props.StatusChanged += UpdateBackground;
|
||||
}
|
||||
}
|
||||
|
||||
// Background is set once by checking if the version is present in InstalledVersionsCatalog
|
||||
public class RemoteGameVersionItemView : GameVersionItemView
|
||||
{
|
||||
public readonly RemoteVersionDescriptorProps Props;
|
||||
|
||||
public RemoteGameVersionItemView(RemoteVersionDescriptorProps props)
|
||||
: base(props.id, LauncherApp.InstalledVersionCatalog.versions.ContainsKey(props.id))
|
||||
{
|
||||
Props = props;
|
||||
}
|
||||
}
|
||||
@ -25,10 +25,6 @@
|
||||
<Setter Property="MinWidth" Value="50"/>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Button.button_dark">
|
||||
<Setter Property="Background" Value="#65656070"/>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Border.menu_separator">
|
||||
<Setter Property="Background" Value="#ff505050"/>
|
||||
<Setter Property="Width" Value="1"/>
|
||||
|
||||
@ -1,17 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
using Mlaumcherb.Client.Avalonia.сеть.Update;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.зримое;
|
||||
|
||||
public class LauncherApp : Application
|
||||
{
|
||||
public static LauncherLogger Logger = new();
|
||||
public static Config Config = null!;
|
||||
public static InstalledVersionCatalog InstalledVersionCatalog = null!;
|
||||
public static Config Config = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@ -20,47 +16,11 @@ public class LauncherApp : Application
|
||||
Logger.DebugLogEnabled = Config.debug;
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
|
||||
try
|
||||
{
|
||||
SelfUpdateAsync();
|
||||
|
||||
// some file required by forge installer
|
||||
if (!File.Exists("launcher_profiles.json"))
|
||||
{
|
||||
File.WriteAllText("launcher_profiles.json", "{}");
|
||||
}
|
||||
|
||||
InstalledVersionCatalog = InstalledVersionCatalog.Load();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorHelper.ShowMessageBox(nameof(LauncherApp), e);
|
||||
}
|
||||
}
|
||||
|
||||
private async void SelfUpdateAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
Logger.LogInfo(nameof(LauncherApp), "checking for updates...");
|
||||
var upd = new UpdateHelper(Config.gitea);
|
||||
upd.DeleteBackupFiles();
|
||||
if (await upd.IsUpdateAvailable())
|
||||
{
|
||||
Logger.LogInfo(nameof(LauncherApp), "downloading update...");
|
||||
await upd.UpdateSelf();
|
||||
Logger.LogInfo(nameof(LauncherApp), "restarting...");
|
||||
upd.RestartSelf();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInfo(nameof(LauncherApp), "no updates found");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorHelper.ShowMessageBox(nameof(LauncherApp), e);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
|
||||
@ -34,30 +34,20 @@
|
||||
<ScrollViewer Grid.Row="0"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Margin="10" Spacing="6">
|
||||
<TextBlock>Ник:</TextBlock>
|
||||
<TextBox Background="Transparent"
|
||||
Text="{Binding #window.PlayerName}"/>
|
||||
|
||||
<TextBlock>Версия игры:</TextBlock>
|
||||
<ComboBox Name="InstalledVersionCatalogComboBox"/>
|
||||
<Button Name="RescanInstalledVersionsButton"
|
||||
Click="RescanInstalledVersionsButton_OnClick"
|
||||
Classes="button_dark">
|
||||
Обновить список
|
||||
</Button>
|
||||
<StackPanel Margin="10" Spacing="10">
|
||||
<TextBlock>Версия:</TextBlock>
|
||||
<ComboBox Name="InstalledVersionComboBox"/>
|
||||
<Button Name="DeleteVersionButton"
|
||||
Click="DeleteVersionButton_OnClick"
|
||||
Classes="button_dark">
|
||||
Click="DeleteVersionButton_OnClick">
|
||||
Удалить версию
|
||||
</Button>
|
||||
|
||||
<Expander Header="Добавление версий"
|
||||
BorderThickness="1" BorderBrush="Gray"
|
||||
Padding="4">
|
||||
<StackPanel Spacing="6">
|
||||
<StackPanel>
|
||||
<TextBlock>Источник:</TextBlock>
|
||||
<ComboBox Name="RemoteVersionCatalogComboBox"/>
|
||||
<ComboBox Name="VersionCatalogComboBox"/>
|
||||
<WrapPanel>
|
||||
<CheckBox Name="ReleaseVersionTypeCheckBox" IsChecked="True">релиз</CheckBox>
|
||||
<CheckBox Name="SnapshotVersionTypeCheckBox">снапшот</CheckBox>
|
||||
@ -65,20 +55,22 @@
|
||||
<CheckBox Name="OtherVersionTypeAlphaCheckBox">другое</CheckBox>
|
||||
</WrapPanel>
|
||||
<Button Name="SearchVersionsButton"
|
||||
Click="SearchVersionsButton_OnClick"
|
||||
Classes="button_dark">
|
||||
Click="SearchVersionsButton_OnClick">
|
||||
Поиск
|
||||
</Button>
|
||||
<TextBlock>Доступные версии:</TextBlock>
|
||||
<ComboBox Name="RemoteVersionCatalogItemsComboBox"/>
|
||||
<ComboBox Name="VersionCatalogItemsComboBox"/>
|
||||
<Button Name="AddVersionButton" IsEnabled="False"
|
||||
Click="AddVersionButton_OnClick"
|
||||
Classes="button_dark">
|
||||
Click="AddVersionButton_OnClick">
|
||||
Добавить
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Expander>
|
||||
|
||||
<TextBlock>Ник:</TextBlock>
|
||||
<TextBox Background="Transparent"
|
||||
Text="{Binding #window.PlayerName}"/>
|
||||
|
||||
<TextBlock>
|
||||
<Run>Выделенная память:</Run>
|
||||
<TextBox Background="Transparent" Padding="0"
|
||||
@ -92,8 +84,8 @@
|
||||
Value="{Binding #window.MemoryLimit}">
|
||||
</Slider>
|
||||
|
||||
<CheckBox IsChecked="{Binding #window.UpdateGameFiles}">
|
||||
Обновить файлы игры
|
||||
<CheckBox IsChecked="{Binding #window.CheckGameFiles}">
|
||||
Проверять файлы игры
|
||||
</CheckBox>
|
||||
<CheckBox IsChecked="{Binding #window.EnableJavaDownload}">
|
||||
Скачивать джаву
|
||||
@ -178,7 +170,6 @@
|
||||
<Button Classes="menu_button button_no_border" Click="ОткрытьФайлЛогов">лог-файл</Button>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<TextBlock Name="LauncherVersionTextBox"/>
|
||||
<Button Classes="menu_button button_no_border" Click="ОткрытьРепозиторий">исходный код</Button>
|
||||
<gif:GifImage
|
||||
Width="30" Height="30" Stretch="Uniform"
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
using System.Reflection;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Data;
|
||||
@ -33,13 +32,13 @@ public partial class MainWindow : Window
|
||||
set => SetValue(MemoryLimitProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> UpdateGameFilesProperty =
|
||||
AvaloniaProperty.Register<MainWindow, bool>(nameof(UpdateGameFiles),
|
||||
public static readonly StyledProperty<bool> CheckGameFilesProperty =
|
||||
AvaloniaProperty.Register<MainWindow, bool>(nameof(CheckGameFiles),
|
||||
defaultBindingMode: BindingMode.TwoWay, defaultValue: false);
|
||||
public bool UpdateGameFiles
|
||||
public bool CheckGameFiles
|
||||
{
|
||||
get => GetValue(UpdateGameFilesProperty);
|
||||
set => SetValue(UpdateGameFilesProperty, value);
|
||||
get => GetValue(CheckGameFilesProperty);
|
||||
set => SetValue(CheckGameFilesProperty, value);
|
||||
}
|
||||
|
||||
|
||||
@ -66,79 +65,38 @@ public partial class MainWindow : Window
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
protected override async void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
LauncherApp.Logger.OnLogMessage += GuiLogMessage;
|
||||
LauncherVersionTextBox.Text = $"v{Assembly.GetExecutingAssembly().GetName().Version}";
|
||||
|
||||
PlayerName = LauncherApp.Config.player_name;
|
||||
MemoryLimit = LauncherApp.Config.max_memory;
|
||||
EnableJavaDownload = LauncherApp.Config.download_java;
|
||||
RedirectGameOutput = LauncherApp.Config.redirect_game_output;
|
||||
|
||||
InstalledVersionComboBox.SelectedIndex = 0;
|
||||
InstalledVersionComboBox.IsEnabled = false;
|
||||
var versions = await GameVersion.GetAllVersionsAsync();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
foreach (var p in versions)
|
||||
{
|
||||
InstalledVersionComboBox.Items.Add(new VersionItemView(p));
|
||||
// select last played version
|
||||
if (LauncherApp.Config.last_launched_version != null &&
|
||||
p.Name == LauncherApp.Config.last_launched_version)
|
||||
InstalledVersionComboBox.SelectedIndex = InstalledVersionComboBox.Items.Count - 1;
|
||||
}
|
||||
InstalledVersionComboBox.IsEnabled = true;
|
||||
|
||||
foreach (var vc in LauncherApp.Config.version_catalogs)
|
||||
{
|
||||
RemoteVersionCatalogComboBox.Items.Add(vc);
|
||||
VersionCatalogComboBox.Items.Add(vc);
|
||||
}
|
||||
RemoteVersionCatalogComboBox.SelectedIndex = 0;
|
||||
|
||||
UpdateInstalledVersionsCatalogView(LauncherApp.Config.last_launched_version);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUnloaded(RoutedEventArgs e)
|
||||
{
|
||||
SaveGuiPropertiesToConfig();
|
||||
}
|
||||
|
||||
private void SaveGuiPropertiesToConfig()
|
||||
{
|
||||
LauncherApp.Config.player_name = PlayerName;
|
||||
LauncherApp.Config.max_memory = MemoryLimit;
|
||||
LauncherApp.Config.download_java = EnableJavaDownload;
|
||||
LauncherApp.Config.redirect_game_output = RedirectGameOutput;
|
||||
LauncherApp.Config.SaveToFile();
|
||||
}
|
||||
|
||||
private void UpdateInstalledVersionsCatalogView(string? selectVersion)
|
||||
{
|
||||
LauncherApp.InstalledVersionCatalog.CheckInstalledVersions();
|
||||
InstalledVersionCatalogComboBox.IsEnabled = false;
|
||||
InstalledVersionCatalogComboBox.Items.Clear();
|
||||
foreach (var p in LauncherApp.InstalledVersionCatalog.versions)
|
||||
{
|
||||
InstalledVersionCatalogComboBox.Items.Add(new InstalledGameVersionItemView(p.Value));
|
||||
}
|
||||
|
||||
InstalledVersionCatalogComboBox.SelectedItem = null;
|
||||
if(selectVersion is not null
|
||||
&& LauncherApp.InstalledVersionCatalog.versions.TryGetValue(selectVersion, out var props))
|
||||
{
|
||||
foreach (InstalledGameVersionItemView? view in InstalledVersionCatalogComboBox.Items)
|
||||
{
|
||||
if (view?.Props.Id == props.Id)
|
||||
{
|
||||
InstalledVersionCatalogComboBox.SelectedItem = view;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InstalledVersionCatalogComboBox.IsEnabled = true;
|
||||
}
|
||||
|
||||
private void RescanInstalledVersionsButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var selectedVersionView = InstalledVersionCatalogComboBox.SelectedItem as InstalledGameVersionItemView;
|
||||
UpdateInstalledVersionsCatalogView(selectedVersionView?.Props.Id);
|
||||
VersionCatalogComboBox.SelectedIndex = 0;
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -163,18 +121,21 @@ public partial class MainWindow : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
if (InstalledVersionCatalogComboBox.SelectedItem is not InstalledGameVersionItemView selectedVersionView)
|
||||
Dispatcher.UIThread.Invoke(() => LaunchButton.IsEnabled = false);
|
||||
|
||||
var selectedVersionView = (VersionItemView?)InstalledVersionComboBox.SelectedItem;
|
||||
var selectedVersion = selectedVersionView?.Props;
|
||||
LauncherApp.Config.last_launched_version = selectedVersion?.Name;
|
||||
LauncherApp.Config.player_name = PlayerName;
|
||||
LauncherApp.Config.max_memory = MemoryLimit;
|
||||
LauncherApp.Config.download_java = EnableJavaDownload;
|
||||
LauncherApp.Config.redirect_game_output = RedirectGameOutput;
|
||||
LauncherApp.Config.SaveToFile();
|
||||
if (selectedVersion == null)
|
||||
return;
|
||||
|
||||
Dispatcher.UIThread.Invoke(() => LaunchButton.IsEnabled = false);
|
||||
LauncherApp.Config.last_launched_version = selectedVersionView.Props.Id;
|
||||
SaveGuiPropertiesToConfig();
|
||||
|
||||
var v = await selectedVersionView.Props.LoadDescriptor(UpdateGameFiles);
|
||||
|
||||
try
|
||||
{
|
||||
await v.Download(UpdateGameFiles, nt =>
|
||||
var v = await GameVersion.CreateFromPropsAsync(selectedVersion, CheckGameFiles);
|
||||
await v.UpdateFiles(CheckGameFiles, nt =>
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
@ -183,15 +144,9 @@ public partial class MainWindow : Window
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
UpdateGameFiles = false;
|
||||
CheckGameFiles = false;
|
||||
});
|
||||
await v.Launch();
|
||||
}
|
||||
@ -201,7 +156,10 @@ public partial class MainWindow : Window
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() => LaunchButton.IsEnabled = true);
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
LaunchButton.IsEnabled = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,10 +167,7 @@ public partial class MainWindow : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
string workingDir = Directory.GetCurrent().ToString();
|
||||
LauncherApp.Logger.LogDebug(nameof(MainWindow),
|
||||
$"opening working directory: {workingDir}");
|
||||
Launcher.LaunchDirectoryInfoAsync(new DirectoryInfo(workingDir))
|
||||
Launcher.LaunchDirectoryInfoAsync(new DirectoryInfo(Directory.GetCurrent().ToString()))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -225,10 +180,7 @@ public partial class MainWindow : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
string logFilePath = LauncherApp.Logger.LogFilePath.ToString();
|
||||
LauncherApp.Logger.LogDebug(nameof(MainWindow),
|
||||
$"opening log file: {logFilePath}");
|
||||
Launcher.LaunchFileInfoAsync(new FileInfo(logFilePath))
|
||||
Launcher.LaunchFileInfoAsync(new FileInfo(LauncherApp.Logger.LogfileName.ToString()))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -241,10 +193,7 @@ public partial class MainWindow : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
var sourcesUri = new Uri(LauncherApp.Config.gitea.GetRepoUrl());
|
||||
LauncherApp.Logger.LogDebug(nameof(MainWindow),
|
||||
$"opening in web browser: {sourcesUri}");
|
||||
Launcher.LaunchUriAsync(sourcesUri)
|
||||
Launcher.LaunchUriAsync(new Uri("https://timerix.ddns.net:3322/Timerix/mlaumcherb"))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -269,32 +218,71 @@ public partial class MainWindow : Window
|
||||
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
|
||||
{
|
||||
if(RemoteVersionCatalogComboBox.SelectedItem is not GameVersionCatalogProps catalogProps)
|
||||
var catalogProps = VersionCatalogComboBox.SelectedItem as VersionCatalogProps;
|
||||
if(catalogProps is null)
|
||||
return;
|
||||
|
||||
var catalog = await catalogProps.GetVersionCatalogAsync();
|
||||
var searchParams = new VersionSearchParams
|
||||
var searchParams = new VersionSearchParams();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
ReleaseTypeAllowed = ReleaseVersionTypeCheckBox.IsChecked ?? false,
|
||||
SnapshotTypeAllowed = SnapshotVersionTypeCheckBox.IsChecked ?? false,
|
||||
OldTypeAllowed = OldVersionTypeCheckBox.IsChecked ?? false,
|
||||
OtherTypeAllowed = OtherVersionTypeAlphaCheckBox.IsChecked ?? false
|
||||
};
|
||||
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(() =>
|
||||
{
|
||||
RemoteVersionCatalogItemsComboBox.IsEnabled = false;
|
||||
RemoteVersionCatalogItemsComboBox.Items.Clear();
|
||||
VersionCatalogItemsComboBox.IsEnabled = false;
|
||||
VersionCatalogItemsComboBox.Items.Clear();
|
||||
foreach (var p in versions)
|
||||
{
|
||||
RemoteVersionCatalogItemsComboBox.Items.Add(new RemoteGameVersionItemView(p));
|
||||
VersionCatalogItemsComboBox.Items.Add(new VersionItemView(p));
|
||||
}
|
||||
RemoteVersionCatalogItemsComboBox.IsEnabled = true;
|
||||
VersionCatalogItemsComboBox.SelectedIndex = 0;
|
||||
VersionCatalogItemsComboBox.IsEnabled = true;
|
||||
AddVersionButton.IsEnabled = versions.Count > 0;
|
||||
});
|
||||
}
|
||||
@ -308,57 +296,12 @@ public partial class MainWindow : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
if(RemoteVersionCatalogComboBox.SelectedItem is not GameVersionCatalogProps catalogProps)
|
||||
var selectedVersionView = VersionCatalogItemsComboBox.SelectedItem as VersionItemView;
|
||||
if(selectedVersionView is null)
|
||||
return;
|
||||
|
||||
if(RemoteVersionCatalogItemsComboBox.SelectedItem is not RemoteGameVersionItemView sel)
|
||||
return;
|
||||
|
||||
var installedProps = new InstalledGameVersionProps(sel.Props.id, catalogProps, sel.Props);
|
||||
if (!LauncherApp.InstalledVersionCatalog.versions.TryAdd(sel.Props.id, installedProps))
|
||||
throw new Exception("Версия уже была добавлена");
|
||||
LauncherApp.InstalledVersionCatalog.Save();
|
||||
|
||||
var propsView = new InstalledGameVersionItemView(installedProps);
|
||||
InstalledVersionCatalogComboBox.Items.Insert(0, propsView);
|
||||
InstalledVersionCatalogComboBox.SelectedItem = propsView;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorHelper.ShowMessageBox(nameof(MainWindow), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private async void DeleteVersionButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(InstalledVersionCatalogComboBox.SelectedItem is not InstalledGameVersionItemView sel)
|
||||
return;
|
||||
|
||||
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
|
||||
{
|
||||
ButtonDefinitions = new List<ButtonDefinition> { new() { Name = "Да" }, new() { Name = "Нет" } },
|
||||
ContentTitle = $"Удаление версии {sel.Props.Id}",
|
||||
ContentMessage = $"Вы уверены, что хотите удалить версию {sel.Props.Id}? Все файлы, включая сохранения, будут удалены!",
|
||||
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.Delete();
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
InstalledVersionCatalogComboBox.Items.Remove(sel);
|
||||
LauncherApp.InstalledVersionCatalog.versions.Remove(sel.Props.Id);
|
||||
LauncherApp.InstalledVersionCatalog.Save();
|
||||
});
|
||||
InstalledVersionComboBox.Items.Insert(0, new VersionItemView(selectedVersionView.Props));
|
||||
InstalledVersionComboBox.SelectedIndex = 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Mlaumcherb.Client.Avalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Mlaumcherb.Client.Avalonia.зримое.GameVersionItemView"
|
||||
x:Class="Mlaumcherb.Client.Avalonia.зримое.VersionItemView"
|
||||
Padding="2">
|
||||
<TextBlock Name="text" Background="Transparent"/>
|
||||
</UserControl>
|
||||
34
Mlaumcherb.Client.Avalonia/зримое/VersionItemView.axaml.cs
Normal file
34
Mlaumcherb.Client.Avalonia/зримое/VersionItemView.axaml.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.зримое;
|
||||
|
||||
public partial class VersionItemView : ListBoxItem
|
||||
{
|
||||
public GameVersionProps Props { get; }
|
||||
private SolidColorBrush _avaliableColor = new(Color.FromRgb(30, 130, 40));
|
||||
private SolidColorBrush _unavaliableColor = new(Color.FromRgb(170, 70, 70));
|
||||
|
||||
public VersionItemView()
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
public VersionItemView(GameVersionProps props)
|
||||
{
|
||||
Props = props;
|
||||
InitializeComponent();
|
||||
text.Text = props.Name;
|
||||
props.StatusChanged += UpdateBackground;
|
||||
UpdateBackground(props.IsDownloaded);
|
||||
}
|
||||
|
||||
private void UpdateBackground(bool isDownloaded)
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
Background = isDownloaded ? _avaliableColor : _unavaliableColor
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -10,12 +10,12 @@ public record VersionSearchParams
|
||||
|
||||
public class GameVersionCatalog
|
||||
{
|
||||
[JsonRequired] public List<RemoteVersionDescriptorProps> versions { get; set; } = new();
|
||||
[JsonRequired] public List<RemoteVersionDescriptorProps> versions { get; set; } = null!;
|
||||
|
||||
/// <returns>empty list if couldn't find any remote versions</returns>
|
||||
public List<RemoteVersionDescriptorProps> GetDownloadableVersions(VersionSearchParams p)
|
||||
public List<GameVersionProps> GetDownloadableVersions(VersionSearchParams p)
|
||||
{
|
||||
var _versionPropsList = new List<RemoteVersionDescriptorProps>();
|
||||
var _versionPropsList = new List<GameVersionProps>();
|
||||
foreach (var r in versions)
|
||||
{
|
||||
bool match = r.type switch
|
||||
@ -26,7 +26,7 @@ public class GameVersionCatalog
|
||||
_ => p.OtherTypeAllowed
|
||||
};
|
||||
if(match)
|
||||
_versionPropsList.Add(r);
|
||||
_versionPropsList.Add(new GameVersionProps(r));
|
||||
}
|
||||
return _versionPropsList;
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ public class GameVersionDescriptor
|
||||
[JsonRequired] public DateTime releaseTime { get; set; }
|
||||
[JsonRequired] public string type { get; set; } = "";
|
||||
[JsonRequired] public string mainClass { get; set; } = "";
|
||||
[JsonRequired] public List<Library> libraries { get; set; } = new();
|
||||
[JsonRequired] public List<Library> libraries { get; set; } = null!;
|
||||
[JsonRequired] public AssetIndexProperties assetIndex { get; set; } = null!;
|
||||
[JsonRequired] public string assets { get; set; } = "";
|
||||
public Downloads? downloads { get; set; } = null;
|
||||
@ -67,7 +67,7 @@ public class Library
|
||||
public List<Rule>? rules { get; set; }
|
||||
public Natives? natives { get; set; }
|
||||
public Extract? extract { get; set; }
|
||||
public LibraryDownloads? downloads { get; set; }
|
||||
[JsonRequired] public LibraryDownloads downloads { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class AssetIndexProperties
|
||||
|
||||
@ -5,9 +5,9 @@ namespace Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
public class JavaVersionCatalog
|
||||
{
|
||||
[JsonProperty("linux-i386")]
|
||||
public Dictionary<string, JavaVersionProps[]>? linux_x86 { get; set; }
|
||||
[JsonProperty("linux")]
|
||||
public Dictionary<string, JavaVersionProps[]>? linux_x86 { get; set; }
|
||||
[JsonProperty("linux-i386")]
|
||||
public Dictionary<string, JavaVersionProps[]>? linux_x64 { get; set; }
|
||||
[JsonProperty("mac-os")]
|
||||
public Dictionary<string, JavaVersionProps[]>? osx_x64 { get; set; }
|
||||
@ -67,7 +67,7 @@ public class JavaVersionProps
|
||||
|
||||
public class JavaDistributiveManifest
|
||||
{
|
||||
[JsonRequired] public Dictionary<string, JavaDistributiveElementProps> files { get; set; } = new();
|
||||
[JsonRequired] public Dictionary<string, JavaDistributiveElementProps> files { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class JavaDistributiveElementProps
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
public class ModpackFilesManifest
|
||||
{
|
||||
public class FileProps
|
||||
{
|
||||
[JsonRequired] public string sha1 { get; set; }
|
||||
public bool allow_edit { get; set; } = false;
|
||||
}
|
||||
|
||||
/// relative_path, hash
|
||||
[JsonRequired] public Dictionary<string, FileProps> files { get; set; } = new();
|
||||
|
||||
public bool CheckFiles(IOPath basedir, bool checkHashes, HashSet<IOPath> unmatchedFilesLocalPaths)
|
||||
{
|
||||
foreach (var p in files)
|
||||
{
|
||||
var localPath = new IOPath(p.Key);
|
||||
var realPath = Path.Concat(basedir, localPath);
|
||||
if (!HashHelper.CheckFileSHA1(realPath, p.Value.sha1, checkHashes && !p.Value.allow_edit))
|
||||
{
|
||||
unmatchedFilesLocalPaths.Add(localPath);
|
||||
}
|
||||
}
|
||||
|
||||
return unmatchedFilesLocalPaths.Count == 0;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
public class GameVersionProps : IComparable<GameVersionProps>, IEquatable<GameVersionProps>
|
||||
{
|
||||
public string Name { get; }
|
||||
public IOPath LocalDescriptorPath { get; }
|
||||
public RemoteVersionDescriptorProps? RemoteProps { get; }
|
||||
private bool _isDownloaded;
|
||||
public bool IsDownloaded
|
||||
{
|
||||
get => _isDownloaded;
|
||||
set
|
||||
{
|
||||
if(_isDownloaded != value)
|
||||
{
|
||||
_isDownloaded = value;
|
||||
StatusChanged?.Invoke(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public event Action<bool>? StatusChanged;
|
||||
|
||||
private GameVersionProps(string name, RemoteVersionDescriptorProps? remoteProps)
|
||||
{
|
||||
|
||||
Name = name;
|
||||
RemoteProps = remoteProps;
|
||||
LocalDescriptorPath = PathHelper.GetVersionDescriptorPath(name);
|
||||
IsDownloaded = File.Exists(PathHelper.GetVersionJarFilePath(name));
|
||||
}
|
||||
|
||||
public GameVersionProps(string name)
|
||||
: this(name, null)
|
||||
{ }
|
||||
|
||||
public GameVersionProps(RemoteVersionDescriptorProps remoteProps)
|
||||
: this(remoteProps.id, remoteProps)
|
||||
{ }
|
||||
|
||||
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 int GetHashCode() => Name.GetHashCode();
|
||||
|
||||
public int CompareTo(GameVersionProps? other)
|
||||
{
|
||||
if (ReferenceEquals(this, other)) return 0;
|
||||
if (other is null) return 1;
|
||||
|
||||
if (Version.TryParse(Name, out var version1) && Version.TryParse(other.Name, out var version2))
|
||||
{
|
||||
return version1.CompareTo(version2);
|
||||
}
|
||||
|
||||
return String.Compare(Name, other.Name, StringComparison.InvariantCulture);
|
||||
}
|
||||
|
||||
public bool Equals(GameVersionProps? other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return Name == other.Name;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is GameVersionProps other) return Equals(other);
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1,137 +0,0 @@
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using Mlaumcherb.Client.Avalonia.сеть;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
public class InstalledGameVersionProps : IComparable<InstalledGameVersionProps>, IEquatable<InstalledGameVersionProps>
|
||||
{
|
||||
[JsonRequired] public string Id { get; }
|
||||
public GameVersionCatalogProps? CatalogProps { get; set; }
|
||||
|
||||
public RemoteVersionDescriptorProps? DescriptorProps { get; set; }
|
||||
|
||||
|
||||
private bool _isInstalled;
|
||||
[JsonIgnore]
|
||||
public bool IsInstalled
|
||||
{
|
||||
get => _isInstalled;
|
||||
set
|
||||
{
|
||||
_isInstalled = value;
|
||||
StatusChanged?.Invoke(value);
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore] public IOPath DescriptorPath { get; }
|
||||
|
||||
public event Action<bool>? StatusChanged;
|
||||
|
||||
public InstalledGameVersionProps(string id, GameVersionCatalogProps? catalogProps, RemoteVersionDescriptorProps? descriptorProps)
|
||||
{
|
||||
this.Id = id;
|
||||
this.CatalogProps = catalogProps;
|
||||
this.DescriptorProps = descriptorProps;
|
||||
DescriptorPath = PathHelper.GetVersionDescriptorPath(id);
|
||||
IsInstalled = File.Exists(PathHelper.GetVersionJarFilePath(id));
|
||||
}
|
||||
|
||||
public async Task<GameVersion> LoadDescriptor(bool checkForUpdates)
|
||||
{
|
||||
// check if DescriptorProps had been changed on on remote version catalog server
|
||||
if (checkForUpdates && CatalogProps is not null && DescriptorProps is not null)
|
||||
{
|
||||
var remoteCatalog = await NetworkHelper.DownloadStringAndDeserialize<GameVersionCatalog>(CatalogProps.url);
|
||||
|
||||
DescriptorProps = remoteCatalog.versions.Find(remoteProps => remoteProps.id == Id);
|
||||
if(DescriptorProps is null)
|
||||
LauncherApp.Logger.LogWarn(nameof(InstalledGameVersionProps),
|
||||
$"Game version '{Id}' was deleted from remote catalog '{CatalogProps.name}'."
|
||||
+ "It is kept locally, but can't be updated anymore.");
|
||||
}
|
||||
|
||||
// Descriptor is downloaded here
|
||||
if (!HashHelper.CheckFileSHA1(DescriptorPath, DescriptorProps?.sha1, checkForUpdates))
|
||||
{
|
||||
if (DescriptorProps is null)
|
||||
throw new NullReferenceException(
|
||||
$"can't download game version descriptor '{Id}', because RemoteDescriptor is null");
|
||||
// download descriptor
|
||||
await NetworkHelper.DownloadFile(DescriptorProps.url, DescriptorPath);
|
||||
}
|
||||
|
||||
string descriptorText = File.ReadAllText(DescriptorPath);
|
||||
JObject descriptorRaw = JObject.Parse(descriptorText);
|
||||
|
||||
// Descriptors can inherit from other descriptors.
|
||||
// For example, timerix-anarx-2 inherits from 1.12.2-forge-14.23.5.2860, which inherits from 1.12.2
|
||||
while (descriptorRaw.TryGetValue("inheritsFrom", out var v))
|
||||
{
|
||||
string parentDescriptorId = v.Value<string>()
|
||||
?? throw new Exception("inheritsFrom is null");
|
||||
LauncherApp.Logger.LogInfo(Id, $"merging descriptor '{parentDescriptorId}' with '{Id}'");
|
||||
|
||||
IOPath parentDescriptorPath = PathHelper.GetVersionDescriptorPath(parentDescriptorId);
|
||||
if (!File.Exists(parentDescriptorPath))
|
||||
throw new Exception($"Версия '{Id} требует установить версию '{parentDescriptorId}'");
|
||||
JObject parentDescriptorRaw = JObject.Parse(File.ReadAllText(parentDescriptorPath));
|
||||
|
||||
// Remove `inheritsFrom: parentDescriptor.Id` to prevent overriding of `parentDescriptor.inheritsFrom`
|
||||
descriptorRaw.Remove("inheritsFrom");
|
||||
// Merge child descriptor into its parent.
|
||||
// Child descriptor values override values of parent.
|
||||
// Array values are merged together.
|
||||
parentDescriptorRaw.Merge(descriptorRaw,
|
||||
new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Concat });
|
||||
descriptorRaw = parentDescriptorRaw;
|
||||
}
|
||||
|
||||
var descriptor = descriptorRaw.ToObject<GameVersionDescriptor>()
|
||||
?? throw new Exception($"can't parse descriptor file '{DescriptorPath}'");
|
||||
|
||||
return new GameVersion(this, descriptor);
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
if(!IsInstalled)
|
||||
return;
|
||||
|
||||
LauncherApp.Logger.LogInfo(Id, "Deleting files...");
|
||||
var verdir = PathHelper.GetVersionDir(Id);
|
||||
if(Directory.Exists(verdir))
|
||||
Directory.Delete(verdir);
|
||||
LauncherApp.Logger.LogInfo(Id, "Files deleted");
|
||||
IsInstalled = false;
|
||||
}
|
||||
|
||||
public override string ToString() => Id;
|
||||
|
||||
public override int GetHashCode() => Id.GetHashCode();
|
||||
|
||||
public int CompareTo(InstalledGameVersionProps? other)
|
||||
{
|
||||
if (ReferenceEquals(this, other))
|
||||
return 0;
|
||||
if (other is null)
|
||||
return 1;
|
||||
|
||||
return String.Compare(Id, other.Id, StringComparison.InvariantCulture);
|
||||
}
|
||||
|
||||
public bool Equals(InstalledGameVersionProps? other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return Id == other.Id;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is InstalledGameVersionProps other) return Equals(other);
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1,78 +0,0 @@
|
||||
using System.Linq;
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
public class InstalledVersionCatalog
|
||||
{
|
||||
/// version_id, props
|
||||
[JsonRequired] public Dictionary<string, InstalledGameVersionProps> versions { get; set; } = new();
|
||||
|
||||
private IComparer<InstalledGameVersionProps> reverseComparer = new ReverseComparer<InstalledGameVersionProps>();
|
||||
|
||||
public static InstalledVersionCatalog Load()
|
||||
{
|
||||
InstalledVersionCatalog catalog;
|
||||
var installedCatalogPath = PathHelper.GetInstalledVersionCatalogPath();
|
||||
if (!File.Exists(installedCatalogPath))
|
||||
{
|
||||
LauncherApp.Logger.LogDebug(nameof(InstalledVersionCatalog), "creating new catalog");
|
||||
catalog = new InstalledVersionCatalog();
|
||||
}
|
||||
else
|
||||
{
|
||||
LauncherApp.Logger.LogDebug(nameof(InstalledVersionCatalog), "loading catalog from file");
|
||||
catalog = JsonConvert.DeserializeObject<InstalledVersionCatalog>(
|
||||
File.ReadAllText(installedCatalogPath))
|
||||
?? throw new NullReferenceException($"can't deserialize {installedCatalogPath}");
|
||||
}
|
||||
|
||||
catalog.CheckInstalledVersions();
|
||||
return catalog;
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
var installedCatalogPath = PathHelper.GetInstalledVersionCatalogPath();
|
||||
LauncherApp.Logger.LogDebug(nameof(InstalledVersionCatalog), "saving catalog to file");
|
||||
var text = JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
File.WriteAllText(installedCatalogPath, text);
|
||||
LauncherApp.Logger.LogDebug(nameof(InstalledVersionCatalog), "catalog has been saved");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if any versions were installed or deleted manually.
|
||||
/// Calls <see cref="Save"/>
|
||||
/// </summary>
|
||||
public void CheckInstalledVersions()
|
||||
{
|
||||
var versionsUpdated = new List<InstalledGameVersionProps>();
|
||||
Directory.Create(PathHelper.GetVersionsDir());
|
||||
foreach (var subdir in Directory.GetDirectories(PathHelper.GetVersionsDir()))
|
||||
{
|
||||
string id = subdir.LastName().ToString();
|
||||
if (!File.Exists(PathHelper.GetVersionDescriptorPath(id)))
|
||||
{
|
||||
LauncherApp.Logger.LogWarn(nameof(CheckInstalledVersions),
|
||||
$"Can't find version descriptor file in directory '{subdir}'. " +
|
||||
$"Rename it as directory name.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (versions.TryGetValue(id, out var foundProps))
|
||||
versionsUpdated.Add(foundProps);
|
||||
else versionsUpdated.Add(new InstalledGameVersionProps(id, null, null));
|
||||
}
|
||||
|
||||
// reverse sort
|
||||
versionsUpdated.Sort(reverseComparer);
|
||||
// create dictionary from list
|
||||
versions = new Dictionary<string, InstalledGameVersionProps>(
|
||||
versionsUpdated.Select(props =>
|
||||
new KeyValuePair<string, InstalledGameVersionProps>(props.Id, props)
|
||||
));
|
||||
|
||||
Save();
|
||||
}
|
||||
}
|
||||
@ -7,28 +7,13 @@ public class Libraries
|
||||
{
|
||||
private static readonly string[] enabled_features = [];
|
||||
|
||||
public record JarLib(string name, IOPath jarFilePath, Artifact? artifact);
|
||||
public record NativeLib(string name, IOPath jarFilePath, Artifact? artifact, Extract? extractionOptions)
|
||||
public record JarLib(string name, IOPath jarFilePath, Artifact artifact);
|
||||
public record NativeLib(string name, IOPath jarFilePath, Artifact artifact, Extract? extractionOptions)
|
||||
: JarLib(name, jarFilePath, artifact);
|
||||
|
||||
public IReadOnlyCollection<JarLib> Libs { get; }
|
||||
|
||||
public static IOPath GetPathFromMavenName(string mavenName, string ext = "jar")
|
||||
{
|
||||
int sep_0 = mavenName.IndexOf(':');
|
||||
if (sep_0 == -1)
|
||||
throw new ArgumentException($"Invalid maven name: {mavenName}");
|
||||
int sep_1 = mavenName.IndexOf(':', sep_0 + 1);
|
||||
if (sep_1 == -1)
|
||||
throw new ArgumentException($"Invalid maven name: {mavenName}");
|
||||
var package = mavenName.Substring(0, sep_0).Replace('.', '/');
|
||||
var artifact = mavenName.Substring(sep_0 + 1, sep_1 - sep_0 - 1);
|
||||
var version = mavenName.Substring(sep_1 + 1);
|
||||
string file_name = $"{artifact}-{version}.{ext}";
|
||||
return Path.Concat(PathHelper.GetLibrariesDir(), package, artifact, version, file_name);
|
||||
}
|
||||
|
||||
private static IOPath GetPathFromArtifact(Artifact artifact)
|
||||
private IOPath GetJarFilePath(Artifact artifact)
|
||||
{
|
||||
string relativePath;
|
||||
if (!string.IsNullOrEmpty(artifact.path))
|
||||
@ -75,30 +60,26 @@ public class Libraries
|
||||
}
|
||||
|
||||
Artifact artifact = null!;
|
||||
if(l.downloads?.classifiers != null && !l.downloads.classifiers.TryGetValue(nativesKey, out artifact!))
|
||||
if(l.downloads.classifiers != null && !l.downloads.classifiers.TryGetValue(nativesKey, out artifact!))
|
||||
throw new Exception($"can't find artifact for '{l.name}' with nativesKey '{nativesKey}'");
|
||||
|
||||
// skipping duplicates (WHO THE HELL CREATES THIS DISCRIPTORS AAAAAAAAA)
|
||||
if(!libHashes.Add(artifact.sha1))
|
||||
continue;
|
||||
|
||||
libs.Add(new NativeLib(l.name, GetPathFromArtifact(artifact), artifact, l.extract));
|
||||
}
|
||||
else
|
||||
{
|
||||
Artifact? artifact = l.downloads?.artifact;
|
||||
if (artifact is null)
|
||||
{
|
||||
libs.Add(new JarLib(l.name, GetPathFromMavenName(l.name), artifact));
|
||||
libs.Add(new NativeLib(l.name, GetJarFilePath(artifact), artifact, l.extract));
|
||||
}
|
||||
else
|
||||
{
|
||||
Artifact? artifact = l.downloads.artifact;
|
||||
if (artifact == null)
|
||||
throw new NullReferenceException($"artifact for '{l.name}' is null");
|
||||
|
||||
// skipping duplicates
|
||||
if(!libHashes.Add(artifact.sha1))
|
||||
continue;
|
||||
|
||||
libs.Add(new JarLib(l.name, GetPathFromArtifact(artifact), artifact));
|
||||
}
|
||||
libs.Add(new JarLib(l.name, GetJarFilePath(artifact), artifact));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
19
Mlaumcherb.Client.Avalonia/классы/Пролетариат/MyModpack.cs
Normal file
19
Mlaumcherb.Client.Avalonia/классы/Пролетариат/MyModpack.cs
Normal file
@ -0,0 +1,19 @@
|
||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
public class MyModpackRemoteProps
|
||||
{
|
||||
[JsonRequired] public int format_version { get; set; }
|
||||
[JsonRequired] public Artifact artifact { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class MyModpackV1
|
||||
{
|
||||
|
||||
// 1
|
||||
[JsonRequired] public int format_version { get; set; }
|
||||
[JsonRequired] public string name { get; set; }
|
||||
// zip archive with all files
|
||||
[JsonRequired] public Artifact zip { get; set; } = null!;
|
||||
// ModpackFilesManifest
|
||||
[JsonRequired] public Artifact manifest { get; set; } = null!;
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
public class MyModpackRemoteProps
|
||||
{
|
||||
[JsonRequired] public int format_version { get; set; }
|
||||
[JsonRequired] public Artifact artifact { get; set; } = null!;
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
public class MyModpackV2
|
||||
{
|
||||
// 2
|
||||
[JsonRequired] public int format_version { get; set; }
|
||||
[JsonRequired] public string name { get; set; } = "";
|
||||
/// relative_path, props
|
||||
// ReSharper disable once CollectionNeverUpdated.Global
|
||||
[JsonRequired] public Dictionary<string, FileProps> files { get; set; } = new();
|
||||
|
||||
|
||||
public class FileProps
|
||||
{
|
||||
[JsonRequired] public Artifact artifact { get; set; } = null!;
|
||||
// disable hash validation, allowing users to edit this file
|
||||
public bool allow_edit { get; set; }
|
||||
// don't re-download file if it was deleted by user
|
||||
public bool optional { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public record FileCheckResult(FileProps props, IOPath relativePath, IOPath absolutePath);
|
||||
public List<FileCheckResult> CheckFiles(IOPath basedir, bool checkHashes, bool downloadOptionalFiles)
|
||||
{
|
||||
List<FileCheckResult> unmatchedFiles = new();
|
||||
IOPath launcherRoot = PathHelper.GetRootFullPath();
|
||||
foreach (var p in files)
|
||||
{
|
||||
if(!downloadOptionalFiles && p.Value.optional)
|
||||
continue;
|
||||
|
||||
IOPath relativePath = new IOPath(p.Key);
|
||||
// libraries can be in modpacks, they are placed in global libraries directory
|
||||
var absolutePath = Path.Concat(relativePath.StartsWith("libraries")
|
||||
? launcherRoot : basedir, relativePath);
|
||||
if (!HashHelper.CheckFileSHA1(absolutePath, p.Value.artifact.sha1, checkHashes && !p.Value.allow_edit))
|
||||
{
|
||||
unmatchedFiles.Add(new FileCheckResult(p.Value, relativePath, absolutePath));
|
||||
}
|
||||
}
|
||||
|
||||
return unmatchedFiles;
|
||||
}
|
||||
}
|
||||
@ -3,13 +3,14 @@
|
||||
namespace Mlaumcherb.Client.Avalonia.классы;
|
||||
|
||||
|
||||
public class GameVersionCatalogProps
|
||||
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);
|
||||
@ -12,7 +12,6 @@ public static class NetworkHelper
|
||||
// thanks for Sashok :3
|
||||
// https://github.com/new-sashok724/Launcher/blob/23485c3f7de6620d2c6b7b2dd9339c3beb6a0366/Launcher/source/helper/IOHelper.java#L259
|
||||
_http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
|
||||
_http.Timeout = TimeSpan.FromSeconds(4);
|
||||
}
|
||||
|
||||
public static Task<string> GetString(string url, CancellationToken ct = default) => _http.GetStringAsync(url, ct);
|
||||
@ -43,25 +42,23 @@ public static class NetworkHelper
|
||||
}
|
||||
|
||||
|
||||
/// <returns>(file_content, didDownload)</returns>
|
||||
public static async Task<(string, bool)> ReadOrDownload(IOPath filePath, string url,
|
||||
public static async Task<string> ReadOrDownload(IOPath filePath, string url,
|
||||
string? sha1, bool checkHashes)
|
||||
{
|
||||
if (HashHelper.CheckFileSHA1(filePath, sha1, checkHashes))
|
||||
return (File.ReadAllText(filePath), false);
|
||||
return File.ReadAllText(filePath);
|
||||
|
||||
string txt = await NetworkHelper.GetString(url);
|
||||
File.WriteAllText(filePath, txt);
|
||||
return (txt, true);
|
||||
return txt;
|
||||
}
|
||||
|
||||
/// <returns>(file_content, didDownload)</returns>
|
||||
public static async Task<(T, bool)> ReadOrDownloadAndDeserialize<T>(IOPath filePath, string url,
|
||||
public static async Task<T> ReadOrDownloadAndDeserialize<T>(IOPath filePath, string url,
|
||||
string? sha1, bool checkHashes)
|
||||
{
|
||||
(string text, bool didDownload) = await ReadOrDownload(filePath, url, sha1, checkHashes);
|
||||
string text = await ReadOrDownload(filePath, url, sha1, checkHashes);
|
||||
var result = JsonConvert.DeserializeObject<T>(text)
|
||||
?? throw new Exception($"can't deserialize {typeof(T).Name}");
|
||||
return (result, didDownload);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -22,26 +22,24 @@ public class AssetsDownloadTaskFactory : INetworkTaskFactory
|
||||
|
||||
public async Task<NetworkTask?> CreateAsync(bool checkHashes)
|
||||
{
|
||||
NetworkTask? networkTask = null;
|
||||
if (!await CheckFilesAsync(checkHashes))
|
||||
{
|
||||
networkTask = new NetworkTask(
|
||||
return new NetworkTask(
|
||||
$"assets '{_descriptor.assetIndex.id}'",
|
||||
GetTotalSize(),
|
||||
Download
|
||||
);
|
||||
}
|
||||
|
||||
return networkTask;
|
||||
return null;
|
||||
}
|
||||
private async Task<bool> CheckFilesAsync(bool checkHashes)
|
||||
{
|
||||
(AssetIndex assetIndex, _) = await ReadOrDownloadAndDeserialize<AssetIndex>(
|
||||
var assetIndex = await ReadOrDownloadAndDeserialize<AssetIndex>(
|
||||
_indexFilePath,
|
||||
_descriptor.assetIndex.url,
|
||||
_descriptor.assetIndex.sha1,
|
||||
checkHashes);
|
||||
|
||||
_assetsToDownload.Clear();
|
||||
// removing duplicates for Dictionary (idk how can it be possible, but Newtonsoft.Json creates them)
|
||||
HashSet<string> assetHashes = new HashSet<string>();
|
||||
foreach (var pair in assetIndex.objects)
|
||||
|
||||
@ -28,14 +28,11 @@ public class JavaDownloadTaskFactory : INetworkTaskFactory
|
||||
|
||||
NetworkTask? networkTask = null;
|
||||
if (!CheckFiles(checkHashes))
|
||||
{
|
||||
networkTask = new NetworkTask(
|
||||
networkTask = new(
|
||||
$"java runtime '{_descriptor.javaVersion.component}'",
|
||||
GetTotalSize(),
|
||||
Download
|
||||
);
|
||||
}
|
||||
|
||||
return networkTask;
|
||||
}
|
||||
|
||||
|
||||
@ -24,14 +24,11 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
NetworkTask? networkTask = null;
|
||||
if (!CheckFiles(checkHashes))
|
||||
{
|
||||
networkTask = new NetworkTask(
|
||||
$"libraries '{_descriptor.id}'",
|
||||
GetTotalSize(),
|
||||
Download
|
||||
);
|
||||
}
|
||||
|
||||
return Task.FromResult(networkTask);
|
||||
}
|
||||
|
||||
@ -42,22 +39,16 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory
|
||||
|
||||
foreach (var l in _libraries.Libs)
|
||||
{
|
||||
if (l is Libraries.NativeLib native)
|
||||
{
|
||||
//TODO: replace with actual native libraries check
|
||||
if(!nativeDirExists || checkHashes)
|
||||
if (!HashHelper.CheckFileSHA1(l.jarFilePath, l.artifact.sha1, checkHashes))
|
||||
{
|
||||
_libsToDownload.Add(l);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!HashHelper.CheckFileSHA1(l.jarFilePath, l.artifact?.sha1, checkHashes))
|
||||
//TODO: replace with actual native assets check
|
||||
else if (!nativeDirExists && l is Libraries.NativeLib)
|
||||
{
|
||||
_libsToDownload.Add(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _libsToDownload.Count == 0;
|
||||
}
|
||||
@ -66,7 +57,7 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
long total = 0;
|
||||
foreach (var l in _libsToDownload)
|
||||
total += l.artifact?.size ?? 0;
|
||||
total += l.artifact.size;
|
||||
return total;
|
||||
}
|
||||
|
||||
@ -82,21 +73,24 @@ public class LibrariesDownloadTaskFactory : INetworkTaskFactory
|
||||
await Parallel.ForEachAsync(_libsToDownload, opt, async (l, _ct) =>
|
||||
{
|
||||
LauncherApp.Logger.LogDebug(nameof(NetworkHelper), $"downloading library '{l.name}' to '{l.jarFilePath}'");
|
||||
if(string.IsNullOrEmpty(l.artifact?.url))
|
||||
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);
|
||||
if (l is Libraries.NativeLib n)
|
||||
{
|
||||
await using var zipf = File.OpenRead(n.jarFilePath);
|
||||
using var archive = new ZipArchive(zipf);
|
||||
foreach (var entry in archive.Entries)
|
||||
//TODO: replace following code with manual extraction
|
||||
ZipFile.ExtractToDirectory(zipf, _nativesDir.ToString(), true);
|
||||
if (n.extractionOptions?.exclude != null)
|
||||
{
|
||||
if (n.extractionOptions?.exclude?.Contains(entry.FullName) is true or null)
|
||||
continue;
|
||||
|
||||
var real_path = Path.Concat(_nativesDir, entry.FullName);
|
||||
Directory.Create(real_path.ParentDir());
|
||||
entry.ExtractToFile(real_path.ToString(), true);
|
||||
foreach (var excluded in n.extractionOptions.exclude)
|
||||
{
|
||||
IOPath path = Path.Concat(_nativesDir, excluded);
|
||||
if(Directory.Exists(path))
|
||||
Directory.Delete(path);
|
||||
if(File.Exists(path))
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
using System.IO.Compression;
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
||||
|
||||
@ -10,10 +13,9 @@ public class ModpackDownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
if(descriptor.modpack is null)
|
||||
throw new ArgumentNullException(nameof(descriptor.modpack));
|
||||
|
||||
_implementationVersion = descriptor.modpack.format_version switch
|
||||
{
|
||||
2 => new MyModpackV2DownloadTaskFactory(descriptor),
|
||||
1 => new MyModpackV1DownloadTaskFactory(descriptor),
|
||||
_ => throw new Exception($"Unknown Modpack format_version: {descriptor.modpack.format_version}")
|
||||
};
|
||||
}
|
||||
@ -23,3 +25,78 @@ public class ModpackDownloadTaskFactory : INetworkTaskFactory
|
||||
return _implementationVersion.CreateAsync(checkHashes);
|
||||
}
|
||||
}
|
||||
|
||||
public class MyModpackV1DownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
private IOPath _modpackManifesPath;
|
||||
private readonly GameVersionDescriptor _descriptor;
|
||||
private IOPath _modpackDescriptorPath;
|
||||
private IOPath _versionDir;
|
||||
private MyModpackV1? _modpack;
|
||||
private ModpackFilesManifest? _modpackManifest;
|
||||
private HashSet<IOPath> _filesToDosnload = new();
|
||||
|
||||
public MyModpackV1DownloadTaskFactory(GameVersionDescriptor descriptor)
|
||||
{
|
||||
_descriptor = descriptor;
|
||||
_modpackDescriptorPath = PathHelper.GetModpackDescriptorPath(_descriptor.id);
|
||||
_modpackManifesPath = PathHelper.GetModpackManifestPath(_descriptor.id);
|
||||
_versionDir = PathHelper.GetVersionDir(_descriptor.id);
|
||||
}
|
||||
|
||||
public async Task<NetworkTask?> CreateAsync(bool checkHashes)
|
||||
{
|
||||
if(_descriptor.modpack is null)
|
||||
throw new ArgumentNullException(nameof(_descriptor.modpack));
|
||||
|
||||
|
||||
_modpack = await NetworkHelper.ReadOrDownloadAndDeserialize<MyModpackV1>(
|
||||
_modpackDescriptorPath,
|
||||
_descriptor.modpack.artifact.url,
|
||||
_descriptor.modpack.artifact.sha1,
|
||||
checkHashes);
|
||||
if (_modpack.format_version != _descriptor.modpack.format_version)
|
||||
throw new Exception($"Modpack.format_version mismatches descriptor.modpack.version: " +
|
||||
$"{_modpack.format_version} != {_descriptor.modpack.format_version}");
|
||||
|
||||
_modpackManifest = await NetworkHelper.ReadOrDownloadAndDeserialize<ModpackFilesManifest>(
|
||||
_modpackManifesPath,
|
||||
_modpack.manifest.url,
|
||||
_modpack.manifest.sha1,
|
||||
checkHashes);
|
||||
|
||||
if(!_modpackManifest.CheckFiles(_versionDir, checkHashes, _filesToDosnload))
|
||||
return new NetworkTask(
|
||||
$"modpack '{_descriptor.assetIndex.id}'",
|
||||
_modpack.zip.size,
|
||||
Download
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
|
||||
{
|
||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading modpack '{_modpack!.name}'");
|
||||
if(string.IsNullOrEmpty(_modpack.zip.url))
|
||||
throw new Exception($"modpack '{_modpack.name}' doesn't have a url to download");
|
||||
|
||||
var _archivePath = Path.Concat("downloads/modpacks", _modpack.name + ".zip");
|
||||
await NetworkHelper.DownloadFile(_modpack.zip.url, _archivePath, ct, pr.AddBytesCount);
|
||||
|
||||
await using var zipf = File.OpenRead(_archivePath);
|
||||
using var archive = new ZipArchive(zipf);
|
||||
foreach (var entry in archive.Entries)
|
||||
{
|
||||
IOPath localPath = new(entry.FullName);
|
||||
if(_filesToDosnload.Contains(localPath))
|
||||
{
|
||||
var real_path = Path.Concat(_versionDir, localPath);
|
||||
Directory.Create(real_path.ParentDir());
|
||||
entry.ExtractToFile(real_path.ToString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"finished downloading modpack '{_modpack.name}'");
|
||||
}
|
||||
}
|
||||
@ -1,71 +0,0 @@
|
||||
using System.Linq;
|
||||
using Mlaumcherb.Client.Avalonia.зримое;
|
||||
using Mlaumcherb.Client.Avalonia.классы;
|
||||
using Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.сеть.TaskFactories;
|
||||
|
||||
public class MyModpackV2DownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
private readonly GameVersionDescriptor _descriptor;
|
||||
private IOPath _modpackDescriptorPath;
|
||||
private IOPath _versionDir;
|
||||
private MyModpackV2? _modpack;
|
||||
// relative, absolute
|
||||
private List<MyModpackV2.FileCheckResult> _filesToDownload = new();
|
||||
|
||||
public MyModpackV2DownloadTaskFactory(GameVersionDescriptor descriptor)
|
||||
{
|
||||
_descriptor = descriptor;
|
||||
_modpackDescriptorPath = PathHelper.GetModpackDescriptorPath(_descriptor.id);
|
||||
_versionDir = PathHelper.GetVersionDir(_descriptor.id);
|
||||
}
|
||||
|
||||
public async Task<NetworkTask?> CreateAsync(bool checkHashes)
|
||||
{
|
||||
if(_descriptor.modpack is null)
|
||||
throw new ArgumentNullException(nameof(_descriptor.modpack));
|
||||
|
||||
(_modpack, bool didDownloadModpackDescriptor) = await NetworkHelper.ReadOrDownloadAndDeserialize<MyModpackV2>(
|
||||
_modpackDescriptorPath,
|
||||
_descriptor.modpack.artifact.url,
|
||||
_descriptor.modpack.artifact.sha1,
|
||||
checkHashes);
|
||||
if (_modpack.format_version != _descriptor.modpack.format_version)
|
||||
throw new Exception($"Modpack.format_version mismatches descriptor.modpack.version: " +
|
||||
$"{_modpack.format_version} != {_descriptor.modpack.format_version}");
|
||||
|
||||
NetworkTask? networkTask = null;
|
||||
_filesToDownload = _modpack.CheckFiles(_versionDir, checkHashes, didDownloadModpackDescriptor);
|
||||
if(_filesToDownload.Count > 0)
|
||||
{
|
||||
networkTask = new NetworkTask(
|
||||
$"modpack '{_modpack.name}'",
|
||||
_filesToDownload.Sum(f => f.props.artifact.size),
|
||||
Download
|
||||
);
|
||||
}
|
||||
|
||||
return networkTask;
|
||||
}
|
||||
|
||||
private async Task Download(NetworkProgressReporter pr, CancellationToken ct)
|
||||
{
|
||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"started downloading modpack '{_modpack!.name}'");
|
||||
|
||||
ParallelOptions opt = new()
|
||||
{
|
||||
MaxDegreeOfParallelism = LauncherApp.Config.max_parallel_downloads,
|
||||
CancellationToken = ct
|
||||
};
|
||||
await Parallel.ForEachAsync(_filesToDownload, opt, async (f, _ct) =>
|
||||
{
|
||||
LauncherApp.Logger.LogDebug(nameof(NetworkHelper), $"downloading file '{f.relativePath}'");
|
||||
if(string.IsNullOrEmpty(f.props.artifact.url))
|
||||
throw new Exception($"file '{f.relativePath}' doesn't have a url to download");
|
||||
await NetworkHelper.DownloadFile(f.props.artifact.url, f.absolutePath, _ct, pr.AddBytesCount);
|
||||
});
|
||||
|
||||
LauncherApp.Logger.LogInfo(nameof(NetworkHelper), $"finished downloading modpack '{_modpack.name}'");
|
||||
}
|
||||
}
|
||||
@ -20,14 +20,11 @@ public class VersionJarDownloadTaskFactory : INetworkTaskFactory
|
||||
{
|
||||
NetworkTask? networkTask = null;
|
||||
if (!CheckFiles(checkHashes))
|
||||
{
|
||||
networkTask = new NetworkTask(
|
||||
$"game version jar '{_descriptor.id}'",
|
||||
GetTotalSize(),
|
||||
Download
|
||||
);
|
||||
}
|
||||
|
||||
return Task.FromResult(networkTask);
|
||||
}
|
||||
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.сеть.Update;
|
||||
|
||||
public class Release
|
||||
{
|
||||
[JsonRequired] public int id { get; set; }
|
||||
[JsonRequired] public string tag_name { get; set; } = "";
|
||||
[JsonRequired] public DateTime created_at { get; set; }
|
||||
// ReSharper disable once CollectionNeverUpdated.Global
|
||||
public List<Asset> assets { get; set; } = new();
|
||||
|
||||
public class Asset
|
||||
{
|
||||
[JsonRequired] public int id { get; set; }
|
||||
[JsonRequired] public string name { get; set; } = "";
|
||||
[JsonRequired] public int size { get; set; }
|
||||
[JsonRequired] public DateTime created_at { get; set; }
|
||||
[JsonRequired] public string browser_download_url { get; set; } = "";
|
||||
|
||||
public async Task Download(IOPath localPath)
|
||||
{
|
||||
await NetworkHelper.DownloadFile(browser_download_url, localPath);
|
||||
}
|
||||
}
|
||||
|
||||
public Asset? FindAssetByName(string name) =>
|
||||
assets.FirstOrDefault(a => a.name == name);
|
||||
}
|
||||
|
||||
public class GiteaClient(string ServerUrl)
|
||||
{
|
||||
public async Task<Release> GetLatestRelease(string user, string repo)
|
||||
{
|
||||
string url = $"{ServerUrl}/api/v1/repos/{user}/{repo}/releases/latest";
|
||||
return await NetworkHelper.DownloadStringAndDeserialize<Release>(url);
|
||||
}
|
||||
}
|
||||
@ -1,76 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Mlaumcherb.Client.Avalonia.сеть.Update;
|
||||
|
||||
public class UpdateHelper
|
||||
{
|
||||
private readonly string _executableName = "млаумчерб.exe";
|
||||
private readonly IOPath executablePathActual;
|
||||
private readonly IOPath executablePathOld;
|
||||
private readonly IOPath executablePathNew;
|
||||
|
||||
private readonly GiteaConfig _giteaConfig;
|
||||
|
||||
public class GiteaConfig
|
||||
{
|
||||
[JsonRequired] public required string serverUrl { get; set; }
|
||||
[JsonRequired] public required string user { get; set; }
|
||||
[JsonRequired] public required string repo { get; set; }
|
||||
|
||||
public string GetRepoUrl() => $"{serverUrl}/{user}/{repo}";
|
||||
}
|
||||
|
||||
|
||||
public UpdateHelper(GiteaConfig giteaConfig)
|
||||
{
|
||||
_giteaConfig = giteaConfig;
|
||||
executablePathActual = _executableName;
|
||||
executablePathOld = _executableName + ".old";
|
||||
executablePathNew = _executableName + ".new";
|
||||
Gitea = new GiteaClient(giteaConfig.serverUrl);
|
||||
}
|
||||
|
||||
public GiteaClient Gitea { get; }
|
||||
|
||||
public void DeleteBackupFiles()
|
||||
{
|
||||
if(File.Exists(executablePathOld))
|
||||
File.Delete(executablePathOld);
|
||||
}
|
||||
|
||||
public async Task<bool> IsUpdateAvailable()
|
||||
{
|
||||
var latest = await Gitea.GetLatestRelease(_giteaConfig.user, _giteaConfig.repo);
|
||||
if (!Version.TryParse(latest.tag_name, out var latestVersion))
|
||||
throw new Exception($"Can't parse version of latest release: {latest.tag_name}");
|
||||
|
||||
Version? currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
if(currentVersion is null)
|
||||
throw new Exception($"Can't get current version from {Assembly.GetExecutingAssembly().GetName()}");
|
||||
|
||||
return currentVersion < latestVersion;
|
||||
}
|
||||
|
||||
public async Task UpdateSelf()
|
||||
{
|
||||
if(File.Exists(executablePathNew))
|
||||
File.Delete(executablePathNew);
|
||||
|
||||
var latest = await Gitea.GetLatestRelease(_giteaConfig.user, _giteaConfig.repo);
|
||||
var asset = latest.FindAssetByName(_executableName);
|
||||
if(asset == null)
|
||||
throw new Exception($"Can't find updated executable on gitea: {_executableName}");
|
||||
await asset.Download(executablePathNew);
|
||||
|
||||
File.Move(executablePathActual, executablePathOld, true);
|
||||
File.Move(executablePathNew, executablePathActual, true);
|
||||
}
|
||||
|
||||
public void RestartSelf()
|
||||
{
|
||||
Process.Start(executablePathActual.ToString());
|
||||
Thread.Sleep(500);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
@ -29,21 +29,19 @@ case "$mode" in
|
||||
args="$args_selfcontained"
|
||||
;;
|
||||
*)
|
||||
echo "ПОЛЬЗОВАНИЕ: ./build.sh [способ]"
|
||||
echo "ПОЛЬЗОВАНИЕ: ./собрать.sh [способ]"
|
||||
echo " СПОСОБЫ:"
|
||||
echo " aot, native, бинарное - компилирует промежуточный (управляемый) код в машинный вместе с рантаймом"
|
||||
echo " self-contained, selfcontained, небинарное - приделывает промежуточный (управляемый) код к рантайму"
|
||||
echo " Оба способа собирают программу в один файл, который не является 80-мегабайтовым умственно отсталым кубом.\
|
||||
Он 20-мегабайтовый >w<"
|
||||
echo " бинарное - компилирует промежуточный (управляемый) код в машинный вместе с рантаймом"
|
||||
echo " небинарное - приделывает промежуточный (управляемый) код к рантайму"
|
||||
echo " Оба способа собирают программу в один файл, который не является 80-мегабайтовым умственно отсталым кубом. Он 20-мегабайтовый >w<"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
rm -rf "$outdir"
|
||||
# when internet breaks again add --source /mnt/c/Users/User/.nuget/packages/
|
||||
command="dotnet publish -c Release -o $outdir $args"
|
||||
echo "$command"
|
||||
$command
|
||||
|
||||
find "$outdir" -name '*.pdb' -delete -printf "deleted '%p'\n"
|
||||
tree -sh "$outdir"
|
||||
ls -shk "$outdir" | sort -h
|
||||
@ -24,8 +24,8 @@ public static class HashHelper
|
||||
if (!File.Exists(f))
|
||||
return false;
|
||||
|
||||
if(checkHash && sha1 is not null)
|
||||
return HashFileSHA1(f) == sha1;
|
||||
if(checkHash)
|
||||
return sha1 is not null && HashFileSHA1(f) == sha1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -40,17 +40,14 @@ public static class PathHelper
|
||||
|
||||
public static IOPath GetJavaBinDir(string id) =>
|
||||
Path.Concat(GetJavaRuntimeDir(id), "bin");
|
||||
public static IOPath GetJavaExecutablePath(string id, bool redirectOutput)
|
||||
public static IOPath GetJavaExecutablePath(string id, bool debug)
|
||||
{
|
||||
string executable_name = "java";
|
||||
if (!redirectOutput)
|
||||
executable_name = "javaw";
|
||||
if (debug)
|
||||
executable_name += "w";
|
||||
if(OperatingSystem.IsWindows())
|
||||
executable_name += ".exe";
|
||||
var path = Path.Concat(GetJavaBinDir(id), executable_name);
|
||||
if(!redirectOutput && !File.Exists(path))
|
||||
return GetJavaExecutablePath(id, true);
|
||||
return path;
|
||||
return Path.Concat(GetJavaBinDir(id), executable_name);
|
||||
}
|
||||
|
||||
public static string GetLog4jConfigFileName() => "log4j.xml";
|
||||
@ -61,8 +58,6 @@ public static class PathHelper
|
||||
public static IOPath GetModpackDescriptorPath(string game_version) =>
|
||||
Path.Concat(GetVersionDir(game_version), "timerix_modpack.json");
|
||||
|
||||
public static IOPath GetCacheDir() =>
|
||||
Path.Concat(GetRootFullPath(), "cache");
|
||||
public static IOPath GetInstalledVersionCatalogPath() =>
|
||||
Path.Concat(GetCacheDir(), "installed_versions.json");
|
||||
public static IOPath GetModpackManifestPath(string game_version) =>
|
||||
Path.Concat(GetVersionDir(game_version), "timerix_modpack_files.json");
|
||||
}
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
namespace Mlaumcherb.Client.Avalonia.холопы;
|
||||
|
||||
// compares Y with X instead of X with Y
|
||||
public class ReverseComparer<T> : IComparer<T> where T : IComparable<T>
|
||||
{
|
||||
public int Compare(T? x, T? y)
|
||||
{
|
||||
if (y is null)
|
||||
return x is null ? 0 : -1;
|
||||
return y.CompareTo(x);
|
||||
}
|
||||
}
|
||||
14
README.md
14
README.md
@ -1,14 +0,0 @@
|
||||
# Mlaumcherb - a minecraft laumcherb
|
||||
|
||||
<img src="./images/cheems.png" alt="silly-dog-picture" style="width:200px;"/>
|
||||
|
||||
## Features
|
||||
- Downloads minecraft from mojang server or any other
|
||||
- Downloads java or uses whatever you specified in config
|
||||
- Downloads modpacks of my custom format
|
||||
- Automatic launcher updates from git releases
|
||||
|
||||
## How to build
|
||||
```sh
|
||||
./build.sh selfcontained
|
||||
```
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 19 KiB |
@ -5,8 +5,6 @@ EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFolder", "SolutionFolder", "{A3217C18-CC0D-4CE8-9C48-1BDEC1E1B333}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.gitignore = .gitignore
|
||||
README.md = README.md
|
||||
build.sh = build.sh
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
|
||||
Loading…
Reference in New Issue
Block a user