diff --git a/Cargo.lock b/Cargo.lock index 6b68dd1..da4b3b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2022,9 +2022,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vpin" -version = "0.15.2" +version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faa675d7942a18a68d9dcafee262b29ee4d70dfa8175676ce745a566e3ba3637" +checksum = "58b6c8c30c1a38b58ed1612077dd813b47382bf1551136ab24dd49e166fcc485" dependencies = [ "byteorder", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 7ecd08a..a654844 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ figment = { version = "0.10", features = ["toml", "env"] } toml = "0.8.14" is_executable = "1.0.1" regex = { version = "1.10.5", features = [] } -vpin = { version = "0.15.2" } +vpin = { version = "0.15.3" } rust-ini = "0.21.0" edit = "0.1.5" diff --git a/src/lib.rs b/src/lib.rs index fddf7da..b5488de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ use std::path::{Path, PathBuf}; use std::process::{exit, ExitCode}; use vpin::directb2s::read; use vpin::vpx; -use vpin::vpx::jsonmodel::info_to_json; +use vpin::vpx::jsonmodel::{game_data_to_json, info_to_json}; use vpin::vpx::{expanded, extractvbs, importvbs, tableinfo, verify, ExtractResult, VerifyResult}; pub mod config; @@ -66,6 +66,9 @@ const CMD_INFO_DIFF: &str = "diff"; const CMD_IMAGES: &str = "images"; const CMD_IMAGES_WEBP: &str = "webp"; +const CMD_GAMEDATA: &str = "gamedata"; +const CMD_GAMEDATA_SHOW: &str = "show"; + pub struct ProgressBarProgress { pb: ProgressBar, } @@ -659,6 +662,22 @@ fn handle_command(matches: ArgMatches) -> io::Result { } _ => unreachable!(), }, + Some((CMD_GAMEDATA, sub_matches)) => match sub_matches.subcommand() { + Some((CMD_GAMEDATA_SHOW, sub_matches)) => { + let path = sub_matches + .get_one::("VPXPATH") + .map(|s| s.as_str()) + .unwrap_or_default(); + let expanded_path = expand_path(path)?; + let mut vpx_file = vpx::open(expanded_path)?; + let game_data = vpx_file.read_gamedata()?; + let json = game_data_to_json(&game_data); + let pretty = serde_json::to_string_pretty(&json)?; + println!("{}", pretty)?; + Ok(ExitCode::SUCCESS) + } + _ => unreachable!(), + }, _ => unreachable!(), // If all subcommands are defined above, anything else is unreachable!() } } @@ -924,6 +943,19 @@ fn build_command() -> Command { ), ), ) + .subcommand( + Command::new(CMD_GAMEDATA) + .subcommand_required(true) + .about("Vpx gamedata related commands") + .subcommand( + Command::new(CMD_GAMEDATA_SHOW) + .about("Show the gamedata for a vpx file") + .arg( + arg!( "The path to the vpx file") + .required(true), + ), + ), + ) } fn open_or_fail(vbs_path: &Path, config: Option<&ResolvedConfig>) -> io::Result {