Skip to content

重构 Config#4394

Merged
Glavo merged 26 commits intoHMCL-dev:mainfrom
Glavo:config
Sep 5, 2025
Merged

重构 Config#4394
Glavo merged 26 commits intoHMCL-dev:mainfrom
Glavo:config

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented Sep 4, 2025

本 PR

  1. 重新排序了 Config 的字段,使未来我们添加字段更容易;
  2. 重新实现了 Config 的序列化
    1. 现在 Config 仅会序列化被修改过的字段,不会将字段默认值写入配置文件,以便我们未来调整这些字段的默认值。
    2. 现在 Config 在反序列化时会保存所有未知字段,避免旧版本 HMCL 损坏新版本 HMCL 的配置文件

@Glavo Glavo requested a review from Copilot September 4, 2025 15:24

This comment was marked as outdated.

@HMCL-dev HMCL-dev deleted a comment from Copilot AI Sep 4, 2025
@HMCL-dev HMCL-dev deleted a comment from Copilot AI Sep 4, 2025
@Glavo Glavo requested a review from Copilot September 5, 2025 08:44

This comment was marked as outdated.

@HMCL-dev HMCL-dev deleted a comment from Copilot AI Sep 5, 2025
…Field.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@HMCL-dev HMCL-dev deleted a comment from Copilot AI Sep 5, 2025
@Glavo Glavo requested a review from Copilot September 5, 2025 09:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the Config class to improve field organization, implement selective serialization, and preserve unknown fields for backward compatibility.

  • Reorganizes Config fields with better logical grouping and organization
  • Implements selective serialization that only writes modified fields to avoid storing default values
  • Adds support for preserving unknown fields during deserialization to prevent config corruption between different HMCL versions

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
DirtyTracker.java New utility for tracking which Observable properties have been modified
ObservableField.java New reflection-based utility for handling JavaFX Observable properties with Gson serialization
TypeUtils.java Utility class copied from Gson for advanced type resolution and manipulation
Config.java Major refactoring with field reorganization, custom adapter for selective serialization, and unknown field preservation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +791 to +797
FIELDS.forEach(field -> {
JsonElement value = values.remove(field.getSerializedName());
if (value != null) {
config.tracker.markDirty(field.get(config));
field.deserialize(config, value, context);
}
});
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

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

This logic doesn't handle fields with alternate names defined by @SerializedName annotation. The code only checks for the primary serialized name but ignores the alternate names, which could cause deserialization to fail for fields using alternate names.

Copilot uses AI. Check for mistakes.
@HMCL-dev HMCL-dev deleted a comment from Copilot AI Sep 5, 2025
@HMCL-dev HMCL-dev deleted a comment from Copilot AI Sep 5, 2025
@HMCL-dev HMCL-dev deleted a comment from Copilot AI Sep 5, 2025
@Glavo Glavo merged commit f4a8e3d into HMCL-dev:main Sep 5, 2025
2 checks passed
@Glavo Glavo deleted the config branch September 5, 2025 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants