From 0608f220acb1dcdf5e9bf197d750b54bdd4f9d2f Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 21 Aug 2024 20:46:03 +0200 Subject: [PATCH] Support license string --- .../psxcdgen_ex/src/config_reader/xml.rs | 13 +++++----- src/Tools/psxcdgen_ex/src/encoder/cd.rs | 24 +++++++++++++------ src/Tools/psxcdgen_ex/src/types/mod.rs | 13 +++++++--- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/Tools/psxcdgen_ex/src/config_reader/xml.rs b/src/Tools/psxcdgen_ex/src/config_reader/xml.rs index 5c629152..e7345602 100644 --- a/src/Tools/psxcdgen_ex/src/config_reader/xml.rs +++ b/src/Tools/psxcdgen_ex/src/config_reader/xml.rs @@ -7,11 +7,12 @@ use crate::{config_reader::Directory, types::LicenseFile}; use super::{CDAudioFile, CommonProperties, Configuration, Error, File, FileKind, LZ4State}; mod attribute_names { - pub const NAME: &'static str = "name"; - pub const HIDDEN: &'static str = "hidden"; - pub const PADDED_SIZE: &'static str = "padded_size"; - pub const LBA_SOURCE: &'static str = "lba_source"; - pub const LZ4_STATE: &'static str = "lz4"; + pub const NAME: &'static str = "name"; + pub const HIDDEN: &'static str = "hidden"; + pub const PADDED_SIZE: &'static str = "padded_size"; + pub const LBA_SOURCE: &'static str = "lba_source"; + pub const LZ4_STATE: &'static str = "lz4"; + pub const ALTLICENSE_TEXT: &'static str = "text"; } mod tag_names { @@ -68,7 +69,7 @@ fn parse_description(description: roxmltree::Node, config: &mut Configuration) - } fn parse_altlicense_path(license: roxmltree::Node) -> LicenseFile { - LicenseFile::from_tmd_option(path_from_node(&license, tag_names::ALTLICENSE).ok()) + LicenseFile::from_tmd_option(path_from_node(&license, tag_names::ALTLICENSE).ok(), license.attribute(attribute_names::ALTLICENSE_TEXT)) } for node in description.descendants() { diff --git a/src/Tools/psxcdgen_ex/src/encoder/cd.rs b/src/Tools/psxcdgen_ex/src/encoder/cd.rs index 60bd328a..7c31447f 100644 --- a/src/Tools/psxcdgen_ex/src/encoder/cd.rs +++ b/src/Tools/psxcdgen_ex/src/encoder/cd.rs @@ -235,7 +235,7 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit format_if_error!(write_audio_zeros(sec_writer), "Writing license audio zeros failed with: {error_text}") } - fn write_tmd_file(sec_writer: &mut dyn SectorWriter, tmd_file: BufferedInputFile) -> Result<(), Error> { + fn write_tmd_file(sec_writer: &mut dyn SectorWriter, tmd_file: BufferedInputFile, lic_text: &Option) -> Result<(), Error> { fn write_license_string(sec_writer: &mut dyn SectorWriter, text: &str) -> Result<(), Error> { let text_len = text.len(); @@ -275,10 +275,20 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit Ok(()) } - format_if_error!(write_data_zeros(sec_writer), "Writing alt-license data zeros failed with: {error_text}")?; - format_if_error!(write_license_string(sec_writer, " Not licensed by Sony Will not work on all hardware/software"), "Writing alt-license string from file failed with: {error_text}")?; - format_if_error!(write_license_logo(sec_writer, tmd_file), "Writing alt-license logo from file failed with: {error_text}")?; - format_if_error!(write_audio_zeros(sec_writer), "Writing alt-license audio zeros failed with: {error_text}") + let lic_text = { + if let Some(lic_text) = lic_text { + lic_text.as_ref() + } + + else { + "" + } + }; + + format_if_error!(write_data_zeros(sec_writer), "Writing alt-license data zeros failed with: {error_text}")?; + format_if_error!(write_license_string(sec_writer, lic_text), "Writing alt-license string from file failed with: {error_text}")?; + format_if_error!(write_license_logo(sec_writer, tmd_file), "Writing alt-license logo from file failed with: {error_text}")?; + format_if_error!(write_audio_zeros(sec_writer), "Writing alt-license audio zeros failed with: {error_text}") } let system_area_lba = system_area.lba.get_track_relative(); @@ -292,10 +302,10 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit let license_file = format_if_error!(open_input_file_buffered(license_path), "Loading license file from {} failed with: {error_text}", license_path.to_string_lossy())?; write_license_file(sec_writer, license_file) }, - LicenseFile::TMD(tmd_path) => { + LicenseFile::TMD(tmd_path, lic_text) => { print_warning(format!("WARNING: An alternative license file was provided. {}", NOT_BOOTING_CD_STR)); let tmd_file = format_if_error!(open_input_file_buffered(tmd_path), "Loading TMD file from {} failed with: {error_text}", tmd_path.to_string_lossy())?; - write_tmd_file(sec_writer, tmd_file) + write_tmd_file(sec_writer, tmd_file, lic_text) }, LicenseFile::None => { // No license specified - filling it with zeros diff --git a/src/Tools/psxcdgen_ex/src/types/mod.rs b/src/Tools/psxcdgen_ex/src/types/mod.rs index c9137268..acf64fcc 100644 --- a/src/Tools/psxcdgen_ex/src/types/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/mod.rs @@ -108,7 +108,7 @@ impl CDDesc { pub enum LicenseFile { None, Authentic(PathBuf), - TMD(PathBuf) + TMD(PathBuf, Option) } impl LicenseFile { @@ -122,9 +122,16 @@ impl LicenseFile { } } - pub fn from_tmd_option(option: Option) -> LicenseFile { + pub fn from_tmd_option(option: Option, lic_text: Option<&str>) -> LicenseFile { if let Some(path) = option { - LicenseFile::TMD(path) + LicenseFile::TMD(path, { + if let Some(lic_text) = lic_text { + Some(lic_text.to_owned()) + } + else { + None + } + }) } else {