/// <summary> /// Determines whether this instance and a specified object, which must also be a <seealso cref="VdfsEntry"/>, have the same values of all properties and the same content. /// </summary> public override bool Equals(Object obj) { VdfsEntry other = obj as VdfsEntry; if (other == null) { return(false); } else { bool isContentEquals; if (Content == null && other.Content == null) { isContentEquals = true; } else if (Content == null || other.Content == null) { return(false); } else { isContentEquals = Content.SequenceEqual(other.Content); } return(Name.Equals(other.Name) && Offset.Equals(other.Offset) && Type.Equals(other.Type) && Size.Equals(other.Size) && Attributes.Equals(other.Attributes) && isContentEquals); } }
/// <summary> /// Adds child node. /// </summary> public VdfsEntriesTree AddChild(VdfsEntry item) { var childNode = new VdfsEntriesTree(item); Childrens.Add(childNode); return(childNode); }
/// <summary> /// Initializes a new instance of the <see cref="VdfsEntriesTree"/> class. /// </summary> public VdfsEntriesTree() { Entry = new VdfsEntry { Name = "(root)", Type = Vdfs.EntryType.Directory, Attributes = Vdfs.FileAttribute.Hidden }; }
/// <summary> /// Reads entry content from archive. /// </summary> public byte[] ReadEntryContent(VdfsEntry entry) { long positonBackup = _reader.BaseStream.Position; _reader.BaseStream.Seek(entry.Offset, SeekOrigin.Begin); var toReturn = _reader.ReadBytes((int)entry.Size); _reader.BaseStream.Position = positonBackup; return(toReturn); }
/// <summary> /// Reads all entries from archive and return as <see cref="IEnumerable{T}"/> /// </summary> /// <param name="readContent">Specifies whether to read entry content.</param> public IEnumerable <VdfsEntry> ReadEntries(bool readContent) { _reader.BaseStream.Seek(Header.RootOffset, SeekOrigin.Begin); for (uint i = 0; i < Header.EntryCount; i++) { var entry = new VdfsEntry() { Name = decodeBytesToString(_reader.ReadBytes(64)).TrimEnd(' '), Offset = _reader.ReadUInt32(), Size = _reader.ReadUInt32(), Type = (Vdfs.EntryType)_reader.ReadUInt32(), Attributes = (Vdfs.FileAttribute)_reader.ReadUInt32(), }; if ((entry.Type.HasFlag(Vdfs.EntryType.Directory) == false) && (readContent)) { entry.Content = ReadEntryContent(entry); } yield return(entry); } }
public void AddDirectory(string path, string searchPattern) { var directories = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly).Where((x) => { return(Directory.GetFiles(x, searchPattern, SearchOption.AllDirectories).Length > 0); }).ToArray(); var files = Directory.GetFiles(path, searchPattern, SearchOption.TopDirectoryOnly); uint offset = (uint)(Entries.Count + directories.Length + files.Length); for (int i = 0; i < directories.Length; i++) { var filesInside = Directory.GetFiles(directories[i], searchPattern, SearchOption.AllDirectories).Length; if (filesInside == 0) { continue; } Entries.Add(new VdfsEntry() { Name = Path.GetFileName(directories[i]).ToUpper(), Type = Vdfs.EntryType.Directory, Attributes = 0, Size = 0, Offset = offset }); var directoriesInside = Directory.GetDirectories(directories[i], "*", SearchOption.AllDirectories).Length; offset += (uint)(filesInside + directoriesInside); } for (int i = 0; i < files.Length; i++) { var content = File.ReadAllBytes(files[i]); var entry = new VdfsEntry() { Name = Path.GetFileName(files[i]).ToUpper(), Content = content, Size = (uint)content.Length }; var fileAttributes = File.GetAttributes(files[i]); if (fileAttributes.HasFlag(FileAttributes.Archive)) { entry.Attributes = entry.Attributes | Vdfs.FileAttribute.Archive; } Entries.Add(entry); } if (Entries.Count > 0) { Entries.Last().Type = Entries.Last().Type | Vdfs.EntryType.Last; } for (int i = 0; i < directories.Length; i++) { if (Directory.GetFiles(directories[i], searchPattern, SearchOption.AllDirectories).Length > 0) { AddDirectory(directories[i], searchPattern); } } }
/// <summary> /// Initializes a new instance of the <see cref="VdfsEntriesTree"/> class. /// </summary> public VdfsEntriesTree(VdfsEntry entry) { Entry = entry; }