예제 #1
0
        /// <summary>
        /// Reads all entries in the archive into memory.
        /// </summary>
        /// <param name="ThrowException">Wether or not to throw an exception if the archive was not a FAR. If false, function will return.</param>
        public bool ReadArchive(bool ThrowException)
        {
            if (m_Reader == null)
            {
                m_Reader = new FileReader(m_Path, false);
            }

            lock (m_Reader)
            {
                ASCIIEncoding Enc         = new ASCIIEncoding();
                string        MagicNumber = Enc.GetString(m_Reader.ReadBytes(8));

                if (!MagicNumber.Equals("FAR!byAZ", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (ThrowException)
                    {
                        throw new FAR1Exception("MagicNumber was wrong - FAR1Archive.cs!");
                    }
                    else
                    {
                        m_Reader.Close();
                        return(false);
                    }
                }

                if (m_Reader.ReadUInt32() != 1) //Version.
                {
                    return(false);
                }

                m_Reader.Seek(m_Reader.ReadUInt32());

                uint NumFiles = m_Reader.ReadUInt32();

                for (int i = 0; i < NumFiles; i++)
                {
                    FAR1Entry Entry = new FAR1Entry();
                    Entry.CompressedDataSize   = m_Reader.ReadUInt32();
                    Entry.DecompressedDataSize = m_Reader.ReadUInt32();
                    Entry.DataOffset           = m_Reader.ReadUInt32();
                    Entry.FilenameLength       = m_Reader.ReadUShort();

                    if (IsAssemblyDebugBuild(Assembly.GetExecutingAssembly()))
                    {
                        string Filename = Enc.GetString(m_Reader.ReadBytes(Entry.FilenameLength));
                        Entry.Filename     = Filename;
                        Entry.EntryType    = GetEntryType(Filename);
                        Entry.FilenameHash = FileUtilities.GenerateHash(Filename);
                    }
                    else
                    {
                        Entry.FilenameHash = FileUtilities.GenerateHash(Enc.GetString(m_Reader.ReadBytes(Entry.FilenameLength)));
                    }

                    m_Entries.Add(Entry.FilenameHash, Entry);
                }

                return(true);
            }
        }
예제 #2
0
        public void AddEntry(FAR1Entry Entry, Stream EntryData, bool Backup = true)
        {
            m_Entries.Add(Entry.FilenameHash, Entry);

            List <Stream> DataOfEntries = GrabEntries(GetHashList());

            DataOfEntries.Add(EntryData);

            CreateNew(Path, DataOfEntries, Backup);
        }
예제 #3
0
        /// <summary>
        /// Returns an entry in this archive as a Stream instance.
        /// Throws a FAR3Exception if entry was not found.
        /// </summary>
        /// <param name="ID">ID of the entry to grab from archive.</param>
        /// <returns>The entry's data as a Stream instance.</returns>
        public Stream GrabEntry(string Filename)
        {
            if (!ContainsEntry(Filename))
            {
                throw new FAR1Exception("Couldn't find entry - FAR1Archive.cs!");
            }

            FAR1Entry Entry = m_Entries[Filename];

            if (m_Reader == null)
            {
                m_Reader = new FileReader(File.Open(m_Path, FileMode.Open), false);
            }

            m_Reader.Seek(Entry.DataOffset);

            MemoryStream Data = new MemoryStream(m_Reader.ReadBytes((int)Entry.DecompressedDataSize));

            return(Data);
        }
예제 #4
0
        /// <summary>
        /// Reads all entries in the archive into memory.
        /// </summary>
        /// <param name="ThrowException">Wether or not to throw an exception if the archive was not a FAR. If false, function will return.</param>
        public void ReadArchive(bool ThrowException)
        {
            if (m_Reader == null)
                m_Reader = new FileReader(m_Path, false);

            lock (m_Reader)
            {
                ASCIIEncoding Enc = new ASCIIEncoding();
                string MagicNumber = Enc.GetString(m_Reader.ReadBytes(8));

                if (!MagicNumber.Equals("FAR!byAZ", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (ThrowException)
                        throw new FAR1Exception("MagicNumber was wrong - FAR1Archive.cs!");
                    else
                    {
                        m_Reader.Close();
                        return;
                    }
                }

                m_Reader.ReadUInt32(); //Version.
                m_Reader.Seek(m_Reader.ReadUInt32());

                uint NumFiles = m_Reader.ReadUInt32();

                for (int i = 0; i < NumFiles; i++)
                {
                    FAR1Entry Entry = new FAR1Entry();
                    Entry.CompressedDataSize = m_Reader.ReadUInt32();
                    Entry.DecompressedDataSize = m_Reader.ReadUInt32();
                    Entry.DataOffset = m_Reader.ReadUInt32();
                    Entry.FilenameLength = m_Reader.ReadUShort();
                    Entry.FilenameHash = FileUtilities.GenerateHash(Enc.GetString(m_Reader.ReadBytes(Entry.FilenameLength)));

                    m_Entries.Add(Entry);
                }
            }
        }