separate wad/header

png-branch
an 2019-02-12 18:03:18 -05:00
parent 5b3c8fcbe1
commit a2c6e7eeff
2 changed files with 18 additions and 14 deletions

View File

@ -6,8 +6,7 @@ use std::{collections::HashSet,
fn make_tga(fname: &str, im: &impl Image) -> ResultS<()>
{
let out = fs::File::create(fname)?;
let mut out = io::BufWriter::new(out);
let mut out = io::BufWriter::new(fs::File::create(fname)?);
write_tga(&mut out, im)
}
@ -15,8 +14,7 @@ fn make_chunk(opt: &Options, cid: &Ident, cnk: &[u8], eid: u16) -> ResultS<()>
{
let cid = mac_roman_conv(cid);
let fname = format!("{}/{:04}{}.bin", opt.out_dir, eid, cid);
let out = fs::File::create(&fname)?;
let mut out = io::BufWriter::new(out);
let mut out = io::BufWriter::new(fs::File::create(&fname)?);
out.write(cnk)?;
Ok(())
}
@ -87,7 +85,7 @@ fn process_wad(opt: &Options, b: &[u8]) -> ResultS<()>
let wad = wad::Wad::new(b)?;
if opt.wad_header {
make_yaml(&wad)?;
make_yaml(&wad.head)?;
}
for (eid, ent) in wad.entries {
@ -160,9 +158,9 @@ fn main() -> ResultS<()>
let mut ap = ArgumentParser::new();
ap.set_description(env!("CARGO_PKG_DESCRIPTION"));
ap.add_option(&["-v", "--version"],
Print(format!("{} {}",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"))),
Print(concat!(env!("CARGO_PKG_NAME"),
" ",
env!("CARGO_PKG_VERSION")).to_string()),
"Show the version");
ap.refer(&mut opt.shp_tab)
.add_option(&["--shp-write-tab"], StoreTrue,

View File

@ -55,7 +55,7 @@ impl Wad<'_>
p += entsize + appsize;
}
Ok(Wad{wadver, dataver, appsize, origname, entries})
Ok(Wad{head: WadHeader{wadver, dataver, appsize, origname}, entries})
}
}
@ -80,20 +80,26 @@ type Chunk<'a> = &'a [u8];
type ChunkMap<'a> = BTreeMap<Ident, Chunk<'a>>;
type EntryMap<'a> = BTreeMap<u16, Entry<'a>>;
#[derive(Serialize)]
pub struct Entry<'a>
{
pub chunks: ChunkMap<'a>,
pub appdata: &'a [u8],
}
#[derive(Debug, Serialize)]
pub struct WadHeader
{
pub wadver: Ver,
pub dataver: u16,
pub origname: String,
pub appsize: usize,
}
#[derive(Debug, Serialize)]
pub struct Wad<'a>
{
wadver: Ver,
dataver: u16,
origname: String,
appsize: usize,
#[serde(skip)]
pub head: WadHeader,
pub entries: EntryMap<'a>,
}