public static List<DATFile> FindFiles(DAT dat, BinaryReader br) { List<DATFile> DatFiles = new List<DATFile>(); uint FileIndex = 0; br.BaseStream.Seek(-(dat.TreeSize + 4), SeekOrigin.End); while (FileIndex < dat.FilesTotal) { DATFile file = new DATFile(); file.br = br; file.FileNameSize = br.ReadInt32(); char[] namebuf = new Char[file.FileNameSize]; br.Read(namebuf, 0, (int)file.FileNameSize); file.Path = new String(namebuf, 0, namebuf.Length); file.FileName = Path.GetFileName(file.Path); file.Compression = br.ReadByte(); file.UnpackedSize = br.ReadInt32(); file.PackedSize = br.ReadInt32(); if (file.Compression==0x00&&(file.UnpackedSize != file.PackedSize)) file.Compression = 1; file.Offset = br.ReadInt32(); long oldoffset = br.BaseStream.Position; // Read whole file into a buffer br.BaseStream.Position = file.Offset; file.Buffer = new Byte[file.PackedSize]; br.Read(file.Buffer, 0, file.PackedSize); br.BaseStream.Position = oldoffset; DatFiles.Add(file); FileIndex++; } return DatFiles; }
public void AddFile(string filename, string virtualfilename) { DATFile file = new DATFile(); file.Path = virtualfilename; file.FileNameSize = System.Text.ASCIIEncoding.ASCII.GetByteCount(file.Path); file.Buffer = File.ReadAllBytes(filename); file.UnpackedSize = file.Buffer.Length; file.PackedSize = file.Buffer.Length; file.Compression = 0x00; FileList.Add(file); FilesTotal++; }
public static List <DATFile> FindFiles(DAT dat, BinaryReader br) { List <DATFile> DatFiles = new List <DATFile>(); uint FileIndex = 0; br.BaseStream.Seek(-(dat.TreeSize + 4), SeekOrigin.End); while (FileIndex < dat.FilesTotal) { DATFile file = new DATFile(); file.br = br; file.FileNameSize = br.ReadInt32(); char[] namebuf = new Char[file.FileNameSize]; br.Read(namebuf, 0, (int)file.FileNameSize); file.Path = new String(namebuf, 0, namebuf.Length); file.FileName = Path.GetFileName(file.Path); file.Compression = br.ReadByte(); file.UnpackedSize = br.ReadInt32(); file.PackedSize = br.ReadInt32(); if (file.Compression == 0x00 && (file.UnpackedSize != file.PackedSize)) { file.Compression = 1; } file.Offset = br.ReadInt32(); long oldoffset = br.BaseStream.Position; // Read whole file into a buffer br.BaseStream.Position = file.Offset; file.Buffer = new Byte[file.PackedSize]; br.Read(file.Buffer, 0, file.PackedSize); br.BaseStream.Position = oldoffset; DatFiles.Add(file); FileIndex++; } return(DatFiles); }