diff --git a/Cargo.toml b/Cargo.toml index 7662640..af3eba5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,4 +27,4 @@ webbrowser = { version = "0.6.0", optional = true } ansi_term = "0.12.1" cpal = { version = "0.13.5", optional = true } rubato = { version = "0.11.0", optional = true } -winapi = { version = "0.3.9", features = ["timeapi"], optional = true } \ No newline at end of file +winapi = { version = "0.3.9", features = ["timeapi"], optional = true } diff --git a/src/main.rs b/src/main.rs index 99f2f8f..efa686b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -164,7 +164,10 @@ fn load_cart(filename: &Path, config: &Config) -> (Result>, Vec if let Some(ref pack_config) = config.pack { cart = uw8_tool::pack(&cart, pack_config)?; - println!("packed size: {} bytes", cart.len()); + println!( + "\npacked size: {:.2} bytes", + uw8_tool::compressed_size(&cart) + ); } if let Some(ref path) = config.output_path { diff --git a/uw8-tool/Cargo.lock b/uw8-tool/Cargo.lock index 780032b..3bd1117 100644 --- a/uw8-tool/Cargo.lock +++ b/uw8-tool/Cargo.lock @@ -189,7 +189,7 @@ checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "upkr" version = "0.1.0" -source = "git+https://github.com/exoticorn/upkr.git?rev=2e7983fc#2e7983fc650788d98da2eecef2d16f63e849e4a0" +source = "git+https://github.com/exoticorn/upkr.git?rev=d93aec186c9fb91d962c488682a2db125c61306c#d93aec186c9fb91d962c488682a2db125c61306c" dependencies = [ "anyhow", "cdivsufsort", diff --git a/uw8-tool/Cargo.toml b/uw8-tool/Cargo.toml index ee75be9..ec7d252 100644 --- a/uw8-tool/Cargo.toml +++ b/uw8-tool/Cargo.toml @@ -11,5 +11,5 @@ wasm-encoder = "0.8" walrus = "0.19" anyhow = "1" pico-args = "0.4" -upkr = { git = "https://github.com/exoticorn/upkr.git", rev = "2e7983fc" } +upkr = { git = "https://github.com/exoticorn/upkr.git", rev = "d93aec186c9fb91d962c488682a2db125c61306c" } pbr = "1" \ No newline at end of file diff --git a/uw8-tool/src/base_module.rs b/uw8-tool/src/base_module.rs index 1e3a29c..f6e0816 100644 --- a/uw8-tool/src/base_module.rs +++ b/uw8-tool/src/base_module.rs @@ -286,7 +286,7 @@ impl BaseModule { pub fn create_binary(path: &Path) -> Result<()> { let base1 = BaseModule::for_format_version(1)?.to_wasm(); - let data = upkr::pack(&base1, 4, None); + let data = upkr::pack(&base1, 4, false, None); File::create(path)?.write_all(&data)?; Ok(()) } diff --git a/uw8-tool/src/lib.rs b/uw8-tool/src/lib.rs index e3fd271..b5ab0e6 100644 --- a/uw8-tool/src/lib.rs +++ b/uw8-tool/src/lib.rs @@ -1,7 +1,15 @@ mod base_module; -mod pack; mod filter_exports; +mod pack; pub use base_module::BaseModule; -pub use pack::{pack, pack_file, unpack, unpack_file, PackConfig}; pub use filter_exports::filter_exports; +pub use pack::{pack, pack_file, unpack, unpack_file, PackConfig}; + +pub fn compressed_size(cart: &[u8]) -> f32 { + if cart[0] != 2 { + cart.len() as f32 + } else { + upkr::compressed_size(&cart[1..]) + 1. + } +} diff --git a/uw8-tool/src/pack.rs b/uw8-tool/src/pack.rs index 22fdd7b..640bb00 100644 --- a/uw8-tool/src/pack.rs +++ b/uw8-tool/src/pack.rs @@ -63,6 +63,7 @@ pub fn pack(data: &[u8], config: &PackConfig) -> Result> { uw8.extend_from_slice(&upkr::pack( &result[8..], level, + false, Some(&mut |pos| { pb.set(pos as u64); }), @@ -89,7 +90,7 @@ pub fn unpack(data: Vec) -> Result> { let (version, data) = match data[0] { 0 => return Ok(data), 1 => (1, data[1..].to_vec()), - 2 => (1, upkr::unpack(&data[1..])), + 2 => (1, upkr::unpack(&data[1..], false)), other => bail!("Uknown format version {}", other), };