Skip to content

Commit

Permalink
feat(cli): added a cli
Browse files Browse the repository at this point in the history
  • Loading branch information
bddvlpr committed Jun 27, 2024
1 parent 2455eac commit 07ed3dd
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 4 deletions.
158 changes: 158 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ in

src = ./.;

cargoHash = "sha256-w5BshLg1OiqiJJ+JRm9JQkjMtWAex/eMtHmlOfQ7Kt4=";
cargoHash = "sha256-EnfAFP/4cmtUuzmmXn9A6AYG3Yud2zBBYm0ORe282uc=";

meta = with lib; {
description = "Manipulate Unity's portable package files";
Expand Down
2 changes: 2 additions & 0 deletions unitypkg-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ license.workspace = true
keywords.workspace = true

[dependencies]
clap = { version = "4.5.7", features = ["derive"] }
unitypkg-core = { path = "../unitypkg-core" }
31 changes: 30 additions & 1 deletion unitypkg-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
fn main() {}
use std::{
fs::{create_dir_all, File},
path::PathBuf,
};

use clap::Parser;
use unitypkg_core::{reader::read_package, unpack::unpack_package};

#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Cli {
#[arg(short, long, required = true)]
input: Vec<PathBuf>,

output: PathBuf,
}

fn main() {
let cli = Cli::parse();

for input in cli.input {
let package = read_package(File::open(input).unwrap());

if !cli.output.exists() {
create_dir_all(&cli.output).unwrap();
}

unpack_package(package, &cli.output);
}
}
4 changes: 2 additions & 2 deletions unitypkg-core/src/unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use crate::Package;

pub fn unpack_package(package: Package, directory: PathBuf) {
pub fn unpack_package(package: Package, directory: &PathBuf) {
create_dir_all(&directory).expect("Failed to create root directory");

for asset in package.assets.values() {
Expand Down Expand Up @@ -61,7 +61,7 @@ mod test {
builder.meta = Some(vec![5, 6, 7, 8]);
package.assets.insert(uuid, builder.build());

unpack_package(package, temp_dir.clone());
unpack_package(package, &temp_dir);

let asset_file = temp_dir.join("Assets/SomeMaterial");
let meta_file = asset_file.with_extension("meta");
Expand Down

0 comments on commit 07ed3dd

Please sign in to comment.