mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 10:44:07 +02:00
restore UnexpectedHeader
This commit is contained in:
parent
8f6496e456
commit
7f2c927e7b
2 changed files with 10 additions and 1 deletions
|
|
@ -12,7 +12,14 @@ pub struct BspFile<'a> {
|
|||
impl<'a> BspFile<'a> {
|
||||
pub fn new(data: &'a [u8]) -> BspResult<Self> {
|
||||
let mut cursor = Cursor::new(data);
|
||||
let header: Header = cursor.read_le()?;
|
||||
let header: Header = cursor.read_le().map_err(|err| match err {
|
||||
binrw::Error::BadMagic { .. } => {
|
||||
BspError::UnexpectedHeader(data[..4].try_into().expect(
|
||||
"always enough data because otherwise a different binrw error would be hit",
|
||||
))
|
||||
}
|
||||
error => BspError::MalformedData(error),
|
||||
})?;
|
||||
let directories = cursor.read_le()?;
|
||||
|
||||
Ok(BspFile {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ use zip::result::ZipError;
|
|||
#[non_exhaustive]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum BspError {
|
||||
#[error("unexpected magic numbers or version: {0:?}")]
|
||||
UnexpectedHeader([u8; 4]),
|
||||
#[error("bsp lump is out of bounds of the bsp file")]
|
||||
LumpOutOfBounds(LumpEntry),
|
||||
#[error("bsp game lump is out of bounds of the bsp file")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue