From b4d64c50d01ac1e983e6f34a6dba3a024746cb6a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 17 Jul 2020 20:57:46 +0200 Subject: [PATCH] Fix lib bug, check game exe more, preview support Fixed the game folder method returning the library file Checking the game's exe when starting Added support for the preview branch of the game Added support for preview versions of mods --- GCMM/MainForm.cs | 10 +++++----- GCMM/MainModInstaller.cs | 2 +- GCMM/MainModList.cs | 29 +++++++++++++++++++++++++---- GCMM/MainPatcher.cs | 2 +- GCMM/MainUtils.cs | 29 ++++++++++++++++++++++------- 5 files changed, 54 insertions(+), 18 deletions(-) diff --git a/GCMM/MainForm.cs b/GCMM/MainForm.cs index 016d349..19f08cc 100644 --- a/GCMM/MainForm.cs +++ b/GCMM/MainForm.cs @@ -54,7 +54,7 @@ If you encounter an issue while the game is patched, report it to us. If you thi modlist.Items.Clear(); UpdateButton(installbtn, false); modinfobox.Text = defaultInfo; - if (string.IsNullOrWhiteSpace(Settings.Default.GamePath)) + if (string.IsNullOrWhiteSpace(Settings.Default.GamePath) || GetExe() == null) { Settings.Default.GamePath = GetGameFolder(); if (string.IsNullOrWhiteSpace(Settings.Default.GamePath)) @@ -114,9 +114,9 @@ If you encounter an issue while the game is patched, report it to us. If you thi if(up) { modinfobox.Select(0, "New version available!".Length); - modinfobox.SelectionColor = Color.Aqua; - modinfobox.DeselectAll(); - modinfobox.SelectionColor = modinfobox.ForeColor; + //modinfobox.SelectionColor = Color.Aqua; + //modinfobox.DeselectAll(); + //modinfobox.SelectionColor = modinfobox.ForeColor; } } else @@ -170,7 +170,7 @@ If you encounter an issue while the game is patched, report it to us. If you thi { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { - Process.Start("explorer.exe", "/select,"+Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\Freejam\Gamecraft\Player.log"); + Process.Start("explorer.exe", $@"/select,{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}Low\Freejam\{GetExe().Replace(".exe", "")}\Player.log"); } } diff --git a/GCMM/MainModInstaller.cs b/GCMM/MainModInstaller.cs index 80e147f..208b64d 100644 --- a/GCMM/MainModInstaller.cs +++ b/GCMM/MainModInstaller.cs @@ -16,7 +16,7 @@ namespace GCMM public async Task InstallMod(ModInfo mod) { if (mod.DownloadURL == null) return; - if (!File.Exists(GamePath(@"\Gamecraft.exe"))) + if (GetExe() == null) { MessageBox.Show("Gamecraft not found. Set the correct path in Settings."); return; diff --git a/GCMM/MainModList.cs b/GCMM/MainModList.cs index 1396fe7..2d6c658 100644 --- a/GCMM/MainModList.cs +++ b/GCMM/MainModList.cs @@ -36,6 +36,7 @@ namespace GCMM public async void GetAvailableMods() { + bool preview = GetExe()?.Contains("Preview") ?? false; using (var client = GetClient()) { string str = await client.DownloadStringTaskAsync("https://exmods.org/mods/modlist.tsv"); @@ -48,21 +49,39 @@ namespace GCMM Author = sp[0].Trim(), Name = sp[1].Trim() }; - if (await FetchModInfo(mod)) //If it's actually a mod + if (await FetchModInfo(mod, preview)) //If it's actually a mod AddUpdateModInList(mod); } } } - public async Task FetchModInfo(ModInfo mod) + public async Task FetchModInfo(ModInfo mod, bool preview) { string repoURL = "/api/v1/repos/" + mod.Author + "/" + mod.Name + "/releases"; using (var client = GetClient()) { var arr = JArray.Parse(await client.DownloadStringTaskAsync(repoURL)); - var release = arr.FirstOrDefault(rel => !(bool)rel["prerelease"] && !(bool)rel["draft"]); + var release = arr.FirstOrDefault(rel => + { + if ((bool) rel["prerelease"] || (bool) rel["draft"]) + return false; + var vs = rel["tag_name"].ToString(); + int ind = vs.IndexOf('-'); + if (ind != -1) + { + if (vs.Substring(ind + 1).Equals("preview", StringComparison.InvariantCultureIgnoreCase) + && !preview) + return false; + } + return true; + }); if (release == null) return false; + var verstr = release["tag_name"].ToString().Replace("v", ""); + int index = verstr.IndexOf('-'); + if (index != -1) + verstr = verstr.Substring(0, index); + JToken asset; if (release["assets"].Count() == 1) asset = release["assets"].First; @@ -72,9 +91,11 @@ namespace GCMM string name = token["name"].ToString(); return name == mod.Name + ".dll" || name == mod.Name + ".zip"; }); + mod.DownloadURL = asset?["browser_download_url"]?.ToString(); mod.LastUpdated = (DateTime)release["published_at"]; - var ver = release["tag_name"].ToString().Replace("v", "").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 mod.LatestVersion = new Version(getver(0), getver(1), getver(2), getver(3)); mod.UpdateDetails = release["name"] + "\n\n" + release["body"].ToString(); diff --git a/GCMM/MainPatcher.cs b/GCMM/MainPatcher.cs index cf7fffb..f6a8bec 100644 --- a/GCMM/MainPatcher.cs +++ b/GCMM/MainPatcher.cs @@ -77,7 +77,7 @@ namespace GCMM } if (!status.Value ^ unpatched.Checked) { //TODO: Wine - var psi = new ProcessStartInfo(GamePath(@"\IPA.exe"), "Gamecraft.exe " + var psi = new ProcessStartInfo(GamePath(@"\IPA.exe"), GetExe() + " " + (unpatched.Checked ? "--revert " : "") + "--nowait") { UseShellExecute = false, diff --git a/GCMM/MainUtils.cs b/GCMM/MainUtils.cs index 6679872..45b300e 100644 --- a/GCMM/MainUtils.cs +++ b/GCMM/MainUtils.cs @@ -38,7 +38,7 @@ namespace GCMM libs = @"C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf"; else return null; - foreach (var line in File.ReadAllLines(libs).Concat(new[] { @"C:\Program Files (x86)\Steam\" })) + foreach (var line in File.ReadAllLines(libs).Concat(new[] {@"C:\Program Files (x86)\Steam\"})) { var regex = new Regex("\\t\"\\d+\"\\t\\t\"(.+)\""); var match = regex.Match(line); @@ -46,18 +46,18 @@ namespace GCMM continue; string library = match.Groups[1].Value.Replace("\\\\", "\\"); library += @"\steamapps\common\"; - if (File.Exists(library + @"Gamecraft\Gamecraft.exe")) + if (GetExe(library + "Gamecraft") != null) return library + "Gamecraft"; - if (File.Exists(library + @"RobocraftX\Gamecraft.exe")) + if (GetExe(library + "RobocraftX") != null) return library + "RobocraftX"; } - return libs; + return null; } public string SelectGameFolder() { var ofd = new OpenFileDialog(); - ofd.Filter = "Gamecraft executable|Gamecraft.exe"; + ofd.Filter = "Gamecraft executable|Gamecraft.exe|Gamecraft Preview executable|GamecraftPreview.exe"; ofd.Title = "Game location"; ofd.InitialDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\"; //TODO ofd.CheckFileExists = true; @@ -125,9 +125,24 @@ namespace GCMM modlist_SelectedIndexChanged(modlist, null); } - public string GamePath(string path) + /// + /// Path must start with \ + /// + /// + /// + /// + public string GamePath(string path, string gamepath = null) { - return (Settings.Default.GamePath + path).Replace('\\', Path.DirectorySeparatorChar); + return ((gamepath ?? Settings.Default.GamePath) + path).Replace('\\', Path.DirectorySeparatorChar); + } + + public string GetExe(string path = null) + { + if (File.Exists(GamePath("\\Gamecraft.exe", path))) + return "Gamecraft.exe"; + if (File.Exists(GamePath("\\GamecraftPreview.exe", path))) + return "GamecraftPreview.exe"; + return null; } } }