scan enum, Source property missing if fatal

This commit is contained in:
Quaternions 2023-09-11 19:18:55 -07:00
parent 06384f1086
commit ffb4b09e77

View File

@ -78,6 +78,11 @@ fn download(map_list: Vec<u64>) -> Result<(), Box<dyn std::error::Error>>{
}
Ok(())
}
enum Scan{
Passed,
Blocked,
}
fn scan() -> Result<(), Box<dyn std::error::Error>>{
let mut id = 0u32;
match std::fs::read_to_string("id"){
@ -106,15 +111,15 @@ fn scan() -> Result<(), Box<dyn std::error::Error>>{
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<dyn std::error::Error>>{
}
}
}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(())