internal override void ValidateArchive(RarVolume archive)
 {
     if (archive.IsMultiVolume)
     {
         throw new MultiVolumeExtractionException("Streamed archive is a Multi-volume archive.  Use different RarReader method to extract.");
     }
 }
Example #2
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            long destination = 0;

            switch (origin)
            {
            case SeekOrigin.Begin:
                destination = offset;
                break;

            case SeekOrigin.Current:
                destination = currentPos + offset;
                break;

            case SeekOrigin.End:
                destination = packedFileLength - 1 + offset;
                break;
            }

            if (destination < 0L)
            {
                throw new ArgumentOutOfRangeException();
            }

            currentPos = destination;

            if (currentVol == null || currentPos < currentVol.PackedFileRangeStart || currentPos > currentVol.PackedFileRangeEnd)
            {
                currentVol = null;
                foreach (RarVolume vol in rarVolumes)
                {
                    if (currentPos >= vol.PackedFileRangeStart && currentPos <= vol.PackedFileRangeEnd)
                    {
                        currentVol = vol;
                        break;
                    }
                }
            }

            return(currentPos);
        }
Example #3
0
 internal override void ValidateArchive(RarVolume archive)
 {
 }
Example #4
0
 internal abstract void ValidateArchive(RarVolume archive);
Example #5
0
        public RarStream(string rarPath)
        {
            bool     oldNameFormat = true;
            RarBlock block         = null;

            using (RarReader rdr = new RarReader(rarPath, RarReadMode.RAR))
                while ((block = rdr.Read()) != null)
                {
                    if (block is RarVolumeHeaderBlock && ((block.Flags & (ushort)RarVolumeHeaderBlock.FlagValues.Volume) != 0))
                    {
                        oldNameFormat = (block.Flags & (ushort)RarVolumeHeaderBlock.FlagValues.NewNumbering) == 0;
                    }
                    else if (block is RarPackedFileBlock)
                    {
                        if ((block.Flags & (ushort)RarPackedFileBlock.FlagValues.SplitBefore) != 0)
                        {
                            throw new InvalidDataException("You must start with the first volume from a RAR set");
                        }

                        break;
                    }
                }

            // this constructor implementation picks the first packed file encountered in the archive and sets up to read it
            //  an alternate constructor might have a parameter to specify the packed file to read.
            string packedFileName = null;
            string nextFileName   = rarPath;

            while (File.Exists(nextFileName))
            {
                using (RarReader rdr = new RarReader(nextFileName, RarReadMode.RAR))
                    while ((block = rdr.Read()) != null)
                    {
                        RarPackedFileBlock fblock = block as RarPackedFileBlock;
                        if (fblock != null)
                        {
                            if (string.IsNullOrEmpty(packedFileName))
                            {
                                packedFileName = fblock.FileName;
                            }

                            if (packedFileName == fblock.FileName)
                            {
                                if (fblock.CompressionMethod != 0x30)
                                {
                                    throw new InvalidDataException("Compressed RARs are not supported");
                                }

                                currentVol                      = new RarVolume();
                                currentVol.FilePath             = nextFileName;
                                currentVol.PackedFileRangeStart = packedFileLength;
                                currentVol.PackedFileRangeEnd   = packedFileLength + (long)fblock.PackedSize - 1;
                                currentVol.PackedFileOffset     = fblock.BlockPosition + fblock.RawData.LongLength;

                                rarVolumes.Add(currentVol);

                                packedFileLength += (long)fblock.PackedSize;
                            }
                        }
                    }

                nextFileName = RarFileNameFinder.FindNextFileName(nextFileName, oldNameFormat);
            }

            currentVol = rarVolumes[0];
        }