diff --git a/CHANGELOG.md b/CHANGELOG.md index 9427c25..71a7e01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [0.2.0] + +### Added + +- Ignoring extensions during unpacking + ## [0.1.0] Initial version. \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index acf7af9..0a8f21e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lwa_unity_unpack" -version = "0.1.0" +version = "0.2.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 e11128b..105d97a 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,14 @@ Options: -i, --input .unitypackage file to extract -o, --output target directory -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 -h, --help Print help -V, --version Print version - ``` +``` -`lwa_unity_unpack -i "C:\\PROJECTS\\lwa_unity_unpack\\POLYGON_Snow_Kit_Unity_2020_3_v1_4.unitypackage" -o "output" -f "C:\\tools\\FBX2glTF.exe"` +`lwa_unity_unpack -i "C:\\PROJECTS\\lwa_unity_unpack\\POLYGON_Snow_Kit_Unity_2020_3_v1_4.unitypackage" -o "output" -f "C:\\tools\\FBX2glTF.exe" --ignore-extensions "mat" --ignore-extensions "prefab"` ## Install diff --git a/src/main.rs b/src/main.rs index 52544ec..615e13f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,10 @@ struct Args { /// optional- path to the tool that will auto convert fbx files to gltf during unpacking #[arg(short, long)] fbx_to_gltf: Option, + + /// optional- extensions that will be ignored during unpacking + #[arg(long, action = clap::ArgAction::Append)] + ignore_extensions: Option>, } pub fn extract_archive(archive_path: &Path, extract_to: &Path) -> io::Result<()> { @@ -37,7 +41,8 @@ pub fn extract_archive(archive_path: &Path, extract_to: &Path) -> io::Result<()> } fn main() { - let args = Args::parse(); + let args : Args = Args::parse(); + let ignored_extensions = args.ignore_extensions.unwrap_or(vec![]); let archive_path = Path::new(&args.input); let tmp_dir = Path::new("./tmp_dir"); let output_dir = Path::new(&args.output); @@ -63,7 +68,8 @@ fn main() { let root_file = entry.path(); let asset = entry.file_name().into_string().unwrap(); if root_file.is_dir() { - let mut real_path = String::new(); + let mut real_path= String::new() ; + let mut extension = None; let mut has_asset = false; for sub_entry in fs::read_dir(root_file.clone()).unwrap() { let sub_entry = sub_entry.unwrap(); @@ -74,14 +80,19 @@ fn main() { let buf_reader = BufReader::new(file); let line = buf_reader.lines().next(); match line { - Some(Ok(path)) => real_path = path, + Some(Ok(path)) => { + real_path = path; + if let Some(e) = Path::new(&real_path).extension().and_then(OsStr::to_str) { + extension = Some(String::from(e)); + } + }, _ => continue, } } else if file_name == "asset" { has_asset = true; } } - if has_asset { + if has_asset && !ignored_extensions.contains(&extension.unwrap_or_default()){ mapping.insert(asset, real_path); } }