From 854e02dd0d03c0058f32614ea54e79da6d4cd39b Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 31 Dec 2020 18:05:38 +0100 Subject: [PATCH] Show outdated mods in orange --- GCMM/MainForm.cs | 2 ++ GCMM/MainModList.cs | 10 +++++----- GCMM/MainUtils.cs | 21 +++++++++++++++++++++ GCMM/ModInfo.cs | 3 +++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/GCMM/MainForm.cs b/GCMM/MainForm.cs index 8bd90ca..976139f 100644 --- a/GCMM/MainForm.cs +++ b/GCMM/MainForm.cs @@ -25,6 +25,7 @@ namespace GCMM private readonly Dictionary mods = new Dictionary(); private readonly ModInfo gcipa = new ModInfo { Author = "modtainers", Name = "GCIPA" }; private readonly ModInfo gcmm = new ModInfo { Author = "NorbiPeti", Name = "GCMM" }; + private DateTime lastGameUpdateTime; private const string defaultInfo = @" Gamecraft Mod Manager @@ -239,6 +240,7 @@ You may also want to verify the game's files by right clicking the game in Steam private async void refreshbtn_Click(object sender, EventArgs e) { CheckIfPatched(); //Set from placeholder + lastGameUpdateTime = GetLastGameUpdateTime(); var mods = GetInstalledMods(); await GetAvailableMods(); CheckUninstalledMods(mods); diff --git a/GCMM/MainModList.cs b/GCMM/MainModList.cs index e3e842b..a199fc8 100644 --- a/GCMM/MainModList.cs +++ b/GCMM/MainModList.cs @@ -33,7 +33,7 @@ namespace GCMM var an = AssemblyName.GetAssemblyName(modPath); if (an.Name == "0Harmony") continue; //Use filename to avoid differences between repository & assembly name casing - var mod = new ModInfo { Name = Path.GetFileNameWithoutExtension(modPath), Version = an.Version, LastUpdated = File.GetLastWriteTime(modPath) }; + var mod = new ModInfo { Name = Path.GetFileNameWithoutExtension(modPath), Version = an.Version }; AddUpdateModInList(mod); installed.Add(mod.Name); } @@ -48,7 +48,6 @@ namespace GCMM { var an = AssemblyName.GetAssemblyName(ipath); gcipa.Version = an.Version; - gcipa.LastUpdated = File.GetLastWriteTime(ipath); } } catch (BadImageFormatException) @@ -61,7 +60,6 @@ namespace GCMM { var an = AssemblyName.GetAssemblyName(mmpath); gcmm.Version = an.Version; - gcmm.LastUpdated = File.GetLastWriteTime(mmpath); } } catch (BadImageFormatException) @@ -178,7 +176,7 @@ namespace GCMM omod.UpdateDetails = mod.UpdateDetails ?? omod.UpdateDetails; items[1].Text = omod.Author ?? ""; items[2].Text = (omod.Version ?? omod.LatestVersion)?.ToString(); - items[3].Text = omod.LastUpdated.ToString(); + items[3].Text = omod.LatestVersion != null ? omod.LastUpdated.ToString() : ""; item.Group = omod.Installed ? modlist.Groups["installed"] : modlist.Groups["available"]; modlist.Sort(); mod = omod; @@ -186,12 +184,14 @@ namespace GCMM else { mods.Add(mod.Name, mod); - item = new ListViewItem(new[] { mod.Name, mod.Author ?? "", (mod.Version ?? mod.LatestVersion)?.ToString() ?? "", mod.LastUpdated.ToString() }, modlist.Groups[mod.Installed ? "installed" : "available"]); + item = new ListViewItem(new[] { mod.Name, mod.Author ?? "", (mod.Version ?? mod.LatestVersion)?.ToString() ?? "", mod.LatestVersion != null ? mod.LastUpdated.ToString() : "" }, modlist.Groups[mod.Installed ? "installed" : "available"]); item.Name = mod.Name; modlist.Items.Add(item); } if (mod.LatestVersion != null && mod.Version != null && mod.Version < mod.LatestVersion) item.ForeColor = Color.Blue; + else if (mod.LastUpdated < lastGameUpdateTime) + item.ForeColor = Color.DarkOrange; else item.ForeColor = modlist.ForeColor; } diff --git a/GCMM/MainUtils.cs b/GCMM/MainUtils.cs index 661227a..83867ba 100644 --- a/GCMM/MainUtils.cs +++ b/GCMM/MainUtils.cs @@ -160,5 +160,26 @@ namespace GCMM } return false; } + + public DateTime GetLastGameUpdateTime() + { + if (GetExe() == null) + return default; + foreach (var line in File.ReadAllLines(GamePath(@"\..\..\appmanifest_1078000.acf"))) + { + var regex = new Regex("\\t\"LastUpdated\"\\t\\t\"(\\d+)\""); + var match = regex.Match(line); + if (!match.Success) + continue; + string updated = match.Groups[1].Value; + if (string.IsNullOrWhiteSpace(updated)) + return default; + var updatedTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); + updatedTime = updatedTime.AddSeconds(double.Parse(updated)).ToLocalTime(); + return updatedTime; + + } + return default; + } } } diff --git a/GCMM/ModInfo.cs b/GCMM/ModInfo.cs index b682303..cd31934 100644 --- a/GCMM/ModInfo.cs +++ b/GCMM/ModInfo.cs @@ -22,6 +22,9 @@ namespace GCMM /// Can be null. /// public string Author { get; set; } + /// + /// The time when the mod was last updated by its author. + /// public DateTime LastUpdated { get; set; } public bool Installed => Version != null; public string DownloadURL { get; set; }