Exemple #1
0
        private static IvffResult CheckBlockNext(
            Stream stream,
            ref IvCommonCheckWork checkWork,
            ref IvCommonBlockHeader common)
        {
            int val2 = Math.Min(checkWork.DivideSize, checkWork.RemainSize);

            checkWork.RemainSize -= val2;
            ++checkWork.NowCount;
            int size;

            for (; 0 < val2; val2 -= size)
            {
                size = Math.Min(16777216, val2);
                byte[] bytes = new byte[size];
                int    readSize;
                if (Ivff.IsResultError(Ivff.ReadNext(stream, bytes, size, out readSize)) || size != readSize)
                {
                    return(IvffResult.READ_ERROR);
                }
                checkWork.CurSum = IvaUtils.CalcSum32(checkWork.CurSum, bytes, size);
            }
            if (0 < checkWork.RemainSize)
            {
                return(IvffResult.CONTINUE);
            }
            return((int)common.BlockDataSum == (int)checkWork.CurSum ? IvffResult.OK : IvffResult.INVALID);
        }
Exemple #2
0
 private static IvffResult CheckBlockFirst(
     Stream stream,
     ref IvCommonCheckWork checkWork,
     int divideSize,
     ref IvCommonBlockHeader workHeader,
     uint blockID)
 {
     return(Ivff.CheckBlockFirst <IvCommonBlockHeader>(stream, out checkWork, divideSize, ref workHeader, ref workHeader, blockID));
 }
Exemple #3
0
        private static IvffResult CheckBlockFirst <T>(
            Stream stream,
            out IvCommonCheckWork checkWork,
            int divideSize,
            ref T header,
            ref IvCommonBlockHeader workHeader,
            uint blockID)
            where T : struct
        {
            checkWork = new IvCommonCheckWork();
            IvffResult result1 = Ivff.LoadBlockHeader <T>(stream, ref header);

            if (Ivff.IsResultError(result1))
            {
                return(result1);
            }
            if ((int)workHeader.BlockHeaderSize != Marshal.SizeOf(typeof(IvCommonBlockHeader)))
            {
                IvffResult result2 = Ivff.SeekCommonBlockDataTop(stream, ref workHeader);
                if (Ivff.IsResultError(result2))
                {
                    return(result2);
                }
            }
            if (blockID != 0U && (int)workHeader.BlockID != (int)blockID)
            {
                return(IvffResult.UNMACH_BLOCK);
            }
            checkWork.RemainSize = checkWork.TotalSize = workHeader.BlockSize - Marshal.SizeOf(typeof(IvCommonBlockHeader));
            if (divideSize == 0)
            {
                checkWork.DivideSize  = checkWork.TotalSize;
                checkWork.DivideCount = 1U;
                IvffResult ivffResult = Ivff.CheckBlockNext(stream, ref checkWork, ref workHeader);
                while (ivffResult == IvffResult.CONTINUE)
                {
                    ivffResult = Ivff.CheckBlockNext(stream, ref checkWork, ref workHeader);
                }
                return(ivffResult);
            }
            checkWork.DivideSize  = divideSize;
            checkWork.DivideCount = (uint)((workHeader.BlockSize - Marshal.SizeOf(typeof(IvCommonBlockHeader))) / checkWork.DivideSize);
            return(IvffResult.CONTINUE);
        }