Add command-line argument parsing
This commit is contained in:
parent
c1e0e83206
commit
d7d9314ba5
|
|
@ -87,6 +87,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2"
|
checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
|
"clap_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -101,6 +102,18 @@ dependencies = [
|
||||||
"strsim",
|
"strsim",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_derive"
|
||||||
|
version = "4.4.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_lex"
|
name = "clap_lex"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
|
|
@ -192,6 +205,12 @@ dependencies = [
|
||||||
"miniz_oxide",
|
"miniz_oxide",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.151"
|
version = "0.2.151"
|
||||||
|
|
@ -232,6 +251,24 @@ dependencies = [
|
||||||
"adler",
|
"adler",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.70"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rayon"
|
name = "rayon"
|
||||||
version = "1.8.0"
|
version = "1.8.0"
|
||||||
|
|
@ -280,6 +317,17 @@ version = "0.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.41"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tar"
|
name = "tar"
|
||||||
version = "0.4.40"
|
version = "0.4.40"
|
||||||
|
|
@ -291,6 +339,12 @@ dependencies = [
|
||||||
"xattr",
|
"xattr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8parse"
|
name = "utf8parse"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "4.4"
|
clap = { version = "4.4", features = ["derive"] }
|
||||||
flate2 = "1.0"
|
flate2 = "1.0"
|
||||||
rayon = "1.8.0"
|
rayon = "1.8.0"
|
||||||
tar = "0.4"
|
tar = "0.4"
|
||||||
|
|
|
||||||
35
src/main.rs
35
src/main.rs
|
|
@ -1,6 +1,6 @@
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::{fs, io, sync::Arc};
|
use std::{fs, io, sync::Arc};
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use flate2::read::GzDecoder;
|
use flate2::read::GzDecoder;
|
||||||
use tar::Archive;
|
use tar::Archive;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
@ -10,6 +10,23 @@ use std::io::prelude::*;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
/// Program for unpacking unitypackages files.
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(author, version, about, long_about = None)]
|
||||||
|
struct Args {
|
||||||
|
/// .unitypackage file to extract
|
||||||
|
#[arg(short, long)]
|
||||||
|
input: PathBuf,
|
||||||
|
/// target directory
|
||||||
|
#[arg(short, long)]
|
||||||
|
output: PathBuf,
|
||||||
|
|
||||||
|
/// optional- path to the tool that will auto convert fbx files to gltf during unpacking
|
||||||
|
#[arg(short,long)]
|
||||||
|
fbx_to_gltf: Option<PathBuf>
|
||||||
|
}
|
||||||
|
|
||||||
pub fn extract_archive(archive_path: &Path, extract_to: &Path) -> io::Result<()> {
|
pub fn extract_archive(archive_path: &Path, extract_to: &Path) -> io::Result<()> {
|
||||||
let tar_gz = File::open(archive_path)?;
|
let tar_gz = File::open(archive_path)?;
|
||||||
|
|
@ -20,9 +37,13 @@ pub fn extract_archive(archive_path: &Path, extract_to: &Path) -> io::Result<()>
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let archive_path = Path::new("C:\\PROJECTS\\lwa_unity_unpack\\POLYGON_Snow_Kit_Unity_2020_3_v1_4.unitypackage");
|
let args = Args::parse();
|
||||||
|
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("./output");
|
let output_dir = Path::new(&args.output);
|
||||||
|
if !archive_path.exists() {
|
||||||
|
panic!("Input file does not exits");
|
||||||
|
}
|
||||||
if tmp_dir.exists() {
|
if tmp_dir.exists() {
|
||||||
println!("Temp directory exits, cleaning up first.");
|
println!("Temp directory exits, cleaning up first.");
|
||||||
fs::remove_dir_all(tmp_dir).unwrap();
|
fs::remove_dir_all(tmp_dir).unwrap();
|
||||||
|
|
@ -78,10 +99,12 @@ fn main() {
|
||||||
process_directory(asset_hash, asset_path, &result_path);
|
process_directory(asset_hash, asset_path, &result_path);
|
||||||
check_source_asset_exists(&source_asset);
|
check_source_asset_exists(&source_asset);
|
||||||
|
|
||||||
|
if args.fbx_to_gltf.is_some() {
|
||||||
if let Some("fbx") = path.extension().and_then(OsStr::to_str) {
|
if let Some("fbx") = path.extension().and_then(OsStr::to_str) {
|
||||||
process_fbx_file(&source_asset, &result_path);
|
process_fbx_file(&source_asset, &result_path, &args.fbx_to_gltf.clone().unwrap());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
process_non_fbx_file(&source_asset, &result_path);
|
process_non_fbx_file(&source_asset, &result_path);
|
||||||
});
|
});
|
||||||
|
|
@ -102,10 +125,10 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_fbx_file(source_asset: &Path, result_path: &Path) {
|
fn process_fbx_file(source_asset: &Path, result_path: &Path, tool: &PathBuf) {
|
||||||
let out_path = result_path.with_extension("");
|
let out_path = result_path.with_extension("");
|
||||||
println!("{:?}", &["--input", source_asset.to_str().unwrap(), "--output", out_path.to_str().unwrap()]);
|
println!("{:?}", &["--input", source_asset.to_str().unwrap(), "--output", out_path.to_str().unwrap()]);
|
||||||
let output = Command::new("C:\\tools\\FBX2glTF.exe")
|
let output = Command::new(tool)
|
||||||
.args(&["--input", source_asset.to_str().unwrap(), "-b", "--output", out_path.to_str().unwrap()])
|
.args(&["--input", source_asset.to_str().unwrap(), "-b", "--output", out_path.to_str().unwrap()])
|
||||||
.output().unwrap();
|
.output().unwrap();
|
||||||
let output_result = String::from_utf8_lossy(&output.stdout);
|
let output_result = String::from_utf8_lossy(&output.stdout);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue