extract fn, store assets in Unpacker struct
This commit is contained in:
parent
ef54eef2e0
commit
08aecd4004
|
|
@ -6,8 +6,9 @@ use clap::Parser;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = crate::args::Args::parse();
|
let args = crate::args::Args::parse();
|
||||||
let unpacker = crate::unpacker::Unpacker { args };
|
let mut unpacker = crate::unpacker::Unpacker { args, assets: vec![] };
|
||||||
|
|
||||||
unpacker.prepare_environment();
|
unpacker.prepare_environment();
|
||||||
|
unpacker.extract();
|
||||||
unpacker.process_data();
|
unpacker.process_data();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ use rayon::prelude::*;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
use std::io::BufReader;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
|
@ -16,6 +15,7 @@ use tar::Archive;
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Unpacker {
|
pub struct Unpacker {
|
||||||
pub args: crate::args::Args,
|
pub args: crate::args::Args,
|
||||||
|
pub assets: Vec<crate::asset::Asset>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Unpacker {
|
impl Unpacker {
|
||||||
|
|
@ -35,12 +35,10 @@ impl Unpacker {
|
||||||
fs::remove_dir_all(output_dir).unwrap();
|
fs::remove_dir_all(output_dir).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn extract(&mut self) {
|
||||||
pub fn process_data(&self) {
|
|
||||||
let archive_path = Path::new(&self.args.input);
|
let archive_path = Path::new(&self.args.input);
|
||||||
let output_dir = Path::new(&self.args.output);
|
|
||||||
let copy_meta_files = self.args.copy_meta_files;
|
|
||||||
let tmp_path = Path::new("./tmp_dir");
|
let tmp_path = Path::new("./tmp_dir");
|
||||||
|
|
||||||
if let Err(e) = Unpacker::extract_archive(archive_path, tmp_path) {
|
if let Err(e) = Unpacker::extract_archive(archive_path, tmp_path) {
|
||||||
println!("Failed to extract archive: {}", e);
|
println!("Failed to extract archive: {}", e);
|
||||||
}
|
}
|
||||||
|
|
@ -61,12 +59,18 @@ impl Unpacker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
self.assets = receiver.iter().collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn process_data(&self) {
|
||||||
|
let output_dir = Path::new(&self.args.output);
|
||||||
|
let copy_meta_files = self.args.copy_meta_files;
|
||||||
|
let tmp_path = Path::new("./tmp_dir");
|
||||||
|
|
||||||
|
let mapping_arc = Arc::new(&self.assets);
|
||||||
let tmp_dir = Arc::new(tmp_path);
|
let tmp_dir = Arc::new(tmp_path);
|
||||||
fs::create_dir(output_dir).unwrap();
|
fs::create_dir(output_dir).unwrap();
|
||||||
let output_dir = Arc::new(output_dir);
|
let output_dir = Arc::new(output_dir);
|
||||||
let mapping: Vec<Asset> = receiver.iter().collect();
|
|
||||||
let mapping_arc = Arc::new(mapping);
|
|
||||||
|
|
||||||
mapping_arc.par_iter().for_each(|asset| {
|
mapping_arc.par_iter().for_each(|asset| {
|
||||||
let asset_hash = &asset.hash;
|
let asset_hash = &asset.hash;
|
||||||
|
|
@ -82,7 +86,10 @@ impl Unpacker {
|
||||||
let result_path = output_dir.join(meta_path);
|
let result_path = output_dir.join(meta_path);
|
||||||
fs::rename(source_meta, result_path).unwrap();
|
fs::rename(source_meta, result_path).unwrap();
|
||||||
}
|
}
|
||||||
check_source_asset_exists(&source_asset);
|
|
||||||
|
if !source_asset.exists() {
|
||||||
|
panic!("SOURCE ASSET DOES NOT EXIST: {}", source_asset.display());
|
||||||
|
}
|
||||||
|
|
||||||
if self.args.fbx_to_gltf.is_some() {
|
if self.args.fbx_to_gltf.is_some() {
|
||||||
if let Some("fbx") = path.extension().and_then(OsStr::to_str) {
|
if let Some("fbx") = path.extension().and_then(OsStr::to_str) {
|
||||||
|
|
@ -108,12 +115,6 @@ impl Unpacker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_source_asset_exists(source_asset: &Path) {
|
|
||||||
if !source_asset.exists() {
|
|
||||||
panic!("SOURCE ASSET DOES NOT EXIST: {}", source_asset.display());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn process_fbx_file(source_asset: &Path, result_path: &Path, tool: &PathBuf) {
|
fn process_fbx_file(source_asset: &Path, result_path: &Path, tool: &PathBuf) {
|
||||||
let out_path = result_path.with_extension("");
|
let out_path = result_path.with_extension("");
|
||||||
println!(
|
println!(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue