Skip to content

Commit

Permalink
重写资源补全逻辑极大提高了下载速度
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSpring114 committed Mar 15, 2024
1 parent fb72aa9 commit eccae8e
Show file tree
Hide file tree
Showing 10 changed files with 608 additions and 322 deletions.
79 changes: 39 additions & 40 deletions MinecraftLaunch.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,45 @@
using MinecraftLaunch.Components.Fetcher;
using MinecraftLaunch.Components.Installer;
using MinecraftLaunch.Extensions;

MirrorDownloadManager.IsUseMirrorDownloadSource = true;

foreach (var item in await ForgeInstaller.EnumerableFromVersionAsync("1.12.2")){
Console.WriteLine(item.ForgeVersion);
using MinecraftLaunch.Components.Checker;
using MinecraftLaunch.Utilities;

try {
MirrorDownloadManager.IsUseMirrorDownloadSource = true;

var account = new OfflineAuthenticator("Yang114").Authenticate();
var resolver = new GameResolver(".minecraft");
var id = "1.12.2";

VanlliaInstaller installer = new(resolver, id, MirrorDownloadManager.Bmcl);
installer.ProgressChanged += (sender, args) => {
Console.WriteLine($"{args.Progress * 100:0.00}% --- {args.ProgressStatus} --- {args.Status}");
};

await installer.InstallAsync();

var config = new LaunchConfig {
Account = account,
IsEnableIndependencyCore = true,
JvmConfig = new(JavaUtil.GetCurrentJava(new JavaFetcher().Fetch(), resolver.GetGameEntity(id)).JavaPath) {
MaxMemory = 1024,
}
};

Launcher launcher = new(resolver, config);
var gameProcessWatcher = await launcher.LaunchAsync(id);

//获取输出日志
gameProcessWatcher.OutputLogReceived += (sender, args) => {
Console.WriteLine(args.Text);
};

//检测游戏退出
gameProcessWatcher.Exited += (sender, args) => {
Console.WriteLine("exit");
};
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
}

var account = new OfflineAuthenticator("Yang114").Authenticate();
var resolver = new GameResolver("C:\\Users\\w\\Desktop\\总整包\\MC\\mc启动器\\LauncherX\\.minecraft");

var installer = new VanlliaInstaller(resolver, "1.19.4", MirrorDownloadManager.Bmcl);
installer.ProgressChanged += (_, args) => {
Console.WriteLine($"{args.ProgressStatus} - {args.Progress * 100:0.00}%");
};

installer.Completed += (_, _) => {
Console.WriteLine("Completed!");
};

await installer.InstallAsync();

var config = new LaunchConfig {
Account = account,
IsEnableIndependencyCore = true,
JvmConfig = new(@"C:\Program Files\Java\jdk1.8.0_301\bin\javaw.exe") {
MaxMemory = 1024,
}
};

Launcher launcher = new(resolver, config);
var gameProcessWatcher = await launcher.LaunchAsync("1.12.2");

//获取输出日志
gameProcessWatcher.OutputLogReceived += (sender, args) => {
Console.WriteLine(args.Text);
};

//检测游戏退出
gameProcessWatcher.Exited += (sender, args) => {
Console.WriteLine("exit");
};

Console.ReadKey();
28 changes: 23 additions & 5 deletions MinecraftLaunch/Classes/Models/Download/DownloadRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,33 @@
/// 下载请求信息配置记录类
/// </summary>
public sealed record DownloadRequest {
public int Size { get; set; }
/// <summary>
/// 大文件判断阈值
/// </summary>
public long FileSizeThreshold { get; set; }

public bool IsCompleted { get; set; }
/// <summary>
/// 分片数量
/// </summary>
public int MultiPartsCount { get; set; }

public int DownloadedBytes { get; set; }
/// <summary>
/// 最大并行下载线程数
/// </summary>
public int MultiThreadsCount { get; set; }

public required string Url { get; init; }
/// <summary>
/// 下载链接
/// </summary>
public string Url { get; init; }

public required FileInfo FileInfo { get; set; }
/// <summary>
/// 保存文件信息
/// </summary>
public FileInfo FileInfo { get; set; }

/// <summary>
/// 是否启用大文件分片下载
/// </summary>
public bool IsPartialContentSupported { get; set; }
}
9 changes: 9 additions & 0 deletions MinecraftLaunch/Classes/Models/Download/MultiPartRange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MinecraftLaunch.Classes.Models.Download;

public record MultiPartRange {
public long End { get; set; }

public long Start { get; set; }

public string TempFilePath { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
namespace MinecraftLaunch.Classes.Models.Event;

public sealed class DownloadProgressChangedEventArgs : EventArgs {
public double Speed { get; set; }

public int TotalCount { get; set; }

public double TotalBytes { get; set; }

public int FailedCount { get; set; }

public int CompletedCount { get; set; }

public double DownloadedBytes { get; set; }
}
Loading

0 comments on commit eccae8e

Please sign in to comment.