max
6e41c2579c
the idea of the compiler project is to have a tool that generates and compiles the solution + csproj files for the project. This is then used by the editor or via the command line.
62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Nerfed.Compiler;
|
|
|
|
public class CSProject
|
|
{
|
|
public string Name { get; set; }
|
|
public string Guid { get; set; }
|
|
//public bool IsEditor { get; set; }
|
|
// Add platform stuff here..?
|
|
// Add dll's here..?
|
|
// Add dependencies here..?
|
|
|
|
public static bool Create(string projectFilePath, string name, out CSProject project)
|
|
{
|
|
project = null;
|
|
|
|
if (File.Exists(projectFilePath))
|
|
{
|
|
Console.WriteLine($"ERROR: File already exists!");
|
|
return false;
|
|
}
|
|
|
|
// Create project file.
|
|
project = new CSProject
|
|
{
|
|
Name = name,
|
|
Guid = System.Guid.NewGuid().ToString("B").ToUpper(),
|
|
};
|
|
|
|
return true;
|
|
}
|
|
|
|
public static bool Save(CSProject project, string projectFilePath)
|
|
{
|
|
string jsonString = JsonSerializer.Serialize(project, CSProjectContext.Default.CSProject);
|
|
|
|
File.WriteAllText(projectFilePath, jsonString);
|
|
|
|
return true;
|
|
}
|
|
|
|
public static bool Open(string projectFilePath, out CSProject project)
|
|
{
|
|
string jsonString = File.ReadAllText(projectFilePath);
|
|
project = JsonSerializer.Deserialize(jsonString, CSProjectContext.Default.CSProject);
|
|
|
|
if (project == null)
|
|
{
|
|
Console.WriteLine($"ERROR: Could not open {typeof(CSProject)}.");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
[JsonSerializable(typeof(CSProject))]
|
|
public partial class CSProjectContext : JsonSerializerContext
|
|
{
|
|
} |