import PathBuf
This commit is contained in:
parent
4199d41d3f
commit
dc9fd2c442
68
src/main.rs
68
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<std::path::PathBuf>,
|
||||
path:Option<PathBuf>,
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
@ -32,7 +32,7 @@ enum Commands {
|
||||
|
||||
#[derive(Args)]
|
||||
struct PathBufList {
|
||||
paths:Vec<std::path::PathBuf>
|
||||
paths:Vec<PathBuf>
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
@ -342,7 +342,7 @@ SurfaceAppearance.NormalMap
|
||||
SurfaceAppearance.RoughnessMap
|
||||
SurfaceAppearance.TexturePack
|
||||
*/
|
||||
fn download_textures(paths: Vec<std::path::PathBuf>) -> AResult<()>{
|
||||
fn download_textures(paths: Vec<PathBuf>) -> 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<std::path::PathBuf>) -> AResult<()>{
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn download_meshes(paths: Vec<std::path::PathBuf>) -> AResult<()>{
|
||||
fn download_meshes(paths: Vec<PathBuf>) -> 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<std::path::PathBuf>) -> AResult<()>{
|
||||
fn extract(paths: Vec<PathBuf>) -> AResult<()>{
|
||||
let mut id = 0;
|
||||
//Construct allowed scripts
|
||||
let mut script_set = std::collections::HashSet::<String>::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_loader<F:Fn(String)->AResult<Option<Vec<u8>>>>(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_loader<F:Fn(String)->AResult<Option<Vec<u8>>>>(find_stuff:&F,ma
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_paths:Vec<std::path::PathBuf>)->AResult<()>{
|
||||
fn extract_textures(paths:Vec<PathBuf>,vpk_paths:Vec<PathBuf>)->AResult<()>{
|
||||
let vpk_list:Vec<vpk::VPK>=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<std::path::PathBuf>,vpk_paths:Vec<std::path::PathB
|
||||
//grab texture names from props
|
||||
for model_name in model_dedupe{
|
||||
//.mdl, .vvd, .dx90.vtx
|
||||
let mut path=std::path::PathBuf::from(model_name);
|
||||
let file_name=std::path::PathBuf::from(path.file_stem().unwrap());
|
||||
let mut path=PathBuf::from(model_name);
|
||||
let file_name=PathBuf::from(path.file_stem().unwrap());
|
||||
path.pop();
|
||||
path.push(file_name);
|
||||
let mut vvd_path=path.clone();
|
||||
@ -1158,7 +1158,7 @@ fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_paths:Vec<std::path::PathB
|
||||
let model=vmdl::Model::from_parts(mdl,vtx,vvd);
|
||||
for texture in model.textures(){
|
||||
for search_path in &texture.search_paths{
|
||||
let mut path=std::path::PathBuf::from(search_path.as_str());
|
||||
let mut path=PathBuf::from(search_path.as_str());
|
||||
path.push(texture.name.as_str());
|
||||
deduplicate.insert(path);
|
||||
}
|
||||
@ -1195,7 +1195,7 @@ fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_paths:Vec<std::path::PathB
|
||||
)?;
|
||||
|
||||
//write dds
|
||||
let mut dest=std::path::PathBuf::from("textures/dds");
|
||||
let mut dest=PathBuf::from("textures/dds");
|
||||
dest.push(write_file_name);
|
||||
dest.set_extension("dds");
|
||||
std::fs::create_dir_all(dest.parent().unwrap())?;
|
||||
@ -1221,12 +1221,12 @@ fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_paths:Vec<std::path::PathB
|
||||
Ok::<Option<Vec<u8>>,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<std::path::PathBuf>,vpk_paths:Vec<std::path::PathB
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn vpk_contents(vpk_path:std::path::PathBuf)->AResult<()>{
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user