Rewrite into single file application start

This commit is contained in:
Booklordofthedings 2024-09-07 23:31:57 +02:00
parent fccdcb3f97
commit 71412a34fc
3 changed files with 100 additions and 2 deletions

View file

@ -1,4 +1,5 @@
FileVersion = 1
Dependencies = {corlib = "*", Bofa = "*"}
[Project]
Name = "pkkg"

View file

@ -1,5 +1,5 @@
FileVersion = 1
Projects = {pkkg = {Path = "."}}
Projects = {pkkg = {Path = "."}, Bofa = {Path = "deps/Bofa"}}
[Workspace]
StartupProject = "pkkg"

View file

@ -1,11 +1,108 @@
namespace pkkg;
using System;
using System.IO;
using System.Collections;
using Bofa;
using Bofa.Serialization;
class Program
{
public static void Main(String[] pArgs)
public static int32 VersionMajor = 1;
public static int32 VersionMinor = 0;
public static int32 VersionPatch = 0;
public static String TemplateFile = """
#This is the pkkg template file
""";
public static String PkkgFile = "pkkg";
public static String LogFile = "pkkg.log";
public enum ReturnValues : int32
{
//Errors
UnknownError = -1,
FileWriteError = -2,
FileReadError = -3,
//Sucesses
CreatedTemplateFile = 1,
}
public static int32 Main(String[] pArgs)
{
Log(scope $"Starting pkkg {VersionMajor}.{VersionMinor}.{VersionPatch}");
if(!File.Exists(PkkgFile))
{
if(File.WriteAllText(PkkgFile, TemplateFile) case .Err)
{
Log("Unable to write template file");
return (.)ReturnValues.FileWriteError;
}
Log("Wrote template file");
return (.)ReturnValues.CreatedTemplateFile;
}
//pkkg file already exists, trying to parse it
Log("Attempting to read pkkg file");
var packageFile = scope String();
if(File.ReadAllText(PkkgFile, packageFile) case .Err)
{
Log("Unable to read config file");
return (.)ReturnValues.FileReadError;
}
Log("Read file attempting to parse it");
Package current = new .();
if(current.Deserialize())
{
}
}
///Log a message to the console and to a file
public static void Log(StringView pMessage)
{
Console.WriteLine(pMessage);
if(!LogFile.IsEmpty)
File.WriteAllText(LogFile, pMessage, true).IgnoreError();
}
public static Result<void> ParseBofa(StringView pMessage)
{
Dictionary<StringView, Bofa> results = new .();
defer { DeleteDictionaryAndValues!(results); }
List<int64> errors = scope .();
BofaParser.Parse(pMessage, results, errors);
if(errors.Count > 0)
return .Err; //We are hardcode like that
}
}
[BofaSerialize]
class Package
{
public String Name ~ delete _;
public String Description ~ delete _;
public String Url ~ delete _;
[BofaSerialize]
public class Author
{
public String Name ~ delete _;
public String Url ~ delete _;
}
public List<Author> Authors ~ DeleteContainerAndItems!(_);
[BofaSerialize]
public class Dependency
{
public String Name ~ delete _;
public String GitUrl ~ delete _;
public String Branch ~ delete _;
}
public List<Dependency> Dependencies ~ DeleteContainerAndItems!(_);
}