//! For tools/winws-dry-run.sh: a preset's winws arguments as the service builds them, one //! per line. `zapret_args [ ]`, Windows paths with a //! trailing separator. With rules, their lists are written into the lists dir. use ps_core::config::{GameFilter, HostlistRule}; use ps_core::zapret::{ReleaseLists, expand, find_preset, preset_args, rule, rule_lists, with_rules}; fn main() { let a: Vec = std::env::args().collect(); let (release, win_root, win_lists, preset, game) = (&a[1], &a[2], &a[3], &a[4], &a[5]); let release = std::path::Path::new(release); let files: Vec = std::fs::read_dir(release).unwrap().filter_map(|e| e.ok()?.file_name().into_string().ok()).collect(); let game: GameFilter = serde_json::from_value(serde_json::json!(game)).unwrap(); let bin = format!("{win_root}bin\\"); let ex = |args: &[String]| expand(args, &bin, win_lists, win_root, game); let args_of = |name: &str| -> Result, String> { let file = find_preset(&files, name)?; Ok(ex(&preset_args(&std::fs::read_to_string(release.join(file)).unwrap())?)) }; let mut args = args_of(preset).unwrap(); if let (Some(json), Some(lists)) = (a.get(6), a.get(7)) { let read = |f: &str| std::fs::read_to_string(release.join("lists").join(f)).unwrap_or_default(); let (general, google, ipset_all) = (read("list-general.txt"), read("list-google.txt"), read("ipset-all.txt")); let release_lists = ReleaseLists { general: &general, google: &google, ipset_all: &ipset_all }; let raw: Vec = serde_json::from_str(&std::fs::read_to_string(json).unwrap()).unwrap(); let rules: Vec<_> = raw.iter().map(|r| rule(r, &release_lists).unwrap()).collect(); for r in &rules { let (list, ipset) = rule_lists(r); for (file, entries) in [(list, &r.domains), (ipset, &r.ips)] { if !entries.is_empty() { std::fs::write(std::path::Path::new(lists).join(file), format!("{}\n", entries.join("\n"))).unwrap(); } } } args = match with_rules(args, &rules, win_lists, &args_of, &ex) { Ok(a) => a, Err(e) => { eprintln!("{e}"); std::process::exit(2); } }; } for arg in args { println!("{arg}"); } }