2020-07-20 13:48:12 +00:00
|
|
|
using System;
|
2017-10-02 21:24:00 +00:00
|
|
|
using Microsoft.Build.Construction;
|
|
|
|
|
2019-07-03 07:44:53 +00:00
|
|
|
namespace GodotTools.ProjectEditor
|
2017-10-02 21:24:00 +00:00
|
|
|
{
|
2020-04-22 12:39:42 +00:00
|
|
|
public sealed class MSBuildProject
|
|
|
|
{
|
2020-07-20 13:48:12 +00:00
|
|
|
internal ProjectRootElement Root { get; set; }
|
2020-04-22 12:39:42 +00:00
|
|
|
|
2020-04-23 14:12:22 +00:00
|
|
|
public bool HasUnsavedChanges { get; set; }
|
2020-04-22 12:39:42 +00:00
|
|
|
|
|
|
|
public void Save() => Root.Save();
|
|
|
|
|
|
|
|
public MSBuildProject(ProjectRootElement root)
|
|
|
|
{
|
|
|
|
Root = root;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
public static class ProjectUtils
|
|
|
|
{
|
2020-04-22 12:39:42 +00:00
|
|
|
public static MSBuildProject Open(string path)
|
|
|
|
{
|
|
|
|
var root = ProjectRootElement.Open(path);
|
|
|
|
return root != null ? new MSBuildProject(root) : null;
|
|
|
|
}
|
|
|
|
|
2020-07-20 13:48:12 +00:00
|
|
|
public static void MigrateToProjectSdksStyle(MSBuildProject project, string projectName)
|
2020-06-15 19:29:16 +00:00
|
|
|
{
|
2020-07-20 13:48:12 +00:00
|
|
|
var origRoot = project.Root;
|
2020-06-15 19:29:16 +00:00
|
|
|
|
2020-07-20 13:48:12 +00:00
|
|
|
if (!string.IsNullOrEmpty(origRoot.Sdk))
|
2020-06-15 19:29:16 +00:00
|
|
|
return;
|
|
|
|
|
2020-07-20 13:48:12 +00:00
|
|
|
project.Root = ProjectGenerator.GenGameProject(projectName);
|
|
|
|
project.Root.FullPath = origRoot.FullPath;
|
2020-06-15 19:29:16 +00:00
|
|
|
project.HasUnsavedChanges = true;
|
|
|
|
}
|
|
|
|
|
2020-07-20 13:48:12 +00:00
|
|
|
public static void EnsureGodotSdkIsUpToDate(MSBuildProject project)
|
2020-05-10 20:56:35 +00:00
|
|
|
{
|
|
|
|
var root = project.Root;
|
2020-07-20 13:48:12 +00:00
|
|
|
string godotSdkAttrValue = ProjectGenerator.GodotSdkAttrValue;
|
2020-05-10 20:56:35 +00:00
|
|
|
|
2020-07-20 13:48:12 +00:00
|
|
|
if (!string.IsNullOrEmpty(root.Sdk) && root.Sdk.Trim().Equals(godotSdkAttrValue, StringComparison.OrdinalIgnoreCase))
|
2020-05-10 20:56:35 +00:00
|
|
|
return;
|
|
|
|
|
2020-07-20 13:48:12 +00:00
|
|
|
root.Sdk = godotSdkAttrValue;
|
2020-05-10 20:56:35 +00:00
|
|
|
project.HasUnsavedChanges = true;
|
|
|
|
}
|
2017-10-02 21:24:00 +00:00
|
|
|
}
|
|
|
|
}
|