Skip to content

Commit

Permalink
Fixed many issues with utils, v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
G2-Games committed Oct 18, 2024
1 parent db52e23 commit 263a990
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 18 deletions.
5 changes: 2 additions & 3 deletions cz/src/compression.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use byteorder::{ReadBytesExt, WriteBytesExt, LE};
use std::{
collections::HashMap,
io::{Cursor, Read, Seek, Write},
io::{Read, Seek, Write},
};

use crate::binio::BitIo;
Expand Down Expand Up @@ -362,8 +362,7 @@ fn compress_lzw2(data: &[u8], last: Vec<u8>) -> (usize, Vec<u8>, Vec<u8>) {
element = last
}

let output_buf = Vec::new();
let mut bit_io = BitIo::new(output_buf);
let mut bit_io = BitIo::new(vec![0u8; 0xF0000]);
let write_bit = |bit_io: &mut BitIo, code: u64| {
if code > 0x7FFF {
bit_io.write_bit(1, 1);
Expand Down
8 changes: 6 additions & 2 deletions utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "utils"
version = "0.1.2"
version = "0.2.0"
edition = "2021"
license = "GPL-3.0-or-later"
authors.workspace = true
build = "build.rs"

[[bin]]
name = "czutil"
Expand All @@ -16,7 +17,10 @@ cz = { path = "../cz/", features = ["png"] }
luca_pak = { path = "../luca_pak/" }

image = { version = "0.25", default-features = false, features = ["png"] }
clap = { version = "4.5.9", features = ["derive"] }
clap = { version = "4.5", features = ["derive", "error-context"] }

[build-dependencies]
vergen-git2 = { version = "1.0", features = ["build", "cargo", "rustc", "si"] }

[lints]
workspace = true
17 changes: 17 additions & 0 deletions utils/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use vergen_git2::{BuildBuilder, CargoBuilder, Emitter, Git2Builder, RustcBuilder, SysinfoBuilder};

fn main() {
let build = BuildBuilder::all_build().unwrap();
let cargo = CargoBuilder::all_cargo().unwrap();
let git2 = Git2Builder::all_git().unwrap();
let rustc = RustcBuilder::all_rustc().unwrap();
let si = SysinfoBuilder::all_sysinfo().unwrap();

Emitter::default()
.add_instructions(&build).unwrap()
.add_instructions(&cargo).unwrap()
.add_instructions(&git2).unwrap()
.add_instructions(&rustc).unwrap()
.add_instructions(&si).unwrap()
.emit().unwrap();
}
31 changes: 26 additions & 5 deletions utils/src/bin/czutil.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
use clap::{error::ErrorKind, Error, Parser, Subcommand};
use clap::{error::ErrorKind, Command, Error, Parser, Subcommand};
use std::{
fs,
path::{Path, PathBuf},
path::{Path, PathBuf}, process::exit,
};

/// Utility to maniuplate CZ image files from the LUCA System game engine by
/// Prototype Ltd.
#[derive(Parser)]
#[command(name = "CZ Utility")]
#[command(version, about, long_about = None)]
#[command(author, version, about, long_about = None, disable_version_flag = true)]
#[command(arg_required_else_help(true))]
struct Cli {
/// Show program version information
#[arg(short('V'), long)]
version: bool,

#[command(subcommand)]
command: Commands,
command: Option<Commands>,
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -63,8 +68,24 @@ enum Commands {
fn main() {
let cli = Cli::parse();

if cli.version {
println!(
"{}, {} v{}-{}",
env!("CARGO_BIN_NAME"),
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
&env!("VERGEN_GIT_SHA")[0..=6]
);
exit(0);
}

let command = match cli.command {
Some(c) => c,
None => exit(0),
};

// Check what subcommand was run
match &cli.command {
match &command {
Commands::Decode {
input,
output,
Expand Down
42 changes: 34 additions & 8 deletions utils/src/bin/pakutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ use clap::{
Parser, Subcommand,
};
use luca_pak::Pak;
use std::{fs, path::PathBuf};
use std::{fs, path::PathBuf, process::exit};

/// Utility to maniuplate PAK archive files from the LUCA System game engine by
/// Prototype Ltd.
#[derive(Parser)]
#[command(name = "PAK Utility")]
#[command(version, about, long_about = None)]
#[command(author, version, about, long_about = None, disable_version_flag = true)]
struct Cli {
#[arg(value_name = "PAK FILE")]
input: PathBuf,
/// Show program version information
#[arg(short('V'), long)]
version: bool,

#[arg(value_name = "PAK FILE", required_unless_present("version"))]
input: Option<PathBuf>,

#[command(subcommand)]
command: Commands,
command: Option<Commands>,
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -59,12 +63,30 @@ enum Commands {
fn main() {
let cli = Cli::parse();

let mut pak = match Pak::open(&cli.input) {
if cli.version {
println!(
"{}, {} v{}-{}",
env!("CARGO_BIN_NAME"),
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
&env!("VERGEN_GIT_SHA")[0..=6]
);
exit(0);
}

let mut pak = match Pak::open(&cli.input.unwrap()) {
Ok(pak) => pak,
Err(err) => fmt_error(&format!("Could not open PAK file: {}", err)).exit(),
};

match cli.command {
let command = match cli.command {
Some(c) => c,
None => {
exit(0);
},
};

match command {
Commands::Extract { output } => {
if output.exists() && !output.is_dir() {
fmt_error("The output given was not a directory").exit()
Expand All @@ -74,7 +96,11 @@ fn main() {

for entry in pak.entries() {
let mut outpath = output.clone();
outpath.push(entry.display_name());
if let Some(n) = entry.name() {
outpath.push(n);
} else {
outpath.push(entry.index().to_string())
}
entry.save(&outpath).unwrap();
}
}
Expand Down

0 comments on commit 263a990

Please sign in to comment.