/// <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);
        public bool TryOpenFile(int fileId, out RomFileInfo fileInfo)
        {
            if (FileTable.TryGetValue(fileId, out RomKeyValuePair <FileRomEntry> keyValuePair))
            {
                fileInfo = keyValuePair.Value.Info;
                return(true);
            }

            fileInfo = default;
            return(false);
        }
        public bool TryOpenFile(string path, out RomFileInfo fileInfo)
        {
            FindPathRecursive(Util.GetUtf8Bytes(path), out RomEntryKey key);

            if (FileTable.TryGetValue(ref key, out RomKeyValuePair <FileRomEntry> keyValuePair))
            {
                fileInfo = keyValuePair.Value.Info;
                return(true);
            }

            fileInfo = default;
            return(false);
        }
示例#4
0
        /// <summary>
        /// Adds a file to the RomFS.
        /// </summary>
        /// <param name="path">The full path in the RomFS</param>
        /// <param name="file">An <see cref="IFile"/> of the file data to add.</param>
        public void AddFile(string path, IFile file)
        {
            var  fileInfo = new RomFileInfo();
            long fileSize = file.GetSize();

            fileInfo.Offset = CurrentOffset;
            fileInfo.Length = fileSize;

            IStorage fileStorage = file.AsStorage();

            Sources.Add(fileStorage);

            long newOffset = CurrentOffset + fileSize;

            CurrentOffset = Util.AlignUp(newOffset, FileAlignment);

            var padding = new NullStorage(CurrentOffset - newOffset);

            Sources.Add(padding);

            FileTable.AddFile(path, ref fileInfo);
        }