From 6078b787b1380174abd7dc83bb1f32019cc68854 Mon Sep 17 00:00:00 2001 From: Brett Mayson Date: Thu, 24 Oct 2024 01:47:13 +0000 Subject: [PATCH] fix pointer scanning, add duplicate prefix error --- libs/common/src/prefix.rs | 3 ++ libs/workspace/src/lib.rs | 58 ++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/libs/common/src/prefix.rs b/libs/common/src/prefix.rs index e5b10ecb..bfd95362 100644 --- a/libs/common/src/prefix.rs +++ b/libs/common/src/prefix.rs @@ -117,6 +117,9 @@ pub enum Error { #[error("Invalid prefix: {0}")] /// Invalid prefix InvalidPrefix(String), + #[error("Duplicate prefix: {0}")] + /// Duplicate prefix + DuplicatePrefix(String), } #[cfg(test)] diff --git a/libs/workspace/src/lib.rs b/libs/workspace/src/lib.rs index ee102f06..f3f31c46 100644 --- a/libs/workspace/src/lib.rs +++ b/libs/workspace/src/lib.rs @@ -95,31 +95,45 @@ impl Workspace { } fn discover(&mut self) -> Result<(), Error> { - for entry in self.vfs.walk_dir()? { - let Ok(entry) = entry else { - trace!("unknown issue with entry: {:?}", entry); - continue; - }; - if entry.as_str().contains(".hemtt") { + for root in &["include", "optionals", "addons"] { + let root = self.vfs.join(root)?; + if !root.exists()? { continue; } - match entry.filename().to_lowercase().as_str() { - "config.cpp" => { - trace!("config.cpp: {:?}", entry); - self.addons.push(entry); - } - "mission.sqm" => { - trace!("mission.sqm: {:?}", entry); - self.missions.push(entry); + for entry in root.walk_dir()? { + let Ok(entry) = entry else { + trace!("unknown issue with entry: {:?}", entry); + continue; + }; + if entry.as_str().contains(".hemtt") { + continue; } - _ => { - if FILES.contains(&entry.filename().to_lowercase().as_str()) { - trace!("Prefix: {:?}", entry); - let prefix = Prefix::new(&entry.read_to_string()?)?; - self.pointers.insert( - format!("/{}", prefix.to_string().to_lowercase().replace('\\', "/")), - entry.parent(), - ); + match entry.filename().to_lowercase().as_str() { + "config.cpp" => { + trace!("config.cpp: {:?}", entry); + self.addons.push(entry); + } + "mission.sqm" => { + trace!("mission.sqm: {:?}", entry); + self.missions.push(entry); + } + _ => { + if FILES.contains(&entry.filename().to_lowercase().as_str()) { + trace!("Prefix: {:?}", entry); + let prefix = Prefix::new(&entry.read_to_string()?)?; + let prefix_str = format!( + "/{}", + prefix.to_string().to_lowercase().replace('\\', "/") + ); + if self.pointers.contains_key(&prefix_str) { + return Err(Error::Prefix( + hemtt_common::prefix::Error::DuplicatePrefix( + prefix.to_string(), + ), + )); + } + self.pointers.insert(prefix_str, entry.parent()); + } } } }