load modpack info before modpack installer
This commit is contained in:
@@ -10,15 +10,35 @@ public class ModpackInfo
|
||||
|
||||
[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)
|
||||
{
|
||||
File.WriteAllText(Conversions.ToString(GetFilePath(mcRoot)), JsonConvert.SerializeObject(this));
|
||||
LocaLPath = mcRoot;
|
||||
Save();
|
||||
}
|
||||
|
||||
public static ModpackInfo TryLoad(string mcRoot)
|
||||
{
|
||||
if (HasModpackInfo(mcRoot))
|
||||
return Load(mcRoot);
|
||||
return new();
|
||||
}
|
||||
|
||||
public static ModpackInfo Load(string mcRoot)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<ModpackInfo>(File.ReadAllText(Conversions.ToString(GetFilePath(mcRoot))));
|
||||
var info = JsonConvert.DeserializeObject<ModpackInfo>(File.ReadAllText(GetFilePath(mcRoot)));
|
||||
info.LocaLPath = mcRoot;
|
||||
return info;
|
||||
}
|
||||
|
||||
public static bool HasModpackInfo(string mcRoot)
|
||||
@@ -26,7 +46,7 @@ public class ModpackInfo
|
||||
return File.Exists(Conversions.ToString(GetFilePath(mcRoot)));
|
||||
}
|
||||
|
||||
private static object GetFilePath(string mcRoot)
|
||||
private static string GetFilePath(string mcRoot)
|
||||
{
|
||||
return Path.Combine(mcRoot, FILENAME_MODPACKINFO);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user