copy meta files alongside regular files, v0.3.0

This commit is contained in:
Piotr Siuszko 2023-12-27 23:42:22 +01:00
parent a9426fc3b9
commit ef54eef2e0
5 changed files with 21 additions and 3 deletions

View File

@ -2,6 +2,10 @@
## [0.3.0]
### Added
- New flag `--copy-meta-files` for copying meta files alongside assets.
### Changed
- Multithreaded unpacking improvements.

View File

@ -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"

View File

@ -18,6 +18,8 @@ Options:
-f, --fbx-to-gltf <FBX_TO_GLTF> optional- path to the tool that will auto convert fbx files to gltf during unpacking
--ignore-extensions <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
```

View File

@ -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<Vec<String>>,
/// copy meta files alongside regular files
#[arg(long, default_value = "false", default_missing_value = "true")]
pub copy_meta_files: bool,
}

View File

@ -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<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 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() {