-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cc44ec
commit 2c5049c
Showing
4 changed files
with
111 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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 QuiltBuildEntry { | ||
[JsonPropertyName("intermediary")] | ||
public QuiltMavenItem Intermediary { get; set; } | ||
|
||
[JsonPropertyName("loader")] | ||
public QuiltMavenItem Loader { get; set; } | ||
|
||
[JsonPropertyName("launcherMeta")] | ||
public QuiltLauncherMeta LauncherMeta { get; set; } | ||
|
||
[JsonIgnore] | ||
public string BuildVersion => Loader.Version; | ||
|
||
[JsonIgnore] | ||
public string McVersion => Intermediary.Version; | ||
|
||
[JsonIgnore] | ||
public string DisplayVersion => $"{McVersion}-{Loader.Version}"; | ||
} | ||
|
||
public record QuiltLauncherMeta { | ||
[JsonPropertyName("mainClass")] | ||
public Dictionary<string, string> MainClass { get; set; } | ||
} | ||
|
||
public record QuiltMavenItem { | ||
[JsonPropertyName("separator")] | ||
public string Separator { get; set; } | ||
|
||
[JsonPropertyName("maven")] | ||
public string Maven { get; set; } | ||
|
||
[JsonPropertyName("version")] | ||
public string Version { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,72 @@ | ||
using MinecraftLaunch.Classes.Interfaces; | ||
using MinecraftLaunch.Classes.Models.Event; | ||
using Flurl.Http; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using MinecraftLaunch.Extensions; | ||
using MinecraftLaunch.Components.Resolver; | ||
using MinecraftLaunch.Classes.Models.Game; | ||
using MinecraftLaunch.Classes.Models.Install; | ||
using MinecraftLaunch.Classes.Models.Download; | ||
using System.Diagnostics; | ||
|
||
namespace MinecraftLaunch.Components.Installer { | ||
public class QuiltInstaller : IInstaller { | ||
public event EventHandler<EventArgs> Completed; | ||
public class QuiltInstaller(GameEntry inheritedFrom, QuiltBuildEntry entry, string customId = default, MirrorDownloadSource source = default) : InstallerBase { | ||
private readonly string _customId = customId; | ||
private QuiltBuildEntry _quiltBuildEntry = entry; | ||
private readonly GameEntry _inheritedFrom = inheritedFrom; | ||
|
||
public event EventHandler<ProgressChangedEventArgs> ProgressChanged; | ||
public override async ValueTask<bool> InstallAsync() { | ||
/* | ||
* Parse build | ||
*/ | ||
ReportProgress(0.0d, "Start parse build", TaskStatus.Created); | ||
string url = $"https://meta.quiltmc.org/v3/versions/loader/{_quiltBuildEntry.McVersion}/{_quiltBuildEntry.BuildVersion}/profile/json"; | ||
var versionInfoNode = JsonNode.Parse(await url.GetStringAsync()); | ||
var libraries = LibrariesResolver.GetLibrariesFromJsonArray(versionInfoNode | ||
.GetEnumerable("libraries"), | ||
_inheritedFrom.GameFolderPath); | ||
|
||
|
||
/* | ||
* Download dependent resources | ||
*/ | ||
ReportProgress(0.25d, "Start downloading dependent resources", TaskStatus.WaitingToRun); | ||
foreach (var library in libraries) { | ||
Debug.WriteLine(library.Url); | ||
} | ||
|
||
await libraries.DownloadResourceEntrysAsync(source, x => { | ||
ReportProgress(x.ToPercentage().ToPercentage(0.25d, 0.75d), $"Downloading dependent resources:{x.CompletedCount}/{x.TotalCount}", | ||
TaskStatus.Running); | ||
}); | ||
|
||
/* | ||
* Write information to version json | ||
*/ | ||
ReportProgress(0.85d, "Write information to version json", TaskStatus.WaitingToRun); | ||
if (!string.IsNullOrEmpty(_customId)) { | ||
versionInfoNode = versionInfoNode.SetString("id", _customId); | ||
} | ||
|
||
var id = versionInfoNode.GetString("id"); | ||
var jsonFile = new FileInfo(Path.Combine(_inheritedFrom.GameFolderPath, | ||
"versions", id, $"{id}.json")); | ||
|
||
if (!jsonFile.Directory.Exists) { | ||
jsonFile.Directory.Create(); | ||
} | ||
|
||
File.WriteAllText(jsonFile.FullName, versionInfoNode.ToString()); | ||
ReportProgress(1.0d, "Installation is complete", TaskStatus.Canceled); | ||
return true; | ||
|
||
public ValueTask<bool> InstallAsync() { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void ReportProgress(double progress, string progressStatus, TaskStatus status) { | ||
throw new NotImplementedException(); | ||
public static async ValueTask<IEnumerable<QuiltBuildEntry>> EnumerableFromVersionAsync(string mcVersion) { | ||
string url = $"https://meta.quiltmc.org/v3/versions/loader/{mcVersion}"; | ||
string json = await url.GetStringAsync(); | ||
|
||
var entries = JsonSerializer.Deserialize<List<QuiltBuildEntry>>(json); | ||
return entries; | ||
} | ||
} | ||
} |