From 6c2047f6c0eb4a330c19911bef3cd7f026f10284 Mon Sep 17 00:00:00 2001 From: MattN-L Date: Sat, 30 Mar 2024 13:31:52 -0400 Subject: [PATCH] Fix exception when moving skin under or below a folder --- PCK-Studio/Classes/IO/TGA/TGAExtentionData.cs | 2 +- PCK-Studio/MainForm.cs | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/PCK-Studio/Classes/IO/TGA/TGAExtentionData.cs b/PCK-Studio/Classes/IO/TGA/TGAExtentionData.cs index 55485144..3f5d6e45 100644 --- a/PCK-Studio/Classes/IO/TGA/TGAExtentionData.cs +++ b/PCK-Studio/Classes/IO/TGA/TGAExtentionData.cs @@ -49,7 +49,7 @@ namespace PckStudio.IO.TGA extensionData.JobTime = new TimeSpan(extensionData.TimeStamp.Hour, extensionData.TimeStamp.Minute, extensionData.TimeStamp.Second); extensionData.SoftwareID = Application.ProductName; Version.TryParse(Application.ProductVersion, out Version currentVersion); - extensionData.SoftwareVersion = [(byte)currentVersion.Major, (byte)currentVersion.Minor, (byte)currentVersion.Build]; + extensionData.SoftwareVersion = new byte[] { (byte)currentVersion.Major, (byte)currentVersion.Minor, (byte)currentVersion.Build }; extensionData.KeyColor = 0; extensionData.PixelAspectRatio = 0; extensionData.GammaValue = 0; diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 0e3430ab..a5d18cf3 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -2276,21 +2276,28 @@ namespace PckStudio int index = pck.IndexOfFile(file); - if (index + amount < 0 || index + amount > pck.FileCount) return; - pck.RemoveFile(file); - pck.InsertFile(index + amount, file); + try + { + if (index + amount < 0 || index + amount > pck.FileCount) return; + pck.RemoveFile(file); + pck.InsertFile(index + amount, file); - if (IsSubPCK) - { - using (var stream = new MemoryStream()) + if (IsSubPCK) { - var writer = new PckFileWriter(pck, LittleEndianCheckBox.Checked ? OMI.Endianness.LittleEndian : OMI.Endianness.BigEndian); - writer.WriteToStream(stream); - (GetSubPCK(path).Tag as PckFileData).SetData(stream.ToArray()); + using (var stream = new MemoryStream()) + { + var writer = new PckFileWriter(pck, LittleEndianCheckBox.Checked ? OMI.Endianness.LittleEndian : OMI.Endianness.BigEndian); + writer.WriteToStream(stream); + (GetSubPCK(path).Tag as PckFileData).SetData(stream.ToArray()); + } } + BuildMainTreeView(); + wasModified = true; } - BuildMainTreeView(); - wasModified = true; + catch(Exception ex) + { + MessageBox.Show("Can't move file under or above a folder"); + } } [Obsolete] private void moveUpToolStripMenuItem_Click(object sender, EventArgs e) => moveFile(-1);