Пример #1
0
        /// <summary>
        /// Populates the details of each file entry within the archive.
        /// </summary>
        private static void PopulateFileEntries()
        {
            // Allocate Memory
            fileList = new List <XanaduStructs.XanaduFileEntry>((int)fileHeader.fileCount);

            // Create file pointer & set to first entry.
            UInt32 filePointer = fileHeader.fileEntryOffset;

            // Read each file entry
            for (int x = 0; x < fileHeader.fileCount; x++)
            {
                // Generate file entry.
                XanaduStructs.XanaduFileEntry xanaduFileEntry = new XanaduStructs.XanaduFileEntry();

                // Read file entry details & increment pointer.
                xanaduFileEntry.filePackedTime = BitConverter.ToUInt32(xanaduArchive, (int)filePointer);
                filePointer += sizeof(UInt32);

                xanaduFileEntry.unknown = BitConverter.ToUInt32(xanaduArchive, (int)filePointer);
                filePointer            += sizeof(UInt32);

                xanaduFileEntry.compressedSize = BitConverter.ToUInt32(xanaduArchive, (int)filePointer);
                filePointer += sizeof(UInt32);

                xanaduFileEntry.uncompressedSize = BitConverter.ToUInt32(xanaduArchive, (int)filePointer);
                filePointer += sizeof(UInt32);

                xanaduFileEntry.fileNameLength = BitConverter.ToUInt16(xanaduArchive, (int)filePointer);
                filePointer += sizeof(UInt16);

                xanaduFileEntry.fileFlags = BitConverter.ToUInt16(xanaduArchive, (int)filePointer);
                filePointer += sizeof(UInt16);

                xanaduFileEntry.fileOffset = BitConverter.ToUInt32(xanaduArchive, (int)filePointer);
                filePointer += sizeof(UInt32);

                xanaduFileEntry.fileName = Encoding.ASCII.GetString(xanaduArchive.SubArray((int)filePointer, (int)xanaduFileEntry.fileNameLength));
                filePointer += (uint)xanaduFileEntry.fileName.Length;

                // Sanitize File name
                xanaduFileEntry.fileName = xanaduFileEntry.fileName.ForceValidFilePath();

                // Trim file extension
                if (trimExtension)
                {
                    xanaduFileEntry.fileName = xanaduFileEntry.fileName.Substring(0, xanaduFileEntry.fileName.IndexOf(".") + 4);
                }

                // Add onto list
                fileList.Add(xanaduFileEntry);
            }
        }
Пример #2
0
        /// <summary>
        /// Populates the details of each file entry within the archive.
        /// </summary>
        private static void PopulateFileEntries()
        {
            // Allocate Memory
            fileList = new List <XanaduStructs.XanaduFileEntry>((int)fileHeader.fileCount);

            // Create file pointer & set to first entry.
            UInt32 filePointer = fileHeader.fileEntryOffset;

            // Read each file entry
            for (int x = 0; x < fileHeader.fileCount; x++)
            {
                // Generate file entry.
                XanaduStructs.XanaduFileEntry xanaduFileEntry = new XanaduStructs.XanaduFileEntry();

                // Read file entry details & increment pointer.
                xanaduFileEntry.filePackedTime = BitConverter.ToUInt32(xanaduArchive, (int)filePointer);
                filePointer += sizeof(UInt32);

                xanaduFileEntry.unknown = BitConverter.ToUInt32(xanaduArchive, (int)filePointer);
                filePointer            += sizeof(UInt32);

                xanaduFileEntry.compressedSize = BitConverter.ToUInt32(xanaduArchive, (int)filePointer);
                filePointer += sizeof(UInt32);

                xanaduFileEntry.uncompressedSize = BitConverter.ToUInt32(xanaduArchive, (int)filePointer);
                filePointer += sizeof(UInt32);

                xanaduFileEntry.fileNameLength = BitConverter.ToUInt16(xanaduArchive, (int)filePointer);
                filePointer += sizeof(UInt16);

                xanaduFileEntry.fileFlags = BitConverter.ToUInt16(xanaduArchive, (int)filePointer);
                filePointer += sizeof(UInt16);

                xanaduFileEntry.fileOffset = BitConverter.ToUInt32(xanaduArchive, (int)filePointer);
                filePointer += sizeof(UInt32);

                xanaduFileEntry.fileName = Encoding.ASCII.GetString(xanaduArchive.SubArray((int)filePointer, (int)xanaduFileEntry.fileNameLength));
                filePointer += (uint)xanaduFileEntry.fileName.Length;

                // Sanitize File name
                xanaduFileEntry.fileName = xanaduFileEntry.fileName.ForceValidFilePath();

                // Trim file extension
                if (trimExtension)
                {
                    xanaduFileEntry.fileName = xanaduFileEntry.fileName.Substring(0, xanaduFileEntry.fileName.IndexOf(".") + 4);
                }

                var Ext = xanaduFileEntry.fileName.Substring(xanaduFileEntry.fileName.IndexOf(".")).ToLower();
                if (Ext.Length > 3)
                {
                    var KnowExts = new string[] { "cl3", "ogg", "dat", "dds", "ffu", "gbin", "gstr", "png", "env", "lip" };
                    foreach (var KnowExt in KnowExts)
                    {
                        if (Ext.Contains(KnowExt))
                        {
                            var FN = xanaduFileEntry.fileName;
                            FN = FN.Substring(0, FN.IndexOf('.') + 1) + KnowExt;
                            xanaduFileEntry.fileName = FN;
                            break;
                        }
                    }
                }

                // Add onto list
                fileList.Add(xanaduFileEntry);
            }
        }