Example #1
0
        /// <summary>
        /// Gets an entry's data from a Far3Entry instance.
        /// </summary>
        /// <param name="Entry">The Far3Entry instance.</param>
        /// <returns>The entry's data.</returns>
        public byte[] GetEntry(Far3Entry Entry)
        {
            lock (m_Reader)
            {
                m_Reader.BaseStream.Seek((long)Entry.DataOffset, SeekOrigin.Begin);

                isReadingSomething = true;

                if (Entry.IsCompressed == 0x01)
                {
                    m_Reader.ReadBytes(9);
                    uint   Filesize      = m_Reader.ReadUInt32();
                    ushort CompressionID = m_Reader.ReadUInt16();

                    if (CompressionID == 0xFB10)
                    {
                        byte[] Dummy            = m_Reader.ReadBytes(3);
                        uint   DecompressedSize = (uint)((Dummy[0] << 0x10) | (Dummy[1] << 0x08) | +Dummy[2]);

                        Decompresser Dec = new Decompresser();
                        Dec.CompressedSize   = Filesize;
                        Dec.DecompressedSize = DecompressedSize;

                        byte[] DecompressedData = Dec.Decompress(m_Reader.ReadBytes((int)Filesize));
                        //m_Reader.Close();

                        isReadingSomething = false;

                        return(DecompressedData);
                    }
                    else
                    {
                        m_Reader.BaseStream.Seek((m_Reader.BaseStream.Position - 15), SeekOrigin.Begin);

                        byte[] Data = m_Reader.ReadBytes((int)Entry.DecompressedFileSize);
                        //m_Reader.Close();

                        isReadingSomething = false;

                        return(Data);
                    }
                }
                else
                {
                    byte[] Data = m_Reader.ReadBytes((int)Entry.DecompressedFileSize);
                    //m_Reader.Close();

                    isReadingSomething = false;

                    return(Data);
                }
            }

            throw new FAR3Exception("FAR3Entry didn't exist in archive - FAR3Archive.GetEntry()");
        }
Example #2
0
        private byte[] GetEntry(Far3Entry Entry)
        {
            lock (m_Reader)
            {
                //m_Reader = new BinaryReader(File.Open(m_ArchivePath, FileMode.Open, FileAccess.Read));
                m_Reader.BaseStream.Seek((long)Entry.DataOffset, SeekOrigin.Begin);

                isReadingSomething = true;

                if (Entry.Compressed == 0x01)
                {
                    m_Reader.ReadBytes(9);
                    uint Filesize = m_Reader.ReadUInt32();
                    ushort CompressionID = m_Reader.ReadUInt16();

                    if (CompressionID == 0xFB10)
                    {
                        byte[] Dummy = m_Reader.ReadBytes(3);
                        uint DecompressedSize = (uint)((Dummy[0] << 0x10) | (Dummy[1] << 0x08) | +Dummy[2]);

                        Decompresser Dec = new Decompresser();
                        Dec.CompressedSize = Filesize;
                        Dec.DecompressedSize = DecompressedSize;

                        byte[] DecompressedData = Dec.Decompress(m_Reader.ReadBytes((int)Filesize));
                        //m_Reader.Close();

                        isReadingSomething = false;

                        return DecompressedData;
                    }
                    else
                    {
                        m_Reader.BaseStream.Seek((m_Reader.BaseStream.Position - 15), SeekOrigin.Begin);

                        byte[] Data = m_Reader.ReadBytes((int)Entry.DecompressedFileSize);
                        //m_Reader.Close();

                        isReadingSomething = false;

                        return Data;
                    }
                }
                else
                {
                    byte[] Data = m_Reader.ReadBytes((int)Entry.DecompressedFileSize);
                    //m_Reader.Close();

                    isReadingSomething = false;

                    return Data;
                }
            }
            throw new FAR3Exception("FAR3Entry didn't exist in archive - FAR3Archive.GetEntry()");
        }
        private byte[] GetEntry(Far3Entry Entry)
        {
            m_Reader = new BinaryReader(File.Open(m_ArchivePath, FileMode.Open));
            m_Reader.BaseStream.Seek((long)Entry.DataOffset, SeekOrigin.Begin);

            if (Entry.Compressed == 0x01)
            {
                m_Reader.ReadBytes(9);
                uint Filesize = m_Reader.ReadUInt32();
                ushort CompressionID = m_Reader.ReadUInt16();

                if (CompressionID == 0xFB10)
                {
                    byte[] Dummy = m_Reader.ReadBytes(3);
                    uint DecompressedSize = (uint)((Dummy[0] << 0x10) | (Dummy[1] << 0x08) | +Dummy[2]);

                    Decompresser Dec = new Decompresser();
                    Dec.CompressedSize = Filesize;
                    Dec.DecompressedSize = DecompressedSize;

                    byte[] DecompressedData = Dec.Decompress(m_Reader.ReadBytes((int)Filesize));
                    m_Reader.Close();

                    return DecompressedData;
                }
                else
                {
                    m_Reader.BaseStream.Seek((m_Reader.BaseStream.Position - 15), SeekOrigin.Begin);

                    byte[] Data = m_Reader.ReadBytes((int)Entry.DecompressedFileSize);
                    m_Reader.Close();

                    return Data;
                }
            }
            else
            {
                byte[] Data = m_Reader.ReadBytes((int)Entry.DecompressedFileSize);
                m_Reader.Close();

                return Data;
            }
            throw new FAR3Exception("FileID didn't match any in the archive! (FAR3Archive.GetItemByID())");
        }