예제 #1
0
        /// <summary>
        /// Opens a stream for reading. This will detect the stream type automatically based on the extension and filetype
        /// </summary>
        /// <param name="path">The path of the inputfile.</param>
        /// <param name="calculateHash">Wether or not to calculate the md5 hash of the stream.</param>
        public Ripp3rStream(string path, bool calculateHash = true)
        {
            if (calculateHash)
            {
                StartCalculateHash();
            }

            input = true;

            switch (Path.GetExtension(path))
            {
            case ".zip":
            case ".001":
                ZipStream zipStream = ZipStream.Create(path, FileMode.Open, FileAccess.Read);
                internalStream = FindFile(zipStream);
                parts          = zipStream.Parts;
                if (internalStream == null)
                {
                    throw new FileNotFoundException("Cannot find an iso or decrypted iso file in the zip file.");
                }
                StreamType = StreamType.Zip;
                break;

            case ".iso":
            case ".dec":
                internalStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                StreamType     = StreamType.Normal;
                break;

            default:
                throw new FileLoadException("Invalid file type");
            }
            filename = Path.GetFileName(path);
        }
예제 #2
0
        public Ripp3rStream(StreamType streamType, string filename, bool calculateHash = true)
        {
            StreamType    = streamType;
            this.filename = Path.GetFileName(filename);
            string outputFile = filename;

            if (streamType == StreamType.Zip)
            {
                string ext = Path.GetExtension(outputFile);
                outputFile = outputFile.Replace(ext, ".zip");
            }

            if (calculateHash)
            {
                StartCalculateHash();
            }

            switch (streamType)
            {
            case StreamType.Zip:
                ZipStream       zipStream    = ZipStream.Create(outputFile, FileMode.Create, FileAccess.Write);
                ZipOutputStream outputStream = new ZipOutputStream(zipStream, false)
                {
                    ParallelDeflateThreshold = 0,
                    EnableZip64 = Zip64Option.AsNecessary
                };
                outputStream.PutNextEntry(this.filename);
                internalStream = outputStream;
                parts          = zipStream.Parts;
                break;

            default:
                internalStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
                break;
            }
        }