From 7d503e8abacab43c943e63ecc113bf7ac987283c Mon Sep 17 00:00:00 2001 From: stephenmk Date: Tue, 2 May 2023 08:45:13 -0500 Subject: [PATCH] Add support for exploding graphics files --- src/bin/monokakido-explode.rs | 13 +++++++++++++ src/dict.rs | 9 ++++++--- src/lib.rs | 4 ++-- src/{audio.rs => media.rs} | 36 +++++++++++++++++------------------ 4 files changed, 39 insertions(+), 23 deletions(-) rename src/{audio.rs => media.rs} (69%) diff --git a/src/bin/monokakido-explode.rs b/src/bin/monokakido-explode.rs index ea3cd7d..cea1145 100644 --- a/src/bin/monokakido-explode.rs +++ b/src/bin/monokakido-explode.rs @@ -33,6 +33,7 @@ fn explode() -> Result<(), Error> { let pages_dir = out_dir(&dict) + "pages/"; let audio_dir = out_dir(&dict) + "audio/"; + let graphics_dir = out_dir(&dict) + "graphics/"; create_dir_all(&pages_dir)?; let mut path = String::from(&pages_dir); @@ -56,6 +57,18 @@ fn explode() -> Result<(), Error> { } } + if let Some(graphics) = &mut dict.graphics { + create_dir_all(&graphics_dir)?; + let mut path = String::from(&graphics_dir); + for idx in graphics.idx_iter()? { + let (id, graphics) = graphics.get_by_idx(idx)?; + write!(&mut path, "{id}")?; + let mut file = File::create(&path)?; + path.truncate(graphics_dir.len()); + file.write_all(graphics)?; + } + } + write_index(&dict, &dict.keys.index_len, "index_len.tsv")?; write_index(&dict, &dict.keys.index_prefix, "index_prefix.tsv")?; write_index(&dict, &dict.keys.index_suffix, "index_suffix.tsv")?; diff --git a/src/dict.rs b/src/dict.rs index ecb2d38..b010806 100644 --- a/src/dict.rs +++ b/src/dict.rs @@ -5,12 +5,13 @@ use std::{ path::{Path, PathBuf}, }; -use crate::{audio::Audio, key::Keys, pages::Pages, Error}; +use crate::{media::Media, key::Keys, pages::Pages, Error}; pub struct MonokakidoDict { paths: Paths, pub pages: Pages, - pub audio: Option