manager: migrate base project structure & deps

This commit is contained in:
2025-11-10 18:28:20 +01:00
parent da25510543
commit 6cf27b4867
28 changed files with 304 additions and 155 deletions

View File

@@ -9,41 +9,42 @@ 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; }
public Version? Version { get; set; }
public string? ConfigUrl { get; set; }
public string? ExtrasKey { get; set; }
public InstallOptionValueDictionary Options { get; } = [];
[JsonIgnore]
public string LocaLPath { get; private set; }
public string? LocalPath { get; private set; }
[JsonIgnore]
public bool Exists => File.Exists(GetFilePath(LocaLPath));
public bool Exists => LocalPath != null && File.Exists(GetFilePath(LocalPath));
public void Save()
{
File.WriteAllText(GetFilePath(LocaLPath), JsonConvert.SerializeObject(this));
if (LocalPath != null)
File.WriteAllText(GetFilePath(LocalPath), JsonConvert.SerializeObject(this));
}
public void Save(string mcRoot)
{
LocaLPath = mcRoot;
LocalPath = mcRoot;
Save();
}
public static ModpackInfo TryLoad(string mcRoot)
public static ModpackInfo TryLoad(string? mcRoot)
{
if (HasModpackInfo(mcRoot))
if (mcRoot != null && HasModpackInfo(mcRoot))
return Load(mcRoot);
return new()
{
LocaLPath = mcRoot
LocalPath = mcRoot
};
}
public static ModpackInfo Load(string mcRoot)
{
var info = JsonConvert.DeserializeObject<ModpackInfo>(File.ReadAllText(GetFilePath(mcRoot)));
info.LocaLPath = mcRoot;
var info = JsonConvert.DeserializeObject<ModpackInfo>(File.ReadAllText(GetFilePath(mcRoot))) ?? new();
info.LocalPath = mcRoot;
return info;
}