示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
            }
        }
示例#5
0
        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);
        }
示例#6
0
        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);
            }
        }
示例#7
0
        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);
        }
示例#8
0
        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);
            }
        }
示例#9
0
        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);
            }
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
        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!");
        }
示例#14
0
 public int CalculateDataOffset(ref BigFileSegmentHeader segmentHeader, ref BigFileHeaderStruct header)
 {
     return(CalculateDataOffset(this.version, ref segmentHeader, ref header));
 }