Changed patcher to use the parent of the game file by default if no directory is given.

This commit is contained in:
2020-05-01 19:29:06 +01:00
parent b98c2ef50e
commit 406f38b65e
3 changed files with 25 additions and 23 deletions

View File

@@ -34,10 +34,12 @@ mod panic;
use cli::CliData;
// Dcb
use dcb::{game::card::Table as CardTable, GameFile};
use dcb::{
game::{card::Table as CardTable, deck::Table as DeckTable},
GameFile,
};
// Errors
use err_backtrace::ErrBacktraceExt;
use err_ext::ResultExt;
use err_panic::ErrorExtPanic;
@@ -56,20 +58,15 @@ fn main() {
// Get the cards table
let cards_table = CardTable::deserialize(&mut game_file).panic_err_msg("Unable to deserialize cards table from game file");
let cards_table_yaml = serde_yaml::to_string(&cards_table).panic_err_msg("Unable to serialize cards table to yaml");
log::info!("Extracted {} cards", cards_table.card_count());
// Get the decks table
let decks_table = DeckTable::deserialize(&mut game_file).panic_err_msg("Unable to deserialize decks table from game file");
let decks_table_yaml = serde_yaml::to_string(&decks_table).panic_err_msg("Unable to serialize decks table to yaml");
// And output everything to the files
let cards_table_output_filename = output_dir.join("cards.yaml");
std::fs::write(&cards_table_output_filename, cards_table_yaml)
.map_err(|err| {
log::warn!(
"Unable to write output file {}:\n{}",
cards_table_output_filename.display(),
err.err_backtrace()
)
})
.ignore();
std::fs::write(&output_dir.join("cards.yaml"), cards_table_yaml).panic_err_msg("Unable to write cards table to file");
std::fs::write(&output_dir.join("decks.yaml"), decks_table_yaml).panic_err_msg("Unable to write decks table to file");
}
/// Initializes the global logger

View File

@@ -30,12 +30,11 @@ impl CliData {
.arg(ClapArg::with_name("GAME_FILE").help("Sets the game file to use").required(true).index(1))
.arg(
ClapArg::with_name("INPUT")
.help("Sets the output directory to use")
.help("Sets the input directory to use")
.short("i")
.long("input")
.index(2)
.takes_value(true)
.required(true),
.required(false),
)
.get_matches();
@@ -47,13 +46,11 @@ impl CliData {
.map(Path::to_path_buf)
.panic_msg("Unable to get required argument `GAME_FILE`");
// Get the input dir
// Note: required
// Get the input dir as either an input, the game file directory or the current directory
let input_dir = matches
.value_of("INPUT")
.map(Path::new)
.map(Path::to_path_buf)
.panic_msg("Unable to get required argument `INPUT`");
.map_or_else(|| game_file_path.parent().unwrap_or_else(|| Path::new(".")), Path::new)
.to_path_buf();
// Return the cli data
Self { game_file_path, input_dir }

View File

@@ -33,7 +33,10 @@ mod panic;
use cli::CliData;
// Dcb
use dcb::{game::card::Table as CardTable, GameFile};
use dcb::{
game::{card::Table as CardTable, deck::Table as DeckTable},
GameFile,
};
// Errors
use err_ext::ResultExt;
@@ -51,6 +54,10 @@ fn main() {
let cards_table_file = std::fs::File::open(input_dir.join("cards.yaml")).panic_err_msg("Unable to open `cards.yaml`");
let cards_table: CardTable = serde_yaml::from_reader(cards_table_file).panic_err_msg("Unable to parse `cards.yaml`");
// Load the decks table
let decks_table_file = std::fs::File::open(input_dir.join("decks.yaml")).panic_err_msg("Unable to open `decks.yaml`");
let decks_table: DeckTable = serde_yaml::from_reader(decks_table_file).panic_err_msg("Unable to parse `decks.yaml`");
// Open the game file
let game_file = std::fs::OpenOptions::new()
.write(true)
@@ -59,8 +66,9 @@ fn main() {
.panic_err_msg("Unable to open game file");
let mut game_file = GameFile::from_reader(game_file).panic_err_msg("Unable to initialize game file");
// And write the cards table
// And write everything
cards_table.serialize(&mut game_file).panic_err_msg("Unable to serialize cards table");
decks_table.serialize(&mut game_file).panic_err_msg("Unable to serialize decks table");
}
/// Initializes the global logger