67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
using Serilog;
|
|
using System.Text.Json.Serialization;
|
|
// Defines a Package
|
|
|
|
|
|
sealed class Package
|
|
{
|
|
|
|
public string PackageName { get; private set; }
|
|
public Version Version { get; private set; }
|
|
public int Size { get; private set; }
|
|
public string SHA256 { get; private set; }
|
|
public string Filename { get; private set; }
|
|
|
|
[JsonConstructor] // NOTE: without this it would be impossible to deserialise a Package
|
|
private Package(string PackageName, Version Version, int Size, string SHA256, string Filename)
|
|
{
|
|
this.PackageName = PackageName;
|
|
this.Version = Version;
|
|
this.Size = Size;
|
|
this.SHA256 = SHA256;
|
|
this.Filename = Filename;
|
|
}
|
|
|
|
public Package(string packageString)
|
|
{
|
|
Log.Information("Creating package from string");
|
|
Log.Debug("PackageString : \n{str}", packageString);
|
|
// we assume the user is passing only one package.
|
|
string[] packageLines = packageString.Split('\n');
|
|
Log.Debug("Split result : \n{@spl}", packageLines);
|
|
PackageName = packageLines
|
|
.Where(line => line.Contains("Package:"))
|
|
.First()
|
|
.Split(": ")
|
|
.Last();
|
|
Version = new Version(packageLines
|
|
.Where(line => line.Contains("Version:"))
|
|
.First()
|
|
.Split(": ")
|
|
.Last());
|
|
Size = int.Parse(
|
|
packageLines
|
|
.Where(line => line.Contains("Size:"))
|
|
.First()
|
|
.Split(": ")
|
|
.Last());
|
|
SHA256 = packageLines
|
|
.Where(line => line.Contains("SHA256:"))
|
|
.First()
|
|
.Split(": ")
|
|
.Last();
|
|
Filename = packageLines
|
|
.Where(line => line.Contains("Filename:"))
|
|
.First()
|
|
.Split(": ")
|
|
.Last();
|
|
}
|
|
|
|
}
|
|
|
|
/* TODO: capture dependencies and create method to find them.
|
|
- This would probably need distro specific lookup tables.
|
|
- Also would ideally need code to shell out (at root level)
|
|
to perform installs...
|
|
*/
|