From 7f88f0934402c058f9235f88079de2b5bf4283dc Mon Sep 17 00:00:00 2001 From: MattNL Date: Thu, 18 Aug 2022 16:01:23 -0400 Subject: [PATCH] crash fix when accessing owner form --- .../Forms/Editor/AudioEditor.Designer.cs | 1 + PCK-Studio/Forms/Editor/AudioEditor.cs | 22 +++--- PCK-Studio/Forms/Editor/AudioEditor.resx | 72 +++++++++---------- 3 files changed, 49 insertions(+), 46 deletions(-) diff --git a/PCK-Studio/Forms/Editor/AudioEditor.Designer.cs b/PCK-Studio/Forms/Editor/AudioEditor.Designer.cs index ddda179f..9698dabe 100644 --- a/PCK-Studio/Forms/Editor/AudioEditor.Designer.cs +++ b/PCK-Studio/Forms/Editor/AudioEditor.Designer.cs @@ -300,6 +300,7 @@ namespace PckStudio.Forms.Editor this.Theme = MetroFramework.MetroThemeStyle.Dark; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AudioEditor_FormClosing); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.AudioEditor_FormClosed); + this.Shown += new System.EventHandler(this.AudioEditor_Shown); this.contextMenuStrip1.ResumeLayout(false); this.menuStrip.ResumeLayout(false); this.menuStrip.PerformLayout(); diff --git a/PCK-Studio/Forms/Editor/AudioEditor.cs b/PCK-Studio/Forms/Editor/AudioEditor.cs index 62ec0489..c0d47720 100644 --- a/PCK-Studio/Forms/Editor/AudioEditor.cs +++ b/PCK-Studio/Forms/Editor/AudioEditor.cs @@ -21,13 +21,12 @@ namespace PckStudio.Forms.Editor { public bool saved = false; public string defaultType = "yes"; - private string DataDirectory = ""; string tempDir = ""; PCKAudioFile audioFile = null; PCKFile.FileData audioPCK; LOCFile loc; bool _isLittleEndian = false; - MainForm parent; // Parent Form + MainForm parent = null; public static readonly List Categories = new List { @@ -82,7 +81,6 @@ namespace PckStudio.Forms.Editor // so the Creative songs aren't combined until after the forms are closed. // this will prevent potential problems with editing the categories after merging. this.saveToolStripMenuItem1.Click += (sender, e) => saveToolStripMenuItem1_Click(sender, e, false); - parent = Owner.Owner as MainForm; loc = locFile; tempDir = Path.Combine(Directory.GetCurrentDirectory(), "temp"); _isLittleEndian = isLittleEndian; @@ -121,7 +119,6 @@ namespace PckStudio.Forms.Editor treeNode.Tag = category; treeView1.Nodes.Add(treeNode); } - playOverworldInCreative.Enabled = audioFile.HasCategory(PCKAudioFile.AudioCategory.EAudioType.Creative); } @@ -172,7 +169,7 @@ namespace PckStudio.Forms.Editor var entry = treeView2.SelectedNode; if (!parent.CreateDataFolder()) return; - string FileName = Path.Combine(DataDirectory, entry.Text + ".binka"); + string FileName = Path.Combine(parent.GetDataPath(), entry.Text + ".binka"); if (File.Exists(FileName)) MessageBox.Show("\"" + entry.Text + ".binka\" exists in the \"Data\" folder", "File found"); else MessageBox.Show("\"" + entry.Text + ".binka\" does not exist in the \"Data\" folder. The game will crash when attempting to load this track.", "File missing"); @@ -269,7 +266,7 @@ namespace PckStudio.Forms.Editor { if (Path.GetExtension(file) == ".binka" || Path.GetExtension(file) == ".wav") { - string new_loc = Path.Combine(DataDirectory, Path.GetFileNameWithoutExtension(file) + ".binka"); + string new_loc = Path.Combine(parent.GetDataPath(), Path.GetFileNameWithoutExtension(file) + ".binka"); bool duplicate_song = false; // To handle if a file already in the pack is dropped back in if (File.Exists(new_loc)) { @@ -316,8 +313,8 @@ namespace PckStudio.Forms.Editor else if (!duplicate_song) { Console.WriteLine(Path.GetFileName(file)); - File.Delete(Path.Combine(DataDirectory, Path.GetFileName(file))); - File.Copy(file, Path.Combine(DataDirectory, Path.GetFileName(file))); + File.Delete(Path.Combine(parent.GetDataPath(), Path.GetFileName(file))); + File.Copy(file, Path.Combine(parent.GetDataPath(), Path.GetFileName(file))); } var songName = Path.GetFileNameWithoutExtension(file); @@ -427,7 +424,7 @@ namespace PckStudio.Forms.Editor if (!parent.CreateDataFolder()) return; int totalDeleted = 0; - foreach (string song in Directory.GetFiles(DataDirectory, "*.binka")) + foreach (string song in Directory.GetFiles(parent.GetDataPath(), "*.binka")) { if (!totalSongList.Contains(Path.GetFileNameWithoutExtension(song))) { @@ -486,7 +483,12 @@ namespace PckStudio.Forms.Editor private void openDataFolderToolStripMenuItem_Click(object sender, EventArgs e) { if (!parent.CreateDataFolder()) return; - Process.Start("explorer.exe", DataDirectory); + Process.Start("explorer.exe", parent.GetDataPath()); + } + + private void AudioEditor_Shown(object sender, EventArgs e) + { + parent = this.Owner.Owner as MainForm; } } } diff --git a/PCK-Studio/Forms/Editor/AudioEditor.resx b/PCK-Studio/Forms/Editor/AudioEditor.resx index 31e897ad..4bc90331 100644 --- a/PCK-Studio/Forms/Editor/AudioEditor.resx +++ b/PCK-Studio/Forms/Editor/AudioEditor.resx @@ -410,42 +410,6 @@ False - - 37, 20 - - - File - - - 192, 22 - - - Credits Editor - - - 192, 22 - - - Delete Unused BINKAs - - - 192, 22 - - - Open Data Folder - - - 46, 20 - - - Tools - - - 44, 20 - - - Help - 20, 60 @@ -470,6 +434,12 @@ 7 + + 37, 20 + + + File + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO @@ -486,6 +456,30 @@ Save + + 46, 20 + + + Tools + + + 192, 22 + + + Credits Editor + + + 192, 22 + + + Delete Unused BINKAs + + + 44, 20 + + + Help + 245, 22 @@ -653,6 +647,12 @@ 2 + + 192, 22 + + + Open Data Folder + True