Nerfed/Nerfed.Compiler/CSProject.cs

64 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(),
};
Save(project, projectFilePath);
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
{
}