expose more internals for external use

This commit is contained in:
Jimmy-Z 2023-08-19 20:56:21 +08:00
parent 5ec9bd59ec
commit 243006ceff
5 changed files with 9 additions and 13 deletions

View file

@ -60,9 +60,7 @@ impl Paths {
} }
pub(crate) fn key_path(&self) -> PathBuf { pub(crate) fn key_path(&self) -> PathBuf {
let mut pb = PathBuf::from(&self.base_path); let mut pb = self.contents_path();
pb.push("Contents");
pb.push(&self.contents_dir);
pb.push("key"); pb.push("key");
pb pb
} }
@ -74,9 +72,7 @@ impl Paths {
} }
pub(crate) fn headline_path(&self) -> PathBuf { pub(crate) fn headline_path(&self) -> PathBuf {
let mut pb = PathBuf::from(&self.base_path); let mut pb = self.contents_path();
pb.push("Contents");
pb.push(&self.contents_dir);
pb.push("headline"); pb.push("headline");
pb pb
} }
@ -136,7 +132,7 @@ impl MonokakidoDict {
}; };
let pages = Pages::new(&paths)?; let pages = Pages::new(&paths)?;
let audio = Audio::new(&paths)?; let audio = Audio::new(&paths)?;
let keys = Keys::new(&paths)?; let keys = Keys::new(paths.key_headword_path())?;
Ok(MonokakidoDict { Ok(MonokakidoDict {
paths, paths,

View file

@ -2,6 +2,7 @@ use std::{
borrow::Cow, borrow::Cow,
cmp::Ordering, cmp::Ordering,
fs::File, fs::File,
path::Path,
io::{Read, Seek}, io::{Read, Seek},
mem::size_of, mem::size_of,
str::from_utf8, str::from_utf8,
@ -9,7 +10,6 @@ use std::{
use crate::{ use crate::{
abi_utils::{TransmuteSafe, LE32, read_vec}, abi_utils::{TransmuteSafe, LE32, read_vec},
dict::Paths,
Error, Error,
}; };
@ -119,8 +119,8 @@ impl Keys {
Ok(()) Ok(())
} }
pub fn new(paths: &Paths) -> Result<Keys, Error> { pub fn new<P: AsRef<Path>>(path: P) -> Result<Keys, Error> {
let mut file = File::open(paths.key_headword_path())?; let mut file = File::open(path)?;
let file_size = file.metadata()?.len() as usize; let file_size = file.metadata()?.len() as usize;
let mut hdr = FileHeader::default(); let mut hdr = FileHeader::default();
file.read_exact(hdr.as_bytes_mut())?; file.read_exact(hdr.as_bytes_mut())?;

View file

@ -4,7 +4,7 @@ mod dict;
mod error; mod error;
mod key; mod key;
mod pages; mod pages;
mod resource; pub mod resource;
mod headline; mod headline;
pub use audio::Audio; pub use audio::Audio;

View file

@ -210,7 +210,7 @@ impl Nrsc {
Ok(files) Ok(files)
} }
pub(crate) fn new(path: &Path) -> Result<Self, Error> { pub fn new(path: &Path) -> Result<Self, Error> {
let files = Nrsc::files(path)?; let files = Nrsc::files(path)?;
let index = NrscIndex::new(path)?; let index = NrscIndex::new(path)?;
Ok(Nrsc { Ok(Nrsc {

View file

@ -280,7 +280,7 @@ impl Rsc {
Ok(files) Ok(files)
} }
pub(crate) fn new(path: &Path, rsc_name: &str) -> Result<Self, Error> { pub fn new(path: &Path, rsc_name: &str) -> Result<Self, Error> {
let files = Rsc::files(path, rsc_name)?; let files = Rsc::files(path, rsc_name)?;
let index = RscIndex::new(path, rsc_name)?; let index = RscIndex::new(path, rsc_name)?;
Ok(Self { Ok(Self {