Skip to content

Commit

Permalink
feat: hash generation / checking
Browse files Browse the repository at this point in the history
  • Loading branch information
francisdb committed Jul 10, 2023
1 parent 4cdded8 commit 7442561
Show file tree
Hide file tree
Showing 8 changed files with 754 additions and 63 deletions.
64 changes: 62 additions & 2 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ chrono = "0.4.26"
clap = { version = "4.3.10", features = ["derive", "string"] }
colored = "2.0.2"
console = "0.15.7"
dialoguer = "0.10.4"
# dialoguer = "0.10.4"
dialoguer = {path = "../dialoguer"}
dirs = "5.0.1"
git-version = "0.3.5"
indicatif = "0.17.5"
lzw = "0.10.0"
md2 = "0.10.2"
nom = "7.1.3"
open = "5.0.0"
quick-xml = { version = "0.29.0", features = ["serialize"] }
Expand Down
39 changes: 30 additions & 9 deletions src/frontend.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
fs::File,
io::{self, Write},
io::{Result, Write},
path::{Path, PathBuf},
process::ExitStatus,
};
Expand All @@ -13,7 +13,7 @@ use indicatif::{ProgressBar, ProgressStyle};

use crate::{
indexer, tableinfo,
vpx::{self, extractvbs, vbs_path_for, ExtractResult},
vpx::{self, extractvbs, read_version, vbs_path_for, ExtractResult},
};

const LAUNCH: Emoji = Emoji("🚀", "[launch]");
Expand Down Expand Up @@ -105,6 +105,7 @@ pub fn frontend(
.map(|(path, info)| display_table_line(path, info))
.collect::<Vec<String>>();

// TODO check FuzzySelect, requires feature to be enabled
selection_opt = Select::with_theme(&ColorfulTheme::default())
.with_prompt("Select a table to launch")
.default(selection_opt.unwrap_or(0))
Expand Down Expand Up @@ -142,7 +143,7 @@ pub fn frontend(
prompt(msg.truecolor(255, 125, 0).to_string());
}
},
Some(TableOption::ShowVBSDiff) => match vpx::diff(selected_path.clone()) {
Some(TableOption::ShowVBSDiff) => match vpx::diff(selected_path) {
Ok(diff) => {
prompt(diff);
}
Expand Down Expand Up @@ -171,9 +172,15 @@ pub fn frontend(
}
}
}
Some(TableOption::ShowDetails) => {
prompt("Not implemented");
}
Some(TableOption::ShowDetails) => match gather_table_info(selected_path) {
Ok(info) => {
prompt(info);
}
Err(err) => {
let msg = format!("Unable to gather table info: {}", err);
prompt(msg.truecolor(255, 125, 0).to_string());
}
},
None => (),
}
}
Expand All @@ -182,6 +189,14 @@ pub fn frontend(
}
}

fn gather_table_info(selected_path: &PathBuf) -> Result<String> {
let mut comp = cfb::open(selected_path)?;
let version = read_version(&mut comp)?;
let table_info = tableinfo::read_tableinfo(&mut comp)?;
let msg = format!("version: {:#?}\n{:#?}", version, table_info);
Ok(msg)
}

fn open(path: PathBuf) {
open::that(&path)
.unwrap_or_else(|err| prompt(format!("Unable to open {} {err}", path.to_string_lossy())));
Expand Down Expand Up @@ -243,7 +258,7 @@ fn launch_table(
selected_path: &PathBuf,
vpinball_executable: &Path,
fullscreen: bool,
) -> io::Result<ExitStatus> {
) -> Result<ExitStatus> {
println!("{} {}", LAUNCH, vpinball_executable.display());

// start process ./VPinballX_GL -play [table path]
Expand All @@ -262,10 +277,16 @@ fn display_table_line(path: &Path, info: &tableinfo::TableInfo) -> String {
let file_name = path.file_stem().unwrap().to_str().unwrap().to_string();
Some(info.table_name.to_owned())
.filter(|s| !s.is_empty())
.map(|s| format!("{} {}", capitalize_first_letter(s.as_str()), (format!("({})", file_name)).dimmed()))
.map(|s| {
format!(
"{} {}",
capitalize_first_letter(s.as_str()),
(format!("({})", file_name)).dimmed()
)
})
.unwrap_or(file_name)
}

fn capitalize_first_letter(s: &str) -> String {
s[0..1].to_uppercase() + &s[1..]
}
}
13 changes: 6 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ mod indexer;
pub mod jsonmodel;
pub mod vpx;

use byteorder::{LittleEndian, WriteBytesExt};
use cfb::CompoundFile;
use clap::{arg, Arg, Command};
use colored::Colorize;
use gamedata::Record;
use indicatif::{ProgressBar, ProgressStyle};
use std::fs::{metadata, File};
use std::io::{self, Read};
use std::path::{Path, PathBuf, MAIN_SEPARATOR_STR};
use std::path::{Path, PathBuf};
use std::process::exit;

use std::io::Write;
Expand All @@ -23,12 +22,12 @@ 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, write_tableinfo, TableInfo};
use vpx::{extract_script, write_version};
use vpx::tableinfo::{self};
use vpx::{extractvbs, font, read_gamedata, read_version, ExtractResult};
use vpx::{gamedata, write_endb};
use vpx::{image, write_mac};

// see https://github.com/fusion-engineering/rust-git-version/issues/21
const GIT_VERSION: &str = git_version!(args = ["--tags", "--always", "--dirty=-modified"]);
Expand Down Expand Up @@ -496,7 +495,7 @@ fn extract(vpx_file_path: &str, yes: bool) {

let mut comp = cfb::open(vpx_file_path).unwrap();
let version = read_version(&mut comp).unwrap();
let records = read_gamedata(&mut comp);
let records = read_gamedata(&mut comp).unwrap();

match extract_info(&mut comp, root_dir_path) {
Ok(_) => {}
Expand Down
Loading

0 comments on commit 7442561

Please sign in to comment.