Skip to content

Commit

Permalink
copy meta files alongside regular files, v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Leinnan committed Dec 27, 2023
1 parent a9426fc commit ef54eef
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [0.3.0]

### Added

- New flag `--copy-meta-files` for copying meta files alongside assets.

### Changed

- Multithreaded unpacking improvements.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
6 changes: 5 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use std::path::{PathBuf};
use std::path::PathBuf;

/// Program for unpacking unitypackages files.
#[derive(Parser, Debug, Clone)]
Expand All @@ -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,
}
10 changes: 9 additions & 1 deletion src/unpacker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit ef54eef

Please sign in to comment.