Skip to content

[Bugfix] 修复 #6348 资源包管理处理非UTF-8编码的options.txt文件时出错#6351

Merged
Glavo merged 8 commits into
HMCL-dev:mainfrom
ToobLac:fix/6348
Jul 26, 2026
Merged

[Bugfix] 修复 #6348 资源包管理处理非UTF-8编码的options.txt文件时出错#6351
Glavo merged 8 commits into
HMCL-dev:mainfrom
ToobLac:fix/6348

Conversation

@ToobLac

@ToobLac ToobLac commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #6348

@ToobLac
ToobLac marked this pull request as ready for review July 9, 2026 08:59
@zhuWin

zhuWin commented Jul 9, 2026

Copy link
Copy Markdown

问题似乎解决了,仍需进一步review

image

@Glavo

Glavo commented Jul 9, 2026

Copy link
Copy Markdown
Member

@codex review

Comment thread HMCLCore/src/main/java/org/jackhuang/hmcl/util/StringUtils.java Outdated

@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: 34d122b4b8

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread HMCLCore/src/main/java/org/jackhuang/hmcl/util/StringUtils.java Outdated
@Glavo

Glavo commented Jul 10, 2026

Copy link
Copy Markdown
Member

@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: c1c167216f

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (detected == null || !detected.isSupported()) return OperatingSystem.NATIVE_CHARSET;
var charset = detected.getCharset();
if (charset == StandardCharsets.UTF_8 || charset == StandardCharsets.US_ASCII) return StandardCharsets.UTF_8;
return OperatingSystem.NATIVE_CHARSET;

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 detected non-UTF-8 charset

When options.txt is encoded in a supported non-UTF-8 charset that differs from the current JVM native charset, such as an instance copied from a GBK Windows machine to a UTF-8 Linux/macOS install or a UTF-16 file with a BOM, this branch discards the charset UniversalDetector found and forces loadOptions() to decode with OperatingSystem.NATIVE_CHARSET. That still produces mojibake before the resource pack lists are parsed and later rewritten, so the non-UTF-8 fix only works when the file happens to match the local native charset; return the detected charset for supported non-ASCII encodings instead of falling back here.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

无需担心,这种情况MC也读取不了,就不管了(

Comment thread HMCLCore/src/main/java/org/jackhuang/hmcl/util/StringUtils.java Outdated
@github-actions github-actions Bot added the 40+ label Jul 17, 2026
@Glavo

Glavo commented Jul 22, 2026

Copy link
Copy Markdown
Member

#6477

@Glavo

Glavo commented Jul 22, 2026

Copy link
Copy Markdown
Member

@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: 79dc5c923f

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread HMCLCore/src/main/java/org/jackhuang/hmcl/util/StringUtils.java Outdated
@Glavo

Glavo commented Jul 26, 2026

Copy link
Copy Markdown
Member

@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: 4d7c031405

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

sb.append(entry.getKey()).append(":").append(entry.getValue()).append(System.lineSeparator());
}
FileUtils.saveSafely(optionsFile, sb.toString());
FileUtils.saveSafely(optionsFile, sb.toString(), optionsFileEncoding);

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 Use a Unicode-capable charset for ASCII-only options

When an existing options.txt contains only ASCII (the normal case for a fresh instance), EncodingDetector.MODERN_WEB selects US-ASCII; if the user then enables a resource pack such as 中文.zip, this save silently replaces the newly inserted filename characters with ?. Minecraft consequently receives the wrong resource-pack ID and the activation does not persist, so ASCII detection should fall back to UTF-8 or the selected charset should be upgraded when it cannot encode the resulting content.

Useful? React with 👍 / 👎.

return options;
}

EncodingDetector.Encoding bestEncoding = EncodingDetector.MODERN_WEB.detect(bytes).bestEncoding();

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 Mark the nullable detector result explicitly

bestEncoding() is explicitly handled as possibly null on the following line, but this local variable omits @Nullable, leaving its nullability implicit contrary to the repository's Java nullability requirement; annotate the local declaration accordingly.

AGENTS.md reference: AGENTS.md:L7-L9

Useful? React with 👍 / 👎.

@Glavo
Glavo merged commit 7a4bea1 into HMCL-dev:main Jul 26, 2026
3 checks passed
@ToobLac
ToobLac deleted the fix/6348 branch July 26, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 345 (#6091) 以来的新资源包管理处理非 UTF-8 options.txt 时崩溃

3 participants