-
Notifications
You must be signed in to change notification settings - Fork 9
ModPack提取Overrides文件加速 #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ddb541c
feat: 实现整合包Override资源的单/多线程提取
IksRain d7bedcd
style
IksRain ca2d330
feat(ModPack): 添加回调支持
IksRain 9b05725
fix(ModPack):MIT授权.NET标准库ExtractAsync部分代码,请换.NET10好吗
IksRain 06ecebf
transfer: ModrinthModpackInstaller.cs `ExtractModpackAsync`改为使用ModPac…
IksRain 9c00a36
transfer: McbbsModpackInstaller.cs `ExtractModpackAsync`改为使用ModPackUt…
IksRain 99c2ca1
transfer: CurseforgeModpackInstaller.cs `ExtractModpackAsync`改为使用ModP…
IksRain 22aad59
delapi(ModPack):删除多线程版本,经测试无明显提升
IksRain 4c8fa9f
fix(ModPack):修复若目录原先不存在即无法完成提取的问题
IksRain 2db8ac7
perf: ModrinthModpackInstaller.cs ParseModFiles修改,减少锁开销
IksRain afb712f
perf: 使用trygetvalue减少一次查表操作
IksRain 2cb2c32
async: 提升响应性,声请资源前的取消检查
IksRain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
74 changes: 74 additions & 0 deletions
74
MinecraftLaunch/Components/Installer/Modpack/ModPackUtils.cs
This file contains hidden or 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,74 @@ | ||
| using System.Diagnostics; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.IO.Compression; | ||
| using System.Net.Sockets; | ||
| using MinecraftLaunch.Extensions; | ||
|
|
||
| namespace MinecraftLaunch.Components.Installer.Modpack; | ||
|
|
||
| internal static class ModPackUtils | ||
| { | ||
| public const char ZipPathSeparator = '/'; | ||
|
|
||
|
IksRain marked this conversation as resolved.
|
||
|
|
||
| public static async Task ExtractSingleThreadAsync( | ||
| string srcZipPath, | ||
| string overridesPrefix, | ||
| string independentAndFullWorkingPath, | ||
| /*执行线程不保证*/Action<ZipArchive> whenEachEntryCompleted = null, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| Debug.Assert(srcZipPath is not null || overridesPrefix is not null || independentAndFullWorkingPath is not null); | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
| using var zip = ZipFile.OpenRead(srcZipPath); | ||
| foreach (var item in zip.Entries) | ||
| { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
| // 排除非 <overrides>/文件 | ||
| if (!item.FullName.StartsWith(overridesPrefix, StringComparison.OrdinalIgnoreCase)) continue; | ||
| var targetPath = Path.Combine( | ||
| independentAndFullWorkingPath, | ||
| RemoveOverridesPrefix(item.FullName, overridesPrefix)); | ||
| if (item.FullName.EndsWith(ZipPathSeparator)) | ||
| { | ||
| Directory.CreateDirectory(targetPath); | ||
| continue; | ||
| } | ||
| if (!IsShouldExtract(item, overridesPrefix)) continue; | ||
| await item.ExtractToFileAsync( | ||
| targetPath, | ||
| overwrite:true,cancellationToken | ||
| ).ConfigureAwait(false); | ||
| whenEachEntryCompleted?.Invoke(zip); | ||
| } | ||
| } | ||
|
|
||
| #region Util | ||
|
|
||
| private static bool IsShouldExtract( | ||
| ZipArchiveEntry entry, | ||
| string overridesPrefix) | ||
| { | ||
| // 排除目录 | ||
| if (entry.FullName.EndsWith(ZipPathSeparator)) return false; | ||
| // 排除非 <overrides>/文件 | ||
| if (!entry.FullName.StartsWith(overridesPrefix, StringComparison.OrdinalIgnoreCase)) return false; | ||
| return true; | ||
| } | ||
|
|
||
| // 修正路径 | ||
| private static string RemoveOverridesPrefix( | ||
| string source, | ||
| string overridesPrefix) | ||
| { | ||
| if (overridesPrefix.EndsWith('/')) | ||
| { | ||
| return source[overridesPrefix.Length..]; | ||
| } | ||
|
|
||
| // 补充/ | ||
| return source[(overridesPrefix.Length + 1)..]; | ||
| } | ||
|
|
||
| #endregion | ||
| } | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.