示例#1
0
 public void AddEntry(D2pEntry entry)
 {
     entry.State = D2pEntryState.Added;
     InternalAddEntry(entry);
     IndexTable.EntriesCount++;
     OnPropertyChanged("Entries");
 }
示例#2
0
        public bool RemoveEntry(D2pEntry entry)
        {
            if (entry.Container != this)
            {
                if (!entry.Container.RemoveEntry(entry))
                {
                    return(false);
                }

                if (!m_linksToSave.Contains(entry.Container))
                {
                    m_linksToSave.Enqueue(entry.Container);
                }
            }

            if (m_entries.Remove(entry.FullFileName))
            {
                entry.State = D2pEntryState.Removed;
                InternalRemoveDirectories(entry);
                OnPropertyChanged("Entries");

                if (entry.Container == this)
                {
                    IndexTable.EntriesCount--;
                }

                return(true);
            }

            return(false);
        }
示例#3
0
        public D2pEntry AddFile(string fileName, byte[] data)
        {
            var entry = new D2pEntry(this, fileName, data);

            AddEntry(entry);

            return(entry);
        }
示例#4
0
        public static D2pEntry CreateEntryDefinition(D2pFile container, IDataReader reader)
        {
            var entry = new D2pEntry(container);

            entry.ReadEntryDefinition(reader);

            return(entry);
        }
示例#5
0
        private void ReadEntriesDefinitions()
        {
            m_reader.Seek(IndexTable.EntriesDefinitionOffset, SeekOrigin.Begin);
            for (int i = 0; i < IndexTable.EntriesCount; i++)
            {
                D2pEntry entry = D2pEntry.CreateEntryDefinition(this, m_reader);

                InternalAddEntry(entry);
            }
        }
示例#6
0
        public byte[] ReadFile(string fileName)
        {
            if (!Exists(fileName))
            {
                throw new FileNotFoundException(fileName);
            }

            D2pEntry entry = GetEntry(fileName);

            return(ReadFile(entry));
        }
示例#7
0
        public byte[] ReadFile(D2pEntry entry)
        {
            if (entry.Container != this)
            {
                return(entry.Container.ReadFile(entry));
            }

            if (entry.Index >= 0 && IndexTable.OffsetBase + entry.Index >= 0)
            {
                m_reader.Seek(IndexTable.OffsetBase + entry.Index, SeekOrigin.Begin);
            }

            byte[] data = entry.ReadEntry(m_reader);

            return(data);
        }
示例#8
0
        private void InternalAddDirectories(D2pEntry entry)
        {
            string[] directories = entry.GetDirectoriesName();

            if (directories.Length == 0)
            {
                return;
            }

            D2pDirectory current = null;

            if (!HasDirectory(directories[0]))
            {
                current = new D2pDirectory(directories[0]);

                m_rootDirectories.Add(current);
            }
            else
            {
                current = TryGetDirectory(directories[0]);
            }

            current.Entries.Add(entry);

            foreach (string directory in directories.Skip(1))
            {
                if (!current.HasDirectory(directory))
                {
                    var dir = new D2pDirectory(directory)
                    {
                        Parent = current
                    };
                    current.Directories.Add(dir);

                    current = dir;
                }
                else
                {
                    current = current.TryGetDirectory(directory);
                }

                current.Entries.Add(entry);
            }

            entry.Directory = current;
        }
示例#9
0
        private void InternalAddDirectories(D2pEntry entry)
        {
            string[] directories = entry.GetDirectoriesName();

            if (directories.Length == 0)
            {
                return;
            }

            D2pDirectory current = null;

            if (!m_rootDirectories.ContainsKey(directories[0]))
            {
                m_rootDirectories.Add(directories[0], current = new D2pDirectory(directories[0]));
            }
            else
            {
                current = m_rootDirectories[directories[0]];
            }

            current.Entries.Add(entry);

            foreach (string directory in directories.Skip(1))
            {
                var next = current.TryGetDirectory(directory);
                if (next == null)
                {
                    var dir = new D2pDirectory(directory)
                    {
                        Parent = current
                    };
                    current.Directories.Add(directory, dir);

                    current = dir;
                }
                else
                {
                    current = current.TryGetDirectory(directory);
                }

                current.Entries.Add(entry);
            }

            entry.Directory = current;
        }
示例#10
0
        private void InternalAddEntry(D2pEntry entry)
        {
            D2pEntry registerdEntry = TryGetEntry(entry.FullFileName);

            // shouldn't be possible but dofus don't care about that
            if (registerdEntry != null)
            {
                logger.Warn("Entry '{0}'({1}) already added and will be override ({2})", registerdEntry.FullFileName,
                            registerdEntry.Container.FileName, FileName);
                m_entries[registerdEntry.FullFileName] = entry;
            }
            else
            {
                m_entries.Add(entry.FullFileName, entry);
            }

            InternalAddDirectories(entry);
        }
示例#11
0
        public void ExtractFile(string fileName, bool overwrite = false)
        {
            if (!Exists(fileName))
            {
                throw new FileNotFoundException(fileName);
            }

            D2pEntry entry = GetEntry(fileName);

            string dest = Path.Combine("./", entry.FullFileName);

            if (!Directory.Exists(Path.GetDirectoryName(dest)))
            {
                Directory.CreateDirectory(dest);
            }

            ExtractFile(fileName, dest, overwrite);
        }
示例#12
0
        public bool ModifyFile(string file, byte[] data)
        {
            D2pEntry entry = TryGetEntry(file);

            if (entry == null)
            {
                return(false);
            }

            entry.ModifyEntry(data);

            if (entry.Container != this &&
                !m_linksToSave.Contains(entry.Container))
            {
                m_linksToSave.Enqueue(entry.Container);
            }

            return(true);
        }
示例#13
0
        private void InternalRemoveDirectories(D2pEntry entry)
        {
            D2pDirectory current = entry.Directory;

            while (current != null)
            {
                current.Entries.Remove(entry);

                if (current.Parent != null && current.Entries.Count == 0)
                {
                    current.Parent.Directories.Remove(current);
                }
                else if (current.IsRoot && current.Entries.Count == 0)
                {
                    m_rootDirectories.Remove(current);
                }

                current = current.Parent;
            }
        }
示例#14
0
        private void InternalRemoveDirectories(D2pEntry entry)
        {
            D2pDirectory current = entry.Directory;
            while (current != null)
            {
                current.Entries.Remove(entry);

                if (current.Parent != null && current.Entries.Count == 0)
                    current.Parent.Directories.Remove(current.Name);
                else if (current.IsRoot && current.Entries.Count == 0)
                    m_rootDirectories.Remove(current.Name);

                current = current.Parent;
            }
        }
示例#15
0
        private void InternalAddEntry(D2pEntry entry)
        {
            D2pEntry registerdEntry = TryGetEntry(entry.FullFileName);

            // shouldn't be possible but dofus don't care about that
            if (registerdEntry != null)
            {
                logger.Warn("Entry '{0}'({1}) already added and will be override ({2})", registerdEntry.FullFileName,
                            registerdEntry.Container.FileName, FileName);
                m_entries[registerdEntry.FullFileName] = entry;
            }
            else
                m_entries.Add(entry.FullFileName, entry);

            InternalAddDirectories(entry);
        }
示例#16
0
        private void InternalAddDirectories(D2pEntry entry)
        {
            string[] directories = entry.GetDirectoriesName();

            if (directories.Length == 0)
                return;

            D2pDirectory current = null;
            if (!m_rootDirectories.ContainsKey(directories[0]))
            {
                m_rootDirectories.Add(directories[0], current = new D2pDirectory(directories[0]));
            }
            else
            {
                current = m_rootDirectories[directories[0]];
            }

            current.Entries.Add(entry);

            foreach (string directory in directories.Skip(1))
            {
                var next = current.TryGetDirectory(directory);
                if (next == null)
                {
                    var dir = new D2pDirectory(directory)
                                  {
                                      Parent = current
                                  };
                    current.Directories.Add(directory, dir);

                    current = dir;
                }
                else
                {
                    current = current.TryGetDirectory(directory);
                }

                current.Entries.Add(entry);
            }

            entry.Directory = current;
        }
示例#17
0
        public bool RemoveEntry(D2pEntry entry)
        {
            if (entry.Container != this)
            {
                if (!entry.Container.RemoveEntry(entry))
                    return false;

                if (!m_linksToSave.Contains(entry.Container))
                    m_linksToSave.Enqueue(entry.Container);
            }

            if (m_entries.Remove(entry.FullFileName))
            {
                entry.State = D2pEntryState.Removed;
                InternalRemoveDirectories(entry);
                OnPropertyChanged("Entries");

                if (entry.Container == this)
                    IndexTable.EntriesCount--;

                return true;
            }

            return false;
        }
示例#18
0
        public byte[] ReadFile(D2pEntry entry)
        {
            if (entry.Container != this)
                return entry.Container.ReadFile(entry);

            lock (m_reader)
            {
                if (entry.Index >= 0 && IndexTable.OffsetBase + entry.Index >= 0)
                    m_reader.Seek(IndexTable.OffsetBase + entry.Index, SeekOrigin.Begin);

                byte[] data = entry.ReadEntry(m_reader);

                return data;
            }
        }
示例#19
0
        public D2pEntry AddFile(string fileName, byte[] data)
        {
            var entry = new D2pEntry(this, fileName, data);

            AddEntry(entry);

            return entry;
        }
示例#20
0
 public void AddEntry(D2pEntry entry)
 {
     entry.State = D2pEntryState.Added;
     InternalAddEntry(entry);
     IndexTable.EntriesCount++;
     OnPropertyChanged("Entries");
 }
示例#21
0
 private void InternalAddEntry(D2pEntry entry)
 {
     m_entries.Add(entry.FullFileName, entry);
     InternalAddDirectories(entry);
 }
示例#22
0
        private void InternalAddDirectories(D2pEntry entry)
        {
            var directories = entry.GetDirectoriesName();

            if (directories.Length == 0)
                return;

            D2pDirectory current = null;
            if (!HasDirectory(directories[0]))
            {
                current = new D2pDirectory(directories[0]);

                m_rootDirectories.Add(current);
            }
            else
            {
                current = TryGetDirectory(directories[0]);
            }

            current.Entries.Add(entry);

            foreach (var directory in directories.Skip(1))
            {
                if (!current.HasDirectory(directory))
                {
                    var dir = new D2pDirectory(directory)
                    {
                        Parent = current
                    };
                    current.Directories.Add(dir);

                    current = dir;
                }
                else
                {
                    current = current.TryGetDirectory(directory);
                }

                current.Entries.Add(entry);
            }

            entry.Directory = current;
        }
示例#23
0
        public bool RemoveFile(string file)
        {
            D2pEntry entry = TryGetEntry(file);

            return(entry != null && RemoveEntry(entry));
        }
示例#24
0
        public static D2pEntry CreateEntryDefinition(D2pFile container, IDataReader reader)
        {
            var entry = new D2pEntry(container);
            entry.ReadEntryDefinition(reader);

            return entry;
        }