Skip to content

Commit

Permalink
feat: better biff reading and writing (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
francisdb authored Jul 12, 2023
1 parent 811d5ab commit e4f1bb3
Show file tree
Hide file tree
Showing 7 changed files with 538 additions and 157 deletions.
33 changes: 33 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ clap = { version = "4.3.11", features = ["derive", "string"] }
colored = "2.0.4"
console = "0.15.7"
dialoguer = "0.10.4"
# dialoguer = { path = "../dialoguer" }
dirs = "5.0.1"
encoding_rs = "0.8.32"
git-version = "0.3.5"
indicatif = "0.17.5"
lzw = "0.10.0"
Expand All @@ -31,3 +33,5 @@ utf16string = "0.2.0"
walkdir = "2.3.3"
wild = "2.1.0"

[dev-dependencies]
pretty_assertions = "1.4.0"
46 changes: 40 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod vpx;
use cfb::CompoundFile;
use clap::{arg, Arg, Command};
use colored::Colorize;
use console::Emoji;
use gamedata::Record;
use indicatif::{ProgressBar, ProgressStyle};
use std::fs::{metadata, File};
Expand All @@ -22,11 +23,11 @@ use base64::{engine::general_purpose, Engine as _};

use directb2s::load;
use jsonmodel::table_json;
use vpx::extract_script;
use vpx::gamedata;
use vpx::image;
use vpx::sound::write_sound;
use vpx::tableinfo::{self};
use vpx::{extract_script, verify, VerifyResult};
use vpx::{extractvbs, font, read_gamedata, read_version, ExtractResult};

// see https://github.com/fusion-engineering/rust-git-version/issues/21
Expand All @@ -36,6 +37,9 @@ const GIT_VERSION: &str = git_version!(args = ["--tags", "--always", "--dirty=-m
// write the config if it doesn't exist
// with empty values or defults?

const OK: Emoji = Emoji("✅", "[launch]");
const NOK: Emoji = Emoji("❌", "[crash]");

fn default_vpinball_executable() -> PathBuf {
if cfg!(target_os = "windows") {
// baller installer default
Expand Down Expand Up @@ -156,6 +160,15 @@ fn main() {
.num_args(1..),
),
)
.subcommand(
Command::new("verify")
.about("Verify the structure of a vpx file")
.arg(
arg!(<VPXPATH> "The path(s) to the vpx file(s)")
.required(true)
.num_args(1..),
),
)
.subcommand(
Command::new("assemble")
.about("Assembles a vpx file")
Expand All @@ -175,7 +188,7 @@ fn main() {
let expanded_path = expand_path(path);
println!("showing info for {}", expanded_path);
let json = sub_matches.get_flag("JSON");
info(expanded_path.as_ref(), json);
info(expanded_path.as_ref(), json).unwrap();
}
Some(("diff", sub_matches)) => {
let path = sub_matches.get_one::<String>("VPXPATH").map(|s| s.as_str());
Expand Down Expand Up @@ -270,6 +283,26 @@ fn main() {
}
}
}
Some(("verify", sub_matches)) => {
let paths: Vec<&str> = sub_matches
.get_many::<String>("VPXPATH")
.unwrap_or_default()
.map(|v| v.as_str())
.collect::<Vec<_>>();
for path in paths {
let expanded_path = PathBuf::from(expand_path(path));
match verify(&expanded_path) {
VerifyResult::Ok(vbs_path) => {
println!("{OK} {}", vbs_path.display());
}
VerifyResult::Failed(vbs_path, msg) => {
let warning =
format!("{NOK} {} {}", vbs_path.display(), msg).truecolor(255, 125, 0);
println!("{}", warning);
}
}
}
}
Some(("new", sub_matches)) => {
let path = {
let this = sub_matches.get_one::<String>("VPXPATH").map(|v| v.as_str());
Expand Down Expand Up @@ -457,16 +490,17 @@ fn expand_path(path: &str) -> String {
expanded_path.to_string()
}

fn info(vpx_file_path: &str, json: bool) {
let mut comp = cfb::open(vpx_file_path).unwrap();
let version = read_version(&mut comp);
fn info(vpx_file_path: &str, json: bool) -> io::Result<()> {
let mut comp = cfb::open(vpx_file_path)?;
let version = read_version(&mut comp)?;
// GameData also has a name field that we might want to display here
// where is this shown in the UI?
let table_info = tableinfo::read_tableinfo(&mut comp);
let table_info = tableinfo::read_tableinfo(&mut comp)?;
// TODO come up with a proper format with colors and handle newlines?
// TODO check the json flag
dbg!(version);
dbg!(table_info);
Ok(())
}

fn extract(vpx_file_path: &str, yes: bool) {
Expand Down
Loading

0 comments on commit e4f1bb3

Please sign in to comment.