re-organze namespace
This commit is contained in:
58
ModpackUpdater/ModpackInfo.cs
Normal file
58
ModpackUpdater/ModpackInfo.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Microsoft.VisualBasic.CompilerServices;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace ModpackUpdater;
|
||||
|
||||
public class ModpackInfo
|
||||
{
|
||||
private const string FILENAME_MODPACKINFO = "modpack-info.json";
|
||||
|
||||
[JsonConverter(typeof(VersionConverter))]
|
||||
public Version Version { get; set; }
|
||||
public string ConfigUrl { get; set; }
|
||||
public string ExtrasKey { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public string LocaLPath { get; private set; }
|
||||
[JsonIgnore]
|
||||
public bool Exists => File.Exists(GetFilePath(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()
|
||||
{
|
||||
LocaLPath = mcRoot
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user