From cf98ff248afe3b521fa389885565a9fdca850741 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Mon, 20 Dec 2021 16:49:16 +0100 Subject: [PATCH] Check a csproj exists before trying to edit it When folders are moved/removed from the file system, the `.csproj` may need to be edited to update the path of C# scripts or remove them. If a C# solution has not been created, the `.csproj` file does not exist and therefore there is no need to edit it. --- .../GodotTools/GodotTools/GodotSharpEditor.cs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs index f49108a9f7f..852855c3bb0 100644 --- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs +++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs @@ -75,7 +75,7 @@ namespace GodotTools { Guid = guid, PathRelativeToSolution = name + ".csproj", - Configs = new List {"Debug", "ExportDebug", "ExportRelease"} + Configs = new List { "Debug", "ExportDebug", "ExportRelease" } }; solution.AddNewProject(name, projectInfo); @@ -164,20 +164,28 @@ namespace GodotTools private void _FileSystemDockFileRemoved(string file) { if (Path.GetExtension(file) == Internal.CSharpLanguageExtension) + { ProjectUtils.RemoveItemFromProjectChecked(GodotSharpDirs.ProjectCsProjPath, "Compile", ProjectSettings.GlobalizePath(file)); + } } private void _FileSystemDockFolderMoved(string oldFolder, string newFolder) { - ProjectUtils.RenameItemsToNewFolderInProjectChecked(GodotSharpDirs.ProjectCsProjPath, "Compile", - ProjectSettings.GlobalizePath(oldFolder), ProjectSettings.GlobalizePath(newFolder)); + if (File.Exists(GodotSharpDirs.ProjectCsProjPath)) + { + ProjectUtils.RenameItemsToNewFolderInProjectChecked(GodotSharpDirs.ProjectCsProjPath, "Compile", + ProjectSettings.GlobalizePath(oldFolder), ProjectSettings.GlobalizePath(newFolder)); + } } private void _FileSystemDockFolderRemoved(string oldFolder) { - ProjectUtils.RemoveItemsInFolderFromProjectChecked(GodotSharpDirs.ProjectCsProjPath, "Compile", - ProjectSettings.GlobalizePath(oldFolder)); + if (File.Exists(GodotSharpDirs.ProjectCsProjPath)) + { + ProjectUtils.RemoveItemsInFolderFromProjectChecked(GodotSharpDirs.ProjectCsProjPath, "Compile", + ProjectSettings.GlobalizePath(oldFolder)); + } } public override void _Ready() @@ -431,7 +439,7 @@ namespace GodotTools MSBuildPanel = new MSBuildPanel(); _bottomPanelBtn = AddControlToBottomPanel(MSBuildPanel, "MSBuild".TTR()); - AddChild(new HotReloadAssemblyWatcher {Name = "HotReloadAssemblyWatcher"}); + AddChild(new HotReloadAssemblyWatcher { Name = "HotReloadAssemblyWatcher" }); _menuPopup = new PopupMenu(); _menuPopup.Hide();