예제 #1
0
        /// <summary>
        /// Parse the file table.
        /// </summary>
        /// <returns>Number of files found.</returns>
        public override int ParseFileTable()
        {
            // Set correct position for data section
            this.dataCluster = this.tableCluster +
                               ((this.numFiles * 16) / this.clusterSize);
            if ((this.numFiles * 16) % this.clusterSize != 0)
            {
                this.dataCluster++;
            }

            long offset = this.clusterSize * this.tableCluster;

            this.fileTable = new List <FileItem>();

            string fileNameBase;

            { // Get file name base
                int fileNameStart = this.container.Name.LastIndexOf('\\') + 1;
                int fileNameEnd   = this.container.Name.LastIndexOf('.');
                if (fileNameEnd == -1)
                {
                    fileNameEnd = this.container.Name.Length;
                }
                fileNameBase = this.container.Name.Substring(fileNameStart, fileNameEnd - fileNameStart);
            }

            while (true)
            {
                Uni2FileItem item = new Uni2FileItem();
                item.fileId        = StreamUtility.ReadUIntFromStream(this.container, offset);
                item.startCluster  = StreamUtility.ReadUIntFromStream(this.container, offset + 4);
                item.lengthCluster = StreamUtility.ReadUIntFromStream(this.container, offset + 8);
                item.lengthByte    = StreamUtility.ReadUIntFromStream(this.container, offset + 12);
                offset            += 16;

                if (item.isValid())
                {
                    FileItem FileItem       = ConvertUni2ToGeneral(item, fileNameBase + "-" + Convert.ToSingle(item.fileId));
                    uint     fileIdentifier = StreamUtility.ReadUIntFromStream(this.container, FileItem.FileOffset);
                    string   fileExt        = StreamUtility.GetFileExtension(fileIdentifier);
                    FileItem.FileName += "." + fileExt;
                    fileTable.Add(FileItem);
                }
                else
                {
                    break;
                }
            }

            if (fileTable.Count != this.numFiles)
            {
                throw new FormatException(this.container.Name + ": The real number of files doesn't match the header value!" + System.Environment.NewLine +
                                          "The header indicated: " + Convert.ToString(this.numFiles) + System.Environment.NewLine +
                                          "The real number of files: " + Convert.ToString(fileTable.Count));
            }

            return(fileTable.Count);
        }
예제 #2
0
        /// <summary>
        /// Parse the file table.
        /// </summary>
        /// <returns>Number of files found.</returns>
        public override int ParseFileTable()
        {
            long offset = 8;
            uint fid    = 0;

            this.fileTable = new List <FileItem>();

            string fileNameBase;

            { // Get file name base
                int fileNameStart = this.container.Name.LastIndexOf('\\') + 1;
                int fileNameEnd   = this.container.Name.LastIndexOf('.');
                if (fileNameEnd == -1)
                {
                    fileNameEnd = this.container.Name.Length;
                }
                fileNameBase = this.container.Name.Substring(fileNameStart, fileNameEnd - fileNameStart);
            }

            while (true)
            {
                Lnk4FileItem item = new Lnk4FileItem();
                item.fileId      = fid;
                item.startOffset = StreamUtility.ReadUIntFromStream(this.container, offset, false) << 11;
                offset          += 4;
                item.length      = StreamUtility.ReadUIntFromStream(this.container, offset, false) << 10;
                offset          += 4;

                if (item.isValid())
                {
                    FileItem FileItem       = ConvertLnk4ToGeneral(item, fileNameBase + "-" + Convert.ToSingle(item.fileId));
                    uint     fileIdentifier = StreamUtility.ReadUIntFromStream(this.container, FileItem.FileOffset);
                    string   fileExt        = StreamUtility.GetFileExtension(fileIdentifier);
                    FileItem.FileName += "." + fileExt;
                    fileTable.Add(FileItem);
                }
                else
                {
                    break;
                }

                fid++;
            }

            return(fileTable.Count);
        }
예제 #3
0
        /// <summary>
        /// Parse the file table.
        /// </summary>
        /// <returns>Number of files found.</returns>
        public override int ParseFileTable()
        {
            long offset = this.tableOffset;

            uint[] fileOffset = new uint[numFiles + 1];

            this.fileTable = new List <FileItem>();

            // Read file offsets
            for (int i = 0; i < numFiles; i++)
            {
                fileOffset[i] = StreamUtility.ReadUIntFromStream(this.container, offset);
                offset       += 4;
            }
            fileOffset[numFiles] = (uint)this.container.Length;

            string fileNameBase;

            { // Get file name base
                int fileNameStart = this.container.Name.LastIndexOf('\\') + 1;
                int fileNameEnd   = this.container.Name.LastIndexOf('.');
                if (fileNameEnd == -1)
                {
                    fileNameEnd = this.container.Name.Length;
                }
                fileNameBase = this.container.Name.Substring(fileNameStart, fileNameEnd - fileNameStart);
            }

            for (int i = 0; i < numFiles; i++)
            {
                FileItem item = new FileItem(this.container);
                item.FileName   = fileNameBase + "-" + Convert.ToSingle(i);
                item.FileSize   = fileOffset[i + 1] - fileOffset[i];
                item.FileOffset = fileOffset[i];

                uint   fileIdentifier = StreamUtility.ReadUIntFromStream(this.container, item.FileOffset);
                string fileExt        = StreamUtility.GetFileExtension(fileIdentifier);
                item.FileName += "." + fileExt;
                fileTable.Add(item);
            }

            return(fileTable.Count);
        }
예제 #4
0
        /// <summary>
        /// Construct a Afs file.
        /// </summary>
        /// <param name="file">File stream.</param>
        public AfsContainer(FileStream file)
            : base(file)
        {
            long offset = 0;

            // Confirm 'Afs' identifier
            uint identifier = StreamUtility.ReadUIntFromStream(this.container, offset);

            offset += 4;
            if (!StreamUtility.GetFileExtension(identifier).Equals("afs")) // If file identifier is not Afs
            {
                throw new FormatException(container.Name + ": File is not Afs format!");
            }

            // Get file address
            this.numFiles = StreamUtility.ReadUIntFromStream(this.container, offset, false);
            offset       += 4;

            this.containerType = "Sega AFS";
        }
예제 #5
0
        /// <summary>
        /// Parse the file table.
        /// </summary>
        /// <returns>Number of files found.</returns>
        public override int ParseFileTable()
        {
            long offset = 8;
            uint fid    = 0;

            this.fileTable = new List <FileItem>();

            string fileNameBase;

            { // Get file name base
                int fileNameStart = this.container.Name.LastIndexOf('\\') + 1;
                int fileNameEnd   = this.container.Name.LastIndexOf('.');
                if (fileNameEnd == -1)
                {
                    fileNameEnd = this.container.Name.Length;
                }
                fileNameBase = this.container.Name.Substring(fileNameStart, fileNameEnd - fileNameStart);
            }

            while (true)
            {
                AfsFileItem item = new AfsFileItem();
                item.fileId      = fid;
                item.startOffset = StreamUtility.ReadUIntFromStream(this.container, offset, false);
                offset          += 4;
                item.length      = StreamUtility.ReadUIntFromStream(this.container, offset, false);
                offset          += 4;

                if (item.isValid())
                {
                    FileItem fileItem       = ConvertAfsToGeneral(item, fileNameBase + "-" + Convert.ToSingle(item.fileId));
                    uint     fileIdentifier = StreamUtility.ReadUIntFromStream(this.container, fileItem.FileOffset);
                    string   fileExt        = StreamUtility.GetFileExtension(fileIdentifier);
                    fileItem.FileName += "." + fileExt;
                    fileTable.Add(fileItem);
                }
                else
                {
                    break;
                }

                fid++;
            }

            if (fileTable.Count == this.numFiles + 1)
            {
                // The last one is the file property table.
                FileItem fileItem = fileTable[fileTable.Count - 1];
                offset = fileItem.FileOffset;
                // Retrieve file names
                for (int i = 0; i < this.numFiles; i++)
                {
                    fileTable[i].FileName = StreamUtility.ReadStringFromStream(this.container, offset, -1);
                    offset += 0x30;
                }
                // Remove the file property table
                fileTable.RemoveAt(fileTable.Count - 1);
            }

            if (fileTable.Count != this.numFiles)
            {
                throw new FormatException(this.container.Name + ": The real number of files doesn't match the header value!" + System.Environment.NewLine +
                                          "The header indicated: " + Convert.ToString(this.numFiles) + System.Environment.NewLine +
                                          "The real number of files: " + Convert.ToString(fileTable.Count));
            }

            return(fileTable.Count);
        }