Added Core Features chroium, config,console_ui,headless,webserver,states
This commit is contained in:
parent
4c6c6d572c
commit
c3c60efb81
13 changed files with 688 additions and 0 deletions
57
Core/config/mod.rs
Normal file
57
Core/config/mod.rs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
mod default;
|
||||
|
||||
use default::default_config;
|
||||
use std::{fs, io, path::{Path, PathBuf}};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ChromeCfg {
|
||||
pub path: String, // kann leer sein => auto-download
|
||||
pub args: Vec<String>, // SSL-Flags etc.
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ServerCfg {
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub server: ServerCfg,
|
||||
pub chrome: ChromeCfg,
|
||||
}
|
||||
|
||||
const CONF_NAME: &str = "server.conf";
|
||||
|
||||
pub fn read_config(dir: &Path) -> io::Result<Config> {
|
||||
let path = dir.join(CONF_NAME);
|
||||
|
||||
if !path.exists() {
|
||||
let def = default_config();
|
||||
let toml_str = toml::to_string_pretty(&def)
|
||||
.expect("Default Config serialisieren fehlgeschlagen");
|
||||
fs::write(&path, toml_str)?;
|
||||
Ok(def)
|
||||
} else {
|
||||
let content = fs::read_to_string(&path)?;
|
||||
let cfg: Config = toml::from_str(&content)
|
||||
.unwrap_or_else(|_| {
|
||||
eprintln!("[Aurora] WARNUNG: Config beschädigt – lade Default.");
|
||||
default_config()
|
||||
});
|
||||
Ok(cfg)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save_config(dir: &Path, cfg: &Config) -> io::Result<()> {
|
||||
let path = dir.join(CONF_NAME);
|
||||
let toml_str = toml::to_string_pretty(cfg)
|
||||
.expect("Config serialisieren fehlgeschlagen");
|
||||
fs::write(path, toml_str)
|
||||
}
|
||||
|
||||
/// Hilfsfunktion: macht aus einem (ggf. relativen) Pfad einen absoluten Pfad relativ zur EXE.
|
||||
pub fn resolve_path(exe_dir: &Path, p: &str) -> PathBuf {
|
||||
let pb = PathBuf::from(p);
|
||||
if pb.is_absolute() { pb } else { exe_dir.join(pb) }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue