Skip to content

Commit 263a990

Browse files
committed
Fixed many issues with utils, v0.2.0
1 parent db52e23 commit 263a990

5 files changed

Lines changed: 85 additions & 18 deletions

File tree

cz/src/compression.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use byteorder::{ReadBytesExt, WriteBytesExt, LE};
22
use std::{
33
collections::HashMap,
4-
io::{Cursor, Read, Seek, Write},
4+
io::{Read, Seek, Write},
55
};
66

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

365-
let output_buf = Vec::new();
366-
let mut bit_io = BitIo::new(output_buf);
365+
let mut bit_io = BitIo::new(vec![0u8; 0xF0000]);
367366
let write_bit = |bit_io: &mut BitIo, code: u64| {
368367
if code > 0x7FFF {
369368
bit_io.write_bit(1, 1);

utils/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[package]
22
name = "utils"
3-
version = "0.1.2"
3+
version = "0.2.0"
44
edition = "2021"
55
license = "GPL-3.0-or-later"
66
authors.workspace = true
7+
build = "build.rs"
78

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

1819
image = { version = "0.25", default-features = false, features = ["png"] }
19-
clap = { version = "4.5.9", features = ["derive"] }
20+
clap = { version = "4.5", features = ["derive", "error-context"] }
21+
22+
[build-dependencies]
23+
vergen-git2 = { version = "1.0", features = ["build", "cargo", "rustc", "si"] }
2024

2125
[lints]
2226
workspace = true

utils/build.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use vergen_git2::{BuildBuilder, CargoBuilder, Emitter, Git2Builder, RustcBuilder, SysinfoBuilder};
2+
3+
fn main() {
4+
let build = BuildBuilder::all_build().unwrap();
5+
let cargo = CargoBuilder::all_cargo().unwrap();
6+
let git2 = Git2Builder::all_git().unwrap();
7+
let rustc = RustcBuilder::all_rustc().unwrap();
8+
let si = SysinfoBuilder::all_sysinfo().unwrap();
9+
10+
Emitter::default()
11+
.add_instructions(&build).unwrap()
12+
.add_instructions(&cargo).unwrap()
13+
.add_instructions(&git2).unwrap()
14+
.add_instructions(&rustc).unwrap()
15+
.add_instructions(&si).unwrap()
16+
.emit().unwrap();
17+
}

utils/src/bin/czutil.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
use clap::{error::ErrorKind, Error, Parser, Subcommand};
1+
use clap::{error::ErrorKind, Command, Error, Parser, Subcommand};
22
use std::{
33
fs,
4-
path::{Path, PathBuf},
4+
path::{Path, PathBuf}, process::exit,
55
};
66

77
/// Utility to maniuplate CZ image files from the LUCA System game engine by
88
/// Prototype Ltd.
99
#[derive(Parser)]
1010
#[command(name = "CZ Utility")]
11-
#[command(version, about, long_about = None)]
11+
#[command(author, version, about, long_about = None, disable_version_flag = true)]
12+
#[command(arg_required_else_help(true))]
1213
struct Cli {
14+
/// Show program version information
15+
#[arg(short('V'), long)]
16+
version: bool,
17+
1318
#[command(subcommand)]
14-
command: Commands,
19+
command: Option<Commands>,
1520
}
1621

1722
#[derive(Subcommand)]
@@ -63,8 +68,24 @@ enum Commands {
6368
fn main() {
6469
let cli = Cli::parse();
6570

71+
if cli.version {
72+
println!(
73+
"{}, {} v{}-{}",
74+
env!("CARGO_BIN_NAME"),
75+
env!("CARGO_PKG_NAME"),
76+
env!("CARGO_PKG_VERSION"),
77+
&env!("VERGEN_GIT_SHA")[0..=6]
78+
);
79+
exit(0);
80+
}
81+
82+
let command = match cli.command {
83+
Some(c) => c,
84+
None => exit(0),
85+
};
86+
6687
// Check what subcommand was run
67-
match &cli.command {
88+
match &command {
6889
Commands::Decode {
6990
input,
7091
output,

utils/src/bin/pakutil.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@ use clap::{
33
Parser, Subcommand,
44
};
55
use luca_pak::Pak;
6-
use std::{fs, path::PathBuf};
6+
use std::{fs, path::PathBuf, process::exit};
77

88
/// Utility to maniuplate PAK archive files from the LUCA System game engine by
99
/// Prototype Ltd.
1010
#[derive(Parser)]
1111
#[command(name = "PAK Utility")]
12-
#[command(version, about, long_about = None)]
12+
#[command(author, version, about, long_about = None, disable_version_flag = true)]
1313
struct Cli {
14-
#[arg(value_name = "PAK FILE")]
15-
input: PathBuf,
14+
/// Show program version information
15+
#[arg(short('V'), long)]
16+
version: bool,
17+
18+
#[arg(value_name = "PAK FILE", required_unless_present("version"))]
19+
input: Option<PathBuf>,
1620

1721
#[command(subcommand)]
18-
command: Commands,
22+
command: Option<Commands>,
1923
}
2024

2125
#[derive(Subcommand)]
@@ -59,12 +63,30 @@ enum Commands {
5963
fn main() {
6064
let cli = Cli::parse();
6165

62-
let mut pak = match Pak::open(&cli.input) {
66+
if cli.version {
67+
println!(
68+
"{}, {} v{}-{}",
69+
env!("CARGO_BIN_NAME"),
70+
env!("CARGO_PKG_NAME"),
71+
env!("CARGO_PKG_VERSION"),
72+
&env!("VERGEN_GIT_SHA")[0..=6]
73+
);
74+
exit(0);
75+
}
76+
77+
let mut pak = match Pak::open(&cli.input.unwrap()) {
6378
Ok(pak) => pak,
6479
Err(err) => fmt_error(&format!("Could not open PAK file: {}", err)).exit(),
6580
};
6681

67-
match cli.command {
82+
let command = match cli.command {
83+
Some(c) => c,
84+
None => {
85+
exit(0);
86+
},
87+
};
88+
89+
match command {
6890
Commands::Extract { output } => {
6991
if output.exists() && !output.is_dir() {
7092
fmt_error("The output given was not a directory").exit()
@@ -74,7 +96,11 @@ fn main() {
7496

7597
for entry in pak.entries() {
7698
let mut outpath = output.clone();
77-
outpath.push(entry.display_name());
99+
if let Some(n) = entry.name() {
100+
outpath.push(n);
101+
} else {
102+
outpath.push(entry.index().to_string())
103+
}
78104
entry.save(&outpath).unwrap();
79105
}
80106
}

0 commit comments

Comments
 (0)