From b38f584e8097fa191c0107191c0fc58705d6688d Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 4 Jun 2023 18:26:57 +0200 Subject: [PATCH] MainForm - Allowed only one PCK Manager at a time and added BinkaConverter.cs --- PCK-Studio/Classes/Utils/BinkaConverter.cs | 38 ++++++++++++++++ PCK-Studio/MainForm.cs | 53 ++++++++++------------ PCK-Studio/PckStudio.csproj | 1 + Vendor/OMI-Lib | 2 +- 4 files changed, 63 insertions(+), 31 deletions(-) create mode 100644 PCK-Studio/Classes/Utils/BinkaConverter.cs diff --git a/PCK-Studio/Classes/Utils/BinkaConverter.cs b/PCK-Studio/Classes/Utils/BinkaConverter.cs new file mode 100644 index 00000000..176d4b30 --- /dev/null +++ b/PCK-Studio/Classes/Utils/BinkaConverter.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PckStudio.API.Miles; +using PckStudio.Forms.Additional_Popups; +using System.Windows.Forms; +using System.IO; + +namespace PckStudio.Classes.Utils +{ + internal static class BinkaConverter + { + + public static void ToWav(Stream source, Stream destination) + { + throw new NotImplementedException(); + } + + public static void ToWav(string[] filenames, DirectoryInfo destination) + { + int convertedCount = 0; + InProgressPrompt waitDiag = new InProgressPrompt(); + waitDiag.Show(); + foreach (string file in filenames) + { + Binka.ToWav(file, Path.Combine(destination.FullName, Path.GetFileNameWithoutExtension(file) + ".binka")); + convertedCount++; + } + + waitDiag.Close(); + waitDiag.Dispose(); + MessageBox.Show($"Successfully converted {convertedCount}/{filenames.Length} file{(filenames.Length != 1 ? "s" : "")}", "Done!"); + } + + } +} diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 43b836fb..af50539d 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -31,11 +31,13 @@ using PckStudio.Features; using PckStudio.Extensions; using PckStudio.Popups; using PckStudio.API.Miles; +using PckStudio.Classes.Utils; namespace PckStudio { public partial class MainForm : MetroFramework.Forms.MetroForm { + private PckManager PckManager = null; string saveLocation = string.Empty; PckFile currentPCK = null; bool wasModified = false; @@ -84,7 +86,7 @@ namespace PckStudio labelVersion.Text += $" (Debug build: {CommitInfo.BranchName}@{CommitInfo.CommitHash})"; #endif - pckFileTypeHandler = new Dictionary>(15) + pckFileTypeHandler = new Dictionary>(15) { [PckFile.FileData.FileType.SkinFile] = HandleSkinFile, [PckFile.FileData.FileType.CapeFile] = null, @@ -109,7 +111,7 @@ namespace PckStudio checkSaveState(); treeViewMain.Nodes.Clear(); currentPCK = openPck(filepath); - if (currentPCK == null) + if (currentPCK == null) { MessageBox.Show(string.Format("Failed to load {0}", Path.GetFileName(filepath)), "Error"); return; @@ -709,9 +711,11 @@ namespace PckStudio TrySetLocFile(locFile); } } - currentPCK.Files.Remove(file); - node.Remove(); - wasModified = true; + if (currentPCK.Files.Remove(file)) + { + node.Remove(); + wasModified = true; + } } else if (MessageBox.Show("Are you sure want to delete this folder? All contents will be deleted", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) @@ -2198,8 +2202,14 @@ namespace PckStudio private void openPckManagerToolStripMenuItem_Click(object sender, EventArgs e) { - PckManager installer = new PckManager(); - installer.Show(this); + PckManager ??= new PckManager(); + PckManager.BringToFront(); + PckManager.Focus(); + if (!PckManager.Visible) + { + PckManager.FormClosed += delegate { PckManager = null; }; + PckManager.Show(this); + } } private async void wavBinkaToolStripMenuItem_Click(object sender, EventArgs e) @@ -2216,7 +2226,7 @@ namespace PckStudio InProgressPrompt waitDiag = new InProgressPrompt(); waitDiag.Show(this); - int convertedCounter = 0; + int convertedCount = 0; foreach (string waveFilepath in fileDialog.FileNames) { string[] a = Path.GetFileNameWithoutExtension(waveFilepath).Split(Path.GetInvalidFileNameChars()); @@ -2245,44 +2255,27 @@ namespace PckStudio exitCode = Binka.FromWav(cacheSongLoc, Path.Combine(Path.GetDirectoryName(waveFilepath), Path.GetFileNameWithoutExtension(waveFilepath) + ".binka"), 4); }); - if (exitCode != 0) - continue; - - convertedCounter++; + if (exitCode == 0) + convertedCount++; } int fileCount = fileDialog.FileNames.Length; waitDiag.Close(); waitDiag.Dispose(); - MessageBox.Show(this, $"Successfully converted {convertedCounter}/{fileCount} file{(fileCount != 1 ? "s" : "")}", "Done!"); + MessageBox.Show(this, $"Successfully converted {convertedCount}/{fileCount} file{(fileCount != 1 ? "s" : "")}", "Done!"); } private void binkaWavToolStripMenuItem_Click(object sender, EventArgs e) { - int success = 0; - using OpenFileDialog fileDialog = new OpenFileDialog { Multiselect = true, Filter = "BINKA files (*.binka)|*.binka", Title = "Please choose BINKA files to convert to WAV" }; - - if (fileDialog.ShowDialog() != DialogResult.OK) - return; - - InProgressPrompt waitDiag = new InProgressPrompt(); - waitDiag.Show(this); - foreach (string file in fileDialog.FileNames) - { - Binka.ToWav(file, Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".binka")); - success++; - } - - waitDiag.Close(); - waitDiag.Dispose(); - MessageBox.Show(this, $"Successfully converted {success}/{fileDialog.FileNames.Length} file{(fileDialog.FileNames.Length != 1 ? "s" : "")}", "Done!"); + if (fileDialog.ShowDialog() == DialogResult.OK) + BinkaConverter.ToWav(fileDialog.FileNames, new DirectoryInfo(Path.GetDirectoryName(fileDialog.FileName))); } private void fullBoxSupportToolStripMenuItem_CheckedChanged(object sender, EventArgs e) diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index e890385b..c01ac9fb 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -173,6 +173,7 @@ Component + diff --git a/Vendor/OMI-Lib b/Vendor/OMI-Lib index ad926eec..cb9cad7f 160000 --- a/Vendor/OMI-Lib +++ b/Vendor/OMI-Lib @@ -1 +1 @@ -Subproject commit ad926eeca12d34189af05afc63c65d9c61d60a14 +Subproject commit cb9cad7feae326db283bf23c9476b5ffa20a3c9c