From f19ed527f2721fda0e7cef6e85335772d8e87fa5 Mon Sep 17 00:00:00 2001 From: MattNL Date: Mon, 3 Oct 2022 01:52:26 -0400 Subject: [PATCH] Updated AudioEditor to use functions from Bink class --- .../Forms/Editor/AudioEditor.Designer.cs | 11 +- PCK-Studio/Forms/Editor/AudioEditor.cs | 74 ++----- PCK-Studio/Forms/Editor/AudioEditor.resx | 186 ++++++++++-------- 3 files changed, 123 insertions(+), 148 deletions(-) diff --git a/PCK-Studio/Forms/Editor/AudioEditor.Designer.cs b/PCK-Studio/Forms/Editor/AudioEditor.Designer.cs index 18fadace..e5940968 100644 --- a/PCK-Studio/Forms/Editor/AudioEditor.Designer.cs +++ b/PCK-Studio/Forms/Editor/AudioEditor.Designer.cs @@ -58,6 +58,7 @@ namespace PckStudio.Forms.Editor this.playOverworldInCreative = new MetroFramework.Controls.MetroCheckBox(); this.compressionUpDown = new System.Windows.Forms.NumericUpDown(); this.metroLabel1 = new MetroFramework.Controls.MetroLabel(); + this.convertToWAVToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.contextMenuStrip1.SuspendLayout(); this.menuStrip.SuspendLayout(); this.contextMenuStrip2.SuspendLayout(); @@ -228,7 +229,8 @@ namespace PckStudio.Forms.Editor this.contextMenuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.addEntryMenuItem, this.removeEntryMenuItem, - this.verifyFileLocationToolStripMenuItem}); + this.verifyFileLocationToolStripMenuItem, + this.convertToWAVToolStripMenuItem}); this.contextMenuStrip2.Name = "contextMenuStrip1"; resources.ApplyResources(this.contextMenuStrip2, "contextMenuStrip2"); // @@ -289,6 +291,12 @@ namespace PckStudio.Forms.Editor this.metroLabel1.Name = "metroLabel1"; this.metroLabel1.Theme = MetroFramework.MetroThemeStyle.Dark; // + // convertToWAVToolStripMenuItem + // + this.convertToWAVToolStripMenuItem.Name = "convertToWAVToolStripMenuItem"; + resources.ApplyResources(this.convertToWAVToolStripMenuItem, "convertToWAVToolStripMenuItem"); + this.convertToWAVToolStripMenuItem.Click += new System.EventHandler(this.convertToWAVToolStripMenuItem_Click); + // // AudioEditor // resources.ApplyResources(this, "$this"); @@ -343,5 +351,6 @@ namespace PckStudio.Forms.Editor private MetroFramework.Controls.MetroLabel metroLabel1; private System.Windows.Forms.ToolStripMenuItem openDataFolderToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem bulkReplaceExistingTracksToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem convertToWAVToolStripMenuItem; } } \ No newline at end of file diff --git a/PCK-Studio/Forms/Editor/AudioEditor.cs b/PCK-Studio/Forms/Editor/AudioEditor.cs index ed22a529..428e92ac 100644 --- a/PCK-Studio/Forms/Editor/AudioEditor.cs +++ b/PCK-Studio/Forms/Editor/AudioEditor.cs @@ -21,6 +21,7 @@ namespace PckStudio.Forms.Editor { public string defaultType = "yes"; string tempDir = ""; + Classes.Bink BINK = new Classes.Bink(); PCKAudioFile audioFile = null; PCKFile.FileData audioPCK; LOCFile loc; @@ -54,21 +55,10 @@ namespace PckStudio.Forms.Editor public AudioEditor(PCKFile.FileData file, LOCFile locFile, bool isLittleEndian) { InitializeComponent(); - // so the Creative songs aren't combined until after the forms are closed. - // this will prevent potential problems with editing the categories after merging. loc = locFile; - tempDir = Path.Combine(Directory.GetCurrentDirectory(), "temp"); _isLittleEndian = isLittleEndian; - try - { - handleUtilFiles(); - //library = LoadLibrary(Path.Combine(tempDir, "mss32.dll")); - } - catch (IOException ex) - { - MessageBox.Show("Failed to get Binka conversion files", "Exception thrown"); - Close(); - } + + BINK.SetUpBinka(); audioPCK = file; using (var stream = new MemoryStream(file.data)) @@ -111,31 +101,10 @@ namespace PckStudio.Forms.Editor } } - private void handleUtilFiles(bool extractFiles = true) - { - string asiPath = Path.Combine(tempDir, "binkawin.asi"); - string mssPath = Path.Combine(tempDir, "mss32.dll"); - string encoderPath = Path.Combine(tempDir, "binka_encode.exe"); - - // Deletes files so that System.IO exceptions are avoided - if (File.Exists(asiPath)) File.Delete(asiPath); - if (File.Exists(mssPath)) File.Delete(mssPath); - if (File.Exists(encoderPath)) File.Delete(encoderPath); - if (Directory.Exists(tempDir)) Directory.Delete(tempDir); - - if (extractFiles) - { - Directory.CreateDirectory(tempDir); - ExtractResource("binka_encode", encoderPath); - ExtractResource("mss32", mssPath); - ExtractResource("binkawin", asiPath); - } - } - private void AudioEditor_FormClosed(object sender, FormClosedEventArgs e) { //FreeLibrary(library); - handleUtilFiles(false); + BINK.CleanUpBinka(); } private void verifyFileLocationToolStripMenuItem_Click(object sender, EventArgs e) @@ -253,33 +222,23 @@ namespace PckStudio.Forms.Editor else if (user_prompt == DialogResult.No) continue; } } - + if (Path.GetExtension(file) == ".wav") // Convert Wave to BINKA { Cursor.Current = Cursors.WaitCursor; pleaseWait waitDiag = new pleaseWait(); waitDiag.Show(this); - int error_code = 0; await Task.Run(() => { - var process = Process.Start(new ProcessStartInfo - { - FileName = Path.Combine(tempDir, "binka_encode.exe"), - Arguments = $"\"{file}\" \"{new_loc}\" -s -b" + compressionUpDown.Value.ToString(), - UseShellExecute = true, - CreateNoWindow = true, - WindowStyle = ProcessWindowStyle.Hidden - }); - process.Start(); - process.WaitForExit(); + BINK.WavToBinka(file, new_loc, (int)compressionUpDown.Value); }); waitDiag.Close(); waitDiag.Dispose(); Cursor.Current = Cursors.Default; - if (error_code != 0) continue; + if (BINK.temp_error_code != 0) continue; } else if (!duplicate_song) { @@ -492,29 +451,24 @@ namespace PckStudio.Forms.Editor pleaseWait waitDiag = new pleaseWait(); waitDiag.Show(this); - int error_code = 0; await Task.Run(() => { - var process = Process.Start(new ProcessStartInfo - { - FileName = Path.Combine(tempDir, "binka_encode.exe"), - Arguments = $"\"{file}\" \"{new_loc}\" -s -b" + compressionUpDown.Value.ToString(), - UseShellExecute = true, - CreateNoWindow = true, - WindowStyle = ProcessWindowStyle.Hidden - }); - process.Start(); - process.WaitForExit(); + BINK.WavToBinka(file, new_loc, (int)compressionUpDown.Value); }); waitDiag.Close(); waitDiag.Dispose(); Cursor.Current = Cursors.Default; - if (error_code != 0) continue; + if (BINK.temp_error_code != 0) continue; } else if(file_ext == ".binka") File.Copy(file, Path.Combine(parent.GetDataPath(), Path.GetFileName(file))); } } + + private void convertToWAVToolStripMenuItem_Click(object sender, EventArgs e) + { + + } } } diff --git a/PCK-Studio/Forms/Editor/AudioEditor.resx b/PCK-Studio/Forms/Editor/AudioEditor.resx index a35db4c7..6bfb3fae 100644 --- a/PCK-Studio/Forms/Editor/AudioEditor.resx +++ b/PCK-Studio/Forms/Editor/AudioEditor.resx @@ -125,6 +125,26 @@ 127, 8 + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + vAAADrwBlbxySQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAABSSURBVDhP5c0x + DsAgDENRxt7/wmkNSpRGf0CCCZAegxNMM7MlGMp3dIU6dxhKf/QMNxRogeQC8ivw5Vn7C0heJlFA+kL5 + jWAohxRkde4wnGftBS90axNmphIGAAAAAElFTkSuQmCC + + + + 168, 22 + + + Add Category + + + 168, 22 + + + Remove Category + 169, 48 @@ -146,7 +166,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADk - MAAAAk1TRnQBSQFMAgEBCQEAAWgBAAFoAQABEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA + MAAAAk1TRnQBSQFMAgEBCQEAAXABAAFwAQABEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA AwABMAMAAQEBAAEgBgABMBIAAzgB/wM1Af8DNQH/AzMB/wMwAf8DLwH/Ay0B/wMtAf8DJAH/AzsB/wM4 Af8DNQH/Ay0B/wMnAf8DNgH/AzIB/8AAAzgB/wN/Af8DeQH/A3kB/wN5Af8DcQH/A3EB/wN5Af8DeQH/ A3EB/wNxAf8DcQH/A3kB/wN5Af8DfwH/AzIB/8AAAzIB/wN2Af8DsAH/A7AB/wOvAf8DrwH/A68B/wOo @@ -384,62 +404,12 @@ 5 - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vAAADrwBlbxySQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAABSSURBVDhP5c0x - DsAgDENRxt7/wmkNSpRGf0CCCZAegxNMM7MlGMp3dIU6dxhKf/QMNxRogeQC8ivw5Vn7C0heJlFA+kL5 - jWAohxRkde4wnGftBS90axNmphIGAAAAAElFTkSuQmCC - - - - 168, 22 - - - Add Category - - - 168, 22 - - - Remove Category - 19, 8 False - - 20, 60 - - - 410, 24 - - - 11 - - - menuStrip1 - - - menuStrip - - - System.Windows.Forms.MenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 7 - - - 37, 20 - - - File - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO @@ -451,16 +421,16 @@ - 98, 22 + 180, 22 Save - - 46, 20 + + 37, 20 - - Tools + + File 220, 22 @@ -486,11 +456,11 @@ Bulk Replace Existing Tracks - - 44, 20 + + 46, 20 - - Help + + Tools 243, 22 @@ -522,14 +492,76 @@ BINKA Compression + + 44, 20 + + + Help + + + 20, 60 + + + 410, 24 + + + 11 + + + menuStrip1 + + + menuStrip + + + System.Windows.Forms.MenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 7 + Top, Bottom, Left, Right 282, 8 + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + vAAADrwBlbxySQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAABSSURBVDhP5c0x + DsAgDENRxt7/wmkNSpRGf0CCCZAegxNMM7MlGMp3dIU6dxhKf/QMNxRogeQC8ivw5Vn7C0heJlFA+kL5 + jWAohxRkde4wnGftBS90axNmphIGAAAAAElFTkSuQmCC + + + + 180, 22 + + + Add Entry + + + 180, 22 + + + Remove Entry + + + 180, 22 + + + Verify File Location + + + 180, 22 + + + Convert to WAV + - 174, 70 + 181, 114 contextMenuStrip2 @@ -558,32 +590,6 @@ 6 - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vAAADrwBlbxySQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAABSSURBVDhP5c0x - DsAgDENRxt7/wmkNSpRGf0CCCZAegxNMM7MlGMp3dIU6dxhKf/QMNxRogeQC8ivw5Vn7C0heJlFA+kL5 - jWAohxRkde4wnGftBS90axNmphIGAAAAAElFTkSuQmCC - - - - 173, 22 - - - Add Entry - - - 173, 22 - - - Remove Entry - - - 173, 22 - - - Verify File Location - True @@ -791,6 +797,12 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + convertToWAVToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + AudioEditor