Skip to content

Commit

Permalink
Add vromf_version subcommand and dependency to handle VROMF versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlareFlo committed Jan 22, 2024
1 parent 18d44c9 commit 84351d7
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ smol-timeout = { version = "0.6.0", optional = true}
tokio = { version = "1.33.0", default-features = false, features = ["rt"], optional = true }
semver = "1.0.18"
zip = { version = "0.6.6", features = ["deflate"], default-features = false}
wt_version = { git = "https://github.com/Warthunder-Open-Source-Foundation/wt_version.git" }

[dependencies.image]
git = "https://github.com/image-rs/image.git"
Expand Down
2 changes: 2 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod diff_yup;
mod update_check;
mod get_instruction_manual;
mod hash;
mod vromf_version;

use clap::{command, Arg, ColorChoice, Command, ValueHint};
use const_format::formatcp;
Expand Down Expand Up @@ -42,4 +43,5 @@ pub fn build_command_structure() -> Command {
.subcommand(update_check::update_check())
.subcommand(get_instruction_manual::get_instruction_manual())
.subcommand(hash::hash())
.subcommand(vromf_version::vromf_version())
}
13 changes: 13 additions & 0 deletions src/cli/vromf_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use clap::{Arg, Command, ValueHint};

pub fn vromf_version() -> Command {
Command::new("vromf_version")
.long_flag("vromf_version")
.arg(Arg::new("input")
.short('i')
.long("input_dir_or_file")
.help("A single vromf file, or a folder of Vromf files. Does not recurse subdirs")
.required(true)
.value_hint(ValueHint::AnyPath))
.about("Prints version(s) from file or folder of vromfs")
}
5 changes: 5 additions & 0 deletions src/subcommands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ use crate::{COMMIT_HASH, logging::init_logging, subcommands::{
unpack_raw_blk::unpack_raw_blk,
unpack_vromf::unpack_vromf,
}};
use crate::subcommands::vromf_version::vromf_version;

mod unpack_dxp_and_grp;
mod unpack_raw_blk;
pub mod unpack_vromf;
mod vromf_version;

pub static CRASHLOG: OnceLock<bool> = OnceLock::new();

Expand Down Expand Up @@ -46,6 +48,9 @@ pub fn branch_subcommands(args: ArgMatches) -> Result<()> {
Some(("hash",_)) => {
println!("https://github.com/Warthunder-Open-Source-Foundation/wt_ext_cli/commit/{}", COMMIT_HASH);
}
Some(("vromf_version", args)) => {
vromf_version(args)?;
}
_ => {
error!("Unmatched subcommand: {:?}", args.subcommand());
if let Some((command,_)) = args.subcommand() {
Expand Down
35 changes: 35 additions & 0 deletions src/subcommands/vromf_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::fs;
use std::path::PathBuf;
use std::str::FromStr;
use clap::ArgMatches;
use wt_blk::vromf::VromfUnpacker;
use wt_version::Version;
use crate::error::CliError;

pub fn vromf_version(args: &ArgMatches) -> color_eyre::Result<()> {
let input_dir = args
.get_one::<String>("input")
.ok_or(CliError::RequiredFlagMissing)?;
let parsed_input_dir = PathBuf::from_str(&input_dir).or(Err(CliError::InvalidPath))?;

let versions: Vec<_> = if parsed_input_dir.is_file() {
let unpacker = VromfUnpacker::from_file((parsed_input_dir.clone(), fs::read(&parsed_input_dir)?))?;
vec![(parsed_input_dir.file_name().unwrap().to_string_lossy().to_string(), unpacker.latest_version().ok())]
} else {
let dir = parsed_input_dir.read_dir()?;
let mut versions = vec![];
for file in dir {
let p = file?.path();
let unpacker = VromfUnpacker::from_file((p.clone(), fs::read(&p)?))?;
versions.push((p.file_name().unwrap().to_string_lossy().to_string(), unpacker.latest_version().ok()));
}
versions
}.into_iter().map(|(mut i,e)|{
i.push(' ');
i.push_str(&e.map(|e|e.to_string()).unwrap_or("0.0.0.0".to_owned()));
i
}).collect();
println!("{}", serde_json::to_string_pretty(&versions)?);

Ok(())
}

0 comments on commit 84351d7

Please sign in to comment.