feat(content): add datapack discovery and world installs

This commit is contained in:
objz committed 2026-08-01 19:47:47 +02:00
1 parent a98426e22a
commit 7986bab3a7
27 files changed
+1138 -119

No files matched your search

+23
View File
@@ -30,6 +30,7 @@ pub fn scan_one_world(path: &Path, file_stem: &str, enabled: bool) -> ContentEnt
.filter(|version| !version.trim().is_empty())
.map(str::to_owned),
size: (size > 0).then(|| format_size(size)),
datapacks: datapack_names(path),
};
ContentEntry {
@@ -56,6 +57,28 @@ pub fn scan_one_world(path: &Path, file_stem: &str, enabled: bool) -> ContentEnt
}
}
pub(crate) fn datapack_names(world: &Path) -> Vec<String> {
let Ok(entries) = std::fs::read_dir(world.join("datapacks")) else {
return Vec::new();
};
let mut names = entries
.flatten()
.filter_map(|entry| {
let path = entry.path();
let name = path.file_name()?.to_str()?;
if path.is_dir() {
Some(name.trim_end_matches(".disabled").to_owned())
} else {
name.strip_suffix(".zip")
.or_else(|| name.strip_suffix(".zip.disabled"))
.map(str::to_owned)
}
})
.collect::<Vec<_>>();
names.sort_by_key(|name| name.to_lowercase());
names
}
pub fn scan_worlds(instances_dir: &Path, instance_name: &str) -> Vec<ContentEntry> {
let saves_dir = instances_dir
.join(instance_name)