public IBigFileFileInfo[] ReadFileInfos(Stream stream, ref BigFileSegmentHeader segmentHeader, ref BigFileHeaderStruct header) { if (version == null) { throw new NullReferenceException("Version cannot be null!"); } log.Info("Reading big file file infos, count: {0}", header.Files); BigFileVersions.DebugLogVersion(version, log); diag.StartStopwatch(); IBigFileFileInfo[] infos = new IBigFileFileInfo[header.Files]; IBigFileFileInfo tmpInfo = version.CreateFileInfo(); int fileOffset = segmentHeader.InfoOffset + header.StructSize; log.Debug("File info offset: {0:X8}", fileOffset); byte[] buffer = buffers[tmpInfo.StructSize]; stream.Seek(fileOffset, SeekOrigin.Begin); for (int i = 0; i < header.Files; i++) { stream.Read(buffer, 0, tmpInfo.StructSize); infos[i] = tmpInfo.FromBytes(buffer); infos[i].DebugLog(log); } log.Info("File infos read! Time taken: {0}ms", diag.StopwatchTime); log.Info("File count: {0}", header.Files); return(infos); }
public IBigFileFolderInfo[] ReadFolderInfos(Stream stream, ref BigFileSegmentHeader segmentHeader, ref BigFileHeaderStruct header) { if (version == null) { throw new NullReferenceException("Version cannot be null!"); } log.Info("Reading big file folders, count: {0}", header.Folders); BigFileVersions.DebugLogVersion(version, log); diag.StartStopwatch(); IBigFileFolderInfo[] infos = new IBigFileFolderInfo[header.Folders]; IBigFileFolderInfo tmpInfo = version.CreateFolderInfo(); int folderOffset = BigFileUtil.CalculateFolderOffset(version, ref segmentHeader, ref header); byte[] buffer = buffers[tmpInfo.StructSize]; stream.Seek(folderOffset, SeekOrigin.Begin); for (short i = 0; i < header.Folders; i++) { stream.Read(buffer, 0, tmpInfo.StructSize); infos[i] = tmpInfo.FromBytes(buffer); infos[i].DebugLog(log); } log.Info("Folder infos read! Time taken: {0}ms", diag.StopwatchTime); return(infos); }
public static int CalculateFolderOffset(IBigFileVersion version, ref BigFileSegmentHeader segmentHeader, ref BigFileHeaderStruct header) { if (version == null) { throw new NullReferenceException("There's no version! Can't calculate folder offset!"); } IBigFileFileInfo tmpFileInfo = version.CreateFileInfo(); int baseSize = (segmentHeader.InfoOffset + header.StructSize) + (header.Files * tmpFileInfo.StructSize); baseSize = (((baseSize - 1) / 8) + 1) * 8; // align to 8 bytes return(baseSize); }
public void WriteSegmentHeader(ref BigFileSegmentHeader header) { if (fileInfo == null || !fileInfo.Exists) { throw new IOException("Can't write segment header!"); } log.Info("Writing segment header to file: " + fileInfo.FullName); using (FileStream fs = File.OpenWrite(fileInfo.FullName)) { WriteSegmentHeader(fs, ref header); } }
public static int CalculateDataOffset(IBigFileVersion version, ref BigFileSegmentHeader segmentHeader, ref BigFileHeaderStruct header) { if (version == null) { throw new NullReferenceException("There's no version! Can't calculate data offset!"); } IBigFileFolderInfo tmpFolderInfo = version.CreateFolderInfo(); int folderOffset = CalculateFolderOffset(version, ref segmentHeader, ref header); int dataOffset = folderOffset + (header.Folders * tmpFolderInfo.StructSize); dataOffset = (((dataOffset - 1) / 8) + 1) * 8; // align to 8 bytes; return(dataOffset); }
public void WriteHeader(ref BigFileSegmentHeader segmentHeader, ref BigFileHeaderStruct header) { if (fileInfo == null || !fileInfo.Exists) { throw new IOException("Can't read header!"); } log.Info("Writing header to file: " + fileInfo.FullName); using (FileStream fs = File.OpenWrite(fileInfo.FullName)) { fs.Seek(segmentHeader.InfoOffset, SeekOrigin.Begin); WriteHeader(fs, ref header); } }
public IBigFileFileInfo[] ReadFileInfos(ref BigFileSegmentHeader segmentHeader, ref BigFileHeaderStruct header) { if (fileInfo == null || !fileInfo.Exists) { throw new Exception("File info cannot be null!"); } log.Debug("Reading file infos from file {0}", fileInfo.FullName); IBigFileFileInfo[] infos; using (FileStream fs = File.OpenRead(fileInfo.FullName)) { infos = ReadFileInfos(fs, ref segmentHeader, ref header); } return(infos); }
public void WriteFolderInfos(ref BigFileSegmentHeader segmentHeader, ref BigFileHeaderStruct header, IBigFileFolderInfo[] infos) { if (fileInfo == null || !fileInfo.Exists) { throw new Exception("File info cannot be null!"); } log.Debug("Writing folder infos to file {0}", fileInfo.FullName); using (FileStream fs = File.OpenWrite(fileInfo.FullName)) { int folderOffset = BigFileUtil.CalculateFolderOffset(version, ref segmentHeader, ref header); fs.Seek(folderOffset, SeekOrigin.Begin); WriteFolderInfos(fs, infos); } }
public void WriteFileInfos(ref BigFileSegmentHeader segmentHeader, ref BigFileHeaderStruct header, IBigFileFileInfo[] infos) { if (fileInfo == null || !fileInfo.Exists) { throw new Exception("File info cannot be null!"); } log.Debug("Writing file infos to file {0}", fileInfo.FullName); using (FileStream fs = File.OpenWrite(fileInfo.FullName)) { int fileOffset = segmentHeader.InfoOffset + header.StructSize; fs.Seek(fileOffset, SeekOrigin.Begin); WriteFileInfos(fs, infos); } }
public BigFileHeaderStruct ReadHeader(Stream stream, ref BigFileSegmentHeader segmentHeader) { BigFileHeaderStruct header = new BigFileHeaderStruct(); log.Info("Reading big file header..."); log.Debug("Header struct size: " + header.StructSize); byte[] buffer = buffers[header.StructSize]; stream.Seek(segmentHeader.InfoOffset, SeekOrigin.Begin); stream.Read(buffer, 0, header.StructSize); header = MarshalUtil.BytesToStruct <BigFileHeaderStruct>(buffer); log.Info("Header read!"); return(header); }
public BigFileHeaderStruct ReadHeader(ref BigFileSegmentHeader segmentHeader) { if (fileInfo == null || !fileInfo.Exists) { throw new IOException("Can't read header!"); } log.Info("Reading header from file: " + fileInfo.FullName); BigFileHeaderStruct header; using (FileStream fs = File.OpenRead(fileInfo.FullName)) { header = ReadHeader(fs, ref segmentHeader); } return(header); }
public BigFileSegmentHeader ReadSegmentHeader(Stream stream) { BigFileSegmentHeader header = new BigFileSegmentHeader(); log.Info("Reading segment header..."); log.Debug("Header struct size: " + header.StructSize); byte[] buffer = buffers[header.StructSize]; stream.Read(buffer, 0, header.StructSize); header = MarshalUtil.BytesToStruct <BigFileSegmentHeader>(buffer); header.DebugLog(log); log.Info("Segment header read!"); return(header); }
public void WriteSegmentHeader(Stream stream, ref BigFileSegmentHeader header) { log.Info("Writing segment header..."); byte[] buffer = buffers[header.StructSize]; int headerSize = MarshalUtil.StructToBytes <BigFileSegmentHeader>(header, buffer); stream.Write(buffer, 0, headerSize); int blankBytesToWrite = (header.InfoOffset - header.StructSize); log.Debug("Blank bytes: " + blankBytesToWrite.ToString()); for (int i = 0; i < blankBytesToWrite; i++) { stream.WriteByte(0x00); } log.Info("Segment header written!"); }
public int CalculateDataOffset(ref BigFileSegmentHeader segmentHeader, ref BigFileHeaderStruct header) { return(CalculateDataOffset(this.version, ref segmentHeader, ref header)); }