Move mod file list to the game's folder (#1)

And improve getting TBMM version
This commit is contained in:
Norbi Peti 2021-07-11 17:04:32 +02:00
parent 3ef12efc9a
commit b6ad8fd3ea
2 changed files with 19 additions and 19 deletions

View file

@ -117,15 +117,22 @@ namespace TBMM
public void SaveFileList(ModInfo mod) public void SaveFileList(ModInfo mod)
{ {
if (mod.ModFiles != null) 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) public void LoadFileList(ModInfo mod)
{ {
if (File.Exists(mod.Name + ".json")) string[] paths =
mod.ModFiles = JsonConvert.DeserializeObject<HashSet<string>>(File.ReadAllText(mod.Name + ".json")); {
else GamePath($"\\ModInfo\\{mod.Name}.json"),
mod.ModFiles = new HashSet<string>(); 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) public void UninstallMod(ModInfo mod)
@ -146,6 +153,9 @@ namespace TBMM
parent.Delete(); //May delete the Plugins dir if empty 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"); File.Delete(mod.Name + ".json");
mod.Version = null; //Not installed mod.Version = null; //Not installed
if (mod.Author != null) if (mod.Author != null)

View file

@ -51,18 +51,8 @@ namespace TBMM
catch (BadImageFormatException) catch (BadImageFormatException)
{ //Not a .NET assembly { //Not a .NET assembly
} }
try
{ tbmm.Version = Assembly.GetExecutingAssembly().GetName().Version;
string mmpath = "TBMM.exe";
if (File.Exists(mmpath))
{
var an = AssemblyName.GetAssemblyName(mmpath);
tbmm.Version = an.Version;
}
}
catch (BadImageFormatException)
{ //Not a .NET assembly
}
return installed; return installed;
} }
@ -152,13 +142,13 @@ namespace TBMM
var ver = verstr.Split('.').Select(str => int.Parse(str)).ToArray(); 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 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.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) if (desc)
{ {
try try
{ {
var obj = JObject.Parse(await client.DownloadStringTaskAsync("/api/v1/repos/" + mod.Author + "/" + mod.Name + "/contents/README.md")); 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) catch (WebException)
{ //It returns a HTTP 500 if it doesn't exist... { //It returns a HTTP 500 if it doesn't exist...