private void CompressBundle(Stream stream) { status.Text = "Compressing..."; justThisFile.Enabled = false; fileAndDependencies.Enabled = false; compressBundle.Enabled = false; DialogResult option = MessageBox.Show("Compress in LZMA?\nYes - LZMA\nNo - LZ4", "Compression options", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); AssetBundleCompressionType comp; if (option == DialogResult.Yes) { comp = AssetBundleCompressionType.LZMA; } else if (option == DialogResult.No) { comp = AssetBundleCompressionType.LZ4; } else { return; } BackgroundWorker bw = new BackgroundWorker(); string error = string.Empty; bw.DoWork += delegate { try { file.reader.Position = 0; file.Pack(file.reader, new AssetsFileWriter(stream), comp); stream.Position = 0; file = new AssetBundleFile(); file.Read(new AssetsFileReader(stream), false); inst.file = file; } catch (Exception ex) { error = ex.ToString(); } }; bw.RunWorkerCompleted += delegate { if (error != string.Empty) { MessageBox.Show("An error occurred:\n" + error, "Assets View", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { decompressBundle.Enabled = true; decompressBundleInMemory.Enabled = true; justThisFile.Enabled = false; fileAndDependencies.Enabled = false; compressBundle.Enabled = false; status.Text = $"Opening bundle file {fileName}..."; } }; bw.RunWorkerAsync(); }