diff --git a/Cargo.lock b/Cargo.lock index a444308..5b5e416 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "fo2dat" -version = "0.0.1" +version = "0.0.5" dependencies = [ "byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index c9cf500..dec4efa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fo2dat" -version = "0.0.1" +version = "0.0.5" authors = ["Adam Kewley "] [dependencies] diff --git a/src/lib.rs b/src/lib.rs index 2fe0fea..ea5af42 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,7 +82,7 @@ pub fn read_tree_entry(data: &[u8]) -> io::Result<(TreeEntry, usize)> { return Err(err); } - let filename = match str::from_utf8(&data[TREE_ENTRY_HEADER_SIZE + 1..filename_len]) { + let filename = match str::from_utf8(&data[TREE_ENTRY_HEADER_SIZE..filename_len]) { Ok(s) => { let mut filename = PathBuf::new(); for el in s.split(TREE_ENTRY_PATH_SEPARATOR) { @@ -130,8 +130,15 @@ pub fn list_contents(dat_path_str: &str) -> io::Result<()> { fn mmap_dat(dat_path_str: &str) -> io::Result { let dat_path = Path::new(&dat_path_str); - let dat_file = File::open(dat_path)?; - unsafe { Mmap::map(&dat_file) } + if dat_path.exists() { + let dat_file = File::open(dat_path)?; + unsafe { Mmap::map(&dat_file) } + } else { + let err_kind = std::io::ErrorKind::NotFound; + let err_msg = format!("{}: no such file", dat_path_str); + let err = std::io::Error::new(err_kind, err_msg); + return Err(err); + } } fn find_entries(dat_file: &[u8]) -> io::Result {