use toml::from_str;
use xcell_types::TypeMetaInfo;
use crate::{config::table::TableLineMode, MergeRules};
use super::*;
#[derive(Clone, Debug)]
pub struct ProjectConfig {
pub root: PathBuf,
pub version: String,
pub include: String,
pub exclude: String,
pub line: TableLineMode,
pub typing: TypeMetaInfo,
pub merge: MergeRules,
pub unity: UnityCodegen,
}
mod der;
mod ser;
impl ProjectConfig {
pub fn new(workspace: &Path) -> Self {
log::info!("工作目录: {}", workspace.display());
let cfg = workspace.join("XCell.toml");
let success;
let mut config = match Self::load_toml(&cfg) {
Ok(o) => {
success = "成功";
o
}
Err(e) => {
success = "失败";
log::error!("{}", e.with_path(&cfg));
Default::default()
}
};
config.root = workspace.to_path_buf();
log::trace!("加载项目配置{success}, 当前配置\n{config:#?}");
config
}
fn load_toml(file: &Path) -> XResult<Self> {
if file.exists() {
let text = read_to_string(file)?;
Ok(from_str(&text)?)
}
else {
Err(XError::table_error("XCell.toml 不存在"))
}
}
}
impl WorkspaceManager {
pub fn get_relative(&self, file: &Path) -> XResult<PathBuf> {
get_relative(file, &self.config.root)
}
pub fn disable_xml(&mut self) {
self.config.unity.xml.enable = false;
}
pub fn disable_json(&self) {
}
pub fn dry_run(&mut self) {
self.disable_xml();
self.disable_json();
}
pub fn clear(&self) -> XResult<()> {
Ok(())
}
}