コード例 #1
0
ファイル: RegionFile.cs プロジェクト: zhanjunxiong/ProjectMTB
        private void ReadHeadData(int x, int z)
        {
            int startPosition = (x * REGION_DEPTH + z) * 4;

            _fs.Position = startPosition;
            byte[] blockOffsetByte = new byte[4];
            _fs.Read(blockOffsetByte, 0, blockOffsetByte.Length - 1);
            int blockOffset = Serialization.ReadIntFromByteArr(blockOffsetByte);

            //如果块的偏移量小于两个扇区大小,那么当前块没有创建
            if (blockOffset < 2)
            {
                return;
            }
            byte blockLength = (byte)_fs.ReadByte();

            if (blockLength == 0)
            {
                _headData[x, z].status = ChunkDataStatus.Length_Error;
                return;
            }

//			//读入时间戳
//			_fs.Position = startPosition + SectorToByte(2);
//			byte[] timestampByte = new byte[4];
//			_fs.Read(timestampByte,0,timestampByte.Length);

            _fs.Position = SectorToByte(blockOffset);
            byte[] chunkSizeByte = new byte[4];
            _fs.Read(chunkSizeByte, 0, chunkSizeByte.Length);
            int             chunkSize      = Serialization.ReadIntFromByteArr(chunkSizeByte);
            MTBCompressType compressFormat = (MTBCompressType)_fs.ReadByte();

            _headData[x, z].BlockOffset     = blockOffset;
            _headData[x, z].BlockLength     = blockLength;
            _headData[x, z].Length          = chunkSize;
            _headData[x, z].CompressionType = compressFormat;
            _headData[x, z].status          = ChunkDataStatus.OK;
            for (int i = blockOffset; i < blockOffset + blockLength; i++)
            {
                _useSector[i] = true;
            }
        }