Files
BusyRabbit/Plugins/UnrealSharp/Managed/UnrealSharpPrograms/UnrealSharpBuildTool/Actions/GenerateSolution.cs
wyatt 648386cd73 Lua向C#逻辑迁移 一期 #13
将整个插件代码上传
2025-10-26 21:48:39 +08:00

48 lines
1.8 KiB
C#

namespace UnrealSharpBuildTool.Actions;
public class GenerateSolution : BuildToolAction
{
public override bool RunAction()
{
using BuildToolProcess generateSln = new BuildToolProcess();
// Create a solution.
generateSln.StartInfo.ArgumentList.Add("new");
generateSln.StartInfo.ArgumentList.Add("sln");
// Assign project name to the solution.
generateSln.StartInfo.ArgumentList.Add("-n");
generateSln.StartInfo.ArgumentList.Add(Program.GetProjectNameAsManaged());
generateSln.StartInfo.WorkingDirectory = Program.GetScriptFolder();
// Force the creation of the solution.
generateSln.StartInfo.ArgumentList.Add("--force");
generateSln.StartBuildToolProcess();
List<string> existingProjectsList = GetExistingProjects()
.Select(x => Path.GetRelativePath(Program.GetScriptFolder(), x))
.ToList();
GenerateProject.AddProjectToSln(existingProjectsList);
return true;
}
private static IEnumerable<string> GetExistingProjects()
{
var scriptsDirectory = new DirectoryInfo(Program.GetScriptFolder());
var pluginsDirectory = new DirectoryInfo(Program.GetPluginsFolder());
return FindCSharpProjects(scriptsDirectory)
.Concat(pluginsDirectory.EnumerateFiles("*.uplugin", SearchOption.AllDirectories)
.Select(x => x.Directory)
.SelectMany(x => x!.EnumerateDirectories("Script"))
.SelectMany(FindCSharpProjects))
.Select(x => x.FullName);
}
private static IEnumerable<FileInfo> FindCSharpProjects(DirectoryInfo directoryInfo)
{
IEnumerable<FileInfo> files = directoryInfo.EnumerateFiles("*.csproj", SearchOption.AllDirectories);
return files;
}
}