From 546b7feca7e52dbd64439d9498ba1df830b71965 Mon Sep 17 00:00:00 2001 From: max Date: Sun, 21 Jul 2024 22:31:04 +0200 Subject: [PATCH] project and solution generation --- Nerfed.Compiler/CSProject.cs | 2 ++ Nerfed.Compiler/Compiler.cs | 9 +++++---- Nerfed.Editor/Project/Project.cs | 13 +++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Nerfed.Compiler/CSProject.cs b/Nerfed.Compiler/CSProject.cs index 9e58acd..1e047c7 100644 --- a/Nerfed.Compiler/CSProject.cs +++ b/Nerfed.Compiler/CSProject.cs @@ -29,6 +29,8 @@ public static bool Create(string projectFilePath, string name, out CSProject pro Guid = System.Guid.NewGuid().ToString("B").ToUpper(), }; + Save(project, projectFilePath); + return true; } diff --git a/Nerfed.Compiler/Compiler.cs b/Nerfed.Compiler/Compiler.cs index aeaf91d..86c3756 100644 --- a/Nerfed.Compiler/Compiler.cs +++ b/Nerfed.Compiler/Compiler.cs @@ -89,7 +89,7 @@ public static bool Compile(string projectFilePath, string configuration = "Debug public static void GenerateSolution(string projectPath, Project project, out string solutionPath) { // Clear files. - string[] csProjectFiles = Directory.GetFiles(projectPath, CSProjFileName, SearchOption.TopDirectoryOnly); + string[] csProjectFiles = Directory.GetFiles(projectPath, $"*{CSProjFileName}", SearchOption.TopDirectoryOnly); foreach (string csProjFile in csProjectFiles) { File.Delete(csProjFile); @@ -103,7 +103,7 @@ public static void GenerateSolution(string projectPath, Project project, out str } // Generate solution. - string[] csProjPaths = Directory.GetFiles(projectPath, CSProjFileName, SearchOption.TopDirectoryOnly); + string[] csProjPaths = Directory.GetFiles(projectPath, $"*{CSProjFileName}", SearchOption.TopDirectoryOnly); string[] csProjGuids = new string[csProjPaths.Length]; for (int i = 0; i < csProjPaths.Length; i++) { @@ -124,8 +124,9 @@ public static void GenerateSolution(string projectPath, Project project, out str string csProjPath = csProjPaths[i]; string projectGuid = csProjGuids[i]; string projectName = Path.GetFileNameWithoutExtension(csProjPath); + string projectRelativePath = Path.GetRelativePath(projectPath, csProjPath); // FAE04EC0-301F-11D3-BF4B-00C04F79EFBC for C# projects. - solutionContent.AppendLine($"Project(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"{projectName}\", \"{csProjPath}\", \"{projectGuid}\""); + solutionContent.AppendLine($"Project(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"{projectName}\", \"{projectRelativePath}\", \"{projectGuid}\""); solutionContent.AppendLine("EndProject"); } @@ -223,7 +224,7 @@ private static void GenerateCSProject(string csProjectFilePath, string projectPa projectContent.AppendLine(""); - string projectName = csProject.Name + ".Runtime.csproj"; + string projectName = csProject.Name + ".csproj"; string filePath = Path.Combine(projectPath, projectName); File.WriteAllText(filePath, projectContent.ToString()); } diff --git a/Nerfed.Editor/Project/Project.cs b/Nerfed.Editor/Project/Project.cs index 395143b..d57f1f6 100644 --- a/Nerfed.Editor/Project/Project.cs +++ b/Nerfed.Editor/Project/Project.cs @@ -38,6 +38,12 @@ internal static bool Open(string path) Project = project; ProjectFilePath = path; ProjectPath = Path.GetDirectoryName(path); + + string projectSolutionFilePath = Path.Combine(ProjectPath, Project.Name + ".sln"); + if (File.Exists(projectSolutionFilePath)) + { + ProjectSolutionFilePath = projectSolutionFilePath; + } SetupDefaultFolders(); Compile(); @@ -112,6 +118,13 @@ private static void SetupDefaultFolders() Directory.CreateDirectory(scriptsRuntimePath); } + // Test create csproject. + string gameplayRuntimePath = Path.Combine(scriptsRuntimePath, ".csproject"); + if (!File.Exists(gameplayRuntimePath)) + { + Compiler.CSProject.Create(gameplayRuntimePath, "Gameplay", out Compiler.CSProject project); + } + string tempPath = Path.Combine(ProjectPath, "Temp"); if (!Directory.Exists(tempPath)) {