Exemplo n.º 1
0
        /// <summary>
        /// Builds the directory and file tree.
        /// </summary>
        /// <param name="currentDirectory">The current directory.</param>
        /// <param name="currentDirectoryContent">The desired content of the current directory.</param>
        /// <param name="records">All <see cref="GgpkRecord">records</see> from the ggpk archive used to find the references.</param>
        private void BuildDirectoryTree(
            GgpkDirectory currentDirectory,
            IEnumerable <GgpkDirectoryRecordEntry> currentDirectoryContent,
            IDictionary <ulong, GgpkRecord> records)
        {
            foreach (GgpkDirectoryRecordEntry recordEntry in currentDirectoryContent)
            {
                GgpkRecord referencedRecord = records[recordEntry.Offset];

                if (referencedRecord is null)
                {
                    throw new GgpkException($"Error while analyzing the ggpk archive file: no element found at offset {recordEntry.Offset}");
                }

                switch (referencedRecord)
                {
                case GgpkDirectoryRecord directoryRecord:

                    GgpkDirectory directory = new GgpkDirectory()
                    {
                        Name            = directoryRecord.DirectoryName,
                        TimeStamp       = recordEntry.TimeStamp,
                        Hash            = directoryRecord.Hash,
                        Parent          = currentDirectory,
                        ArchiveFileName = this.FileName
                    };

                    if (currentDirectory != null)
                    {
                        currentDirectory.Add(directory);
                    }
                    else
                    {
                        this.root = directory;
                    }

                    this.BuildDirectoryTree(directory, directoryRecord.Entries, records);

                    break;

                case GgpkFileRecord fileRecord:

                    GgpkFile file = new GgpkFile()
                    {
                        Name            = fileRecord.FileName,
                        TimeStamp       = recordEntry.TimeStamp,
                        Hash            = fileRecord.Hash,
                        Offset          = fileRecord.FileOffset,
                        Length          = fileRecord.FileLength,
                        Parent          = currentDirectory,
                        ArchiveFileName = this.FileName
                    };

                    currentDirectory.Add(file);

                    break;

                case GgpkFreeRecord freeRecord:
                    break;

                default:
                    throw new GgpkException($"Error while analyzing the ggpk archive file: no element of type directory or file found at offset {recordEntry.Offset}");
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a file to the list of files.
 /// </summary>
 /// <param name="file">The file to add.</param>
 public void Add(GgpkFile file)
 {
     this.files.Add(file);
 }