aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-vfs/src/lib.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 06:04:16 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 06:04:16 +0300
commit7b3a106ff7a376b95b3bb9e52d3186ebe1a9bcaa (patch)
treec08796dc7a745059701845d735156600202c1b24 /crates/fparkan-vfs/src/lib.rs
parent0d8031eccad92190ea01c2c7f9a2cee28adecb62 (diff)
downloadfparkan-7b3a106ff7a376b95b3bb9e52d3186ebe1a9bcaa.tar.xz
fparkan-7b3a106ff7a376b95b3bb9e52d3186ebe1a9bcaa.zip
feat(ui): open saved warbot projects with distinct geometry
Prepare saved Unit DAT geometry alongside factory reserves at mission entry and expose compatible, researched files through the designer. Verified a single-gun assembly in the Field Camp window and after factory release with the ore and power supply established in the test.
Diffstat (limited to 'crates/fparkan-vfs/src/lib.rs')
-rw-r--r--crates/fparkan-vfs/src/lib.rs63
1 files changed, 54 insertions, 9 deletions
diff --git a/crates/fparkan-vfs/src/lib.rs b/crates/fparkan-vfs/src/lib.rs
index 3c92fa17..a2cc3c82 100644
--- a/crates/fparkan-vfs/src/lib.rs
+++ b/crates/fparkan-vfs/src/lib.rs
@@ -81,6 +81,19 @@ pub trait Vfs: Send + Sync {
/// Returns [`VfsError`] when the prefix is invalid, missing, or cannot be
/// traversed by the backing store.
fn list(&self, prefix: &NormalizedPath) -> Result<Vec<VfsEntry>, VfsError>;
+ /// Lists regular files immediately inside a directory.
+ fn list_files(&self, directory: &NormalizedPath) -> Result<Vec<NormalizedPath>, VfsError> {
+ Ok(self
+ .list(directory)?
+ .into_iter()
+ .map(|entry| entry.path)
+ .filter(|path| {
+ path.as_str()
+ .rsplit_once('/')
+ .is_some_and(|(parent, _)| parent.eq_ignore_ascii_case(directory.as_str()))
+ })
+ .collect())
+ }
}
/// Host directory VFS.
@@ -151,6 +164,18 @@ impl Vfs for DirectoryVfs {
entries.sort_by(|a, b| a.path.as_bytes().cmp(b.path.as_bytes()));
Ok(entries)
}
+
+ fn list_files(&self, directory: &NormalizedPath) -> Result<Vec<NormalizedPath>, VfsError> {
+ let mut files = Vec::new();
+ for entry in fs::read_dir(self.host_path(directory)?).map_err(VfsError::Io)? {
+ let entry = entry.map_err(VfsError::Io)?;
+ if entry.file_type().map_err(VfsError::Io)?.is_file() {
+ files.push(normalize_host_path(&self.root, &entry.path())?);
+ }
+ }
+ files.sort_by(|a, b| a.as_bytes().cmp(b.as_bytes()));
+ Ok(files)
+ }
}
fn resolve_casefolded(root: &Path, normalized: &NormalizedPath) -> Result<PathBuf, VfsError> {
@@ -258,22 +283,24 @@ fn list_recursive(root: &Path, dir: &Path, out: &mut Vec<VfsEntry>) -> Result<()
if !metadata.is_file() {
continue;
}
- let rel = child.strip_prefix(root).map_err(|_| VfsError::Path)?;
- #[cfg(unix)]
- let rel_bytes = rel.as_os_str().as_bytes();
- #[cfg(not(unix))]
- let rel_bytes = rel.to_str().ok_or(VfsError::Path)?.as_bytes();
- let path =
- fparkan_path::normalize_relative(rel_bytes, fparkan_path::PathPolicy::HostCompatible)
- .map_err(|_| VfsError::Path)?;
out.push(VfsEntry {
- path,
+ path: normalize_host_path(root, &child)?,
metadata: metadata_from_host_file(&child, &metadata)?,
});
}
Ok(())
}
+fn normalize_host_path(root: &Path, child: &Path) -> Result<NormalizedPath, VfsError> {
+ let relative = child.strip_prefix(root).map_err(|_| VfsError::Path)?;
+ #[cfg(unix)]
+ let bytes = relative.as_os_str().as_bytes();
+ #[cfg(not(unix))]
+ let bytes = relative.to_str().ok_or(VfsError::Path)?.as_bytes();
+ fparkan_path::normalize_relative(bytes, fparkan_path::PathPolicy::HostCompatible)
+ .map_err(|_| VfsError::Path)
+}
+
fn metadata_from_host_file(path: &Path, metadata: &fs::Metadata) -> Result<VfsMetadata, VfsError> {
if !metadata.is_file() {
return Err(VfsError::Path);
@@ -486,6 +513,24 @@ impl Vfs for OverlayVfs {
entries.sort_by(|a, b| a.path.as_bytes().cmp(b.path.as_bytes()));
Ok(entries)
}
+
+ fn list_files(&self, directory: &NormalizedPath) -> Result<Vec<NormalizedPath>, VfsError> {
+ let mut names = BTreeMap::new();
+ for layer in &self.layers {
+ match layer.list_files(directory) {
+ Ok(files) => {
+ for path in files {
+ names
+ .entry(ascii_lookup_key(path.as_bytes()).0)
+ .or_insert(path);
+ }
+ }
+ Err(VfsError::NotFound(_)) => {}
+ Err(error) => return Err(error),
+ }
+ }
+ Ok(names.into_values().collect())
+ }
}
#[cfg(test)]