Compare commits

..

2 Commits

Author SHA1 Message Date
c0239a9c29 Avalonia.Labs.Gif 2024-09-14 14:50:11 +05:00
bf33e186f8 arguments parsing 2024-09-14 14:36:23 +05:00
11 changed files with 201 additions and 19 deletions

7
nuget.config Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- avalonia nightly feed -->
<add key="avalonia-nightly" value="https://nuget-feed-nightly.avaloniaui.net/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>

View File

@ -1,7 +1,4 @@
using DTLib.Filesystem;
using DTLib.Logging;
namespace Млаумчерб.Клиент;
namespace Млаумчерб.Клиент;
public class LauncherLogger : FileLogger
{

View File

@ -6,6 +6,7 @@ global using DTLib.Logging;
global using DTLib.Filesystem;
global using File = DTLib.Filesystem.File;
global using Directory = DTLib.Filesystem.Directory;
global using Path = DTLib.Filesystem.Path;
using System.Globalization;
using Avalonia;

View File

@ -1,6 +1,8 @@
using System.Threading.Tasks;
using DTLib.Filesystem;
using Path = DTLib.Filesystem.Path;
using System.Threading;
using System.Threading.Tasks;
using CliWrap;
using DTLib.Extensions;
using Млаумчерб.Клиент.классы;
namespace Млаумчерб.Клиент;
@ -11,6 +13,7 @@ public interface IGame
Progress<NetworkTransferResult> BeginUpdate();
void EndUpdate();
Task Launch();
void Close();
}
public class MinecraftVersion : IGame
@ -18,6 +21,13 @@ public class MinecraftVersion : IGame
public string Name { get; }
public IOPath InstallationDirectory { get; }
private IOPath JavawFilePath;
private JavaArguments javaArgs;
private GameArguments gameArgs;
private CancellationTokenSource? cts;
private CommandTask<CommandResult> commandTask;
public MinecraftVersion(string name)
{
Name = name;
@ -34,8 +44,28 @@ public class MinecraftVersion : IGame
throw new NotImplementedException();
}
public Task Launch()
public async Task Launch()
{
throw new NotImplementedException();
var javaArgsList = javaArgs.FillPlaceholders([]);
var gameArgsList = gameArgs.FillPlaceholders([]);
var command = Cli.Wrap(JavawFilePath.ToString())
.WithWorkingDirectory(InstallationDirectory.ToString())
.WithArguments(javaArgsList)
.WithArguments(gameArgsList);
Приложение.Логгер.LogInfo(nameof(MinecraftVersion),
$"launching the game" +
"\njava: " + command.TargetFilePath +
"\nworking_dir: " + command.WorkingDirPath +
"\njava_arguments: \n\t" + javaArgsList.MergeToString("\n\t") +
"\ngame_arguments: \n\t" + gameArgsList.MergeToString("\n\t"));
cts = new();
commandTask = command.ExecuteAsync(cts.Token);
var result = await commandTask;
Приложение.Логгер.LogInfo(nameof(MinecraftVersion), $"game exited with code {result.ExitCode}");
}
public void Close()
{
cts?.Cancel();
}
}

View File

@ -17,7 +17,8 @@
<PackageReference Include="Avalonia.Desktop" Version="11.*" />
<PackageReference Include="Avalonia.Themes.Simple" Version="11.*" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.*" />
<PackageReference Include="AvaloniaGif-Unofficial" Version="1.0.0" />
<PackageReference Include="Avalonia.Labs.Gif" Version="11.2.999-cibuild-00051673"/>
<PackageReference Include="CliWrap" Version="3.6.6" />
<PackageReference Include="DTLib" Version="1.3.*" />
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.*" />
<PackageReference Include="DTLib.Logging" Version="1.3.*" />

View File

@ -1,5 +1,4 @@
using DTLib.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json;
namespace Млаумчерб.Клиент;

View File

@ -1,6 +1,6 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gif="clr-namespace:Avalonia.Gif;assembly=Avalonia.Gif"
xmlns:gif="clr-namespace:Avalonia.Labs.Gif;assembly=Avalonia.Labs.Gif"
xmlns:local="clr-namespace:Млаумчерб"
x:Class="Млаумчерб.Клиент.Окне"
Name="window"
@ -98,7 +98,7 @@
<Button Classes="menu_button button_no_border" Click="OpenSourceRepository">source code</Button>
<gif:GifImage
Width="30" Height="30" Stretch="Uniform"
SourceUri="avares://млаумчерб/капитал/лисик.gif"/>
Source="avares://млаумчерб/капитал/лисик.gif"/>
</StackPanel>
</Grid>
</Border>

View File

@ -1,6 +1,5 @@
using Avalonia.Controls;
using DTLib.Ben.Demystifier;
using DTLib.Logging;
using MsBox.Avalonia;
using MsBox.Avalonia.Dto;
using MsBox.Avalonia.Enums;

View File

@ -17,7 +17,8 @@ public class Os
public class Rule
{
[JsonRequired] public string action { get; set; } = "";
[JsonRequired] public Os os { get; set; } = null!;
public Os? os { get; set; }
public Dictionary<string, bool>? features { get; set; }
}
public class Classifiers
@ -80,6 +81,18 @@ public class JavaVersion
[JsonRequired] public int majorVersion { get; set; }
}
public class ArgValue
{
[JsonRequired] public string value { get; set; } = "";
public List<Rule> rules { get; set; } = new();
}
public class ArgumentsNew
{
[JsonRequired] public List<ArgValue> jvm { get; set; } = new();
[JsonRequired] public List<ArgValue> game { get; set; } = new();
}
public class MinecraftVersionDescriptor
{
[JsonRequired] public string id { get; set; } = "";
@ -94,5 +107,52 @@ public class MinecraftVersionDescriptor
[JsonRequired] public List<Library> libraries { get; set; } = null!;
[JsonRequired] public AssetIndex assetIndex { get; set; } = null!;
[JsonRequired] public string assets { get; set; } = "";
// public string minecraftArguments { get; set; }
public string? minecraftArguments { get; set; }
public ArgumentsNew? arguments { get; set; }
}
public static class Буржуазия
{
public static bool CheckOs(Os os)
{
return os.name switch
{
"osx" => OperatingSystem.IsWindows(),
"linux" => OperatingSystem.IsLinux(),
"windows" => OperatingSystem.IsWindows(),
_ => throw new ArgumentOutOfRangeException(os.name)
};
}
public static bool CheckRules(ICollection<Rule> rules, ICollection<string> enabled_features)
{
bool allowed = false;
foreach (var r in rules)
{
if (r.os == null || CheckOs(r.os))
{
if (r.features != null)
{
foreach (var feature in enabled_features)
{
if(r.features.TryGetValue(feature, out bool is_enabled))
{
if (is_enabled)
{
if (r.action == "allow")
allowed = true;
else return false;
}
}
}
}
if (r.action == "allow")
allowed = true;
else return false;
}
}
return allowed;
}
}

View File

@ -1,6 +1,89 @@
namespace Млаумчерб.Клиент.классы;
using DTLib.Extensions;
namespace Млаумчерб.Клиент.классы;
public class Пролетариат
{
}
public class ArgumentsWithPlaceholders
{
protected List<string> raw_args = new();
public List<string> FillPlaceholders(Dictionary<string, string> values)
{
List<string> result = new();
foreach (var a in raw_args)
{
var f = a;
int begin = a.IndexOf('$');
if (begin != -1)
{
int keyBegin = begin + 2;
int end = a.IndexOf('}', keyBegin);
if (end != -1)
{
var key = a.Substring(keyBegin, end - keyBegin);
if (!values.TryGetValue(key, out var v))
throw new Exception($"can't find value for placeholder '{key}'");
f = v;
}
}
result.Add(f);
}
return result;
}
}
public class JavaArguments : ArgumentsWithPlaceholders
{
private static readonly string[] _initial_arguments =
[
];
private static readonly string[] _enabled_features =
[
];
public JavaArguments(MinecraftVersionDescriptor d)
{
raw_args.AddRange(_initial_arguments);
if (d.arguments is not null)
{
foreach (var av in d.arguments.jvm)
{
if(Буржуазия.CheckRules(av.rules, _enabled_features))
raw_args.Add(av.value);
}
}
}
}
public class GameArguments : ArgumentsWithPlaceholders
{
private static readonly string[] _enabled_features =
[
"has_custom_resolution"
];
public GameArguments(MinecraftVersionDescriptor d)
{
if (d.minecraftArguments is not null)
{
raw_args.AddRange(d.minecraftArguments.SplitToList(' ', quot: '"'));
}
else if (d.arguments is not null)
{
foreach (var av in d.arguments.game)
{
if(Буржуазия.CheckRules(av.rules, _enabled_features))
raw_args.Add(av.value);
}
}
}
}

View File

@ -2,6 +2,11 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Млаумчерб.Клиент", "Млаумчерб.Клиент\Млаумчерб.Клиент.csproj", "{9B9D8B05-255F-49C3-89EC-3F43A66491D3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFolder", "SolutionFolder", "{A3217C18-CC0D-4CE8-9C48-1BDEC1E1B333}"
ProjectSection(SolutionItems) = preProject
nuget.config = nuget.config
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU