Exemplo n.º 1
0
            public ResolveStream(DecompressionStream inStream, long Position, long Length)
            {
                this.inStream = inStream;
                fileLength    = Length;
                offset        = Position;

                inStream.Position = Position;
            }
Exemplo n.º 2
0
        public void UnpackNoEvent(string outputPath, List <FileData> fileDatas)
        {
            inputStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)
            {
                Position = compressInfo.DataPos
            };
            long writtenLength = 0;

            if (crypto != null)
            {
                decompStream = new DecompressionStream(inputStream, compressInfo, crypto);
            }
            else
            {
                decompStream = new DecompressionStream(inputStream, compressInfo);
            }

            foreach (FileData file in fileDatas)
            {
                FileStream outputFileStream = new FileStream(outputPath + "\\" + file.FileName, FileMode.Create, FileAccess.ReadWrite);
                if (decompStream.Position != file.Position)
                {
                    decompStream.Position = file.Position;
                }

                for (long i = 0; i < file.Length; i++)
                {
                    if (Token.IsCancellationRequested)
                    {
                        outputFileStream.Dispose();
                        return;
                    }

                    outputFileStream.WriteByte((byte)decompStream.ReadByte());
                    writtenLength++;
                }
                outputFileStream.Dispose();
            }

            decompStream.Dispose();
            inputStream.Dispose();
        }
Exemplo n.º 3
0
        public FileUnpacker(string filePathtoUnpack, CryptoClass crypto, CancellationToken ct)
        {
            Token        = ct;
            filePath     = filePathtoUnpack;
            this.crypto  = crypto;
            inputStream  = new FileStream(filePathtoUnpack, FileMode.Open, FileAccess.Read);
            compressInfo = new CompressionInfo(inputStream, crypto);
            try
            {
                decompStream = new DecompressionStream(inputStream, compressInfo, crypto);
                decompStream.ReadByte();
                decompStream.Dispose();
            }
            catch (System.Security.Cryptography.CryptographicException)
            {
                inputStream.Dispose();
                throw new IncorrectKeyException();
            }

            fileDatas = compressInfo.Files;

            inputStream.Dispose();
        }
Exemplo n.º 4
0
        public void Unpack(string outputPath, List <FileData> fileDatas, long totalLength)
        {
            if (EventRaiser.OnFileNameChange == null && EventRaiser.OnProgressChange == null)
            {
                UnpackNoEvent(outputPath, fileDatas);
                return;
            }
            inputStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)
            {
                Position = compressInfo.DataPos
            };
            long   writtenLength = 0;
            double tempValue     = 0;

            if (crypto != null)
            {
                decompStream = new DecompressionStream(inputStream, compressInfo, crypto);
            }
            else
            {
                decompStream = new DecompressionStream(inputStream, compressInfo);
            }

            foreach (FileData file in fileDatas)
            {
                EventRaiser.OnFileNameChange?.Invoke(file.FileName);
                FileStream outputFileStream = new FileStream(outputPath + "\\" + file.FileName, FileMode.Create, FileAccess.ReadWrite);
                if (decompStream.Position != file.Position)
                {
                    decompStream.Position = file.Position;
                }

                for (long i = 0; i < file.Length; i++)
                {
                    if (Token.IsCancellationRequested)
                    {
                        outputFileStream.Dispose();
                        return;
                    }

                    outputFileStream.WriteByte((byte)decompStream.ReadByte());

                    writtenLength++;

                    if (EventRaiser.OnProgressChange != null)
                    {
                        double value = Math.Round((double)writtenLength / totalLength * 100, 1);

                        if (tempValue != value)
                        {
                            tempValue = value;
                            EventRaiser.OnProgressChange.Invoke(value);
                        }
                    }
                }
                outputFileStream.Dispose();
            }

            decompStream.Dispose();
            inputStream.Dispose();
        }