Пример #1
0
        private static void ExtractSinData(BackgroundWorker sender, BinaryReader br, List <SinFile.BlockInfoHeader> bihs, string destination, bool showProgress = true)
        {
            using (FileStream fsw = new FileStream(destination, FileMode.Create))
                using (BinaryWriter bw = new BinaryWriter(fsw))
                {
                    int  SinVersion = SinFile.GetSinVersion(br);
                    long previousDest = 0, previousLength = 0;
                    int  dataStart = SinFile.GetDataStart(br);
                    br.BaseStream.Position = dataStart;
                    for (int i = 0; i < bihs.Count; i++)
                    {
                        SinFile.BlockInfoHeader bih = bihs[i];
                        if (previousDest + previousLength < bih.dataDest)
                        {
                            FillFF(fsw, (previousDest + previousLength), (bih.dataDest - previousDest - previousLength));
                        }

                        if (SinVersion != 2)
                        {
                            br.BaseStream.Position = dataStart + bih.dataStart;
                        }

                        fsw.Position = bih.dataDest;

                        if (SinFile.isCompressed(bih))
                        {
                            DecompressAndCopy(br, bw, bih);
                        }
                        else
                        {
                            CopyBytes(br, bw, bih.dataLength);
                        }

                        previousDest   = bih.dataDest;
                        previousLength = SinFile.isCompressed(bih) ? bih.destLength : bih.dataLength;
                        if (showProgress)
                        {
                            sender.ReportProgress((int)((float)i / bihs.Count * 100));
                        }
                    }

                    long finallength = SinFile.GetFinalLength(fsw);
                    if (finallength > previousDest + previousLength)
                    {
                        FillFF(fsw, (previousDest + previousLength), (finallength - previousDest - previousLength));
                    }

                    if (showProgress)
                    {
                        sender.ReportProgress(100);
                    }
                }
        }