1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Some more C# formatting

This commit is contained in:
Aaron Franke
2021-07-25 00:16:59 -04:00
parent b73e7623c8
commit 1933df0013
50 changed files with 874 additions and 821 deletions

View File

@@ -9,95 +9,7 @@ namespace GodotTools.ProjectEditor
{
public class DotNetSolution
{
private string directoryPath;
private readonly Dictionary<string, ProjectInfo> projects = new Dictionary<string, ProjectInfo>();
public string Name { get; }
public string DirectoryPath
{
get => directoryPath;
set => directoryPath = value.IsAbsolutePath() ? value : Path.GetFullPath(value);
}
public class ProjectInfo
{
public string Guid;
public string PathRelativeToSolution;
public List<string> Configs = new List<string>();
}
public void AddNewProject(string name, ProjectInfo projectInfo)
{
projects[name] = projectInfo;
}
public bool HasProject(string name)
{
return projects.ContainsKey(name);
}
public ProjectInfo GetProjectInfo(string name)
{
return projects[name];
}
public bool RemoveProject(string name)
{
return projects.Remove(name);
}
public void Save()
{
if (!Directory.Exists(DirectoryPath))
throw new FileNotFoundException("The solution directory does not exist.");
string projectsDecl = string.Empty;
string slnPlatformsCfg = string.Empty;
string projPlatformsCfg = string.Empty;
bool isFirstProject = true;
foreach (var pair in projects)
{
string name = pair.Key;
ProjectInfo projectInfo = pair.Value;
if (!isFirstProject)
projectsDecl += "\n";
projectsDecl += string.Format(ProjectDeclaration,
name, projectInfo.PathRelativeToSolution.Replace("/", "\\"), projectInfo.Guid);
for (int i = 0; i < projectInfo.Configs.Count; i++)
{
string config = projectInfo.Configs[i];
if (i != 0 || !isFirstProject)
{
slnPlatformsCfg += "\n";
projPlatformsCfg += "\n";
}
slnPlatformsCfg += string.Format(SolutionPlatformsConfig, config);
projPlatformsCfg += string.Format(ProjectPlatformsConfig, projectInfo.Guid, config);
}
isFirstProject = false;
}
string solutionPath = Path.Combine(DirectoryPath, Name + ".sln");
string content = string.Format(SolutionTemplate, projectsDecl, slnPlatformsCfg, projPlatformsCfg);
File.WriteAllText(solutionPath, content, Encoding.UTF8); // UTF-8 with BOM
}
public DotNetSolution(string name)
{
Name = name;
}
const string SolutionTemplate =
private const string _solutionTemplate =
@"Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
{0}
@@ -111,23 +23,111 @@ Global
EndGlobal
";
const string ProjectDeclaration =
private const string _projectDeclaration =
@"Project(""{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}"") = ""{0}"", ""{1}"", ""{{{2}}}""
EndProject";
const string SolutionPlatformsConfig =
private const string _solutionPlatformsConfig =
@" {0}|Any CPU = {0}|Any CPU";
const string ProjectPlatformsConfig =
private const string _projectPlatformsConfig =
@" {{{0}}}.{1}|Any CPU.ActiveCfg = {1}|Any CPU
{{{0}}}.{1}|Any CPU.Build.0 = {1}|Any CPU";
private string _directoryPath;
private readonly Dictionary<string, ProjectInfo> _projects = new Dictionary<string, ProjectInfo>();
public string Name { get; }
public string DirectoryPath
{
get => _directoryPath;
set => _directoryPath = value.IsAbsolutePath() ? value : Path.GetFullPath(value);
}
public class ProjectInfo
{
public string Guid;
public string PathRelativeToSolution;
public List<string> Configs = new List<string>();
}
public void AddNewProject(string name, ProjectInfo projectInfo)
{
_projects[name] = projectInfo;
}
public bool HasProject(string name)
{
return _projects.ContainsKey(name);
}
public ProjectInfo GetProjectInfo(string name)
{
return _projects[name];
}
public bool RemoveProject(string name)
{
return _projects.Remove(name);
}
public void Save()
{
if (!Directory.Exists(DirectoryPath))
throw new FileNotFoundException("The solution directory does not exist.");
string projectsDecl = string.Empty;
string slnPlatformsCfg = string.Empty;
string projPlatformsCfg = string.Empty;
bool isFirstProject = true;
foreach (var pair in _projects)
{
string name = pair.Key;
ProjectInfo projectInfo = pair.Value;
if (!isFirstProject)
projectsDecl += "\n";
projectsDecl += string.Format(_projectDeclaration,
name, projectInfo.PathRelativeToSolution.Replace("/", "\\"), projectInfo.Guid);
for (int i = 0; i < projectInfo.Configs.Count; i++)
{
string config = projectInfo.Configs[i];
if (i != 0 || !isFirstProject)
{
slnPlatformsCfg += "\n";
projPlatformsCfg += "\n";
}
slnPlatformsCfg += string.Format(_solutionPlatformsConfig, config);
projPlatformsCfg += string.Format(_projectPlatformsConfig, projectInfo.Guid, config);
}
isFirstProject = false;
}
string solutionPath = Path.Combine(DirectoryPath, Name + ".sln");
string content = string.Format(_solutionTemplate, projectsDecl, slnPlatformsCfg, projPlatformsCfg);
File.WriteAllText(solutionPath, content, Encoding.UTF8); // UTF-8 with BOM
}
public DotNetSolution(string name)
{
Name = name;
}
public static void MigrateFromOldConfigNames(string slnPath)
{
if (!File.Exists(slnPath))
return;
var input = File.ReadAllText(slnPath);
string input = File.ReadAllText(slnPath);
if (!Regex.IsMatch(input, Regex.Escape("Tools|Any CPU")))
return;
@@ -151,7 +151,7 @@ EndProject";
};
var regex = new Regex(string.Join("|", dict.Keys.Select(Regex.Escape)));
var result = regex.Replace(input, m => dict[m.Value]);
string result = regex.Replace(input, m => dict[m.Value]);
if (result != input)
{