public IEnumerable <IHandle> Globber(IDirectoryHandle directory) { using var enumerator = _globs.GetEnumerator(); IEnumerable <IDirectoryHandle> directories = new[] { directory }; Globber?glob = null; if (enumerator.MoveNext()) { while (true) { glob = enumerator.Current !; var next = enumerator.MoveNext(); if (!next) { break; } var globC = glob; directories = directories.SelectMany(d => globC(d)).WhereCast <IHandle, IDirectoryHandle>(); } } return(glob is null?directories.Cast <IHandle>() : directories.SelectMany(d => glob(d))); }
private Mod.Manifest CreateManifest(IDirectoryHandle resources) { if (resources[Filesystem.ManifestName] is not IFileHandle manifestFile) { throw new FileNotFoundException("Manifest file was not present.", Filesystem.ManifestName); } return(_manifestReader(manifestFile)); }
public static IEnumerable <IHandle> Parent(IDirectoryHandle directory) { if (directory is not IChildDirectoryHandle child) { throw new InvalidOperationException("A parent glob was used on the root directory."); } yield return(child.Directory); }
public static IEnumerable <IHandle> Globstar(IDirectoryHandle directory) { yield return(directory); foreach (var child in directory.GetRecursive()) { yield return(child); } }
/// <summary> /// Creates an instance of <see cref="Mod"/> /// </summary> /// <param name="info"></param> /// <param name="resources"></param> public Mod(Manifest info, IDirectoryHandle resources) { var deliCfgPath = Path.Combine(Paths.ConfigPath, Constants.Metadata.Name); Directory.CreateDirectory(deliCfgPath); Info = info; Resources = resources; Config = new ConfigFile(Path.Combine(deliCfgPath, info.Guid + ".cfg"), false); Logger = BepInEx.Logging.Logger.CreateLogSource(info.Name ?? info.Guid); }
/// <summary> /// Enumerates over all the subdirectories contained by the directory, recursively /// </summary> public static IEnumerable <IChildDirectoryHandle> GetDirectoriesRecursive(this IDirectoryHandle @this) { foreach (var directory in @this.GetDirectories()) { yield return(directory); foreach (var subdirectory in directory.GetDirectoriesRecursive()) { yield return(subdirectory); } } }
/// <summary> /// Enumerates over all of the children of the directory, recursively /// </summary> public static IEnumerable <IChildHandle> GetRecursive(this IDirectoryHandle @this) { foreach (var child in @this) { if (child is IDirectoryHandle subdirectory) { foreach (var subchild in subdirectory.GetRecursive()) { yield return(subchild); } } yield return(child); } }
/// <summary> /// Enumerates over all the files contained by the directory, recursively /// </summary> public static IEnumerable <IFileHandle> GetFilesRecursive(this IDirectoryHandle @this) { foreach (var child in @this) { if (child is IDirectoryHandle subdirectory) { foreach (var subfile in subdirectory.GetFilesRecursive()) { yield return(subfile); } } if (child is IFileHandle file) { yield return(file); } } }
public static IEnumerable <IHandle> Current(IDirectoryHandle directory) { yield return(directory); }
public static IEnumerable <IHandle> Root(IDirectoryHandle directory) { yield return(directory.GetRoot()); }
/// <summary> /// Gets a file contained by the directory /// </summary> /// <param name="this"></param> /// <param name="name">The name of the file</param> public static IFileHandle?GetFile(this IDirectoryHandle @this, string name) { return(@this[name] as IFileHandle); }
/// <summary> /// Enumerates over all the files contained by the directory /// </summary> public static IEnumerable <IFileHandle> GetFiles(this IDirectoryHandle @this) { return(@this.WhereCast <IChildHandle, IFileHandle>()); }
/// <summary> /// Gets a subdirectory contained by the directory /// </summary> /// <param name="this"></param> /// <param name="name">The name of the subdirectory</param> public static IChildDirectoryHandle?GetDirectory(this IDirectoryHandle @this, string name) { return(@this[name] as IChildDirectoryHandle); }
private Mod CreateMod(IDirectoryHandle resources) { return(new(CreateManifest(resources), resources)); }
public IEnumerable <IHandle> Globber(IDirectoryHandle directory) { return(directory.Where(c => _regex.IsMatch(c.Name)).Cast <IHandle>()); }
public static string Combine(IDirectoryHandle parent, string child) { return(parent.Path + "/" + child); }
/// <summary> /// Gets the root directory of the VFS that the handle resides in. This could be the provided handle. /// </summary> public static IDirectoryHandle GetRoot(this IDirectoryHandle @this) { return(@this is IChildHandle child?child.GetRoot() : @this); }