using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using Robust.Shared.Utility; namespace Robust.Shared.ContentPack { /// /// Common interface for mounting various things in the VFS. /// public interface IContentRoot { /// /// Initializes the content root. /// Throws an exception if the content root failed to mount. /// void Mount(); /// /// Gets a file from the content root using the relative path. /// /// Relative path from the root directory. /// /// A stream of the file loaded into memory. bool TryGetFile(ResPath relPath, [NotNullWhen(true)] out Stream? stream); /// /// Returns true if the given file exists. /// public bool FileExists(ResPath relPath); /// /// Recursively finds all files in a directory and all sub directories. /// /// Directory to search inside of. /// Enumeration of all relative file paths of the files found. IEnumerable FindFiles(ResPath path); /// /// Recursively returns relative paths to resource files. /// /// Enumeration of all relative file paths. IEnumerable GetRelativeFilePaths(); IEnumerable GetEntries(ResPath path) { var countDirs = path == ResPath.Self ? 0 : path.CanonPath.Split('/').Count(); var options = FindFiles(path).Select(c => { var segment = c.CanonPath.Split('/'); var segCount = segment.Count(); var newPath = segment.Skip(countDirs).First(); if (segCount > countDirs + 1) newPath += "/"; return newPath; }).Distinct(); return options; } } }