Use std::fs::{read, write} for file operations
This commit is contained in:
parent
541fdedbd0
commit
7dbb8c1e62
24
src/main.rs
24
src/main.rs
|
@ -1,5 +1,4 @@
|
||||||
use std::fs::File;
|
use std::fs;
|
||||||
use std::io::prelude::*;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
@ -85,13 +84,6 @@ fn error(message: String) -> Result<()> {
|
||||||
Err(anyhow!(message))
|
Err(anyhow!(message))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_file(name: &PathBuf) -> Result<Vec<u8>> {
|
|
||||||
let mut file = File::open(name)?;
|
|
||||||
let mut data = vec![];
|
|
||||||
file.read_to_end(&mut data)?;
|
|
||||||
Ok(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_basename(path: &PathBuf) -> Option<&str> {
|
fn get_basename(path: &PathBuf) -> Option<&str> {
|
||||||
match path.file_stem() {
|
match path.file_stem() {
|
||||||
Some(stem) => stem.to_str(),
|
Some(stem) => stem.to_str(),
|
||||||
|
@ -106,7 +98,7 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
match opts.subcmd {
|
match opts.subcmd {
|
||||||
SubCommand::UnXWB(opts) => {
|
SubCommand::UnXWB(opts) => {
|
||||||
let xwb_data = read_file(&opts.file)?;
|
let xwb_data = fs::read(&opts.file)?;
|
||||||
let wave_bank = WaveBank::parse(&xwb_data)?;
|
let wave_bank = WaveBank::parse(&xwb_data)?;
|
||||||
info!("Opened wave bank “{}” from {:?}", wave_bank.name, opts.file);
|
info!("Opened wave bank “{}” from {:?}", wave_bank.name, opts.file);
|
||||||
|
|
||||||
|
@ -116,9 +108,7 @@ fn main() -> Result<()> {
|
||||||
Some(sound) => sound,
|
Some(sound) => sound,
|
||||||
None => return error(format!("Entry {} not found in wave bank", name)),
|
None => return error(format!("Entry {} not found in wave bank", name)),
|
||||||
};
|
};
|
||||||
let out_file = format!("{}.wav", name);
|
fs::write(format!("{}.wav", name), &sound.to_wav()?)?;
|
||||||
let mut wav_file = File::create(out_file)?;
|
|
||||||
wav_file.write_all(&sound.to_wav()?)?;
|
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
for (name, sound) in wave_bank.sounds {
|
for (name, sound) in wave_bank.sounds {
|
||||||
|
@ -127,9 +117,7 @@ fn main() -> Result<()> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
info!("Extracting {}", name);
|
info!("Extracting {}", name);
|
||||||
let out_file = format!("{}.wav", name);
|
fs::write(format!("{}.wav", name), &sound.to_wav()?)?;
|
||||||
let mut wav_file = File::create(out_file)?;
|
|
||||||
wav_file.write_all(&sound.to_wav()?)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,13 +138,13 @@ fn main() -> Result<()> {
|
||||||
opts.ssq_file, sound_name, opts.xwb_file, opts.out_file
|
opts.ssq_file, sound_name, opts.xwb_file, opts.out_file
|
||||||
);
|
);
|
||||||
|
|
||||||
let ssq_data = read_file(&opts.ssq_file)?;
|
let ssq_data = fs::read(&opts.ssq_file)?;
|
||||||
let ssq = SSQ::parse(&ssq_data)?;
|
let ssq = SSQ::parse(&ssq_data)?;
|
||||||
|
|
||||||
let convert_config = opts.convert;
|
let convert_config = opts.convert;
|
||||||
let beatmaps = ssq.to_beatmaps(&convert_config)?;
|
let beatmaps = ssq.to_beatmaps(&convert_config)?;
|
||||||
|
|
||||||
let xwb_data = read_file(&opts.xwb_file)?;
|
let xwb_data = fs::read(&opts.xwb_file)?;
|
||||||
let wave_bank = WaveBank::parse(&xwb_data)?;
|
let wave_bank = WaveBank::parse(&xwb_data)?;
|
||||||
|
|
||||||
let audio_data = if wave_bank.sounds.contains_key(sound_name) {
|
let audio_data = if wave_bank.sounds.contains_key(sound_name) {
|
||||||
|
|
Reference in a new issue