This is going to be the last wad info window thingy

Going to remove it to focus on something more interesting

Or at least more achievable
This commit is contained in:
2023-07-27 22:33:08 +01:00
parent 07f7b67119
commit dbe4b550ac
3 changed files with 38 additions and 23 deletions

View File

@@ -5,7 +5,6 @@ use std::fs::File;
use std::fs;
use std::io::{BufReader, Seek, SeekFrom};
use std::path::PathBuf;
use strsim;
/*
A great document I've used as a reference is The Unofficial Doom Specs v1.666
@@ -58,26 +57,25 @@ pub struct OpenWad {
level_indicies: Vec<usize>,
}
pub fn find_txt_file(path: &PathBuf) -> Option<PathBuf> {
pub fn get_summary(path: &PathBuf) -> Option<String> {
if let Some(tf) = find_txt_file(&path) {
println!("{}", tf.display());
let text_file_contents = fs::read_to_string(tf).unwrap();
Some(text_file_contents)
} else {
None
}
}
fn find_txt_file(path: &PathBuf) -> Option<PathBuf> {
if !path.exists() || !path.is_file() {
return None
}
if let (Some(f), Some(p)) = (path.file_name(), path.parent()) {
let files_in_folder = fs::read_dir(&p).unwrap();
let mut txt_file = PathBuf::from(f);
txt_file.set_extension(".txt");
let txt_file = txt_file.into_os_string().into_string().unwrap().to_lowercase();
for f in files_in_folder {
// Jesus this can't be the right way to do things
let f1 = f.unwrap().path().file_name().unwrap().to_os_string().into_string().unwrap();
let f2 = f1.clone().to_lowercase();
let result = strsim::normalized_levenshtein(&txt_file, &f2);
if result > 0.5 {
let mut f3 = PathBuf::from(p);
f3.push(f1);
return Some(f3);
}
}
let mut txt_file = PathBuf::from(path);
txt_file.set_extension("txt");
println!("{}", txt_file.display());
if txt_file.exists() {
return Some(txt_file);
}
None
}