project and solution generation

This commit is contained in:
max 2024-07-21 22:31:04 +02:00
parent 36a134170a
commit 546b7feca7
3 changed files with 20 additions and 4 deletions

View File

@ -29,6 +29,8 @@ public static bool Create(string projectFilePath, string name, out CSProject pro
Guid = System.Guid.NewGuid().ToString("B").ToUpper(), Guid = System.Guid.NewGuid().ToString("B").ToUpper(),
}; };
Save(project, projectFilePath);
return true; return true;
} }

View File

@ -89,7 +89,7 @@ public static bool Compile(string projectFilePath, string configuration = "Debug
public static void GenerateSolution(string projectPath, Project project, out string solutionPath) public static void GenerateSolution(string projectPath, Project project, out string solutionPath)
{ {
// Clear files. // Clear files.
string[] csProjectFiles = Directory.GetFiles(projectPath, CSProjFileName, SearchOption.TopDirectoryOnly); string[] csProjectFiles = Directory.GetFiles(projectPath, $"*{CSProjFileName}", SearchOption.TopDirectoryOnly);
foreach (string csProjFile in csProjectFiles) foreach (string csProjFile in csProjectFiles)
{ {
File.Delete(csProjFile); File.Delete(csProjFile);
@ -103,7 +103,7 @@ public static void GenerateSolution(string projectPath, Project project, out str
} }
// Generate solution. // Generate solution.
string[] csProjPaths = Directory.GetFiles(projectPath, CSProjFileName, SearchOption.TopDirectoryOnly); string[] csProjPaths = Directory.GetFiles(projectPath, $"*{CSProjFileName}", SearchOption.TopDirectoryOnly);
string[] csProjGuids = new string[csProjPaths.Length]; string[] csProjGuids = new string[csProjPaths.Length];
for (int i = 0; i < csProjPaths.Length; i++) 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 csProjPath = csProjPaths[i];
string projectGuid = csProjGuids[i]; string projectGuid = csProjGuids[i];
string projectName = Path.GetFileNameWithoutExtension(csProjPath); string projectName = Path.GetFileNameWithoutExtension(csProjPath);
string projectRelativePath = Path.GetRelativePath(projectPath, csProjPath);
// FAE04EC0-301F-11D3-BF4B-00C04F79EFBC for C# projects. // 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"); solutionContent.AppendLine("EndProject");
} }
@ -223,7 +224,7 @@ private static void GenerateCSProject(string csProjectFilePath, string projectPa
projectContent.AppendLine("</Project>"); projectContent.AppendLine("</Project>");
string projectName = csProject.Name + ".Runtime.csproj"; string projectName = csProject.Name + ".csproj";
string filePath = Path.Combine(projectPath, projectName); string filePath = Path.Combine(projectPath, projectName);
File.WriteAllText(filePath, projectContent.ToString()); File.WriteAllText(filePath, projectContent.ToString());
} }

View File

@ -38,6 +38,12 @@ internal static bool Open(string path)
Project = project; Project = project;
ProjectFilePath = path; ProjectFilePath = path;
ProjectPath = Path.GetDirectoryName(path); ProjectPath = Path.GetDirectoryName(path);
string projectSolutionFilePath = Path.Combine(ProjectPath, Project.Name + ".sln");
if (File.Exists(projectSolutionFilePath))
{
ProjectSolutionFilePath = projectSolutionFilePath;
}
SetupDefaultFolders(); SetupDefaultFolders();
Compile(); Compile();
@ -112,6 +118,13 @@ private static void SetupDefaultFolders()
Directory.CreateDirectory(scriptsRuntimePath); 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"); string tempPath = Path.Combine(ProjectPath, "Temp");
if (!Directory.Exists(tempPath)) if (!Directory.Exists(tempPath))
{ {