extract image assets for yomitan zip

This commit is contained in:
polv committed 2026-03-21 12:46:54 +07:00
1 parent 79deaf9372
commit 52c25992ab
11 files changed
+114 -52

No files matched your search

+24 -1
View File
@@ -7,7 +7,8 @@ use std::{
borrow::Cow,
collections::HashMap,
env::current_dir,
io::{Cursor, Read},
fs::{File, create_dir_all},
io::{self, Cursor, Read},
path::{Path, PathBuf},
};
use zip::ZipArchive;
@@ -437,6 +438,7 @@ impl YomitanWriter {
pub fn import_dictionary_zip_file<Z, Callback>(
&mut self,
zip_file: &Z,
asset_dir: &PathBuf,
lang: &str,
progress_callback: Callback,
) -> anyhow::Result<YomitanZipImportResult, CJDicError>
@@ -452,6 +454,27 @@ impl YomitanWriter {
let cursor = Cursor::new(zip_file.bytes()?);
let mut archive = ZipArchive::new(cursor)?;
for i in 0..archive.len() {
// Metadata — borrow ends before by_index_raw
let (name, is_dir) = {
let f = archive.by_index(i)?;
(f.name().to_owned(), f.is_dir())
};
if !name.starts_with("assets") || is_dir {
continue;
}
let out_path = asset_dir.join(name);
if let Some(parent) = out_path.parent() {
create_dir_all(parent)?;
}
let mut entry = archive.by_index(i)?;
let mut out = File::create(&out_path)?;
io::copy(&mut entry, &mut out)?; // writes plain bytes
}
let index_file = match archive.by_name("index.json") {
Ok(mut f) => {
let mut s = String::new();