Refactor a bit

This commit is contained in:
Piotr Siuszko 2023-12-23 18:06:37 +01:00
parent fe6e8bcf65
commit 4c182f8f67
1 changed files with 34 additions and 16 deletions

View File

@ -5,6 +5,7 @@ use flate2::read::GzDecoder;
use tar::Archive; use tar::Archive;
use std::collections::HashMap; use std::collections::HashMap;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::hash::Hash;
use std::io::prelude::*; use std::io::prelude::*;
use std::io::BufReader; use std::io::BufReader;
use std::process::Command; use std::process::Command;
@ -71,34 +72,51 @@ fn main() {
println!("Results:"); println!("Results:");
for (asset_hash, asset_path) in &mapping { for (asset_hash, asset_path) in &mapping {
println!("{}: {}", asset_hash, asset_path);
let path = Path::new(asset_path); let path = Path::new(asset_path);
let source_asset = Path::new(tmp_dir).join(asset_hash).join("asset"); let source_asset = Path::new(tmp_dir).join(asset_hash).join("asset");
let result_path = output_dir.join(path); let result_path = output_dir.join(&path);
process_directory(asset_hash, asset_path, &result_path);
check_source_asset_exists(&source_asset);
if let Some("fbx") = path.extension().and_then(OsStr::to_str) {
process_fbx_file(&source_asset, &result_path);
continue;
}
process_non_fbx_file(&source_asset, &result_path);
}
fs::remove_dir_all(tmp_dir).unwrap();
fn process_directory(asset_hash: &str, asset_path: &str, result_path: &Path) {
println!("{}: {:?}", asset_hash, asset_path);
let result_dir = result_path.parent().unwrap(); let result_dir = result_path.parent().unwrap();
if !result_dir.exists() { if !result_dir.exists() {
fs::create_dir_all(result_dir).unwrap(); fs::create_dir_all(result_dir).unwrap();
} }
}
fn check_source_asset_exists(source_asset: &Path) {
if !source_asset.exists() { if !source_asset.exists() {
panic!("SOURCE ASSET DOES NOT EXIST: {}", source_asset.display()); panic!("SOURCE ASSET DOES NOT EXIST: {}", source_asset.display());
} }
if let Some("fbx") = path.extension().and_then(OsStr::to_str) { }
fn process_fbx_file(source_asset: &Path, result_path: &Path) {
let out_path = result_path.with_extension(""); let out_path = result_path.with_extension("");
println!("{:?}", &["--input", source_asset.to_str().unwrap(), "--output", out_path.to_str().unwrap()]); println!("{:?}", &["--input", source_asset.to_str().unwrap(), "--output", out_path.to_str().unwrap()]);
let output = Command::new("C:\\tools\\FBX2glTF.exe") let output = Command::new("C:\\tools\\FBX2glTF.exe")
.args(&["--input", source_asset.to_str().unwrap(), "-b", "--output", out_path.to_str().unwrap()]) .args(&["--input", source_asset.to_str().unwrap(), "-b", "--output", out_path.to_str().unwrap()])
.output().unwrap(); .output().unwrap();
let output_result = String::from_utf8_lossy(&output.stdout); let output_result = String::from_utf8_lossy(&output.stdout);
println!("output: {}", output_result); println!("output: {}", output_result);
continue;
} }
fn process_non_fbx_file(source_asset: &Path, result_path: &Path) {
fs::rename(source_asset, result_path).unwrap(); fs::rename(source_asset, result_path).unwrap();
} }
//fs::remove_dir_all(tmp_dir).unwrap();
} }