This commit is contained in:
Piotr Siuszko 2023-12-27 21:32:41 +01:00
parent d174eb5e5c
commit f68aeca902
4 changed files with 26 additions and 7 deletions

View File

@ -1,5 +1,11 @@
# Changelog # Changelog
## [0.2.0]
### Added
- Ignoring extensions during unpacking
## [0.1.0] ## [0.1.0]
Initial version. Initial version.

View File

@ -1,6 +1,6 @@
[package] [package]
name = "lwa_unity_unpack" name = "lwa_unity_unpack"
version = "0.1.0" version = "0.2.0"
edition = "2021" edition = "2021"
repository = "https://github.com/Leinnan/lwa_unity_unpack" repository = "https://github.com/Leinnan/lwa_unity_unpack"
homepage = "https://github.com/Leinnan/lwa_unity_unpack" homepage = "https://github.com/Leinnan/lwa_unity_unpack"

View File

@ -16,12 +16,14 @@ Options:
-i, --input <INPUT> .unitypackage file to extract -i, --input <INPUT> .unitypackage file to extract
-o, --output <OUTPUT> target directory -o, --output <OUTPUT> target directory
-f, --fbx-to-gltf <FBX_TO_GLTF> optional- path to the tool that will auto convert fbx files to gltf during unpacking -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
-h, --help Print help -h, --help Print help
-V, --version Print version -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 ## Install

View File

@ -26,6 +26,10 @@ struct Args {
/// optional- path to the tool that will auto convert fbx files to gltf during unpacking /// optional- path to the tool that will auto convert fbx files to gltf during unpacking
#[arg(short, long)] #[arg(short, long)]
fbx_to_gltf: Option<PathBuf>, fbx_to_gltf: Option<PathBuf>,
/// optional- extensions that will be ignored during unpacking
#[arg(long, action = clap::ArgAction::Append)]
ignore_extensions: Option<Vec<String>>,
} }
pub fn extract_archive(archive_path: &Path, extract_to: &Path) -> io::Result<()> { 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() { 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 archive_path = Path::new(&args.input);
let tmp_dir = Path::new("./tmp_dir"); let tmp_dir = Path::new("./tmp_dir");
let output_dir = Path::new(&args.output); let output_dir = Path::new(&args.output);
@ -64,6 +69,7 @@ fn main() {
let asset = entry.file_name().into_string().unwrap(); let asset = entry.file_name().into_string().unwrap();
if root_file.is_dir() { 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; let mut has_asset = false;
for sub_entry in fs::read_dir(root_file.clone()).unwrap() { for sub_entry in fs::read_dir(root_file.clone()).unwrap() {
let sub_entry = sub_entry.unwrap(); let sub_entry = sub_entry.unwrap();
@ -74,14 +80,19 @@ fn main() {
let buf_reader = BufReader::new(file); let buf_reader = BufReader::new(file);
let line = buf_reader.lines().next(); let line = buf_reader.lines().next();
match line { 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, _ => continue,
} }
} else if file_name == "asset" { } else if file_name == "asset" {
has_asset = true; has_asset = true;
} }
} }
if has_asset { if has_asset && !ignored_extensions.contains(&extension.unwrap_or_default()){
mapping.insert(asset, real_path); mapping.insert(asset, real_path);
} }
} }