diff --git a/TBMM/MainModInstaller.cs b/TBMM/MainModInstaller.cs index aa64c67..75489c2 100644 --- a/TBMM/MainModInstaller.cs +++ b/TBMM/MainModInstaller.cs @@ -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>(File.ReadAllText(mod.Name + ".json")); - else - mod.ModFiles = new HashSet(); + string[] paths = + { + GamePath($"\\ModInfo\\{mod.Name}.json"), + mod.Name + ".json" + }; + mod.ModFiles = + paths.Where(File.Exists).Select(File.ReadAllText).Select(JsonConvert.DeserializeObject>) + .FirstOrDefault() ?? new HashSet(); } 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) diff --git a/TBMM/MainModList.cs b/TBMM/MainModList.cs index 744e7c0..9f98e3c 100644 --- a/TBMM/MainModList.cs +++ b/TBMM/MainModList.cs @@ -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...