Ejemplo n.º 1
0
        /////////////////////////////////////////////////////////////////////////////
        // helper functions
        /////////////////////////////////////////////////////////////////////////////

        internal Stream GetStream(RageArchiveBinaryFile7 file_)
        {
            return(new PartialStream(
                       archive_.BaseStream,
                       delegate() // offset
            {
                return 512 * file_.FileOffset;
            },
                       delegate() // size
            {
                if (file_.FileSize != 0)
                {
                    return file_.FileSize;         // compressed
                }
                else
                {
                    return file_.FileUncompressedSize;         // uncompressed
                }
            },
                       delegate(long newLength)
            {
                RequestBytes(file_, newLength);
            }
                       ));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new binary file inside this directory.
        /// </summary>
        public IArchiveBinaryFile CreateBinaryFile()
        {
            RageArchiveBinaryFile7        realF = new RageArchiveBinaryFile7();
            RageArchiveBinaryFileWrapper7 wrD   = new RageArchiveBinaryFileWrapper7(archiveWrapper, realF);


            realF.Name = "";
            var offset = archiveWrapper.FindSpace(64);

            realF.FileOffset = (uint)(offset / 512);

            directory.Files.Add(realF);

            return(wrD);
        }
Ejemplo n.º 3
0
        public void RequestBytes(RageArchiveBinaryFile7 file_, long newLength)
        {
            // determine header size...
            long x = GetHeaderSize();

            DataBlock thisBlock = null;
            var       blocks    = GetBlocks();

            foreach (var q in blocks)
            {
                if (q.Tag == file_)
                {
                    thisBlock = q;
                }
            }

            long maxlength = ArchiveHelpers.FindSpace(blocks, thisBlock);

            if (maxlength < newLength)
            {
                // move...

                long offset = ArchiveHelpers.FindOffset(blocks, newLength, 512);
                ArchiveHelpers.MoveBytes(archive_.BaseStream, thisBlock.Offset, offset, thisBlock.Length);
                ((IRageArchiveFileEntry7)thisBlock.Tag).FileOffset = (uint)offset / 512;
            }

            if (file_.FileSize != 0)
            {
                file_.FileSize = (uint)newLength;
            }
            else
            {
                file_.FileUncompressedSize = (uint)newLength;
            }
        }
Ejemplo n.º 4
0
 internal RageArchiveBinaryFileWrapper7(RageArchiveWrapper7 archiveWrapper, RageArchiveBinaryFile7 file)
 {
     this.archiveWrapper = archiveWrapper;
     this.file           = file;
 }
Ejemplo n.º 5
0
        private List <DataBlock> GetBlocks()
        {
            var blocks = new List <DataBlock>();

            // header
            blocks.Add(
                new DataBlock(0, GetHeaderSize())
                );

            var st = new Stack <RageArchiveDirectory7>();

            st.Push(archive_.Root);
            while (st.Count > 0)
            {
                var x = st.Pop();

                foreach (var q in x.Directories)
                {
                    st.Push(q);
                }
                foreach (IRageArchiveFileEntry7 q in x.Files)
                {
                    if (q is RageArchiveBinaryFile7)
                    {
                        // if(q.FileSize != 0)
                        RageArchiveBinaryFile7 fff = (RageArchiveBinaryFile7)q;

                        long l = 0;
                        if (q.FileSize == 0)
                        {
                            l = fff.FileUncompressedSize;
                        }
                        else
                        {
                            l = fff.FileSize;
                        }

                        blocks.Add(new DataBlock(q.FileOffset * 512, l, q));
                    }
                    else
                    {
                        // if(q.FileSize != 0)
                        RageArchiveResourceFile7 fff = (RageArchiveResourceFile7)q;

                        long l = fff.FileSize;

                        blocks.Add(new DataBlock(q.FileOffset * 512, l, q));
                    }
                }
            }

            blocks.Sort(
                delegate(DataBlock a, DataBlock b)
            {
                if (a.Offset != b.Offset)
                {
                    return(a.Offset.CompareTo(b.Offset));
                }
                else
                {
                    return(a.Offset.CompareTo(b.Offset));
                }
            }
                );

            return(blocks);
        }