view formats/src/bin/dump_dat.rs @ 772:7492d384d122 default tip

Rust: Add a Glide renderer (2D only for now) This is an experiment for a Rust renderer, iterating over the Python data using pyo3. It requires --feature=glide to be passed to cargo build, doesn’t support NPOT textures, text rendering, the background, or even msg faces, some of that may come in a future changeset.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 05 Sep 2022 17:53:36 +0200
parents ccb04468c5fa
children
line wrap: on
line source

use touhou_formats::th06::pbg3::PBG3;
use std::env;
use std::path::Path;
use std::fs::{File, create_dir_all};
use std::io::{self, BufReader, Write};

fn main() -> io::Result<()> {
    // Parse arguments.
    let args: Vec<_> = env::args().collect();
    if args.len() != 3 {
        eprintln!("Usage: {} <DAT file> <output dir>", args[0]);
        std::process::exit(1);
    }

    let filename = Path::new(&args[1]);
    let output_filename = Path::new(&args[2]);

    let file = File::open(filename)?;
    let file = BufReader::new(file);
    let mut pbg3 = PBG3::from_file(file)?;
    let list = pbg3.list_files().cloned().collect::<Vec<_>>();

    create_dir_all(output_filename)?;
    for filename in list {
        let data = pbg3.get_file(&filename, true)?;
        let mut output = File::create(output_filename.join(filename))?;
        output.write_all(&data)?;
    }

    Ok(())
}