diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2019-07-05 10:29:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-05 10:29:19 +0200 |
| commit | 6e9cb44004b8bd30a5834d06671ccd1c62508bfe (patch) | |
| tree | e3086f5a8a133dc0630e6f5e4b7065e174977df3 /modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectExtensions.cs | |
| parent | a149e412f75e9eef87e8ff54e21402f90161f65b (diff) | |
| parent | 0639946c72ba6632bc3b0953d64f644af328e5e6 (diff) | |
Merge pull request #30282 from neikeq/editor_in_cs_equals_win
Re-write mono module editor code in C#
Diffstat (limited to 'modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectExtensions.cs')
| -rw-r--r-- | modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectExtensions.cs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectExtensions.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectExtensions.cs new file mode 100644 index 0000000000..36961eb45e --- /dev/null +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectExtensions.cs @@ -0,0 +1,61 @@ +using GodotTools.Core; +using System; +using DotNet.Globbing; +using Microsoft.Build.Construction; + +namespace GodotTools.ProjectEditor +{ + public static class ProjectExtensions + { + public static bool HasItem(this ProjectRootElement root, string itemType, string include) + { + GlobOptions globOptions = new GlobOptions(); + globOptions.Evaluation.CaseInsensitive = false; + + string normalizedInclude = include.NormalizePath(); + + foreach (var itemGroup in root.ItemGroups) + { + if (itemGroup.Condition.Length != 0) + continue; + + foreach (var item in itemGroup.Items) + { + if (item.ItemType != itemType) + continue; + + var glob = Glob.Parse(item.Include.NormalizePath(), globOptions); + + if (glob.IsMatch(normalizedInclude)) + { + return true; + } + } + } + + return false; + } + + public static bool AddItemChecked(this ProjectRootElement root, string itemType, string include) + { + if (!root.HasItem(itemType, include)) + { + root.AddItem(itemType, include); + return true; + } + + return false; + } + + public static Guid GetGuid(this ProjectRootElement root) + { + foreach (var property in root.Properties) + { + if (property.Name == "ProjectGuid") + return Guid.Parse(property.Value); + } + + return Guid.Empty; + } + } +} |