From ffb4b09e77e24a52f3330687e8ccec48c832634a Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 11 Sep 2023 19:18:55 -0700 Subject: [PATCH] scan enum, Source property missing if fatal --- src/main.rs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 23c504c..d5395aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,6 +78,11 @@ fn download(map_list: Vec) -> Result<(), Box>{ } Ok(()) } + +enum Scan{ + Passed, + Blocked, +} fn scan() -> Result<(), Box>{ let mut id = 0u32; match std::fs::read_to_string("id"){ @@ -106,15 +111,15 @@ fn scan() -> Result<(), Box>{ let scripts = get_scripts(dom); //check scribb - let mut any_failed=false; + let mut fail_count=0; + let mut fail_type=Scan::Passed; for script in scripts.iter() { if let Some(rbx_dom_weak::types::Variant::String(s)) = script.properties.get("Source") { if allowed_set.contains(s) { - println!("pass"); continue; }else{ - println!("fail"); - any_failed=true; + fail_type=Scan::Blocked;//no need to check for Flagged, it breaks the loop. + fail_count+=1; if !blocked.contains(s) { blocked.insert(s.clone());//all fixed! just clone! std::fs::write(format!("scripts/blocked/{}.lua",id),s)?; @@ -122,18 +127,18 @@ fn scan() -> Result<(), Box>{ } } }else{ - println!("failed to get source"); - any_failed=true; + panic!("FATAL: failed to get source for {:?}",file_thing.file_name()); } } - if any_failed { - println!("One or more scripts are not allowed."); - }else{ - let mut dest=std::path::PathBuf::from("maps/processed"); - dest.set_file_name(file_thing.file_name()); - dest.set_extension("rbxl");//extension is always rbxl even if source file is extensionless - std::fs::rename(file_thing.path(), dest)?; - } + let mut dest=match fail_type { + Scan::Passed => std::path::PathBuf::from("maps/processed"), + Scan::Blocked => { + println!("{:?} - {} {} not allowed.",file_thing.file_name(),fail_count,if fail_count==1 {"script"}else{"scripts"}); + std::path::PathBuf::from("maps/purgatory") + } + }; + dest.push(file_thing.file_name()); + std::fs::rename(file_thing.path(), dest)?; } std::fs::write("id",id.to_string())?; Ok(())