-
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
901a444
commit b4dd725
Showing
9 changed files
with
158 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
using MinecraftLaunch.Components.Authenticator; | ||
using MinecraftLaunch; | ||
using MinecraftLaunch.Classes.Interfaces; | ||
using MinecraftLaunch.Components.Authenticator; | ||
using MinecraftLaunch.Components.Checker; | ||
using MinecraftLaunch.Components.Installer; | ||
using MinecraftLaunch.Components.Resolver; | ||
using MinecraftLaunch.Extensions; | ||
using System.Diagnostics; | ||
|
||
string gameFolder = "C:\\Users\\w\\Desktop\\temp\\.minecraft"; | ||
|
||
var _ = (await VanlliaInstaller.EnumerableGameCoreAsync()); | ||
|
||
var installer = new VanlliaInstaller(gameFolder, "1.12.2", MirrorDownloadManager.Mcbbs); | ||
|
||
installer.ProgressChanged += (_, x) => { | ||
Console.Clear(); | ||
Console.SetCursorPosition(0, 0); | ||
Console.WriteLine($"{x.Status} - {x.ProgressStatus} - {x.Progress:0.00} - {x.Speed}"); | ||
Console.SetCursorPosition(0, 0); | ||
}; | ||
|
||
var result = await installer.InstallAsync(); | ||
|
||
Console.ReadKey(); |
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
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
20 changes: 20 additions & 0 deletions
20
MinecraftLaunch/Classes/Models/Install/VersionManifestEntry.cs
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,20 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MinecraftLaunch.Classes.Models.Install { | ||
public record VersionManifestEntry { | ||
[JsonPropertyName("id")] | ||
public string Id { get; set; } | ||
|
||
[JsonPropertyName("type")] | ||
public string Type { get; set; } | ||
|
||
[JsonPropertyName("url")] | ||
public string Url { get; set; } | ||
|
||
[JsonPropertyName("time")] | ||
public DateTime Time { get; set; } | ||
|
||
[JsonPropertyName("releaseTime")] | ||
public DateTime ReleaseTime { 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,17 +1,103 @@ | ||
using MinecraftLaunch.Classes.Interfaces; | ||
using Flurl.Http; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using MinecraftLaunch.Extensions; | ||
using System.Collections.Immutable; | ||
using MinecraftLaunch.Classes.Interfaces; | ||
using MinecraftLaunch.Classes.Models.Event; | ||
using MinecraftLaunch.Classes.Models.Install; | ||
using MinecraftLaunch.Classes.Models.Download; | ||
using MinecraftLaunch.Components.Checker; | ||
using MinecraftLaunch.Classes.Models.Game; | ||
using MinecraftLaunch.Components.Resolver; | ||
|
||
namespace MinecraftLaunch.Components.Installer { | ||
/// <summary> | ||
/// 原版核心安装器 | ||
/// </summary> | ||
public class VanlliaInstaller : IInstaller { | ||
public class VanlliaInstaller(string gameFoloder, string gameId, MirrorDownloadSource source = default) : IInstaller { | ||
private string _gameId = gameId; | ||
|
||
private ResourceChecker _resourceChecker; | ||
|
||
private string _gameFoloder = gameFoloder; | ||
|
||
private MirrorDownloadSource _source = source; | ||
|
||
private GameResolver _gameResolver = new(gameFoloder); | ||
|
||
private static IEnumerable<VersionManifestEntry> _cache; | ||
|
||
public event EventHandler<EventArgs> Completed; | ||
|
||
public event EventHandler<ProgressChangedEventArgs> ProgressChanged; | ||
|
||
public ValueTask<bool> InstallAsync() { | ||
throw new NotImplementedException(); | ||
public async ValueTask<bool> InstallAsync() { | ||
/* | ||
* Check if the specified id exists | ||
*/ | ||
ReportProgress(0.0d, "Check if the specified id exists", TaskStatus.Created); | ||
if (_cache is null && string.IsNullOrEmpty(_gameId)) { | ||
return false; | ||
} | ||
|
||
/* | ||
* Download game core json | ||
*/ | ||
ReportProgress(0.15d, "Start downloading the game core json", TaskStatus.WaitingToRun); | ||
var coreInfo = _cache.SingleOrDefault(x => x.Id == _gameId); | ||
if (coreInfo is null) { | ||
return false; | ||
} | ||
|
||
var versionJsonFile = Path.Combine(_gameFoloder, "versions", _gameId, | ||
$"{_gameId}.json").ToFileInfo(); | ||
|
||
if (!versionJsonFile.Directory.Exists) { | ||
versionJsonFile.Directory.Create(); | ||
} | ||
|
||
await File.WriteAllTextAsync(versionJsonFile.FullName, | ||
await coreInfo.Url.GetStringAsync()); | ||
|
||
/* | ||
* Download dependent resources | ||
*/ | ||
ReportProgress(0.15d, "Start downloading dependent resources", TaskStatus.WaitingToRun); | ||
_resourceChecker = new(_gameResolver.GetGameEntity(_gameId)); | ||
await _resourceChecker.CheckAsync(); | ||
|
||
await _resourceChecker.MissingResources.DownloadResourceEntrysAsync(source, | ||
x => { | ||
ReportProgress(0.15d, $"Downloading dependent resources:{x.CompletedCount}/{x.TotalCount}", | ||
TaskStatus.Running, x.ToSpeedText()); | ||
}); | ||
|
||
|
||
ReportProgress(0.15d, "Installation is complete", TaskStatus.Canceled); | ||
return true; | ||
} | ||
|
||
public void ReportProgress(double progress, string progressStatus, TaskStatus status) { | ||
ProgressChanged?.Invoke(this, new(status, progress, progressStatus)); | ||
} | ||
|
||
public void ReportProgress(double progress, string progressStatus, TaskStatus status, string speed) { | ||
ProgressChanged?.Invoke(this, new(status, progress, progressStatus) { | ||
Speed = speed | ||
}); | ||
} | ||
|
||
public static async ValueTask<IEnumerable<VersionManifestEntry>> EnumerableGameCoreAsync(MirrorDownloadSource source = default) { | ||
string url = string.Empty; | ||
if (MirrorDownloadManager.IsUseMirrorDownloadSource && source is not null) { | ||
url = source.VersionManifestUrl; | ||
} else { | ||
url = "http://launchermeta.mojang.com/mc/game/version_manifest.json"; | ||
} | ||
|
||
var node = JsonNode.Parse(await url.GetStringAsync()); | ||
return _cache = node.GetEnumerable("versions").Deserialize<IEnumerable<VersionManifestEntry>>(); | ||
} | ||
} | ||
} |
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
File renamed without changes.