Move mod file list to the game's folder (#1)
And improve getting TBMM version
This commit is contained in:
parent
3ef12efc9a
commit
b6ad8fd3ea
2 changed files with 19 additions and 19 deletions
|
@ -117,15 +117,22 @@ namespace TBMM
|
|||
public void SaveFileList(ModInfo mod)
|
||||
{
|
||||
if (mod.ModFiles != null)
|
||||
File.WriteAllText(mod.Name + ".json", JsonConvert.SerializeObject(mod.ModFiles));
|
||||
{
|
||||
Directory.CreateDirectory(GamePath("\\ModInfo"));
|
||||
File.WriteAllText(GamePath($"\\ModInfo\\{mod.Name}.json"), JsonConvert.SerializeObject(mod.ModFiles));
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadFileList(ModInfo mod)
|
||||
{
|
||||
if (File.Exists(mod.Name + ".json"))
|
||||
mod.ModFiles = JsonConvert.DeserializeObject<HashSet<string>>(File.ReadAllText(mod.Name + ".json"));
|
||||
else
|
||||
mod.ModFiles = new HashSet<string>();
|
||||
string[] paths =
|
||||
{
|
||||
GamePath($"\\ModInfo\\{mod.Name}.json"),
|
||||
mod.Name + ".json"
|
||||
};
|
||||
mod.ModFiles =
|
||||
paths.Where(File.Exists).Select(File.ReadAllText).Select(JsonConvert.DeserializeObject<HashSet<string>>)
|
||||
.FirstOrDefault() ?? new HashSet<string>();
|
||||
}
|
||||
|
||||
public void UninstallMod(ModInfo mod)
|
||||
|
@ -146,6 +153,9 @@ namespace TBMM
|
|||
parent.Delete(); //May delete the Plugins dir if empty
|
||||
}
|
||||
}
|
||||
|
||||
if (File.Exists(GamePath($"\\ModInfo\\{mod.Name}.json")))
|
||||
File.Delete(GamePath($"\\ModInfo\\{mod.Name}.json"));
|
||||
File.Delete(mod.Name + ".json");
|
||||
mod.Version = null; //Not installed
|
||||
if (mod.Author != null)
|
||||
|
|
|
@ -51,18 +51,8 @@ namespace TBMM
|
|||
catch (BadImageFormatException)
|
||||
{ //Not a .NET assembly
|
||||
}
|
||||
try
|
||||
{
|
||||
string mmpath = "TBMM.exe";
|
||||
if (File.Exists(mmpath))
|
||||
{
|
||||
var an = AssemblyName.GetAssemblyName(mmpath);
|
||||
tbmm.Version = an.Version;
|
||||
}
|
||||
}
|
||||
catch (BadImageFormatException)
|
||||
{ //Not a .NET assembly
|
||||
}
|
||||
|
||||
tbmm.Version = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
return installed;
|
||||
}
|
||||
|
||||
|
@ -152,13 +142,13 @@ namespace TBMM
|
|||
var ver = verstr.Split('.').Select(str => int.Parse(str)).ToArray();
|
||||
int getver(byte i) => ver.Length > i ? ver[i] : 0; //By default it sets values not present to -1, but we need them to be 0
|
||||
mod.LatestVersion = new Version(getver(0), getver(1), getver(2), getver(3));
|
||||
mod.UpdateDetails = release["name"] + "\n\n" + release["body"].ToString();
|
||||
mod.UpdateDetails = release["name"] + "\n\n" + release["body"];
|
||||
if (desc)
|
||||
{
|
||||
try
|
||||
{
|
||||
var obj = JObject.Parse(await client.DownloadStringTaskAsync("/api/v1/repos/" + mod.Author + "/" + mod.Name + "/contents/README.md"));
|
||||
mod.Description = Encoding.UTF8.GetString(Convert.FromBase64String(obj["content"].ToString()));
|
||||
mod.Description = Encoding.UTF8.GetString(Convert.FromBase64String(obj["content"]?.ToString() ?? string.Empty));
|
||||
}
|
||||
catch (WebException)
|
||||
{ //It returns a HTTP 500 if it doesn't exist...
|
||||
|
|
Loading…
Reference in a new issue