From 3f8d80135cae06f00165e8c115f6e2a150ebc74b Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Tue, 6 Dec 2022 17:28:54 +0100 Subject: [PATCH] Update `InitializeTexturePack` to use MemoryStream with the using keyword --- PCK-Studio/MainForm.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 333348b9..61bee24d 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -1249,27 +1249,27 @@ namespace PckStudio PCKFile infoPCK = new PCKFile(3); - var ms = new MemoryStream(); - var ms2 = new MemoryStream(); - var ms3 = new MemoryStream(); + using (var ms = new MemoryStream()) + { + var icon = new PCKFile.FileData("icon.png", PCKFile.FileData.FileType.TextureFile); + Resources.TexturePackIcon.Save(ms, ImageFormat.Png); + icon.SetData(ms.ToArray()); + infoPCK.Files.Add(icon); + } + using (var ms = new MemoryStream()) + { var comparison = new PCKFile.FileData("comparison.png", PCKFile.FileData.FileType.TextureFile); Resources.Comparison.Save(ms, ImageFormat.Png); comparison.SetData(ms.ToArray()); - - var icon = new PCKFile.FileData("icon.png", PCKFile.FileData.FileType.TextureFile); - Resources.TexturePackIcon.Save(ms2, ImageFormat.Png); - icon.SetData(ms2.ToArray()); - - infoPCK.Files.Add(icon); infoPCK.Files.Add(comparison); + } - PCKFileWriter.Write(ms3, infoPCK, LittleEndianCheckBox.Checked); - texturepackInfo.SetData(ms3.ToArray()); - - ms.Dispose(); - ms2.Dispose(); - ms3.Dispose(); + using (var ms = new MemoryStream()) + { + PCKFileWriter.Write(ms, infoPCK, LittleEndianCheckBox.Checked); + texturepackInfo.SetData(ms.ToArray()); + } currentPCK.Files.Add(texturepackInfo); }