Exemple #1
0
        public static D2pEntry CreateEntryDefinition(D2pFile container, IDataReader reader)
        {
            D2pEntry entry = new D2pEntry(container);

            entry.ReadEntryDefinition(reader);
            return(entry);
        }
Exemple #2
0
 public D2pEntry(D2pFile container, string fileName, byte[] data)
 {
     this.Container    = container;
     this.FullFileName = fileName;
     this.m_newData    = data;
     this.State        = D2pEntryState.Added;
     this.Size         = data.Length;
     this.Index        = -1;
 }
Exemple #3
0
        public void SaveAs(string destination, bool overwrite = true)
        {
            while (this.m_linksToSave.Count > 0)
            {
                D2pFile link = this.m_linksToSave.Dequeue();
                link.Save();
            }
            Stream stream;

            if (!File.Exists(destination))
            {
                stream = File.Create(destination);
            }
            else
            {
                if (!overwrite)
                {
                    throw new InvalidOperationException("Cannot perform SaveAs : file already exist, notify overwrite parameter to true");
                }
                stream = File.OpenWrite(destination);
            }
            using (BigEndianWriter writer = new BigEndianWriter(stream))
            {
                writer.WriteByte(2);
                writer.WriteByte(1);
                D2pEntry[] entries = this.GetEntriesOfInstanceOnly();
                int        offset  = 2;
                D2pEntry[] array   = entries;
                for (int i = 0; i < array.Length; i++)
                {
                    D2pEntry entry = array[i];
                    byte[]   data  = this.ReadFile(entry);
                    entry.Index = (int)writer.Position - offset;
                    writer.WriteBytes(data);
                }
                int entriesDefOffset = (int)writer.Position;
                array = entries;
                for (int i = 0; i < array.Length; i++)
                {
                    D2pEntry entry = array[i];
                    entry.WriteEntryDefinition(writer);
                }
                int propertiesOffset = (int)writer.Position;
                foreach (D2pProperty property in this.m_properties)
                {
                    property.WriteProperty(writer);
                }
                this.IndexTable.OffsetBase              = offset;
                this.IndexTable.EntriesCount            = entries.Length;
                this.IndexTable.EntriesDefinitionOffset = entriesDefOffset;
                this.IndexTable.PropertiesCount         = this.m_properties.Count;
                this.IndexTable.PropertiesOffset        = propertiesOffset;
                this.IndexTable.Size = this.IndexTable.EntriesDefinitionOffset - this.IndexTable.OffsetBase;
                this.IndexTable.WriteTable(writer);
            }
        }
Exemple #4
0
        private bool InternalRemoveLink(D2pFile link)
        {
            bool result;

            if (this.m_links.Remove(link))
            {
                this.OnPropertyChanged("Links");
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
Exemple #5
0
        private void InternalAddLink(string linkFile)
        {
            string path = this.GetLinkFileAbsolutePath(linkFile);

            if (!File.Exists(path))
            {
                throw new FileNotFoundException(linkFile);
            }
            D2pFile link = new D2pFile(path);

            foreach (D2pEntry entry in link.Entries)
            {
                this.InternalAddEntry(entry);
            }
            this.m_links.Add(link);
            this.OnPropertyChanged("Links");
        }
Exemple #6
0
        public bool RemoveLink(D2pFile file)
        {
            D2pProperty property = this.m_properties.FirstOrDefault((D2pProperty entry) => Path.GetFullPath(this.GetLinkFileAbsolutePath(entry.Value)) == Path.GetFullPath(file.FilePath));
            bool        result2;

            if (property == null)
            {
                result2 = false;
            }
            else
            {
                bool result = this.InternalRemoveLink(file) && this.m_properties.Remove(property);
                if (result)
                {
                    this.OnPropertyChanged("Properties");
                }
                result2 = result;
            }
            return(result2);
        }
Exemple #7
0
        public bool RemoveProperty(D2pProperty property)
        {
            if (property.Key == "link")
            {
                D2pFile link = this.m_links.FirstOrDefault((D2pFile entry) => Path.GetFullPath(this.GetLinkFileAbsolutePath(property.Value)) == Path.GetFullPath(entry.FilePath));
                if (link == null || !this.InternalRemoveLink(link))
                {
                    throw new Exception(string.Format("Cannot remove the associated link {0} to this property", property.Value));
                }
            }
            bool result;

            if (this.m_properties.Remove(property))
            {
                this.OnPropertyChanged("Properties");
                this.IndexTable.PropertiesCount--;
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
Exemple #8
0
 public D2pEntry(D2pFile container, string fileName)
 {
     this.Container    = container;
     this.FullFileName = fileName;
     this.Index        = -1;
 }
Exemple #9
0
 private D2pEntry(D2pFile container)
 {
     this.Container = container;
     this.Index     = -1;
 }
Exemple #10
0
 public D2pIndexTable(D2pFile container)
 {
     this.Container = container;
 }