From ef54eef2e009a0aec86d90a05e06870917afe44b Mon Sep 17 00:00:00 2001 From: Piotr Siuszko Date: Wed, 27 Dec 2023 23:42:22 +0100 Subject: [PATCH] copy meta files alongside regular files, v0.3.0 --- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- README.md | 2 ++ src/args.rs | 6 +++++- src/unpacker.rs | 10 +++++++++- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9323173..126ba46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [0.3.0] +### Added + +- New flag `--copy-meta-files` for copying meta files alongside assets. + ### Changed - Multithreaded unpacking improvements. diff --git a/Cargo.toml b/Cargo.toml index 43addfd..fa04568 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lwa_unity_unpack" -version = "0.2.1" +version = "0.3.0" edition = "2021" repository = "https://github.com/Leinnan/lwa_unity_unpack" homepage = "https://github.com/Leinnan/lwa_unity_unpack" diff --git a/README.md b/README.md index b06c8f4..f2b205a 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ Options: -f, --fbx-to-gltf optional- path to the tool that will auto convert fbx files to gltf during unpacking --ignore-extensions optional- extensions that will be ignored during unpacking + --copy-meta-files + copy meta files alongside regular files -h, --help Print help -V, --version Print version ``` diff --git a/src/args.rs b/src/args.rs index c46d32f..6de2b6f 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1,5 +1,5 @@ use clap::Parser; -use std::path::{PathBuf}; +use std::path::PathBuf; /// Program for unpacking unitypackages files. #[derive(Parser, Debug, Clone)] @@ -19,4 +19,8 @@ pub struct Args { /// optional- extensions that will be ignored during unpacking #[arg(long, action = clap::ArgAction::Append)] pub ignore_extensions: Option>, + + /// copy meta files alongside regular files + #[arg(long, default_value = "false", default_missing_value = "true")] + pub copy_meta_files: bool, } diff --git a/src/unpacker.rs b/src/unpacker.rs index 655b7d0..d33eceb 100644 --- a/src/unpacker.rs +++ b/src/unpacker.rs @@ -39,6 +39,7 @@ impl Unpacker { pub fn process_data(&self) { 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"); if let Err(e) = Unpacker::extract_archive(archive_path, tmp_path) { println!("Failed to extract archive: {}", e); @@ -67,13 +68,20 @@ impl Unpacker { let mapping: Vec = 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 path = Path::new(&asset.path_name); let source_asset = Path::new(&*tmp_dir).join(asset_hash).join("asset"); let result_path = output_dir.join(path); process_directory(asset_hash, &asset.path_name, &result_path); + if copy_meta_files && asset.has_meta { + let source_meta = Path::new(&*tmp_dir).join(asset_hash).join("asset.meta"); + let mut meta_path = asset.path_name.clone(); + meta_path.push_str(".meta"); + let result_path = output_dir.join(meta_path); + fs::rename(source_meta, result_path).unwrap(); + } check_source_asset_exists(&source_asset); if self.args.fbx_to_gltf.is_some() {