2017-10-02 21:24:00 +00:00
|
|
|
using System;
|
2018-10-22 17:20:29 +00:00
|
|
|
using DotNet.Globbing;
|
2017-10-02 21:24:00 +00:00
|
|
|
using Microsoft.Build.Construction;
|
|
|
|
|
|
|
|
namespace GodotSharpTools.Project
|
|
|
|
{
|
|
|
|
public static class ProjectExtensions
|
|
|
|
{
|
|
|
|
public static bool HasItem(this ProjectRootElement root, string itemType, string include)
|
|
|
|
{
|
2018-10-22 17:20:29 +00:00
|
|
|
GlobOptions globOptions = new GlobOptions();
|
|
|
|
globOptions.Evaluation.CaseInsensitive = false;
|
|
|
|
|
|
|
|
string normalizedInclude = include.NormalizePath();
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
foreach (var itemGroup in root.ItemGroups)
|
|
|
|
{
|
|
|
|
if (itemGroup.Condition.Length != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
foreach (var item in itemGroup.Items)
|
|
|
|
{
|
2018-10-22 17:20:29 +00:00
|
|
|
if (item.ItemType != itemType)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
var glob = Glob.Parse(item.Include.NormalizePath(), globOptions);
|
|
|
|
|
|
|
|
if (glob.IsMatch(normalizedInclude))
|
2017-10-02 21:24:00 +00:00
|
|
|
{
|
2018-10-22 17:20:29 +00:00
|
|
|
return true;
|
2017-10-02 21:24:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-04 22:10:51 +00:00
|
|
|
public static bool AddItemChecked(this ProjectRootElement root, string itemType, string include)
|
2017-10-02 21:24:00 +00:00
|
|
|
{
|
|
|
|
if (!root.HasItem(itemType, include))
|
|
|
|
{
|
|
|
|
root.AddItem(itemType, include);
|
2017-10-04 22:10:51 +00:00
|
|
|
return true;
|
2017-10-02 21:24:00 +00:00
|
|
|
}
|
2017-10-04 22:10:51 +00:00
|
|
|
|
|
|
|
return false;
|
2017-10-02 21:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|