diff --git a/src/dict.rs b/src/dict.rs index ecb2d38..5545414 100644 --- a/src/dict.rs +++ b/src/dict.rs @@ -60,9 +60,7 @@ impl Paths { } pub(crate) fn key_path(&self) -> PathBuf { - let mut pb = PathBuf::from(&self.base_path); - pb.push("Contents"); - pb.push(&self.contents_dir); + let mut pb = self.contents_path(); pb.push("key"); pb } @@ -74,9 +72,7 @@ impl Paths { } pub(crate) fn headline_path(&self) -> PathBuf { - let mut pb = PathBuf::from(&self.base_path); - pb.push("Contents"); - pb.push(&self.contents_dir); + let mut pb = self.contents_path(); pb.push("headline"); pb } @@ -136,7 +132,7 @@ impl MonokakidoDict { }; let pages = Pages::new(&paths)?; let audio = Audio::new(&paths)?; - let keys = Keys::new(&paths)?; + let keys = Keys::new(paths.key_headword_path())?; Ok(MonokakidoDict { paths, diff --git a/src/key.rs b/src/key.rs index 0695e95..d5603c2 100644 --- a/src/key.rs +++ b/src/key.rs @@ -2,6 +2,7 @@ use std::{ borrow::Cow, cmp::Ordering, fs::File, + path::Path, io::{Read, Seek}, mem::size_of, str::from_utf8, @@ -9,7 +10,6 @@ use std::{ use crate::{ abi_utils::{TransmuteSafe, LE32, read_vec}, - dict::Paths, Error, }; @@ -119,8 +119,8 @@ impl Keys { Ok(()) } - pub fn new(paths: &Paths) -> Result { - let mut file = File::open(paths.key_headword_path())?; + pub fn new>(path: P) -> Result { + let mut file = File::open(path)?; let file_size = file.metadata()?.len() as usize; let mut hdr = FileHeader::default(); file.read_exact(hdr.as_bytes_mut())?; diff --git a/src/lib.rs b/src/lib.rs index 0fd5c29..68fa38d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ mod dict; mod error; mod key; mod pages; -mod resource; +pub mod resource; mod headline; pub use audio::Audio; diff --git a/src/resource/nrsc.rs b/src/resource/nrsc.rs index cab1bba..3eb928a 100644 --- a/src/resource/nrsc.rs +++ b/src/resource/nrsc.rs @@ -210,7 +210,7 @@ impl Nrsc { Ok(files) } - pub(crate) fn new(path: &Path) -> Result { + pub fn new(path: &Path) -> Result { let files = Nrsc::files(path)?; let index = NrscIndex::new(path)?; Ok(Nrsc { diff --git a/src/resource/rsc.rs b/src/resource/rsc.rs index 759fee8..2f6a37a 100644 --- a/src/resource/rsc.rs +++ b/src/resource/rsc.rs @@ -280,7 +280,7 @@ impl Rsc { Ok(files) } - pub(crate) fn new(path: &Path, rsc_name: &str) -> Result { + pub fn new(path: &Path, rsc_name: &str) -> Result { let files = Rsc::files(path, rsc_name)?; let index = RscIndex::new(path, rsc_name)?; Ok(Self {