public int GetEntryCount() { int count = 0; FindPosition position = InitialPosition; HierarchicalRomFileTable <RomFileInfo> tab = ParentFileSystem.FileTable; if (Mode.HasFlag(OpenDirectoryMode.Directories)) { while (tab.FindNextDirectory(ref position, out string _)) { count++; } } if (Mode.HasFlag(OpenDirectoryMode.Files)) { while (tab.FindNextFile(ref position, out RomFileInfo _, out string _)) { count++; } } return(count); }
public RomFsDirectory(RomFsFileSystem fs, string path, FindPosition position, OpenDirectoryMode mode) { ParentFileSystem = fs; InitialPosition = position; FullPath = path; Mode = mode; }
/// <summary> /// Returns the next file in a directory and updates the enumerator's position. /// </summary> /// <param name="position">The current position of the directory enumerator. /// This position will be updated when the method returns.</param> /// <param name="info">When this method returns, contains the file's metadata.</param> /// <param name="name">When this method returns, contains the file's name (Not the full path).</param> /// <returns><see langword="true"/> if the next file was successfully returned. /// <see langword="false"/> if there are no more files to enumerate.</returns> public bool FindNextFile(ref FindPosition position, out RomFileInfo info, out string name) { if (position.NextFile == -1) { info = default; name = default; return(false); } ref FileRomEntry entry = ref FileTable.GetValueReference(position.NextFile, out Span <byte> nameBytes);
/// <summary> /// Opens a directory for enumeration. /// </summary> /// <param name="directoryId">The ID of the directory to open.</param> /// <param name="position">When this method returns, contains the initial position of the directory enumerator.</param> /// <returns><see langword="true"/> if the table contains a directory with the specified path; /// otherwise, <see langword="false"/>.</returns> public bool TryOpenDirectory(int directoryId, out FindPosition position) { if (DirectoryTable.TryGetValue(directoryId, out RomKeyValuePair <DirectoryRomEntry> keyValuePair)) { position = keyValuePair.Value.Pos; return(true); } position = default; return(false); }
/// <summary> /// Opens a directory for enumeration. /// </summary> /// <param name="path">The full path of the directory to open.</param> /// <param name="position">The initial position of the directory enumerator.</param> /// <returns><see langword="true"/> if the table contains a directory with the specified path; /// otherwise, <see langword="false"/>.</returns> public bool TryOpenDirectory(string path, out FindPosition position) { FindPathRecursive(Util.GetUtf8Bytes(path), out RomEntryKey key); if (DirectoryTable.TryGetValue(ref key, out RomKeyValuePair <DirectoryRomEntry> keyValuePair)) { position = keyValuePair.Value.Pos; return(true); } position = default; return(false); }
public IEnumerable <DirectoryEntry> Read() { FindPosition position = InitialPosition; HierarchicalRomFileTable <RomFileInfo> tab = ParentFileSystem.FileTable; if (Mode.HasFlag(OpenDirectoryMode.Directories)) { while (tab.FindNextDirectory(ref position, out string name)) { yield return(new DirectoryEntry(name, PathTools.Combine(FullPath, name), DirectoryEntryType.Directory, 0)); } } if (Mode.HasFlag(OpenDirectoryMode.Files)) { while (tab.FindNextFile(ref position, out RomFileInfo info, out string name)) { yield return(new DirectoryEntry(name, PathTools.Combine(FullPath, name), DirectoryEntryType.File, info.Length)); } } }