diff --git a/FriishProduce/MainForm.cs b/FriishProduce/MainForm.cs index 83c006e..a665865 100644 --- a/FriishProduce/MainForm.cs +++ b/FriishProduce/MainForm.cs @@ -524,6 +524,66 @@ private void OpenProject_Click(object sender, EventArgs e) } } + public bool CleanupRecent() + { + const int max = 10; + bool modified = false; + + // Clean missing projects if there are any + // ******** + for (int x = 0; x < max; x++) + { + var prop = Program.Config.paths.GetType().GetProperty($"recent_{x:D2}"); + var path = prop.GetValue(Program.Config.paths, null)?.ToString(); + + if (path != null && !File.Exists(path)) + { + prop.SetValue(Program.Config.paths, null); + modified = true; + } + } + + // Clean duplicate projects if there are any + // ******** + for (int x = 0; x < max; x++) + { + var prop1 = Program.Config.paths.GetType().GetProperty($"recent_{x:D2}"); + var path1 = prop1.GetValue(Program.Config.paths, null)?.ToString(); + + for (int y = x; y < max; y++) + { + var prop2 = Program.Config.paths.GetType().GetProperty($"recent_{y:D2}"); + var path2 = prop2.GetValue(Program.Config.paths, null)?.ToString(); + + if (path1 == path2 && path2 != null && x != y) + { + prop2.SetValue(Program.Config.paths, null); + modified = true; + } + } + } + + // Resort slots in case of empty ones + // ******** + for (int i = 0; i < max - 1; i++) + { + var prop1 = Program.Config.paths.GetType().GetProperty($"recent_{i:D2}"); + + if (prop1.GetValue(Program.Config.paths, null)?.ToString() == null) + { + var prop2 = Program.Config.paths.GetType().GetProperty($"recent_{i + 1:D2}"); + + prop1.SetValue(Program.Config.paths, prop2.GetValue(Program.Config.paths, null)); + prop2.SetValue(Program.Config.paths, null); + + modified = true; + } + } + + if (modified) Program.Config.Save(); + return modified; + } + public void RefreshRecent() { open_recent.MenuItems.Clear(); @@ -594,22 +654,32 @@ private void OpenProject(string[] files) { foreach (var file in files) { - var project = new Project(); + if (!File.Exists(file)) + { + MessageBox.Show(string.Format(Program.Lang.Msg(11, 1), Path.GetFileName(file))); + if (CleanupRecent()) + RefreshRecent(); + } - try + else { - using Stream stream = File.Open(file, FileMode.Open); - var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); - project = (Project)binaryFormatter.Deserialize(stream); + var project = new Project(); - if (project.ProjectPath != file) project.ProjectPath = file; + try + { + using Stream stream = File.Open(file, FileMode.Open); + var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); + project = (Project)binaryFormatter.Deserialize(stream); - addTab(project.Platform, project); - } + if (project.ProjectPath != file) project.ProjectPath = file; - catch - { - MessageBox.Show(string.Format(Program.Lang.Msg(17, 1), Path.GetFileName(file)), MessageBox.Buttons.Ok, MessageBox.Icons.Error); + addTab(project.Platform, project); + } + + catch + { + MessageBox.Show(string.Format(Program.Lang.Msg(17, 1), Path.GetFileName(file)), MessageBox.Buttons.Ok, MessageBox.Icons.Error); + } } } } diff --git a/FriishProduce/ProjectForm.cs b/FriishProduce/ProjectForm.cs index a5b78e8..bbbe58d 100644 --- a/FriishProduce/ProjectForm.cs +++ b/FriishProduce/ProjectForm.cs @@ -354,51 +354,13 @@ private void SetRecentProjects(string project) } Program.Config.paths.recent_00 = project; - modified = true; - } - - // Clean duplicate projects if there are any - // ******** - for (int x = 0; x < max; x++) - { - var prop1 = Program.Config.paths.GetType().GetProperty($"recent_{x:D2}"); - var path1 = prop1.GetValue(Program.Config.paths, null)?.ToString(); - - for (int y = x; y < max; y++) - { - var prop2 = Program.Config.paths.GetType().GetProperty($"recent_{y:D2}"); - var path2 = prop2.GetValue(Program.Config.paths, null)?.ToString(); - - if (path1 == path2 && path2 != null && x != y) - { - prop2.SetValue(Program.Config.paths, null); - modified = true; - } - } - } - - // Resort slots in case of empty ones - // ******** - for (int i = 0; i < max - 1; i++) - { - var prop1 = Program.Config.paths.GetType().GetProperty($"recent_{i:D2}"); - - if (prop1.GetValue(Program.Config.paths, null)?.ToString() == null) - { - var prop2 = Program.Config.paths.GetType().GetProperty($"recent_{i + 1:D2}"); - - prop1.SetValue(Program.Config.paths, prop2.GetValue(Program.Config.paths, null)); - prop2.SetValue(Program.Config.paths, null); + Program.Config.Save(); - modified = true; - } + modified = true; } - if (modified) - { - Program.Config.Save(); + if (Program.MainForm.CleanupRecent() || modified) Program.MainForm.RefreshRecent(); - } } public void SaveProject(string path)