This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-nitride-cil/src/MfGames.Nitride.IO/Paths/DirectChildPathScanner.cs

47 lines
1.2 KiB
C#

using System.Collections.Generic;
using FluentValidation;
using MfGames.Gallium;
using MfGames.Nitride.Entities;
using Zio;
namespace MfGames.Nitride.IO.Paths;
/// <summary>
/// Implements a scanner that gathers up all the direct child files
/// and folders underneath a given path.
/// </summary>
[WithProperties]
public partial class DirectChildPathScanner : EntityScanner
{
/// <inheritdoc />
public DirectChildPathScanner(IValidator<EntityScanner> validator)
: base(validator)
{
this.GetKeysFromEntity = this.InternalGetKeysFromEntity;
}
private IEnumerable<string>? InternalGetKeysFromEntity(Entity entity)
{
// Get the path for the entity. If we don't have a path, then there
// is nothing to do.
if (!entity.TryGet(out UPath path))
{
return null;
}
// If we are a root path, then we don't have a parent.
if (path.IsEmpty || path.IsNull || path == "/")
{
return null;
}
// If we are using directory indexes, skip when we have an index root.
// Otherwise, get the parent and use that as the key.
return path.GetDirectoryIndexPath() == "/" ? null : new[] { path.GetParentDirectoryIndexPath() };
}
}