Skip to content

refactor(mod-base): 重构 ModBase.cs#3294

Open
Chiloven945 wants to merge 18 commits into
devfrom
refactor/mod-base
Open

refactor(mod-base): 重构 ModBase.cs#3294
Chiloven945 wants to merge 18 commits into
devfrom
refactor/mod-base

Conversation

@Chiloven945

Copy link
Copy Markdown
Member

GPT-5.5 Thinking 辅助并校对

close: #3288

@Chiloven945 Chiloven945 self-assigned this Jul 1, 2026
sourcery-ai[bot]

This comment was marked as abuse.

@pcl-ce-automation pcl-ce-automation Bot added 🚧 正在处理 开发人员正在对该内容进行开发、测试或修复,进展中 size: XXL PR 大小评估:巨型 labels Jul 1, 2026
# Conflicts:
#	Plain Craft Launcher 2/Modules/Minecraft/ModLocalComp.cs
#	Plain Craft Launcher 2/Modules/Network/Downloader/FileDownloader.cs
@Chiloven945 Chiloven945 marked this pull request as ready for review July 4, 2026 11:27
sourcery-ai[bot]

This comment was marked as abuse.

@pcl-ce-automation pcl-ce-automation Bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 and removed 🚧 正在处理 开发人员正在对该内容进行开发、测试或修复,进展中 labels Jul 4, 2026
@Chiloven945 Chiloven945 requested a review from a team July 4, 2026 11:27

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

progressIncrementHandler?.Invoke((double)copiedFiles / totalFiles);

P2 Badge Keep copy progress callbacks incremental

For modpacks with an override folder containing multiple files, CopyOverrideDirectory still adds the callback value to loader.Progress, matching the old CopyDirectory contract of reporting 1 / fileCount increments. This new implementation reports the cumulative fraction (copiedFiles / totalFiles), so the caller adds 1/n + 2/n + ... + 1 and the progress jumps far past the intended range during override copying.


case 8: // #RRGGBBAA
r = Convert.ToInt32(trimmedString[..2], 16);
g = Convert.ToInt32(trimmedString[2..4], 16);
b = Convert.ToInt32(trimmedString[4..6], 16);
a = Convert.ToInt32(trimmedString[6..8], 16);

P2 Badge Parse WPF hex colors as ARGB

When a caller passes an 8-digit WPF color string that the previous ColorConverter path accepted, such as #80FF0000, this now treats it as #RRGGBBAA instead of WPF's #AARRGGBB. Semi-transparent colors are therefore decoded with the alpha byte in the blue channel and often become fully transparent or the wrong color when converted through NColor.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// 解压文件,ProgressIncrementHandler 通过 Lambda 更新进度
ModBase.ExtractFile(fileAddress, installTemp, encode,
delta => loader.Progress += delta * progressIncrement);
Files.ExtractFileAsync(fileAddress, installTemp, delta => loader.Progress += delta * progressIncrement).GetAwaiter().GetResult();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the modpack ZIP filename encoding

When importing a ZIP modpack that contains GB18030/Chinese entry names, this replacement drops the encode value that the old ModBase.ExtractFile(..., encode, ...) passed into ZipFile.Open; Files.ExtractFileAsync opens ZIPs without an encoding override, so non-Unicode entry names are decoded with the library default and extract to garbled paths or fail. This affects local compressed-pack installs with localized filenames.

Useful? React with 👍 / 👎.

Comment on lines +3183 to +3184
(JsonObject)JsonCompat.ParseNode(
Files.ReadAllTextOrEmptyAsync(LauncherFileSystem.ResolvePath(ModFolder.mcFolderSelected + "launcher_profiles.json")).GetAwaiter().GetResult());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Read launcher_profiles with its written encoding

This reads launcher_profiles.json with Files.ReadAllTextOrEmptyAsync's default UTF-8 path, but the same code writes the file as GB18030 immediately below and the old ModBase.ReadFile auto-detected GB18030. If an existing launcher profile contains non-UTF8 bytes, such as Chinese profile names, launch-time profile updates can corrupt the JSON text or fall into the delete-and-recreate path.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 400e7fe3df

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread PCL.Core/IO/PathUtils.cs Outdated
Comment on lines +58 to +59
var queryIndex = path.IndexOfAny(['?', '#']);
if (queryIndex >= 0) path = path[..queryIndex];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve # in local file names

When users install or export a local file whose Windows filename contains a legal # (for example mods\foo#1.jar), this branch treats it like a URL fragment and truncates the name before the filename is returned. Callers use this helper to build destination filenames for local mods/resource packs, so these files can be copied as foo instead of foo#1.jar and lose their extension; only strip # after the input has been identified as a URL.

Useful? React with 👍 / 👎.

# Conflicts:
#	Plain Craft Launcher 2/Application.xaml.cs
#	Plain Craft Launcher 2/Modules/Minecraft/ModComp.cs
#	Plain Craft Launcher 2/Modules/Network/Loaders/LoaderDownload.cs
#	Plain Craft Launcher 2/Modules/Network/Models/DownloadFile.cs
#	Plain Craft Launcher 2/Pages/PageLaunch/PageLoginProfile.xaml.cs
#	Plain Craft Launcher 2/Pages/PageSetup/PageSetupUpdate.xaml.cs
@Chiloven945

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 788cd35247

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// 解压文件,ProgressIncrementHandler 通过 Lambda 更新进度
ModBase.ExtractFile(fileAddress, installTemp, encode,
delta => loader.Progress += delta * progressIncrement);
Files.ExtractFileAsync(fileAddress, installTemp, delta => loader.Progress += delta * progressIncrement).GetAwaiter().GetResult();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle .mrpack files as zip archives

When fileAddress is a Modrinth .mrpack (recognized earlier and passed into InstallPackModrinth), this now calls Files.ExtractFileAsync, whose extension dispatch only treats .zip/.jar as zip archives and throws NotSupportedException for .mrpack. The previous ModBase.ExtractFile treated every non-gz archive as a zip, so local Modrinth modpacks can no longer be installed unless .mrpack is explicitly routed through the zip extraction path or normalized before this call.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ded03161e7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +266 to +270
Files.ExtractFileAsync(
fileAddress,
installTemp,
delta => loader.Progress += delta * progressIncrement,
encode)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Accept archive extensions case-insensitively

When the selected local pack has an uppercase extension such as PACK.ZIP, foo.JAR, or pack.MRPACK, this new path now delegates to Files.ExtractFileAsync, whose extension dispatch uses case-sensitive EndsWithF checks and falls through to NotSupportedException. The previous ModBase.ExtractFile path accepted these on Windows by treating non-.gz archives as zip after a case-insensitive .gz check, so valid local modpacks can no longer be installed unless the extension checks are normalized or made case-insensitive.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

tarStream.Reset(); // 重置流以重新读取条目

P2 Badge Reopen tar streams before extracting entries

When a .tar or .tar.gz archive reaches this path, the first loop has already advanced the TarInputStream to EOF while collecting entries; Reset() does not rewind the archive stream, so the subsequent CopyEntryContentsAsync calls run with no current entry data and tar extraction produces empty/failing output. This affects the newly advertised tar/tar.gz extraction path, including .tar.gz files accepted by crash-log import through the .gz suffix; process entries in a single pass or reopen/seek the underlying stream before copying contents.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bbb06ba481

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@@ -101,7 +101,7 @@ private void RefreshReal()
{
// 本地文件
LogWrapper.Info("[Page] 主页自定义数据来源:本地文件");
content = ModBase.ReadFile(Path.Combine(ModBase.exePath, "PCL", "Custom.xaml"));
content = Files.ReadAllTextOrEmptyAsync(LauncherFileSystem.ResolvePath(Path.Combine(LauncherPaths.ExecutableDirectoryWithSlash, "PCL", "Custom.xaml"))).GetAwaiter().GetResult();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve legacy homepage file decoding

When users enable a local custom homepage and PCL\Custom.xaml was saved with GB18030/ANSI bytes (common for Chinese text in manually edited XAML), this now reads it with ReadAllTextOrEmptyAsync's default UTF-8 path instead of the old ModBase.ReadFile byte decoder with GB18030 fallback. In that scenario the homepage content is corrupted or read as empty and the custom homepage fails to load; pass the legacy encoding/detection path here as was done for other GB18030 files.

Useful? React with 👍 / 👎.

@Chiloven945

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bbb06ba481

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

{
CollectionAssert.AreEqual(Expected, "a12b34".RegexSearch(@"\\d+"));
Assert.AreEqual("12", "a12b34".RegexSeek(@"\\d+"));
Assert.IsTrue("a12".RegexCheck(@"\\d+"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use a real digit regex in the tests

These new regex tests double-escape \d inside a verbatim string, so the pattern searches for a literal \d instead of digits. With inputs like "a12b34", RegexSearch, RegexSeek, and RegexCheck therefore return no matches and the added test fails before validating the extension behavior; use @"\d+" here and in the replacement test below.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XXL PR 大小评估:巨型 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查

Projects

None yet

Development

Successfully merging this pull request may close these issues.

重构 ModBase.cs

1 participant