diff --git a/src/main.rs b/src/main.rs index fd56d4e..1df1b70 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::io::{Read, Seek}; +use std::{io::{Read, Seek}, path::PathBuf}; use clap::{Args, Parser, Subcommand}; use anyhow::Result as AResult; @@ -7,7 +7,7 @@ use anyhow::Result as AResult; #[command(propagate_version = true)] struct Cli { #[arg(long)] - path:Option, + path:Option, #[command(subcommand)] command: Commands, } @@ -32,7 +32,7 @@ enum Commands { #[derive(Args)] struct PathBufList { - paths:Vec + paths:Vec } #[derive(Args)] @@ -342,7 +342,7 @@ SurfaceAppearance.NormalMap SurfaceAppearance.RoughnessMap SurfaceAppearance.TexturePack */ -fn download_textures(paths: Vec) -> AResult<()>{ +fn download_textures(paths: Vec) -> AResult<()>{ println!("download_textures paths:{:?}",paths); let header=format!("Cookie: .ROBLOSECURITY={}",std::env::var("RBXCOOKIE")?); let shared_args=&[ @@ -387,7 +387,7 @@ fn download_textures(paths: Vec) -> AResult<()>{ } Ok(()) } -fn download_meshes(paths: Vec) -> AResult<()>{ +fn download_meshes(paths: Vec) -> AResult<()>{ println!("download_meshes paths:{:?}",paths); let header=format!("Cookie: .ROBLOSECURITY={}",std::env::var("RBXCOOKIE")?); let shared_args=&[ @@ -476,7 +476,7 @@ fn convert(file_thing:std::fs::DirEntry) -> AResult<()>{ )?; //write dds - let mut dest=std::path::PathBuf::from("textures/dds"); + let mut dest=PathBuf::from("textures/dds"); dest.push(file_thing.file_name()); dest.set_extension("dds"); let mut writer = std::io::BufWriter::new(std::fs::File::create(dest)?); @@ -484,14 +484,14 @@ fn convert(file_thing:std::fs::DirEntry) -> AResult<()>{ if let Some(mut extracted)=extracted_input{ //write extracted to processed - let mut dest=std::path::PathBuf::from("textures/processed"); + let mut dest=PathBuf::from("textures/processed"); dest.push(file_thing.file_name()); std::fs::write(dest, &mut extracted)?; //delete ugly gzip file std::fs::remove_file(file_thing.path())?; }else{ //move file to processed - let mut dest=std::path::PathBuf::from("textures/processed"); + let mut dest=PathBuf::from("textures/processed"); dest.push(file_thing.file_name()); std::fs::rename(file_thing.path(), dest)?; } @@ -575,12 +575,12 @@ fn scan() -> AResult<()>{ } } let mut dest=match fail_type { - Scan::Passed => std::path::PathBuf::from("maps/processed"), + Scan::Passed => 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/blocked") + PathBuf::from("maps/blocked") } - Scan::Flagged => std::path::PathBuf::from("maps/flagged") + Scan::Flagged => PathBuf::from("maps/flagged") }; dest.push(file_thing.file_name()); std::fs::rename(file_thing.path(), dest)?; @@ -589,7 +589,7 @@ fn scan() -> AResult<()>{ Ok(()) } -fn extract(paths: Vec) -> AResult<()>{ +fn extract(paths: Vec) -> AResult<()>{ let mut id = 0; //Construct allowed scripts let mut script_set = std::collections::HashSet::::new(); @@ -664,7 +664,7 @@ fn replace() -> AResult<()>{ if any_failed { println!("One or more scripts failed to replace."); }else{ - let mut dest=std::path::PathBuf::from("maps/unprocessed"); + let mut dest=PathBuf::from("maps/unprocessed"); dest.push(file_thing.file_name()); let output = std::io::BufWriter::new(std::fs::File::open(dest)?); //write workspace:GetChildren()[1] @@ -740,7 +740,7 @@ fn upload() -> AResult<()>{ match status.code() { Some(0)=>{ //move file - let mut dest=std::path::PathBuf::from("maps/uploaded"); + let mut dest=PathBuf::from("maps/uploaded"); dest.push(file_thing.file_name()); std::fs::rename(file_thing.path(), dest)?; } @@ -761,7 +761,7 @@ fn upload() -> AResult<()>{ //print output println!("{}", std::str::from_utf8(output.stdout.as_slice())?); //move file - let mut dest=std::path::PathBuf::from("maps/uploaded"); + let mut dest=PathBuf::from("maps/uploaded"); dest.push(file_thing.file_name()); std::fs::rename(file_thing.path(), dest)?; } @@ -948,11 +948,11 @@ fn interactive() -> AResult<()>{ Interactive::Passed => { println!("map={:?} passed with {} {}",file_thing.file_name(),script_count,if script_count==1 {"script"}else{"scripts"}); if replace_count==0{ - std::path::PathBuf::from("maps/passed") + 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"); + let mut dest=PathBuf::from("maps/passed"); dest.push(file_thing.file_name()); let output = std::io::BufWriter::new(std::fs::File::create(dest)?); //write workspace:GetChildren()[1] @@ -962,16 +962,16 @@ fn interactive() -> AResult<()>{ } rbx_binary::to_writer(output, &dom, &[workspace_children[0]])?; //move original to processed folder - std::path::PathBuf::from("maps/unaltered") + 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"}); - std::path::PathBuf::from("maps/blocked") + PathBuf::from("maps/blocked") },//write map into maps/blocked Interactive::Flagged => { println!("map={:?} flagged",file_thing.file_name()); - std::path::PathBuf::from("maps/flagged") + PathBuf::from("maps/flagged") },//write map into maps/flagged }; dest.push(file_thing.file_name()); @@ -994,7 +994,7 @@ fn unzip_all()->AResult<()>{ //read the entire thing to the end so that I can clone the data and write a png to processed images readable.read_to_end(&mut extracted)?; //write extracted - let mut dest=std::path::PathBuf::from("maps/unzipped"); + let mut dest=PathBuf::from("maps/unzipped"); dest.push(file_thing.file_name()); std::fs::write(dest, &mut extracted)?; //delete ugly gzip file @@ -1034,7 +1034,7 @@ fn write_attributes() -> AResult<()>{ } } let mut dest={ - let mut dest=std::path::PathBuf::from("maps/attributes"); + let mut dest=PathBuf::from("maps/attributes"); dest.push(file_thing.file_name()); let output = std::io::BufWriter::new(std::fs::File::create(dest)?); //write workspace:GetChildren()[1] @@ -1044,7 +1044,7 @@ fn write_attributes() -> AResult<()>{ } rbx_binary::to_writer(output, &dom, &[workspace_children[0]])?; //move original to processed folder - std::path::PathBuf::from("maps/unaltered") + PathBuf::from("maps/unaltered") }; dest.push(file_thing.file_name()); std::fs::rename(file_thing.path(), dest)?; @@ -1108,7 +1108,7 @@ fn recursive_vmt_loaderAResult>>>(find_stuff:&F,ma match get_some_texture(material)?{ VMTContent::VMT(s)=>recursive_vmt_loader(find_stuff,get_vmt(find_stuff,s)?), VMTContent::VTF(s)=>{ - let mut texture_file_name=std::path::PathBuf::from("materials"); + let mut texture_file_name=PathBuf::from("materials"); texture_file_name.push(s); texture_file_name.set_extension("vtf"); find_stuff(texture_file_name.into_os_string().into_string().unwrap()) @@ -1126,13 +1126,13 @@ fn recursive_vmt_loaderAResult>>>(find_stuff:&F,ma } } -fn extract_textures(paths:Vec,vpk_paths:Vec)->AResult<()>{ +fn extract_textures(paths:Vec,vpk_paths:Vec)->AResult<()>{ let vpk_list:Vec=vpk_paths.into_iter().map(|vpk_path|vpk::VPK::read(&vpk_path).expect("vpk file does not exist")).collect(); for path in paths{ let mut deduplicate=std::collections::HashSet::new(); let bsp=vbsp::Bsp::read(std::fs::read(path)?.as_ref())?; for texture in bsp.textures(){ - deduplicate.insert(std::path::PathBuf::from(texture.name())); + deduplicate.insert(PathBuf::from(texture.name())); } //dedupe prop models let mut model_dedupe=std::collections::HashSet::new(); @@ -1143,8 +1143,8 @@ fn extract_textures(paths:Vec,vpk_paths:Vec,vpk_paths:Vec,vpk_paths:Vec,vpk_paths:Vec>,anyhow::Error>(None) }; let loader=|texture_name:String|{ - let mut texture_file_name=std::path::PathBuf::from("materials"); + let mut texture_file_name=PathBuf::from("materials"); //lower case let texture_file_name_lowercase=texture_name.to_lowercase(); texture_file_name.push(texture_file_name_lowercase.clone()); //remove stem and search for both vtf and vmt files - let stem=std::path::PathBuf::from(texture_file_name.file_stem().unwrap()); + let stem=PathBuf::from(texture_file_name.file_stem().unwrap()); texture_file_name.pop(); texture_file_name.push(stem); //somehow search for both files @@ -1260,7 +1260,7 @@ fn extract_textures(paths:Vec,vpk_paths:VecAResult<()>{ +fn vpk_contents(vpk_path:PathBuf)->AResult<()>{ let vpk_index=vpk::VPK::read(&vpk_path)?; for (label,entry) in vpk_index.tree.into_iter(){ println!("vpk label={} entry={:?}",label,entry); @@ -1268,7 +1268,7 @@ fn vpk_contents(vpk_path:std::path::PathBuf)->AResult<()>{ Ok(()) } -fn bsp_contents(path:std::path::PathBuf)->AResult<()>{ +fn bsp_contents(path:PathBuf)->AResult<()>{ let bsp=vbsp::Bsp::read(std::fs::read(path)?.as_ref())?; for file_name in bsp.pack.into_zip().into_inner().unwrap().file_names(){ println!("file_name={:?}",file_name);