public HdrArchive Read(string sourcePath) { byte[] hdrFile = ReadFile(sourcePath); IBuffer buffer = BufferProvider.Provide(hdrFile); HdrHeader header = ReadHeader(buffer); List <HdrFile> files = new List <HdrFile>(); int folderIndexStart = header.IndexOffset; int totalFiles = 0; int currentFile = 0; for (int i = 0; i < header.FolderCount; i++) { buffer.Position = folderIndexStart + i * IndexBlockSize; HdrIndex folderIndex = ReadIndex(buffer); buffer.Position = folderIndex.Offset; for (int j = 0; j < folderIndex.Length; j++) { HdrIndex fileIndex = ReadIndex(buffer); int offset = fileIndex.Offset; int lenght = fileIndex.Length; string ext; if (Path.HasExtension(fileIndex.Name)) { ext = Path.GetExtension(fileIndex.Name); switch (ext) { case ".pts": // PTS-Files are PNG files with the first 4byte beeing lengt of the data. // We already know the length from the index. // offset += 4; // lenght -= 4; break; } } else { ext = ""; } HdrFile file = new HdrFile(); file.FileExtension = ext; file.FileName = fileIndex.Name; file.HdrDirectoryPath = folderIndex.Name; file.HdrFullPath = folderIndex.Name + fileIndex.Name; file.Data = buffer.GetBytes(offset, lenght); file.Offset = offset; file.Length = lenght; file.Extension = ext; files.Add(file); currentFile++; } totalFiles += folderIndex.Length; OnProgressChanged(totalFiles, currentFile); } return(new HdrArchive(files, header)); }
public static IBuffer Provide() { return(Provider.Provide()); }