Ejemplo n.º 1
0
        /// <summary>
        /// Adds a file to the archive.
        /// </summary>
        public virtual void AddFile(string filename, byte[] buffer)
        {
            // See if the file already exists in the archive
            if (fileTable.GetEntry(filename, EntryType.File) == null)
            {
                uint offset = GetDataDescriptor(fileTable.NextEntryOffset);
                if (offset != FileTableEntry.NullOffset)
                {
                    if (offset <= fileTable.NextEntryOffset)
                    {
                        // We have reached the data area of the archive, and will need to move
                        // this entry's data to the end of the file, in order to make room
                        // for more entries in the filetable.
                        FileTableEntry moveMe = fileTable.GetEntry(offset);
                        byte[]         data   = ReadFile(moveMe);
                        moveMe.DataOffset = (uint)archiveFile.Length;
                        moveMe.Save(bw);
                        WriteData(moveMe, data);
                    }
                }

                FileTableEntry entry = fileTable.CreateEntry(filename, EntryType.File);
                AddFile(entry, buffer);
            }
        }
Ejemplo n.º 2
0
        public void RemoveEntry(string path, EntryType type)
        {
            FileTableEntry entry           = GetEntry(path, type);
            FileTableEntry parent          = entry.ParentEntry;
            FileTableEntry previousSibling = entry.PreviousSiblingEntry;
            FileTableEntry sibling         = entry.SiblingEntry;
            FileTableEntry child           = entry.ChildEntry;

            if (parent != null)
            {
                parent.ChildEntry = entry.FirstSiblingInChain;
                if (parent.ChildEntry == entry)
                {
                    parent.ChildEntry = null;
                }
                entry.FirstSiblingInChain.ParentEntry = parent;
                entry.FirstSiblingInChain.Save(diskWriter);
                parent.Save(diskWriter);
            }
            if (previousSibling != null)
            {
                previousSibling.SiblingEntry = sibling;
                previousSibling.Save(diskWriter);
            }
            if (sibling != null)
            {
                sibling.PreviousSiblingEntry = previousSibling;
                sibling.Save(diskWriter);
            }
            if (child != null)
            {
                child.ParentEntry = null;
                child.Save(diskWriter);
            }
        }
Ejemplo n.º 3
0
        protected void AddFile(FileTableEntry entry, byte[] buffer)
        {
            entry.DataSize = (uint)buffer.Length;

            // Set the offset to the end of the file.
            entry.DataOffset = (uint)archiveFile.Length;
            entry.Save(bw);
            WriteData(entry, buffer);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Adds the specified entry to the end of the filetable, and updates the heder values.
 /// </summary>
 protected void AddEntryToTable(FileTableEntry entry)
 {
     // Set the offset accordingly.
     entry.Offset          = NextEntryOffset;
     header.FileTableSize += (uint)entry.Size;
     header.FileEntryCount++;
     // Update the header and save the entry to disk.
     WriteHeader();
     entry.Save(diskWriter);
     if (entry.ParentEntry != null)
     {
         entry.ParentEntry.Save(diskWriter);
     }
     if (entry.PreviousSiblingEntry != null)
     {
         entry.PreviousSiblingEntry.Save(diskWriter);
     }
 }