Skip to content

Commit

Permalink
完成Forge安装器,优化资源补全速度
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSpring114 committed Dec 16, 2023
1 parent 2c5049c commit 4b11f80
Show file tree
Hide file tree
Showing 22 changed files with 468 additions and 69 deletions.
8 changes: 5 additions & 3 deletions MinecraftLaunch.Test/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MinecraftLaunch;
using MinecraftLaunch.Components.Fetcher;
using MinecraftLaunch.Components.Installer;
using MinecraftLaunch.Components.Resolver;
using MinecraftLaunch.Extensions;
Expand All @@ -15,8 +16,8 @@

var result = await installer.InstallAsync();

var fInstaller = new QuiltInstaller(new GameResolver(gameFolder).GetGameEntity("1.16.5"),
(await QuiltInstaller.EnumerableFromVersionAsync("1.16.5")).FirstOrDefault());
var fInstaller = new ForgeInstaller(new GameResolver(gameFolder).GetGameEntity("1.16.5"),
(await ForgeInstaller.EnumerableFromVersionAsync("1.16.5")).FirstOrDefault(),new JavaFetcher().Fetch().First().JavaPath);

fInstaller.ProgressChanged += (_, x) => {
Console.Clear();
Expand All @@ -27,4 +28,5 @@

await fInstaller.InstallAsync();

Console.ReadKey();
Console.ReadKey();

10 changes: 0 additions & 10 deletions MinecraftLaunch.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Natsurainko.FluentCore", ".
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinecraftLaunch.Test", "MinecraftLaunch.Test\MinecraftLaunch.Test.csproj", "{76E3BD50-5A2C-43D0-A5B5-CD139EB60C94}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GBCLV3", "..\..\..\Code\GBCLV3-master\GBCLV3\GBCLV3.csproj", "{062AA8ED-1936-4379-9199-C80E1876668A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -43,14 +41,6 @@ Global
{76E3BD50-5A2C-43D0-A5B5-CD139EB60C94}.Release|Any CPU.Build.0 = Release|Any CPU
{76E3BD50-5A2C-43D0-A5B5-CD139EB60C94}.Release|x64.ActiveCfg = Release|Any CPU
{76E3BD50-5A2C-43D0-A5B5-CD139EB60C94}.Release|x64.Build.0 = Release|Any CPU
{062AA8ED-1936-4379-9199-C80E1876668A}.Debug|Any CPU.ActiveCfg = Debug|x64
{062AA8ED-1936-4379-9199-C80E1876668A}.Debug|Any CPU.Build.0 = Debug|x64
{062AA8ED-1936-4379-9199-C80E1876668A}.Debug|x64.ActiveCfg = Debug|x64
{062AA8ED-1936-4379-9199-C80E1876668A}.Debug|x64.Build.0 = Debug|x64
{062AA8ED-1936-4379-9199-C80E1876668A}.Release|Any CPU.ActiveCfg = Release|x64
{062AA8ED-1936-4379-9199-C80E1876668A}.Release|Any CPU.Build.0 = Release|x64
{062AA8ED-1936-4379-9199-C80E1876668A}.Release|x64.ActiveCfg = Release|x64
{062AA8ED-1936-4379-9199-C80E1876668A}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions MinecraftLaunch/Classes/Enums/DownloadEntryType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MinecraftLaunch.Classes.Enums {
public enum DownloadEntryType {
Jar,
Asset,
Library
}
Expand Down
18 changes: 18 additions & 0 deletions MinecraftLaunch/Classes/Models/Game/JarEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using MinecraftLaunch.Classes.Enums;
using MinecraftLaunch.Classes.Interfaces;

namespace MinecraftLaunch.Classes.Models.Game {
public record JarEntry : IDownloadEntry {
public int Size { get; set; }

public string Url { get; set; }

public string Checksum { get; set; }

public string Path { get; set; }

public string McVersion { get; set; }

public DownloadEntryType Type => DownloadEntryType.Jar;
}
}
20 changes: 20 additions & 0 deletions MinecraftLaunch/Classes/Models/Install/ForgeInstallEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.Json.Serialization;

namespace MinecraftLaunch.Classes.Models.Install {
public record ForgeInstallEntry {
[JsonPropertyName("build")]
public int Build { get; set; }

[JsonPropertyName("branch")]
public string Branch { get; set; }

[JsonPropertyName("mcversion")]
public string McVersion { get; set; }

[JsonPropertyName("version")]
public string ForgeVersion { get; set; }

[JsonPropertyName("modified")]
public DateTime ModifiedTime { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace MinecraftLaunch.Classes.Models.Install {
public record HighVersionForgeProcessorEntry {
[JsonPropertyName("jar")]
public string Jar { get; set; }

[JsonPropertyName("sides")]
public List<string> Sides { get; set; } = new();

[JsonPropertyName("classpath")]
public IEnumerable<string> Classpath { get; set; }

[JsonPropertyName("args")]
public IEnumerable<string> Args { get; set; }

[JsonPropertyName("outputs")]
public Dictionary<string, string> Outputs { get; set; } = new();
}
}
19 changes: 13 additions & 6 deletions MinecraftLaunch/Components/Authenticator/MicrosoftAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public async ValueTask<MicrosoftAccount> AuthenticateAsync() {
using var xblJsonReq = await $"https://user.auth.xboxlive.com/user/authenticate"
.PostJsonAsync(xblContent);

var xblTokenNode = JsonNode.Parse(await xblJsonReq.GetStringAsync());
var xblTokenNode = (await xblJsonReq.GetStringAsync())
.AsNode();

/*
* Get Xbox security token service token
Expand All @@ -85,7 +86,8 @@ public async ValueTask<MicrosoftAccount> AuthenticateAsync() {
using var xstsJsonReq = await $"https://xsts.auth.xboxlive.com/xsts/authorize"
.PostJsonAsync(xstsContent);

var xstsTokenNode = JsonNode.Parse(await xstsJsonReq.GetStringAsync());
var xstsTokenNode = (await xstsJsonReq.GetStringAsync())
.AsNode();

/*
* Authenticate minecraft account
Expand All @@ -100,7 +102,9 @@ public async ValueTask<MicrosoftAccount> AuthenticateAsync() {
using var authenticateMinecraftPostRes = await $"https://api.minecraftservices.com/authentication/login_with_xbox"
.PostJsonAsync(authenticateMinecraftContent);

string access_token = JsonNode.Parse(await authenticateMinecraftPostRes.GetStringAsync())
string access_token = (await authenticateMinecraftPostRes
.GetStringAsync())
.AsNode()
.GetString("access_token");

/*
Expand All @@ -111,7 +115,8 @@ public async ValueTask<MicrosoftAccount> AuthenticateAsync() {
.WithHeader("Authorization", $"Bearer {access_token}")
.GetAsync();

var ownNode = JsonNode.Parse(await gameHasRes.GetStringAsync());
var ownNode = (await gameHasRes.GetStringAsync())
.AsNode();
if (!ownNode["items"].AsArray().Any()) {
throw new OperationCanceledException("Game not purchased, login terminated");
}
Expand All @@ -124,7 +129,9 @@ public async ValueTask<MicrosoftAccount> AuthenticateAsync() {
.WithHeader("Authorization", $"Bearer {access_token}")
.GetAsync();

var profileNode = JsonNode.Parse(await profileRes.GetStringAsync());
var profileNode = (await profileRes.GetStringAsync())
.AsNode();

string refreshToken = _oAuth2TokenResponse is null && string
.IsNullOrEmpty(_oAuth2TokenResponse.RefreshToken)
? "None"
Expand Down Expand Up @@ -182,7 +189,7 @@ public async Task<OAuth2TokenResponse> DeviceFlowAuthAsync(Action<DeviceCodeResp
.PostUrlEncodedAsync(new FormUrlEncodedContent(parameters))
.ReceiveString();

var tempTokenResponse = JsonNode.Parse(tokenJson);
var tempTokenResponse = tokenJson.AsNode();

if (tempTokenResponse["error"] == null) {
tokenResponse = new() {
Expand Down
3 changes: 3 additions & 0 deletions MinecraftLaunch/Components/Fetcher/JavaFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace MinecraftLaunch.Components.Fetcher {
public class JavaFetcher : IFetcher<ImmutableArray<JavaEntry>> {
#region Fields
[SupportedOSPlatform(nameof(OSPlatform.OSX))]
private const string _macJavaHomePath = "/Library/Java/JavaVirtualMachines";

Expand Down Expand Up @@ -62,6 +63,8 @@ public class JavaFetcher : IFetcher<ImmutableArray<JavaEntry>> {
"android",
];

#endregion

public ImmutableArray<JavaEntry> Fetch() {
return FetchAsync().GetAwaiter().GetResult();
}
Expand Down
4 changes: 3 additions & 1 deletion MinecraftLaunch/Components/Installer/FabricInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public override async ValueTask<bool> InstallAsync() {
*/
ReportProgress(0.0d, "Start parse build", TaskStatus.Created);
string url = $"https://meta.fabricmc.net/v2/versions/loader/{_fabricBuildEntry.McVersion}/{_fabricBuildEntry.BuildVersion}/profile/json";
var versionInfoNode = JsonNode.Parse(await url.GetStringAsync());
var versionInfoNode = (await url.GetStringAsync())
.AsNode();

var libraries = LibrariesResolver.GetLibrariesFromJsonArray(versionInfoNode
.GetEnumerable("libraries"),
_inheritedFrom.GameFolderPath);
Expand Down
Loading

0 comments on commit 4b11f80

Please sign in to comment.