public void AddEntry(D2pEntry entry) { entry.State = D2pEntryState.Added; InternalAddEntry(entry); IndexTable.EntriesCount++; OnPropertyChanged("Entries"); }
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); }
public D2pEntry AddFile(string fileName, byte[] data) { var entry = new D2pEntry(this, fileName, data); AddEntry(entry); return(entry); }
public static D2pEntry CreateEntryDefinition(D2pFile container, IDataReader reader) { var entry = new D2pEntry(container); entry.ReadEntryDefinition(reader); return(entry); }
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); } }
public byte[] ReadFile(string fileName) { if (!Exists(fileName)) { throw new FileNotFoundException(fileName); } D2pEntry entry = GetEntry(fileName); return(ReadFile(entry)); }
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); }
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; }
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; }
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); }
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); }
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); }
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; } }
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; } }
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); }
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; }
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; }
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; } }
public D2pEntry AddFile(string fileName, byte[] data) { var entry = new D2pEntry(this, fileName, data); AddEntry(entry); return entry; }
private void InternalAddEntry(D2pEntry entry) { m_entries.Add(entry.FullFileName, entry); InternalAddDirectories(entry); }
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; }
public bool RemoveFile(string file) { D2pEntry entry = TryGetEntry(file); return(entry != null && RemoveEntry(entry)); }
public static D2pEntry CreateEntryDefinition(D2pFile container, IDataReader reader) { var entry = new D2pEntry(container); entry.ReadEntryDefinition(reader); return entry; }