Add colored output to most tools; Make mkoverlay more tolerant for missing overlay files; Make psxcdgen_ex emit a warning when no license file is specified

This commit is contained in:
jaby 2023-04-22 15:44:21 +02:00
parent 7ef21179b3
commit 5a137ce644
11 changed files with 52 additions and 24 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "cpp_out"
version = "1.0.1"
version = "1.0.2"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1,6 +1,7 @@
use clap::{Parser};
use std::path::PathBuf;
use cpp_out::{Configuration, Error, FileType};
use std::path::PathBuf;
use tool_helper::exit_with_error;
#[derive(Parser)]
#[clap(about = "Output a file content or stdin to a c++ header/source file", long_about = None)]
@ -48,8 +49,7 @@ fn main() {
match run_main() {
Ok(_) => (),
Err(error) => {
eprintln!("{}", error);
std::process::exit(error.exit_code);
exit_with_error(error)
}
}
}

View File

@ -1,6 +1,6 @@
[package]
name = "jaby_engine_fconv"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1,7 +1,7 @@
use jaby_engine_fconv::images::{*};
use clap::{Parser, Subcommand};
use jaby_engine_fconv::images::*;
use std::path::PathBuf;
use tool_helper::Error;
use tool_helper::{Error, exit_with_error};
#[derive(Parser)]
#[clap(about = "Converts files to various JabyEngine related file formats", long_about = None)]
@ -69,7 +69,6 @@ fn run_main() -> Result<(), Error> {
fn main() {
if let Err(error) = run_main() {
eprintln!("{}", error.text);
std::process::exit(error.exit_code);
exit_with_error(error);
}
}

View File

@ -1,6 +1,6 @@
[package]
name = "mkoverlay"
version = "1.1.0"
version = "1.1.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1,6 +1,7 @@
use clap::Parser;
use tool_helper::{Error, format_if_error, open_input, open_output};
use mkoverlay::types::OverlayDesc;
use std::path::PathBuf;
use tool_helper::{Error, exit_with_error, format_if_error, open_input, open_output};
#[derive(Parser)]
#[clap(about = "Creates a linker script and makefile part for the JabyEngine toolchain", long_about = None)]
@ -12,12 +13,22 @@ struct CommandLine {
ld_file_output: Option<PathBuf>,
#[clap(value_parser, help="Input JSON for creating the files")]
input: PathBuf
input: Option<PathBuf>
}
fn parse_input(input: Option<PathBuf>) -> Result<OverlayDesc, Error> {
if let Some(input) = input {
let input = format_if_error!(open_input(Some(input)), "Opening input file failed with: {error_text}")?;
format_if_error!(mkoverlay::types::json_reader::read_config(input), "Parsing JSON file failed with: {error_text}")
}
else {
Ok(OverlayDesc::new())
}
}
fn run_main(cmd_line: CommandLine) -> Result<(), Error> {
let input = format_if_error!(open_input(Some(cmd_line.input)), "Opening input file failed with: {error_text}")?;
let input = format_if_error!(mkoverlay::types::json_reader::read_config(input), "Parsing JSON file failed with: {error_text}")?;
let input = parse_input(cmd_line.input)?;
let mut mk_output = format_if_error!(open_output(cmd_line.mk_file_output), "Opening file for writing makefile failed with: {error_text}")?;
let mut ld_output = format_if_error!(open_output(cmd_line.ld_file_output), "Opening file for writing linkerfile failed with: {error_text}")?;
@ -30,11 +41,11 @@ fn main() {
Ok(cmd_line) => {
match run_main(cmd_line) {
Ok(_) => (),
Err(error) => eprintln!("{}", error)
Err(error) => exit_with_error(error)
}
},
Err(error) => {
eprintln!("{}", error);
exit_with_error(Error::from_error(error));
}
}
}

View File

@ -1,6 +1,6 @@
[package]
name = "psxcdgen_ex"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
cdtypes = {path = "../cdtypes"}
clap = {version = "*", features = ["derive"]}
colored = "*"
no-comment = "*"
paste = "*"
roxmltree = "*"

View File

@ -2,6 +2,7 @@ use super::{*, SectorWriter, {CDDesc, Error}};
use super::super::types::{helper::{DirectoryRecordMember, PathTableMember}, layout::Layout, *};
use builder::SubModeBuilder;
use cdtypes::types::{cdstring::{AString, DString}, date::*, dir_record::*, helper::{round_bytes_mode2_form1, sector_count_mode2_form1}, path_table::*, pvd as cd_pvd, lsb_msb::*, sector::Mode2Form1};
use colored::*;
use tool_helper::{BufferedInputFile, format_if_error, open_input_file_buffered};
use std::io::{Read, Seek, SeekFrom};
@ -197,7 +198,8 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit
}
else {
// No license specified - filling it with zeros
// No license specified - filling it with zeros
eprintln!("{}", "WARNING: No license file provided. Some emulators (like No$PSX) will not boot this CD.".yellow());
for _ in 0..SYSTEM_AREA_SECTOR_COUNT {
sec_writer.write_cd_xa_data(builder::create_xa_data_zero())?;
}

View File

@ -1,7 +1,7 @@
use clap::{Parser, ValueEnum};
use psxcdgen_ex::{encoder::{EncodingFunctions, psx::{calculate_psx_lbas, calculate_psx_length_for, encode_psx_image}}, file_writer::{ImageType, write_image}, config_reader};
use std::{path::PathBuf, };
use tool_helper::Error;
use std::{path::PathBuf};
use tool_helper::{Error, exit_with_error};
#[derive(Parser)]
#[clap(about = "Creates an ISO image from a description file", long_about = None)]
@ -57,11 +57,11 @@ fn main() {
Ok(cmd_line) => {
match run_main(cmd_line) {
Ok(_) => (),
Err(error) => eprintln!("{}", error)
Err(error) => exit_with_error(error)
}
},
Err(error) => {
eprintln!("{}", error);
exit_with_error(Error::from_error(error))
}
}
}

View File

@ -1,6 +1,6 @@
[package]
name = "tool_helper"
version = "0.7.0"
version = "0.8.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
byteorder = "*"
cdtypes = {path = "../cdtypes"}
colored = "*"
envmnt = "*"
lz4 = "*"
paste = "*"

View File

@ -1,5 +1,6 @@
use std::{boxed::Box, io::{BufReader, BufWriter, Read, Write}, path::PathBuf};
use colored::*;
use envmnt::{ExpandOptions, ExpansionType};
use std::{boxed::Box, io::{BufReader, BufWriter, Read, Write}, path::PathBuf};
pub mod bits;
pub mod compress;
@ -79,6 +80,14 @@ impl Error {
pub fn ok_or_new<T, F>(option: Option<T>, error_text: F) -> Result<T, Error> where F: Fn () -> String{
Ok(option.ok_or(Error::from_callback(error_text))?)
}
pub fn print_generic_to_std_err<T: std::fmt::Display>(object: &T) {
eprintln!("{}", format!("ERROR: {}", object).red());
}
pub fn print_to_std_err(&self) {
Self::print_generic_to_std_err(self)
}
}
impl std::fmt::Display for Error {
@ -105,6 +114,11 @@ impl std::convert::From<std::convert::Infallible> for Error {
}
}
pub fn exit_with_error(error: Error) {
error.print_to_std_err();
std::process::exit(error.exit_code);
}
pub fn prefix_if_error<T>(prefix: &str, result: Result<T, Error>) -> Result<T, Error> {
match result {
Ok(value) => Ok(value),