Exemple #1
0
        private void UnpackSymlink(Pack1Meta.FileEntry file)
        {
            string destPath = Path.Combine(_destinationDirPath, file.Name);

            DebugLogger.Log("Creating symlink: " + destPath);
            // TODO: how to create a symlink?
        }
        private void UnpackRegularFile(Pack1Meta.FileEntry file, Action <double> onProgress, CancellationToken cancellationToken, string destinationDirPath = null)
        {
            string destPath = Path.Combine(destinationDirPath == null ? _destinationDirPath : destinationDirPath, file.Name + _suffix);

            DebugLogger.LogFormat("Unpacking regular file {0} to {1}", file, destPath);

            if (file.Size == null)
            {
                throw new NullReferenceException("File size cannot be null for regular file.");
            }

            if (file.Offset == null)
            {
                throw new NullReferenceException("File offset cannot be null for regular file.");
            }

            Files.CreateParents(destPath);

            var rijn = new RijndaelManaged
            {
                Mode    = CipherMode.CBC,
                Padding = PaddingMode.None,
                KeySize = 256
            };

            var aesAlg = new AesCryptoServiceProvider
            {
                IV  = _iv,
                Key = _key
            };

            ICryptoTransform decryptor = aesAlg.CreateDecryptor(
                aesAlg.Key,
                aesAlg.IV);

            DecompressorCreator decompressorCreator = ResolveDecompressor(_metaData);

            using (var fs = new FileStream(_packagePath, FileMode.Open))
            {
                fs.Seek(file.Offset.Value - _range.Start, SeekOrigin.Begin);

                using (var limitedStream = new BufferedStream(new LimitedStream(fs, file.Size.Value), 2 * 1024 * 1024))
                {
                    //using (var bufferedLimitedStream = new ThreadBufferedStream(limitedStream, 8 * 1024 * 1024))
                    {
                        using (var target = new FileStream(destPath, FileMode.Create))
                        {
                            ExtractFileFromStream(limitedStream, target, file.Size.Value, decryptor, decompressorCreator, onProgress, cancellationToken);
                        }
                    }

                    if (Platform.IsPosix())
                    {
                        Chmod.SetMode(file.Mode.Substring(3), destPath);
                    }
                }
            }

            DebugLogger.Log("File " + file.Name + " unpacked successfully!");
        }
        private void Unpack(Pack1Meta.FileEntry file, Action <double> progress)
        {
            switch (file.Type)
            {
            case "regular":
                UnpackRegularFile(file, progress);
                break;

            case "directory":
                progress(0.0);
                UnpackDirectory(file);
                progress(1.0);
                break;

            case "symlink":
                progress(0.0);
                UnpackSymlink(file);
                progress(1.0);
                break;

            default:
                DebugLogger.LogWarning("Unknown file type: " + file.Type);
                break;
            }
        }
        private void Unpack(Pack1Meta.FileEntry file, Action <double> progress, CancellationToken cancellationToken, string destinationDirPath = null)
        {
            switch (file.Type)
            {
            case Pack1Meta.RegularFileType:
                UnpackRegularFile(file, progress, cancellationToken, destinationDirPath);
                break;

            case Pack1Meta.DirectoryFileType:
                progress(0.0);
                UnpackDirectory(file, cancellationToken);
                progress(1.0);
                break;

            case Pack1Meta.SymlinkFileType:
                progress(0.0);
                UnpackSymlink(file);
                progress(1.0);
                break;

            default:
                DebugLogger.LogWarning("Unknown file type: " + file.Type);
                break;
            }
        }
Exemple #5
0
        private void UnpackDirectory(Pack1Meta.FileEntry file)
        {
            string destPath = Path.Combine(_destinationDirPath, file.Name);

            DebugLogger.Log("Creating directory " + destPath);
            Directory.CreateDirectory(destPath);
            DebugLogger.Log("Directory " + destPath + " created successfully!");
        }
        public void UnarchiveSingleFile(Pack1Meta.FileEntry file, CancellationToken cancellationToken, string destinationDirPath = null)
        {
            OnUnarchiveProgressChanged(file.Name, file.Type == Pack1Meta.RegularFileType, 0, 1, 0.0);

            if (!CanUnpack(file))
            {
                throw new ArgumentOutOfRangeException("file", file, null);
            }

            Unpack(file, progress => OnUnarchiveProgressChanged(file.Name, file.Type == Pack1Meta.RegularFileType, 1, 1, progress), cancellationToken, destinationDirPath);

            OnUnarchiveProgressChanged(file.Name, file.Type == Pack1Meta.RegularFileType, 0, 1, 1.0);
        }
        private bool CanUnpack(Pack1Meta.FileEntry file)
        {
            if (file.Type != Pack1Meta.RegularFileType)
            {
                return(true);
            }

            if (_range.Start == 0 && _range.End == -1)
            {
                return(true);
            }

            return(file.Offset >= _range.Start && file.Offset + file.Size <= _range.End);
        }
Exemple #8
0
        private void UnpackRegularFile(Pack1Meta.FileEntry file, Action <double> onProgress)
        {
            string destPath = Path.Combine(_destinationDirPath, file.Name + _suffix);

            DebugLogger.LogFormat("Unpacking regular file {0} to {1}", file, destPath);

            Files.CreateParents(destPath);

            RijndaelManaged rijn = new RijndaelManaged
            {
                Mode    = CipherMode.CBC,
                Padding = PaddingMode.None,
                KeySize = 256
            };

            using (var fs = new FileStream(_packagePath, FileMode.Open))
            {
                fs.Seek(file.Offset.Value, SeekOrigin.Begin);

                using (var limitedStream = new LimitedStream(fs, file.Size.Value))
                {
                    ICryptoTransform decryptor = rijn.CreateDecryptor(_key, _iv);
                    using (var cryptoStream = new CryptoStream(limitedStream, decryptor, CryptoStreamMode.Read))
                    {
                        using (var gzipStream = new GZipStream(cryptoStream, Ionic.Zlib.CompressionMode.Decompress))
                        {
                            using (var fileWritter = new FileStream(destPath, FileMode.Create))
                            {
                                long      bytesProcessed = 0;
                                const int bufferSize     = 131072;
                                var       buffer         = new byte[bufferSize];
                                int       count;
                                while ((count = gzipStream.Read(buffer, 0, bufferSize)) != 0)
                                {
                                    fileWritter.Write(buffer, 0, count);
                                    bytesProcessed += count;
                                    onProgress(bytesProcessed / (double)file.Size.Value);
                                }
                                if (Platform.IsPosix())
                                {
                                    Chmod.SetMode(file.Mode.Substring(3), destPath);
                                }
                            }
                        }
                    }
                }
            }

            DebugLogger.Log("File " + file.Name + " unpacked successfully!");
        }
Exemple #9
0
        private void Unpack(Pack1Meta.FileEntry file, Action <double> progress, CancellationToken cancellationToken, string destinationDirPath = null)
        {
            switch (file.Type)
            {
            case Pack1Meta.RegularFileType:
                try
                {
                    UnpackRegularFile(file, progress, cancellationToken, destinationDirPath);
                }
                catch (Ionic.Zlib.ZlibException e)
                {
                    if (ContinueOnError)
                    {
                        DebugLogger.LogWarning("ZlibException caught. The process will continue, but I will try to repair it later.");
                        DebugLogger.LogException(e);
                        HasErrors = true;
                    }
                    else
                    {
                        throw;
                    }
                }
                finally
                {
                    _processedFiles += 1;
                }

                break;

            case Pack1Meta.DirectoryFileType:
                progress(0.0);
                UnpackDirectory(file, cancellationToken);
                progress(1.0);
                break;

            case Pack1Meta.SymlinkFileType:
                progress(0.0);
                UnpackSymlink(file);
                progress(1.0);
                break;

            default:
                DebugLogger.LogWarning("Unknown file type: " + file.Type);
                break;
            }
        }
Exemple #10
0
        private void UnpackRegularFile(Pack1Meta.FileEntry file)
        {
            string destPath = Path.Combine(_destinationDirPath, file.Name);

            DebugLogger.LogFormat("Unpacking regular file {0} to {1}", file, destPath);

            Files.CreateParents(destPath);

            RijndaelManaged rijn = new RijndaelManaged
            {
                Mode    = CipherMode.CBC,
                Padding = PaddingMode.None,
                KeySize = 256
            };

            using (var fs = new FileStream(_packagePath, FileMode.Open))
            {
                fs.Seek(file.Offset.Value, SeekOrigin.Begin);

                using (var limitedStream = new LimitedStream(fs, file.Size.Value))
                {
                    ICryptoTransform decryptor = rijn.CreateDecryptor(_key, _iv);
                    using (var cryptoStream = new CryptoStream(limitedStream, decryptor, CryptoStreamMode.Read))
                    {
                        using (var gzipStream = new GZipStream(cryptoStream, Ionic.Zlib.CompressionMode.Decompress))
                        {
                            using (var fileWritter = new FileStream(destPath, FileMode.Create))
                            {
                                Streams.Copy(gzipStream, fileWritter);
                                if (Platform.IsPosix())
                                {
                                    Chmod.SetMode(file.Mode.Substring(3), destPath);
                                }
                            }
                        }
                    }
                }
            }

            DebugLogger.Log("File " + file.Name + " unpacked successfully!");
        }
Exemple #11
0
        private void Unpack(Pack1Meta.FileEntry file)
        {
            switch (file.Type)
            {
            case "regular":
                UnpackRegularFile(file);
                break;

            case "directory":
                UnpackDirectory(file);
                break;

            case "symlink":
                UnpackSymlink(file);
                break;

            default:
                DebugLogger.LogWarning("Unknown file type: " + file.Type);
                break;
            }
        }
        private void UnpackRegularFile(Pack1Meta.FileEntry file, Action <double> onProgress)
        {
            string destPath = Path.Combine(_destinationDirPath, file.Name + _suffix);

            DebugLogger.LogFormat("Unpacking regular file {0} to {1}", file, destPath);

            Files.CreateParents(destPath);

            RijndaelManaged rijn = new RijndaelManaged
            {
                Mode    = CipherMode.CBC,
                Padding = PaddingMode.None,
                KeySize = 256
            };

            using (var fs = new FileStream(_packagePath, FileMode.Open))
            {
                fs.Seek(file.Offset.Value, SeekOrigin.Begin);

                using (var limitedStream = new LimitedStream(fs, file.Size.Value))
                {
                    ICryptoTransform decryptor = rijn.CreateDecryptor(_key, _iv);
                    using (var cryptoStream = new CryptoStream(limitedStream, decryptor, CryptoStreamMode.Read))
                    {
                        using (var gzipStream = new GZipStream(cryptoStream, Ionic.Zlib.CompressionMode.Decompress))
                        {
                            try
                            {
                                using (var fileWritter = new FileStream(destPath, FileMode.Create))
                                {
                                    long      bytesProcessed = 0;
                                    const int bufferSize     = 131072;
                                    var       buffer         = new byte[bufferSize];
                                    int       count;
                                    while ((count = gzipStream.Read(buffer, 0, bufferSize)) != 0)
                                    {
                                        fileWritter.Write(buffer, 0, count);
                                        bytesProcessed += count;
                                        onProgress(bytesProcessed / (double)file.Size.Value);
                                    }
                                    if (Platform.IsPosix())
                                    {
                                        Chmod.SetMode(file.Mode.Substring(3), destPath);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                DebugLogger.LogException(e);

                                var ravenClient
                                    = new RavenClient("https://*****:*****@sentry.io/175617");

                                var sentryEvent = new SentryEvent(e);
                                var logManager  = PatcherLogManager.Instance;
                                PatcherLogSentryRegistry.AddDataToSentryEvent(sentryEvent, logManager.Storage.Guid.ToString());

                                ravenClient.Capture(sentryEvent);

                                throw;
                            }
                        }
                    }
                }
            }

            DebugLogger.Log("File " + file.Name + " unpacked successfully!");
        }