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);
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
        private void UpdateAudioEntries()
        {
            audioEntriesDataGridView.Rows.Clear();

            // Set autosize modes.
            for (int i = 0; i < audioEntriesDataGridView.Columns.Count - 1; i++)
            {
                if (audioEntriesDataGridView.Columns[i].HeaderText != "Sample Rate")
                {
                    audioEntriesDataGridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                }
                else
                {
                    audioEntriesDataGridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                }
            }

            // Add the entries.
            DataGridViewRow[] rows = new DataGridViewRow[_sndAliasBank.Entries.Count];
            for (int i = 0; i < _sndAliasBank.Entries.Count; i++)
            {
                var    entry = _sndAliasBank.Entries[i];
                string name;
                if (SndAliasNameDatabase.Names.TryGetValue(entry.Identifier, out name))
                {
                    name = showFullNameToolStripMenuItem.Checked ? name : Path.GetFileName(name);
                }
                else
                {
                    name = "Sound #" + (i + 1) + SndAliasBankHelper.GetExtensionFromFormat(entry.Format);
                }
                var row = new DataGridViewRow();
                row.CreateCells(audioEntriesDataGridView,
                                name,
                                entry.Offset,
                                entry.Size,
                                SndAliasBankHelper.GetFormatName(entry.Format),
                                entry.Loop,
                                entry.ChannelCount,
                                FormatSampleRate(entry.SampleRate),
                                BitConverter.ToString(_sndAliasBank.Checksums[i]).Replace("-", ""));
                row.ContextMenuStrip = audioEntryContextMenuStrip;
                row.Tag = entry;
                rows[i] = row;
            }

            audioEntriesDataGridView.Rows.AddRange(rows);

            // Fix to allow user to manually size.
            for (int i = 0; i < audioEntriesDataGridView.Columns.Count - 1; i++)
            {
                var column = audioEntriesDataGridView.Columns[i];
                if (column.AutoSizeMode != DataGridViewAutoSizeColumnMode.AllCells)
                {
                    continue;
                }
                int width = column.GetPreferredWidth(column.AutoSizeMode, true);
                column.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet;
                column.Width        = width;
            }
        }