private void exportBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { for (int i = 0; i < _sndAliasBank.Entries.Count; i++) { if (exportBackgroundWorker.CancellationPending) { return; } var entry = _sndAliasBank.Entries[i]; string relativePath; if (!_useOriginalTreeStructure || !SndAliasNameDatabase.Names.TryGetValue(entry.Identifier, out relativePath)) { relativePath = "Sound " + (i + 1) + SndAliasBankHelper.GetExtensionFromFormat(entry.Format); } else { relativePath += SndAliasBankHelper.GetExtensionFromFormat(entry.Format); } using (var audioStream = SndAliasBankHelper.GetAudioStreamFromEntry(entry)) { try { var fullPath = Path.Combine(_outputDirectory, relativePath); string directoryPath; if (relativePath.IndexOf('\\') != -1 && !Directory.Exists((directoryPath = Path.GetDirectoryName(fullPath)))) { Directory.CreateDirectory(directoryPath); } using (var fs = new FileStream(fullPath, FileMode.Create, FileAccess.Write, FileShare.Read)) audioStream.CopyTo(fs); exportBackgroundWorker.ReportProgress((i + 1) * 100 / _sndAliasBank.Entries.Count, Path.GetFileName(fullPath)); } catch (Exception ex) { MessageBox.Show(ex.Message, "Black Ops II Sound Studio", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } } MessageBox.Show("All audio entries have been exported successfully.", "Black Ops II Sound Studio", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void exportToolStripMenuItem_Click(object sender, EventArgs e) { var selectedRow = audioEntriesDataGridView.SelectedRows[0]; var name = selectedRow.Cells[0].Value.ToString(); var entry = (SndAssetBankEntry)selectedRow.Tag; using (var saveFileDialog = new SaveFileDialog()) { var extension = SndAliasBankHelper.GetExtensionFromFormat(entry.Format); if (string.IsNullOrEmpty(extension)) { saveFileDialog.Filter = "All Files|*.*"; } else { saveFileDialog.Filter = extension.Substring(1).ToUpperInvariant() + " Files|*" + extension; } if (!name.EndsWith(extension)) { name += extension; } saveFileDialog.FileName = name; if (saveFileDialog.ShowDialog() != DialogResult.OK) { return; } try { using (var audioStream = SndAliasBankHelper.GetAudioStreamFromEntry(entry)) using (var fs = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.Write, FileShare.Read)) audioStream.CopyTo(fs); MessageBox.Show(Path.GetFileName(saveFileDialog.FileName) + " has been exported successfully.", "Black Ops II Sound Studio", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Black Ops II Sound Studio", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }