不将配置文件保存到磁盘

This commit is contained in:
2026-01-29 00:00:29 +08:00
parent 8caed3c8b4
commit f1a8a6e28a

View File

@@ -124,11 +124,12 @@ is_decompose = {is_decompose}
}
pub fn save_with_comments(&self, path: impl AsRef<Path>) -> io::Result<()> {
let path = path.as_ref();
/*let path = path.as_ref();
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}
fs::write(path, self.to_toml_with_comments())
fs::write(path, self.to_toml_with_comments())*/
Ok(())
}
/// 读取配置:不存在则创建(写入默认值+注释),存在则从文件构造实例。
@@ -136,7 +137,7 @@ is_decompose = {is_decompose}
/// - toml 缺字段:会自动用 Default 补齐(因为 #[serde(default)]
/// - 可选:如果你想“读取后把缺的字段补齐回写”,这里也做了回写
pub fn load_or_create(path: impl AsRef<Path>) -> Result<Self, Box<dyn std::error::Error>> {
let path = path.as_ref();
/*let path = path.as_ref();
if !path.exists() {
let cfg = Self::default();
@@ -149,7 +150,15 @@ is_decompose = {is_decompose}
// 可选:自动回写补全(比如用户旧版配置少字段时,补齐并带注释写回去)
// 如果你不想覆盖用户文件,把下面两行删掉即可。
cfg.save_with_comments(path)?;
cfg.save_with_comments(path)?;*/
let cfg = Config {
is_daily_missions: true,
is_archipelago: true,
is_spiral_abyss: false,
is_demonic_energy: true,
is_forest: true,
is_decompose: true,
};
Ok(cfg)
}