mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-11 22:50:08 +00:00
ability to exclude folders from resource registry
This commit is contained in:
@@ -805,6 +805,7 @@ mod tests {
|
||||
io,
|
||||
loaders,
|
||||
Path::new(TEST_FOLDER1).join("resources.registry"),
|
||||
Default::default(),
|
||||
));
|
||||
|
||||
assert!(std::fs::exists(make_metadata_file_path(TEST_FOLDER1, 0)).unwrap());
|
||||
|
||||
@@ -485,9 +485,10 @@ impl ResourceManagerState {
|
||||
path.display()
|
||||
);
|
||||
|
||||
let task_resource_io = self.resource_io.clone();
|
||||
let task_resource_registry = self.resource_registry.clone();
|
||||
let registry_status = task_resource_registry.lock().status.clone();
|
||||
let resource_io = self.resource_io.clone();
|
||||
let resource_registry = self.resource_registry.clone();
|
||||
let excluded_folders = resource_registry.lock().excluded_folders.clone();
|
||||
let registry_status = resource_registry.lock().status.clone();
|
||||
registry_status.mark_as_loading();
|
||||
let task_loaders = self.loaders.clone();
|
||||
self.task_pool.spawn_task(async move {
|
||||
@@ -495,16 +496,21 @@ impl ResourceManagerState {
|
||||
// Wasm is an exception, because it does not have a file system.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
let new_data =
|
||||
ResourceRegistry::scan(task_resource_io.clone(), task_loaders, &path).await;
|
||||
if let Err(error) = new_data.save(&path, &*task_resource_io).await {
|
||||
let new_data = ResourceRegistry::scan(
|
||||
resource_io.clone(),
|
||||
task_loaders,
|
||||
&path,
|
||||
excluded_folders,
|
||||
)
|
||||
.await;
|
||||
if let Err(error) = new_data.save(&path, &*resource_io).await {
|
||||
err!(
|
||||
"Unable to write the resource registry at the {} path! Reason: {:?}",
|
||||
path.display(),
|
||||
error
|
||||
)
|
||||
}
|
||||
let mut lock = task_resource_registry.lock();
|
||||
let mut lock = resource_registry.lock();
|
||||
lock.set_container(new_data);
|
||||
registry_status.mark_as_loaded();
|
||||
|
||||
@@ -518,9 +524,10 @@ impl ResourceManagerState {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
// Then load the registry.
|
||||
match registry::RegistryContainer::load_from_file(&path, &*task_resource_io).await {
|
||||
match crate::registry::RegistryContainer::load_from_file(&path, &*resource_io).await
|
||||
{
|
||||
Ok(registry) => {
|
||||
let mut lock = task_resource_registry.lock();
|
||||
let mut lock = resource_registry.lock();
|
||||
lock.set_container(registry);
|
||||
|
||||
registry_status.mark_as_loaded();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
use crate::{
|
||||
io::ResourceIo, loader::ResourceLoadersContainer, metadata::ResourceMetadata, state::WakersList,
|
||||
};
|
||||
use fxhash::FxHashSet;
|
||||
use fyrox_core::{
|
||||
append_extension, info, io::FileError, ok_or_return, parking_lot::Mutex, replace_slashes, warn,
|
||||
Uuid,
|
||||
@@ -160,10 +161,26 @@ async fn make_relative_path_async<P: AsRef<Path>>(
|
||||
|
||||
/// Resource registry is responsible for UUID mapping of resource files. It maintains a map of
|
||||
/// `UUID -> Resource Path`.
|
||||
#[derive(Default, Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct ResourceRegistry {
|
||||
pub paths: RegistryContainer,
|
||||
pub status: ResourceRegistryStatusFlag,
|
||||
pub excluded_folders: FxHashSet<PathBuf>,
|
||||
}
|
||||
|
||||
impl Default for ResourceRegistry {
|
||||
fn default() -> Self {
|
||||
let mut excluded_folders = FxHashSet::default();
|
||||
|
||||
// Exclude build artifacts folder by default.
|
||||
excluded_folders.insert(PathBuf::from("target"));
|
||||
|
||||
Self {
|
||||
paths: Default::default(),
|
||||
status: Default::default(),
|
||||
excluded_folders,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ResourceRegistry {
|
||||
@@ -262,6 +279,7 @@ impl ResourceRegistry {
|
||||
resource_io: Arc<dyn ResourceIo>,
|
||||
loaders: Arc<Mutex<ResourceLoadersContainer>>,
|
||||
root: impl AsRef<Path>,
|
||||
excluded_folders: FxHashSet<PathBuf>,
|
||||
) -> RegistryContainer {
|
||||
let registry_path = root.as_ref();
|
||||
let registry_folder = registry_path
|
||||
@@ -276,11 +294,13 @@ impl ResourceRegistry {
|
||||
|
||||
let mut container = RegistryContainer::default();
|
||||
|
||||
let file_iterator = ok_or_return!(
|
||||
resource_io.walk_directory(®istry_folder).await,
|
||||
let mut paths_to_visit = ok_or_return!(
|
||||
resource_io.read_directory(®istry_folder).await,
|
||||
container
|
||||
);
|
||||
for fs_path in file_iterator {
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
while let Some(fs_path) = paths_to_visit.pop() {
|
||||
let path = match make_relative_path_async(&fs_path, &*resource_io).await {
|
||||
Ok(path) => path,
|
||||
Err(err) => {
|
||||
@@ -294,6 +314,24 @@ impl ResourceRegistry {
|
||||
}
|
||||
};
|
||||
|
||||
if excluded_folders.contains(&path) {
|
||||
warn!(
|
||||
"Skipping {} folder, because it is in the excluded folders list!",
|
||||
path.display()
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if resource_io.is_dir(&path).await {
|
||||
// Continue iterating on subfolders.
|
||||
if let Ok(iter) = resource_io.read_directory(&path).await {
|
||||
paths_to_visit.extend(iter);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if !loaders.lock().is_supported_resource(&path) {
|
||||
if path
|
||||
.extension()
|
||||
|
||||
Reference in New Issue
Block a user