Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions PCL.Core/App/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ public static partial class Config
/// </summary>
[ConfigGroup("Download")] partial class DownloadConfigGroup
{
// 保留原配置键,升级后仍沿用用户已设置的数值(值 + 1 为连接上限)。
[ConfigItem<int>("ToolDownloadThread", 63)] public partial int ThreadLimit { get; set; }
[ConfigItem<int>("ToolDownloadFileConnection", 7)] public partial int FileConnectionLimit { get; set; }
[ConfigItem<int>("ToolDownloadSpeed", 42)] public partial int SpeedLimit { get; set; }
[ConfigItem<DownloadHttpMode>("ToolDownloadHttpMode", DownloadHttpMode.Auto)] public partial DownloadHttpMode HttpMode { get; set; }
[ConfigItem<int>("ToolDownloadSource", 1)] public partial int FileSource { get; set; }
[ConfigItem<int>("ToolDownloadVersion", 1)] public partial int VersionListSource { get; set; }
[ConfigItem<bool>("ToolDownloadAutoSelectVersion", true)] public partial bool AutoSelectInstance { get; set; }
Expand Down
10 changes: 10 additions & 0 deletions PCL.Core/App/ConfigEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ public enum LinkProtocolPreference
Udp
}

/// <summary>
/// 文件下载使用的 HTTP 协议模式。
/// </summary>
public enum DownloadHttpMode
{
Auto = 0,
Http11 = 1,
Http2 = 2
}

/// <summary>
/// 主题模式(亮/暗/系统)
/// </summary>
Expand Down
19 changes: 14 additions & 5 deletions PCL.Core/App/Localization/Languages/en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2672,10 +2672,19 @@
<sys:String x:Key="Setup.GameManage.Download.SpeedLimit.ToolTip">Set a download speed cap to prevent other programs that depend on the internet from freezing during downloads.</sys:String>
<sys:String x:Key="Setup.GameManage.Download.TargetFolder">Target folder</sys:String>
<sys:String x:Key="Setup.GameManage.Download.TargetFolder.Hint">Go to Launch → Selection → Folder list to change the download target folder.&#xA;Right-click a folder or game instance to open the corresponding folder.</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads">Max threads</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads">Max concurrent connections</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads.TooManyWarning.Confirm">I see</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads.TooManyWarning.Message">Setting too many download threads may cause serious lag during downloads.&#xA;64 threads are generally enough for most download needs. Unless you know what you are doing, it is not recommended to set a higher value!</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads.ToolTip">More threads can speed up rate-limited downloads, but too many may cause serious lag during downloads.&#xA;In general, 64 threads are enough for most download needs.</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads.TooManyWarning.Message">A high connection limit can lead to severe lag or even stricter throttling strategies from the server.&#xA;64 connections are usually sufficient. Do not set it higher unless you know what you are doing!</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads.ToolTip">Limits the total network connections used by all download tasks. 64 connections are usually sufficient.</sys:String>
<sys:String x:Key="Setup.GameManage.Download.FileConnections">Max connections per file</sys:String>
<sys:String x:Key="Setup.GameManage.Download.FileConnections.ToolTip">The most connections a large file may use at once. A higher value can help sources that cap each connection, but may also trigger source throttling.</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol">File download protocol</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol.Auto">Automatic (recommended)</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol.Auto.ToolTip">Prefer HTTP/2 for small files and batch downloads, and use HTTP/1.1 for large segmented downloads to balance concurrency and compatibility.</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol.Http11">HTTP/1.1</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol.Http11.ToolTip">Force HTTP/1.1 for all file downloads. This can help environments where independent connections improve large-file throughput.</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol.Http2">Prefer HTTP/2</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol.Http2.ToolTip">Prefer HTTP/2 for all file downloads, falling back to HTTP/1.1 when the source or proxy does not support it.</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Unlimited">Unlimited</sys:String>

<!-- Setup.Java -->
Expand Down Expand Up @@ -3226,7 +3235,7 @@
<sys:String x:Key="Speed.Error.Copied">Error details copied!</sys:String>
<sys:String x:Key="Speed.Error.OperationFailed">A task manager operation failed. See the details below.</sys:String>
<sys:String x:Key="Speed.Progress.RemainingFiles">Remaining files</sys:String>
<sys:String x:Key="Speed.Progress.RemainingThreads">Remaining threads</sys:String>
<sys:String x:Key="Speed.Progress.RemainingThreads">Active connections</sys:String>
<sys:String x:Key="Speed.Progress.Speed">Download speed</sys:String>
<sys:String x:Key="Speed.Progress.Total">Total progress</sys:String>

Expand Down Expand Up @@ -3570,4 +3579,4 @@
<sys:String x:Key="Watcher.WindowLoaded">Minecraft window loaded: {0} ({1})</sys:String>
<sys:String x:Key="Watcher.WindowMaximized">Minecraft window maximized: {0}</sys:String>

</ResourceDictionary>
</ResourceDictionary>
19 changes: 14 additions & 5 deletions PCL.Core/App/Localization/Languages/zh-CN.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2672,10 +2672,19 @@
<sys:String x:Key="Setup.GameManage.Download.SpeedLimit.ToolTip">设置下载的速度上限,以避免在下载时导致其他需要联网的程序卡死</sys:String>
<sys:String x:Key="Setup.GameManage.Download.TargetFolder">目标文件夹</sys:String>
<sys:String x:Key="Setup.GameManage.Download.TargetFolder.Hint">请在 启动 → 实例选择 → 文件夹列表 中更改下载目标文件夹。&#xA;在某个文件夹或游戏实例上右键,即可选择打开对应文件夹。</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads">最大线程数</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads">最大并发连接数</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads.TooManyWarning.Confirm">我知道了</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads.TooManyWarning.Message">如果设置过多的下载线程,可能会导致下载时出现非常严重的卡顿。&#xA;一般设置 64 线程即可满足大多数下载需求,除非你知道你在干什么,否则不建议设置更多的线程数!</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads.ToolTip">线程数越多,限速的文件下载越快,但过高的线程数可能会造成下载时非常严重的卡顿。&#xA;一般而言,64 线程已可以保证足够的下载速度。</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads.TooManyWarning.Message">过高的并发连接数可能导致下载时出现非常严重的卡顿,甚至导致服务器使用更严格的限速策略。&#xA;64 个连接通常已经可以满足需求。除非你知道自己在做什么,否则不建议设置更高的并发连接数!</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Threads.ToolTip">限制所有下载任务合计使用的网络连接数。64 个连接通常已经足够。</sys:String>
<sys:String x:Key="Setup.GameManage.Download.FileConnections">单文件最大连接数</sys:String>
<sys:String x:Key="Setup.GameManage.Download.FileConnections.ToolTip">大文件最多同时使用的连接数。提高该值可能加快被单连接限速的下载,但也有可能更容易被下载源限速。</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol">文件下载协议</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol.Auto">自动选择(推荐)</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol.Auto.ToolTip">小文件和批量下载优先使用 HTTP/2;大文件分段下载使用 HTTP/1.1,以兼顾并发和兼容性。</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol.Http11">HTTP/1.1</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol.Http11.ToolTip">所有文件下载强制使用 HTTP/1.1。适合需要多条独立连接提升大文件速度的网络环境。</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol.Http2">优先使用 HTTP/2</sys:String>
<sys:String x:Key="Setup.GameManage.Download.HttpProtocol.Http2.ToolTip">所有文件下载优先使用 HTTP/2;如果下载源或代理不支持,会自动回退到 HTTP/1.1。</sys:String>
<sys:String x:Key="Setup.GameManage.Download.Unlimited">无限制</sys:String>

<!-- Setup.Java -->
Expand Down Expand Up @@ -3226,7 +3235,7 @@
<sys:String x:Key="Speed.Error.Copied">已复制错误详情!</sys:String>
<sys:String x:Key="Speed.Error.OperationFailed">任务管理操作失败。请查看错误详情。</sys:String>
<sys:String x:Key="Speed.Progress.RemainingFiles">剩余文件</sys:String>
<sys:String x:Key="Speed.Progress.RemainingThreads">剩余线程</sys:String>
<sys:String x:Key="Speed.Progress.RemainingThreads">活动连接</sys:String>
<sys:String x:Key="Speed.Progress.Speed">下载速度</sys:String>
<sys:String x:Key="Speed.Progress.Total">总进度</sys:String>

Expand Down Expand Up @@ -3570,4 +3579,4 @@
<sys:String x:Key="Watcher.WindowLoaded">Minecraft 窗口已加载:{0}({1})</sys:String>
<sys:String x:Key="Watcher.WindowMaximized">已最大化 Minecraft 窗口:{0}</sys:String>

</ResourceDictionary>
</ResourceDictionary>
1 change: 1 addition & 0 deletions PCL.Core/IO/Net/NetworkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private static void _Stop()
AllowAutoRedirect = true,
MaxAutomaticRedirections = 20,
UseCookies = false,
EnableMultipleHttp2Connections = true,
ConnectCallback = Config.Network.EnableDoH ? HostConnectionHandler.Instance.GetConnectionAsync : null
};

Expand Down
11 changes: 10 additions & 1 deletion Plain Craft Launcher 2/Modules/Base/ModSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public ModSetup()
// === Tool ===
Config.Download.ThreadLimitConfig.Observe(new ConfigObserver(ConfigEvent.Changed,
e => ToolDownloadThread((int)e.Value!)));
Config.Download.FileConnectionLimitConfig.Observe(new ConfigObserver(ConfigEvent.Changed,
e => ToolDownloadFileConnection((int)e.Value!)));
Config.Download.SpeedLimitConfig.Observe(new ConfigObserver(ConfigEvent.Changed,
e => ToolDownloadSpeed((int)e.Value!)));

Expand Down Expand Up @@ -113,6 +115,7 @@ public static void ApplyAll()

// Tool
ToolDownloadThread(Config.Download.ThreadLimit);
ToolDownloadFileConnection(Config.Download.FileConnectionLimit);
ToolDownloadSpeed(Config.Download.SpeedLimit);

// UI - Launcher
Expand Down Expand Up @@ -195,7 +198,13 @@ public static void LaunchRamType(int type)

public static void ToolDownloadThread(int value)
{
ModNet.NetTaskThreadLimit = value + 1;
ModNet.NetTaskConnectionLimit = Math.Clamp(value + 1, 1, ModNet.NetTaskConnectionLimitMax);
}

public static void ToolDownloadFileConnection(int value)
{
ModNet.NetTaskSingleFileConnectionLimit = Math.Clamp(value + 1, 1,
ModNet.NetTaskSingleFileConnectionLimitMax);
}

public static void ToolDownloadSpeed(int value)
Expand Down
4 changes: 3 additions & 1 deletion Plain Craft Launcher 2/Modules/Minecraft/ModDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ public static DownloadFile DlClientAssetIndexGet(McInstance version)
var indexUrl = (string)(indexInfo["url"] ?? "");
if (string.IsNullOrEmpty(indexUrl)) return null;

// 避免下载器先发一次 Range 探测请求,再回退到顺序下载
var indexSize = indexInfo["size"] is null ? -1L : (long)indexInfo["size"];
return new DownloadFile(DlSourceLauncherOrMetaGet(indexUrl), indexAddress,
new ModBase.FileChecker(canUseExistsFile: false));
new ModBase.FileChecker(actualSize: indexSize, canUseExistsFile: false));
}

/// <summary>
Expand Down
4 changes: 1 addition & 3 deletions Plain Craft Launcher 2/Modules/Minecraft/ModSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ public static string McSkinDownload(string address)
{
if (!File.Exists(fileAddress))
{
FileDownloader.DownloadAsync(address, fileAddress + ModNet.netDownloadEnd).GetAwaiter().GetResult();
File.Delete(fileAddress);
FileSystem.Rename(fileAddress + ModNet.netDownloadEnd, fileAddress);
FileDownloader.DownloadAsync(address, fileAddress).GetAwaiter().GetResult();
ModBase.Log("[Minecraft] 皮肤下载成功:" + fileAddress);
}

Expand Down
Loading
Loading