From d7ce4bdadb10ea4e70f8e48e2ddb990cf3087c49 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 17 May 2020 01:39:32 -0700 Subject: windows --- src/epub.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/epub.rs b/src/epub.rs index 4758a24..fa5f33f 100644 --- a/src/epub.rs +++ b/src/epub.rs @@ -97,7 +97,11 @@ impl Epub { let xml = self.get_text(path); let doc = Document::parse(&xml).unwrap(); - let rootdir = std::path::Path::new(&path).parent().unwrap(); + // zip expects unix path even on windows + let rootdir = match path.rfind('/') { + Some(n) => &path[..n+1], + None => "", + }; let mut manifest = HashMap::new(); doc.root_element() @@ -122,7 +126,7 @@ impl Epub { .unwrap() .attribute("href") .unwrap(); - let xml = self.get_text(rootdir.join(path).to_str().unwrap()); + let xml = self.get_text(&format!("{}{}", rootdir, path)); let doc = Document::parse(&xml).unwrap(); doc.descendants() @@ -141,7 +145,7 @@ impl Epub { }) } else { let path = manifest.get("ncx").unwrap(); - let xml = self.get_text(rootdir.join(path).to_str().unwrap()); + let xml = self.get_text(&format!("{}{}", rootdir, path)); let doc = Document::parse(&xml).unwrap(); doc.descendants() @@ -179,7 +183,7 @@ impl Epub { let id = n.attribute("idref").unwrap(); let path = manifest.remove(id).unwrap(); let label = nav.remove(path).unwrap_or_else(|| i.to_string()); - let path = rootdir.join(path).to_str().unwrap().to_string(); + let path = format!("{}{}", rootdir, path); (path, label) }) .collect() -- cgit v1.2.3