write edited file and report how many scripts were replaced

This commit is contained in:
Quaternions 2023-09-12 17:34:43 -07:00
parent b7d04d1f40
commit 29374e4ff5

View File

@ -315,6 +315,7 @@ fn interactive() -> Result<(), Box<dyn std::error::Error>>{
//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<dyn std::error::Error>>{
//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<dyn std::error::Error>>{
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"});