From 3cb6097d14d1fca836398db2dc3bebbbeb4b997c Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sat, 23 Mar 2024 18:32:46 +0100 Subject: [PATCH] MainForm - Fix importing file that already exists --- PCK-Studio/MainForm.cs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 7b2ebeac..d8fb5d75 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -1949,6 +1949,7 @@ namespace PckStudio } } + [Obsolete()] private void addTextureToolStripMenuItem_Click(object sender, EventArgs e) { using OpenFileDialog fileDialog = new OpenFileDialog(); @@ -1959,8 +1960,12 @@ namespace PckStudio renamePrompt.LabelText = "Path"; if (renamePrompt.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(renamePrompt.NewText)) { - var file = currentPCK.CreateNewFile(renamePrompt.NewText, PckFileType.TextureFile); - file.SetData(File.ReadAllBytes(fileDialog.FileName)); + if (currentPCK.Contains(renamePrompt.NewText, PckFileType.TextureFile)) + { + MessageBox.Show($"'{renamePrompt.NewText}' already exists.", "Import failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + var file = currentPCK.CreateNewFile(renamePrompt.NewText, PckFileType.TextureFile, () => File.ReadAllBytes(fileDialog.FileName)); BuildMainTreeView(); wasModified = true; } @@ -2160,7 +2165,8 @@ namespace PckStudio private void addFileToolStripMenuItem_Click(object sender, EventArgs e) { using var ofd = new OpenFileDialog(); - // Suddenly, and randomly, this started throwing an exception because it wasn't formatted correctly? So now it's formatted correctly and now displays the file type name in the dialog. + // Suddenly, and randomly, this started throwing an exception because it wasn't formatted correctly? + // So now it's formatted correctly and now displays the file type name in the dialog. ofd.Filter = "All files (*.*)|*.*"; ofd.Multiselect = false; @@ -2169,13 +2175,14 @@ namespace PckStudio using AddFilePrompt diag = new AddFilePrompt("res/" + Path.GetFileName(ofd.FileName)); if (diag.ShowDialog(this) == DialogResult.OK) { - PckFileData file = currentPCK.CreateNewFile( - diag.Filepath, - diag.Filetype, - () => File.ReadAllBytes(ofd.FileName)); + if (currentPCK.Contains(diag.Filepath, diag.Filetype)) + { + MessageBox.Show($"'{diag.Filepath}' of type {diag.Filetype} already exists.", "Import failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + PckFileData file = currentPCK.CreateNewFile(diag.Filepath, diag.Filetype, () => File.ReadAllBytes(ofd.FileName)); RebuildSubPCK(treeViewMain.SelectedNode.FullPath); - //else treeViewMain.Nodes.Add(); BuildMainTreeView(); wasModified = true;