2023-11-10 00:29:16 -06:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using YamlDotNet.Serialization.NamingConventions;
|
|
|
|
|
using YamlDotNet.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace LANCommander.SDK.Helpers
|
|
|
|
|
{
|
|
|
|
|
public static class ManifestHelper
|
|
|
|
|
{
|
|
|
|
|
public static readonly ILogger Logger;
|
|
|
|
|
|
|
|
|
|
public const string ManifestFilename = "_manifest.yml";
|
|
|
|
|
|
|
|
|
|
public static GameManifest Read(string installDirectory)
|
|
|
|
|
{
|
2023-11-10 01:32:30 -06:00
|
|
|
|
var source = GetPath(installDirectory);
|
2023-11-10 00:29:16 -06:00
|
|
|
|
var yaml = File.ReadAllText(source);
|
|
|
|
|
|
|
|
|
|
var deserializer = new DeserializerBuilder()
|
2023-11-10 21:37:02 -06:00
|
|
|
|
.WithNamingConvention(new PascalCaseNamingConvention())
|
2023-11-10 00:29:16 -06:00
|
|
|
|
.Build();
|
|
|
|
|
|
2023-11-10 20:53:28 -06:00
|
|
|
|
Logger?.LogTrace("Deserializing manifest");
|
2023-11-10 00:29:16 -06:00
|
|
|
|
|
2023-11-10 21:37:27 -06:00
|
|
|
|
var manifest = deserializer.Deserialize<GameManifest>(yaml);
|
2023-11-10 00:29:16 -06:00
|
|
|
|
|
|
|
|
|
return manifest;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-13 23:07:50 -06:00
|
|
|
|
public static string Write(GameManifest manifest, string installDirectory)
|
2023-11-10 00:29:16 -06:00
|
|
|
|
{
|
2023-11-10 01:32:30 -06:00
|
|
|
|
var destination = GetPath(installDirectory);
|
2023-11-10 00:29:16 -06:00
|
|
|
|
|
2023-11-10 20:53:28 -06:00
|
|
|
|
Logger?.LogTrace("Attempting to write manifest to path {Destination}", destination);
|
2023-11-10 00:29:16 -06:00
|
|
|
|
|
|
|
|
|
var serializer = new SerializerBuilder()
|
2023-11-10 21:37:02 -06:00
|
|
|
|
.WithNamingConvention(new PascalCaseNamingConvention())
|
2023-11-10 00:29:16 -06:00
|
|
|
|
.Build();
|
|
|
|
|
|
2023-11-10 20:53:28 -06:00
|
|
|
|
Logger?.LogTrace("Serializing manifest");
|
2023-11-10 00:29:16 -06:00
|
|
|
|
|
|
|
|
|
var yaml = serializer.Serialize(manifest);
|
|
|
|
|
|
2023-11-10 20:53:28 -06:00
|
|
|
|
Logger?.LogTrace("Writing manifest file");
|
2023-11-10 00:29:16 -06:00
|
|
|
|
|
|
|
|
|
File.WriteAllText(destination, yaml);
|
2023-11-13 23:07:50 -06:00
|
|
|
|
|
|
|
|
|
return destination;
|
2023-11-10 00:29:16 -06:00
|
|
|
|
}
|
2023-11-10 01:32:30 -06:00
|
|
|
|
|
|
|
|
|
public static string GetPath(string installDirectory)
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(installDirectory, ManifestFilename);
|
|
|
|
|
}
|
2023-11-10 00:29:16 -06:00
|
|
|
|
}
|
|
|
|
|
}
|