Skip to content

Commit c11c73b

Browse files
committed
feat: 完善配置默认值与高级项
- 将 AM Daemon 自动启动和命令行补全默认启用并更新栏目名称 - 将 DNS ReplaceHost 默认启用并移除 Enable 的冗余说明 - 按清单标记少改动配置项并生成 example.toml 与 full.toml
1 parent ef8343b commit c11c73b

12 files changed

Lines changed: 288 additions & 57 deletions

File tree

packages/applechu-schema/src/example.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::path::Path;
33

44
use crate::{canonical_key, LocalizedText, Schema};
55

6-
pub const EXAMPLE_CONFIG_FILE: &str = "AppleChu.example.toml";
6+
pub const EXAMPLE_CONFIG_FILE: &str = "example.toml";
7+
pub const FULL_CONFIG_FILE: &str = "full.toml";
78

89
pub const DEFAULT_CONFIG_HEADER: &str = r#"## 这是 AppleChu 的 TOML 配置文件
910
##
@@ -17,6 +18,14 @@ ConfigVersion = 1
1718

1819
impl Schema {
1920
pub fn default_config_toml(&self) -> String {
21+
self.config_toml(false)
22+
}
23+
24+
pub fn full_config_toml(&self) -> String {
25+
self.config_toml(true)
26+
}
27+
28+
fn config_toml(&self, include_advanced: bool) -> String {
2029
let mut output = String::from(DEFAULT_CONFIG_HEADER);
2130
for section in &self.sections {
2231
output.push('\n');
@@ -28,7 +37,7 @@ impl Schema {
2837
append_comment(&mut output, description.zh_or_en());
2938
}
3039
for entry in &section.entries {
31-
if entry.advanced {
40+
if entry.advanced && !include_advanced {
3241
continue;
3342
}
3443
if entry.emit_comment {
@@ -55,10 +64,9 @@ impl Schema {
5564
}
5665

5766
pub fn write_example_config(&self, output: impl AsRef<Path>) -> std::io::Result<()> {
58-
fs::write(
59-
output.as_ref().join(EXAMPLE_CONFIG_FILE),
60-
self.default_config_toml(),
61-
)
67+
let output = output.as_ref();
68+
fs::write(output.join(EXAMPLE_CONFIG_FILE), self.default_config_toml())?;
69+
fs::write(output.join(FULL_CONFIG_FILE), self.full_config_toml())
6270
}
6371
}
6472

@@ -80,7 +88,7 @@ mod tests {
8088
use std::fs;
8189
use std::time::{SystemTime, UNIX_EPOCH};
8290

83-
use crate::{generate_from_rust_dir, EXAMPLE_CONFIG_FILE};
91+
use crate::{generate_from_rust_dir, EXAMPLE_CONFIG_FILE, FULL_CONFIG_FILE};
8492

8593
#[test]
8694
fn example_config_is_written_to_build_output() {
@@ -106,7 +114,13 @@ mod tests {
106114
// Then: 固定文件名中的内容与内嵌默认配置完全一致。
107115
let example = fs::read_to_string(directory.join(EXAMPLE_CONFIG_FILE))
108116
.expect("example config must be readable");
117+
let full = fs::read_to_string(directory.join(FULL_CONFIG_FILE))
118+
.expect("full config must be readable");
109119
fs::remove_dir_all(&directory).expect("output directory must be removed");
110120
assert_eq!(example, schema.default_config_toml());
121+
assert!(full.parse::<toml::Table>().is_ok());
122+
assert!(!example.contains("EnableConsole"));
123+
assert!(full.contains("#EnableConsole = true"));
124+
assert!(full.contains("#AppendConfigArgs = true"));
111125
}
112126
}

packages/applechu-schema/src/lib.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod generator;
44
use sha2::{Digest, Sha256};
55
use std::fmt;
66

7-
pub use example::{DEFAULT_CONFIG_HEADER, EXAMPLE_CONFIG_FILE};
7+
pub use example::{DEFAULT_CONFIG_HEADER, EXAMPLE_CONFIG_FILE, FULL_CONFIG_FILE};
88
pub use generator::generate_from_rust_dir;
99

1010
const MAGIC: &[u8; 8] = b"ACMANI\0\0";
@@ -485,7 +485,7 @@ fn enable_entry(default_on: bool) -> EntrySpec {
485485
min: None,
486486
max: None,
487487
emit_default: true,
488-
emit_comment: true,
488+
emit_comment: false,
489489
hidden: false,
490490
advanced: false,
491491
options: Vec::new(),
@@ -551,6 +551,7 @@ fn inject_enable_entries(
551551
enable.default.clone().expect("enable 必须包含代码默认值"),
552552
);
553553
entry.insert("emit_default".to_owned(), toml::Value::Boolean(true));
554+
entry.insert("emit_comment".to_owned(), toml::Value::Boolean(false));
554555
entry.insert("label".to_owned(), toml::Value::Table(label));
555556
entries.insert(0, toml::Value::Table(entry));
556557
}
@@ -971,9 +972,17 @@ mod tests {
971972
assert!(config.starts_with("## 这是 AppleChu 的 TOML 配置文件"));
972973
assert!(config.contains("ConfigVersion = 1"));
973974
assert!(amdaemon.contains("Enable = true"));
974-
assert!(amdaemon.contains("AutoStart = false"));
975-
assert!(amdaemon.contains("AppendConfigArgs = false"));
976-
assert!(amdaemon.contains("#ConfigFiles = [\"config_*.json\"]"));
975+
assert!(amdaemon.contains("#AutoStart = true"));
976+
assert!(!amdaemon.contains("AppendConfigArgs"));
977+
assert!(!amdaemon.contains("ConfigFiles"));
978+
assert!(!config.lines().any(|line| line == "## 启用"));
979+
assert_eq!(
980+
schema
981+
.entry("Dns", "ReplaceHost")
982+
.and_then(|entry| entry.default.as_ref())
983+
.and_then(toml::Value::as_bool),
984+
Some(true)
985+
);
977986
assert!(document["DisableEncryption"].as_table().is_some());
978987
assert!(document["DisableTLS"].as_table().is_some());
979988
assert!(config.contains("#GameId = \"SDHD\""));

packages/applechu-schema/tests/advanced_entry.rs

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,150 @@ fn advanced_entry_is_marked_and_omitted_from_default_config() {
1818
assert!(manifest.contains("advanced = true"));
1919
assert!(!default_config.contains("EnableConsole"));
2020
}
21+
22+
#[test]
23+
fn configured_advanced_entries_match_the_curated_list() {
24+
// Given: 少改动的配置项按 section 分组列入高级项清单。
25+
let schema = generate_from_rust_dir(concat!(env!("CARGO_MANIFEST_DIR"), "/../applechu/src"))
26+
.expect("Rust config declarations must generate schema");
27+
let expected = [
28+
(
29+
"Amdaemon",
30+
&[
31+
"Executable",
32+
"TerminateOnExit",
33+
"AppendConfigArgs",
34+
"ConfigFiles",
35+
][..],
36+
),
37+
(
38+
"Dns",
39+
&[
40+
"Router",
41+
"Startup",
42+
"Billing",
43+
"Aimedb",
44+
"Title",
45+
"ReplaceHost",
46+
"StartupPort",
47+
"BillingPort",
48+
"AimedbPort",
49+
],
50+
),
51+
(
52+
"Keychip",
53+
&[
54+
"PlatformId",
55+
"Region",
56+
"BillingType",
57+
"SystemFlag",
58+
"Subnet",
59+
"BillingCa",
60+
"BillingPub",
61+
],
62+
),
63+
(
64+
"Aime",
65+
&[
66+
"CvtPort",
67+
"SpPort",
68+
"HighBaud",
69+
"FelicaPath",
70+
"AuthdataPath",
71+
"AimeGen",
72+
"FelicaGen",
73+
"Scan",
74+
"Gen",
75+
"ProxyFlag",
76+
],
77+
),
78+
(
79+
"Io4",
80+
&[
81+
"Foreground",
82+
"Ir",
83+
"Air1",
84+
"Air2",
85+
"Air3",
86+
"Air4",
87+
"Air5",
88+
"Air6",
89+
"Cell1",
90+
"Cell2",
91+
"Cell3",
92+
"Cell4",
93+
"Cell5",
94+
"Cell6",
95+
"Cell7",
96+
"Cell8",
97+
"Cell9",
98+
"Cell10",
99+
"Cell11",
100+
"Cell12",
101+
"Cell13",
102+
"Cell14",
103+
"Cell15",
104+
"Cell16",
105+
"Cell17",
106+
"Cell18",
107+
"Cell19",
108+
"Cell20",
109+
"Cell21",
110+
"Cell22",
111+
"Cell23",
112+
"Cell24",
113+
"Cell25",
114+
"Cell26",
115+
"Cell27",
116+
"Cell28",
117+
"Cell29",
118+
"Cell30",
119+
"Cell31",
120+
"Cell32",
121+
],
122+
),
123+
(
124+
"Led",
125+
&[
126+
"CabLedOutputPipe",
127+
"CabLedOutputSerial",
128+
"ControllerLedOutputPipe",
129+
"ControllerLedOutputSerial",
130+
"ControllerLedOutputOpeNITHM",
131+
"SerialPort",
132+
"SerialBaud",
133+
],
134+
),
135+
(
136+
"Led15093",
137+
&[
138+
"Port0",
139+
"Port1",
140+
"BoardNumber",
141+
"ChipNumber",
142+
"BootChipNumber",
143+
"FwVer",
144+
"FwSum",
145+
"HighBaud",
146+
],
147+
),
148+
("Vfd", &["PortNo", "UtfConversion"]),
149+
("VFS", &["AllowAmfsDownloads"]),
150+
(
151+
"NetEnv",
152+
&["AddrSuffix", "RouterSuffix", "MacAddr", "Broadcast"],
153+
),
154+
];
155+
156+
// When/Then: 每个清单项都由 schema 标记为高级项。
157+
for (section, keys) in expected {
158+
for key in keys {
159+
assert!(
160+
schema
161+
.entry(section, key)
162+
.is_some_and(|entry| entry.advanced),
163+
"{section}.{key} must be advanced"
164+
);
165+
}
166+
}
167+
}

packages/applechu/src/aime/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,38 @@ crate::config_section! {
5454
fields: {
5555
// 两种机台默认使用 COM4,同时保留分模式覆盖项
5656
pub cvt_port: u32 = 4,
57+
advanced: true,
5758
comment: "CVT 模式串口号";
5859
pub sp_port: u32 = 4,
60+
advanced: true,
5961
comment: "SP 模式串口号";
6062
pub high_baudrate: bool = true,
6163
key: "highBaud",
64+
advanced: true,
6265
comment: "使用 115200 高波特率(Chunithm 默认需要)";
6366
pub aime_path: String = String::from("DEVICE\\aime.txt"),
6467
comment: "Aime 卡号文件";
6568
pub felica_path: String = String::from("DEVICE\\felica.txt"),
69+
advanced: true,
6670
comment: "FeliCa 卡号文件";
6771
pub authdata_path: String = String::from("DEVICE\\authdata.bin"),
72+
advanced: true,
6873
comment: "认证数据文件";
6974
pub aime_gen: bool = true,
75+
advanced: true,
7076
comment: "缺少 Aime 卡号时自动生成";
7177
pub felica_gen: bool = false,
78+
advanced: true,
7279
comment: "缺少 FeliCa 卡号时自动生成";
7380
pub scan: i32 = 0x0D,
81+
advanced: true,
7482
comment: "读卡按键的虚拟键码";
7583
// 0 表示按机台模式选择:CVT=Gen2,SP=Gen3
7684
pub gen: u8 = 0,
85+
advanced: true,
7786
comment: "读卡器代数";
7887
pub proxy_flag: u8 = 2,
88+
advanced: true,
7989
comment: "读卡代理标志";
8090
pub iodll: String = String::new(),
8191
comment: "外部 Aime IO DLL 路径";

0 commit comments

Comments
 (0)