53 lines
1.3 KiB
C#
53 lines
1.3 KiB
C#
using Microsoft.VisualBasic.CompilerServices;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Converters;
|
|
|
|
namespace ModpackUpdater.Model;
|
|
|
|
public class ModpackInfo
|
|
{
|
|
private const string FILENAME_MODPACKINFO = "modpack-info.json";
|
|
|
|
[JsonConverter(typeof(VersionConverter))]
|
|
public Version Version { get; set; }
|
|
public string ConfigUrl { get; set; }
|
|
[JsonIgnore]
|
|
public string LocaLPath { get; private set; }
|
|
[JsonIgnore]
|
|
public bool Exists => Directory.Exists(LocaLPath);
|
|
|
|
public void Save()
|
|
{
|
|
File.WriteAllText(Conversions.ToString(GetFilePath(LocaLPath)), JsonConvert.SerializeObject(this));
|
|
}
|
|
|
|
public void Save(string mcRoot)
|
|
{
|
|
LocaLPath = mcRoot;
|
|
Save();
|
|
}
|
|
|
|
public static ModpackInfo TryLoad(string mcRoot)
|
|
{
|
|
if (HasModpackInfo(mcRoot))
|
|
return Load(mcRoot);
|
|
return new();
|
|
}
|
|
|
|
public static ModpackInfo Load(string mcRoot)
|
|
{
|
|
var info = JsonConvert.DeserializeObject<ModpackInfo>(File.ReadAllText(GetFilePath(mcRoot)));
|
|
info.LocaLPath = mcRoot;
|
|
return info;
|
|
}
|
|
|
|
public static bool HasModpackInfo(string mcRoot)
|
|
{
|
|
return File.Exists(Conversions.ToString(GetFilePath(mcRoot)));
|
|
}
|
|
|
|
private static string GetFilePath(string mcRoot)
|
|
{
|
|
return Path.Combine(mcRoot, FILENAME_MODPACKINFO);
|
|
}
|
|
} |