Beispiel #1
0
        private Result ReadImpl(out long entriesRead, ref FindPosition position, Span <DirectoryEntry> entryBuffer)
        {
            HierarchicalRomFileTable <RomFileInfo> tab = ParentFileSystem.FileTable;

            int i = 0;

            if (Mode.HasFlag(OpenDirectoryMode.Directory))
            {
                while ((entryBuffer.IsEmpty || i < entryBuffer.Length) && tab.FindNextDirectory(ref position, out string name))
                {
                    if (!entryBuffer.IsEmpty)
                    {
                        ref DirectoryEntry entry    = ref entryBuffer[i];
                        Span <byte>        nameUtf8 = Encoding.UTF8.GetBytes(name);

                        StringUtils.Copy(entry.Name, nameUtf8);
                        entry.Name[PathTools.MaxPathLength] = 0;

                        entry.Type = DirectoryEntryType.Directory;
                        entry.Size = 0;
                    }

                    i++;
                }
            }
Beispiel #2
0
 public RomFsDirectory(RomFsFileSystem fs, FindPosition position, OpenDirectoryMode mode)
 {
     ParentFileSystem = fs;
     InitialPosition  = position;
     _currentPosition = position;
     Mode             = mode;
 }
Beispiel #3
0
        /// <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 T info, out string name)
        {
            if (position.NextFile == -1)
            {
                UnsafeHelpers.SkipParamInit(out info, out name);
                return(false);
            }

            ref FileRomEntry entry = ref FileTable.GetValueReference(position.NextFile, out Span <byte> nameBytes);
Beispiel #4
0
        /// <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 T 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);
Beispiel #5
0
        /// <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);
        }
Beispiel #6
0
        /// <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);
            }

            UnsafeHelpers.SkipParamInit(out position);
            return(false);
        }
Beispiel #7
0
        /// <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);
        }
Beispiel #8
0
        /// <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(StringUtils.StringToUtf8(path), out RomEntryKey key);

            if (DirectoryTable.TryGetValue(ref key, out RomKeyValuePair <DirectoryRomEntry> keyValuePair))
            {
                position = keyValuePair.Value.Pos;
                return(true);
            }

            UnsafeHelpers.SkipParamInit(out position);
            return(false);
        }
Beispiel #9
0
        public Result GetEntryCount(out long entryCount)
        {
            FindPosition position = InitialPosition;

            return(ReadImpl(out entryCount, ref position, Span <DirectoryEntry> .Empty));
        }
Beispiel #10
0
        protected override Result DoGetEntryCount(out long entryCount)
        {
            FindPosition position = InitialPosition;

            return(ReadImpl(out entryCount, ref position, Span <DirectoryEntry> .Empty));
        }