From fc1519e9b10507aa31af1f785d71d059c864d720 Mon Sep 17 00:00:00 2001 From: youzi-3222 Date: Mon, 3 Feb 2025 21:53:49 +0800 Subject: [PATCH] =?UTF-8?q?:ok=5Fhand:=20:bug:=20:sparkles:=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20@MoYuan-CN=20=E7=9A=84=20Review=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=B7=B2=E7=9F=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Modules/Minecraft/ModModpack.vb | 62 +++++++++++-------- .../PageVersion/PageVersionExport.xaml.vb | 4 +- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/Plain Craft Launcher 2/Modules/Minecraft/ModModpack.vb b/Plain Craft Launcher 2/Modules/Minecraft/ModModpack.vb index 9a380b0..614543b 100644 --- a/Plain Craft Launcher 2/Modules/Minecraft/ModModpack.vb +++ b/Plain Craft Launcher 2/Modules/Minecraft/ModModpack.vb @@ -958,39 +958,36 @@ Retry: End Function #Region "冗余" - Private VersionRedundant As String() = {"screenshots", "backups", "command_history\.txt", '个人文件 - ".*-natives", "server-resource-packs", "user.*cache\.json", "\.optifine", "\.fabric", "\.mixin\.out", '缓存 - ".*\.jar", "downloads", "realms_persistence.json", "\$\{natives_directory\}", "essential", '可联网更新 - "logs", "crash-reports", ".*\.log", "debug", '日志 - ".*\.dat_old", ".*\.old", '备份 - "\$\{quickPlayPath\}", '服务器 - "\.replay_cache", "replay_recordings", "replay_videos", 'ReplayMod - "irisUpdateInfo\.json", 'Iris - "modernfix", 'ModernFix 模组 - "modtranslations", 'Mod 翻译 - "schematics", 'schematics 模组 - ".*\.BakaCoreInfo", 'BakaXL 配置 - "hmclversion\.cfg", "log4j2\.xml", 'HMCL 配置 - "assets", "libraries", "\$natives", "launcher_profiles\.json", "versions" '开启版本隔离时排除的文件 + Private VersionRedundant As String() = {"^screenshots", "^backups", "^command_history\.txt$", '个人文件 + "^.*-natives", "^server-resource-packs", "^user.*cache\.json$", "^\.optifine", "^\.fabric", "^\.mixin\.out", '缓存 + "^.*\.jar$", "^downloads", "^realms_persistence.json$", "^\$\{natives_directory\}", "^essential", '可联网更新 + "^logs", "^crash-reports", ".*\.log$", "^debug", '日志 + ".*\.dat_old$", ".*\.old$", '备份 + "^\$\{quickPlayPath\}", '服务器 + "^\.replay_cache", "^replay_recordings", "^replay_videos", 'ReplayMod + "^irisUpdateInfo\.json$", 'Iris + "^modernfix", 'ModernFix 模组 + "^modtranslations", 'Mod 翻译 + "^schematics", 'schematics 模组 + "^journeymap\\data", 'JourneyMap 模组 + "^mods\\\.connector", '信雅互联 + "^.*\.BakaCoreInfo$", 'BakaXL 配置 + "^hmclversion\.cfg$", "^log4j2\.xml$", 'HMCL 配置 + "^assets$", "^libraries$", "^\$natives$", "^launcher_profiles\.json$", "^versions$" '开启版本隔离时排除的文件 } - Public Function IsVerRedundant(FilePath As String) As Boolean + Public Function IsVerRedundant(FilePath As String, PathIndie As String) As Boolean FilePath = FilePath.Replace("/", "\") For Each regex In VersionRedundant - If RegexCheck(GetFileNameFromPath(FilePath), regex, RegularExpressions.RegexOptions.IgnoreCase) Then Return True - If FilePath.EndsWithF("\journeymap\data\") OrElse - FilePath.EndsWithF("\journeymap\data") OrElse - FilePath.EndsWithF("\mods\.connector") Then - Return True - End If + If RegexCheck(FilePath.Replace(PathIndie, ""), regex, RegularExpressions.RegexOptions.IgnoreCase) Then Return True Next Return False End Function Private MustExport As String() = { "mods", "PCL", ".*\.json" } - Public Function IsMustExport(FilePath As String) As Boolean + Public Function IsMustExport(FilePath As String, PathIndie As String) As Boolean For Each regex In MustExport - If RegexCheck(GetFileNameFromPath(FilePath), regex, RegularExpressions.RegexOptions.IgnoreCase) Then Return True + If RegexCheck(FilePath.Replace(PathIndie, ""), regex, RegularExpressions.RegexOptions.IgnoreCase) AndAlso Not (FilePath.EndsWithF(".zip") OrElse FilePath.EndsWithF("\")) Then Return True Next Return False End Function @@ -1148,11 +1145,26 @@ JumpMod: If String.IsNullOrWhiteSpace(p) Then Continue For '传空字串进去会直接把整个版本文件夹拷过去 If Not p.StartsWithF(GetPathFromFullPath(GetPathFromFullPath(Version.Path)), IgnoreCase:=True) Then Continue For Dim relative As String = p.Replace(Version.Path, "").Replace(GetPathFromFullPath(GetPathFromFullPath(Version.Path)), "") - If File.Exists(p) AndAlso Not IsVerRedundant(p) Then + If File.Exists(p) AndAlso Not IsVerRedundant(p, Version.PathIndie) Then CopyFile(p, $"{tempDir}overrides\{relative}") End If Next - Task.Progress = 0.99 + Task.Progress = 0.96 + + '如果 resourcepacks shaderpacks 文件夹中有文件夹格式的包,则先将文件夹压缩成 Zip 文件后再打包入对应位置 + '这可以避免安装时出现路径长度限制而出错 + If Directory.Exists($"{tempDir}overrides\resourcepacks\") Then + For Each d In Directory.EnumerateDirectories($"{tempDir}overrides\resourcepacks\") + If Not File.Exists(d + ".zip") Then ZipFile.CreateFromDirectory(d, d + ".zip") + DeleteDirectory(d) + Next + End If + If Directory.Exists($"{tempDir}overrides\shaderpacks\") Then + For Each d In Directory.EnumerateDirectories($"{tempDir}overrides\shaderpacks\") + If Not File.Exists(d + ".zip") Then ZipFile.CreateFromDirectory(d, d + ".zip") + DeleteDirectory(d) + Next + End If #End Region If File.Exists(DestPath) Then File.Delete(DestPath) '选择文件的时候已经确认了要替换 diff --git a/Plain Craft Launcher 2/Pages/PageVersion/PageVersionExport.xaml.vb b/Plain Craft Launcher 2/Pages/PageVersion/PageVersionExport.xaml.vb index c237e84..13b514e 100644 --- a/Plain Craft Launcher 2/Pages/PageVersion/PageVersionExport.xaml.vb +++ b/Plain Craft Launcher 2/Pages/PageVersion/PageVersionExport.xaml.vb @@ -75,7 +75,7 @@ For Each d In directories If Directory.EnumerateFileSystemEntries(d).Count = 0 Then Continue For - If IsVerRedundant(d) OrElse IsMustExport(d) Then Continue For + If IsVerRedundant(d, PageVersionLeft.Version.PathIndie) OrElse IsMustExport(d, PageVersionLeft.Version.PathIndie) Then Continue For Dim title As String = "" Dim listItem As New MyListItem If Titles.TryGetValue(GetFolderNameFromPath(d), title) Then 'title 作为引用类型传入 @@ -107,7 +107,7 @@ Next For Each f In files - If IsVerRedundant(f) OrElse IsMustExport(f) Then Continue For + If IsVerRedundant(f, PageVersionLeft.Version.PathIndie) OrElse IsMustExport(f, PageVersionLeft.Version.PathIndie) Then Continue For Dim title As String = "" Dim listItem As New MyListItem If Titles.TryGetValue(f, title) Then 'title 作为引用类型传入