diff --git a/Cargo.toml b/Cargo.toml index 4801b23..b5404e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reskit" -version = "0.0.2" +version = "0.0.3" authors = ["ne0ndrag0n "] edition = "2018" diff --git a/src/reskit/soundtrack/formats/dmf.rs b/src/reskit/soundtrack/formats/dmf.rs index 7ceef64..9260e0e 100644 --- a/src/reskit/soundtrack/formats/dmf.rs +++ b/src/reskit/soundtrack/formats/dmf.rs @@ -1,7 +1,7 @@ use std::{error::Error, fs::File, io::Read, convert::TryInto, collections::HashMap}; use flate2::read::ZlibDecoder; use linked_hash_set::LinkedHashSet; -use crate::reskit::{utility::{get_string, get_u8, skip, get_u32, get_i8, get_i32, get_u16, get_i16, print_info, sanitize_string}, soundtrack::types::{SampleFormat, PsgEnvelope, Note, Sample, PsgSettings, PatternRow, Effect, DcsgChannelMode, NoiseType, Instrument, InstrumentType, Fm2612Operator, Fm2612Settings, Channel, CombinedAssets}}; +use crate::reskit::{utility::{get_string, get_u8, skip, get_u32, get_i8, get_i32, get_u16, get_i16, print_info, sanitize_string, print_warning}, soundtrack::types::{SampleFormat, PsgEnvelope, Note, Sample, PsgSettings, PatternRow, Effect, DcsgChannelMode, NoiseType, Instrument, InstrumentType, Fm2612Operator, Fm2612Settings, Channel, CombinedAssets}}; const DMF_MAGIC_NUMBER: &'static str = ".DelekDefleMask."; const DMF_SUPPORTED_VERSION: u8 = 27; @@ -669,7 +669,10 @@ impl DmfModule { let bitrate = match get_u8( bytes.by_ref() )? { 8 => SampleFormat::Bits8, 16 => SampleFormat::Bits16, - invalid => return Err( format!( "invalid file: invalid bitrate {}", invalid ) )? + invalid => { + print_warning( &format!( "sample with invalid bitrate: {}", invalid ) ); + SampleFormat::Invalid + } }; @@ -685,7 +688,10 @@ impl DmfModule { sample.data.push( get_i16( bytes.by_ref() )? ); } - samples.push( sample ); + // Don't push no-names or invalid bitrates + if sample.name != "" && !matches!( sample.bitrate, SampleFormat::Invalid ) { + samples.push( sample ); + } } Ok( diff --git a/src/reskit/soundtrack/types.rs b/src/reskit/soundtrack/types.rs index 3ae7881..70fd8cc 100644 --- a/src/reskit/soundtrack/types.rs +++ b/src/reskit/soundtrack/types.rs @@ -63,7 +63,8 @@ pub struct CombinedAssets { #[derive(Clone, PartialEq, Debug)] pub enum SampleFormat { Bits8, - Bits16 + Bits16, + Invalid } #[derive(Clone, PartialEq, Debug)]