From 29374e4ff5c2ac3de44174392939257c422bac58 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 12 Sep 2023 17:34:43 -0700 Subject: [PATCH] write edited file and report how many scripts were replaced --- src/main.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9430207..b100163 100644 --- a/src/main.rs +++ b/src/main.rs @@ -315,6 +315,7 @@ fn interactive() -> Result<(), Box>{ //check scribb let mut script_count=0; + let mut replace_count=0; let mut block_count=0; let mut fail_type=Interactive::Passed; for script in scripts.iter() { @@ -392,6 +393,7 @@ fn interactive() -> Result<(), Box>{ //replace the source let location=get_full_name(&write_dom, script); if let (Some(replace_source),Some(replace_script))=(allowed_map.get(&replace_id),write_dom.get_by_ref_mut(script.referent())){ + replace_count+=1; println!("replaced source id={} location={}",replace_id,location); replace_script.properties.insert("Source".to_string(), rbx_dom_weak::types::Variant::String(replace_source.clone())); }else{ @@ -418,7 +420,18 @@ fn interactive() -> Result<(), Box>{ let mut dest=match fail_type{ Interactive::Passed => { println!("map={:?} passed with {} {}",file_thing.file_name(),script_count,if script_count==1 {"script"}else{"scripts"}); - std::path::PathBuf::from("maps/processed") + if replace_count==0{ + std::path::PathBuf::from("maps/passed") + }else{ + //create new file + println!("{} {} replaced - generating new file...",replace_count,if replace_count==1 {"script was"}else{"scripts were"}); + let mut dest=std::path::PathBuf::from("maps/passed"); + dest.push(file_thing.file_name()); + let output = std::io::BufWriter::new(std::fs::File::create(dest)?); + rbx_binary::to_writer(output, &dom, &[dom.root_ref()])?; + //move original to processed folder + std::path::PathBuf::from("maps/unaltered") + } },//write map into maps/processed Interactive::Blocked => { println!("map={:?} blocked with {}/{} {} blocked",file_thing.file_name(),block_count,script_count,if script_count==1 {"script"}else{"scripts"});