From cf33a1e37f8503e4c5575b33e93a72384107a61d Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Wed, 12 Feb 2025 08:07:06 +0100 Subject: [PATCH] MainForm - Check if recent opened file exists --- PCK-Studio/MainForm.cs | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 04bd0b1f..bb3d0717 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -72,6 +72,16 @@ namespace PckStudio { InitializeComponent(); + Text = Application.ProductName; + + labelVersion.Text = $"{Application.ProductName}: {ApplicationScope.CurrentVersion}"; + + ChangelogRichTextBox.Text = Resources.CHANGELOG; + + pckOpen.AllowDrop = true; + + treeViewMain.TreeViewNodeSorter = new PckNodeSorter(); + skinToolStripMenuItem1.Click += (sender, e) => SetFileType(PckAssetType.SkinFile); capeToolStripMenuItem.Click += (sender, e) => SetFileType(PckAssetType.CapeFile); textureToolStripMenuItem.Click += (sender, e) => SetFileType(PckAssetType.TextureFile); @@ -85,14 +95,6 @@ namespace PckStudio behavioursFileBINToolStripMenuItem.Click += (sender, e) => SetFileType(PckAssetType.BehavioursFile); entityMaterialsFileBINToolStripMenuItem.Click += (sender, e) => SetFileType(PckAssetType.MaterialFile); - treeViewMain.TreeViewNodeSorter = new PckNodeSorter(); - - pckOpen.AllowDrop = true; - - Text = Application.ProductName; - - labelVersion.Text = $"{Application.ProductName}: {ApplicationScope.CurrentVersion}"; - ChangelogRichTextBox.Text = Resources.CHANGELOG; pckFileTypeHandler = new Dictionary>(15) { @@ -211,19 +213,36 @@ namespace PckStudio for (int i = 0; i < Settings.Default.RecentFiles.Count && i < 5; i++) { string filepath = Settings.Default.RecentFiles[i]; - if (!string.IsNullOrWhiteSpace(filepath)) + if (!string.IsNullOrWhiteSpace(filepath) && File.Exists(filepath)) { string displayFilepath = Regex.Replace(filepath, @"([A-Z]{1}\:\\[Uu]sers\\)([^\\]*\\)(.*)", "~\\$3"); ToolStripItem item = recentlyOpenToolStripMenuItem.DropDownItems.Add(displayFilepath, null, HandleOpenFile); item.Tag = filepath; } } + if (recentlyOpenToolStripMenuItem.DropDownItems.Count > 0) + { + void clearRecentFileList(object sender, EventArgs e) + { + Settings.Default.RecentFiles.Clear(); + LoadRecentFileList(); + } + recentlyOpenToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator()); + recentlyOpenToolStripMenuItem.DropDownItems.Add("Clear", null, clearRecentFileList); + } } private void HandleOpenFile(object sender, EventArgs e) { - if (sender is ToolStripItem menuItem && menuItem.Tag is string filepath && File.Exists(filepath)) + if (sender is ToolStripItem menuItem && menuItem.Tag is string filepath) + { + if (!File.Exists(filepath)) + { + menuItem.Available = false; + return; + } LoadPckFromFile(filepath); + } } private void SaveToRecentFiles(string filepath)