Show outdated mods in orange

This commit is contained in:
Norbi Peti 2020-12-31 18:05:38 +01:00
parent c3c9ee0a16
commit 854e02dd0d
4 changed files with 31 additions and 5 deletions

View file

@ -25,6 +25,7 @@ namespace GCMM
private readonly Dictionary<string, ModInfo> mods = new Dictionary<string, ModInfo>(); private readonly Dictionary<string, ModInfo> mods = new Dictionary<string, ModInfo>();
private readonly ModInfo gcipa = new ModInfo { Author = "modtainers", Name = "GCIPA" }; private readonly ModInfo gcipa = new ModInfo { Author = "modtainers", Name = "GCIPA" };
private readonly ModInfo gcmm = new ModInfo { Author = "NorbiPeti", Name = "GCMM" }; private readonly ModInfo gcmm = new ModInfo { Author = "NorbiPeti", Name = "GCMM" };
private DateTime lastGameUpdateTime;
private const string defaultInfo = @" private const string defaultInfo = @"
Gamecraft Mod Manager 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) private async void refreshbtn_Click(object sender, EventArgs e)
{ {
CheckIfPatched(); //Set from placeholder CheckIfPatched(); //Set from placeholder
lastGameUpdateTime = GetLastGameUpdateTime();
var mods = GetInstalledMods(); var mods = GetInstalledMods();
await GetAvailableMods(); await GetAvailableMods();
CheckUninstalledMods(mods); CheckUninstalledMods(mods);

View file

@ -33,7 +33,7 @@ namespace GCMM
var an = AssemblyName.GetAssemblyName(modPath); var an = AssemblyName.GetAssemblyName(modPath);
if (an.Name == "0Harmony") continue; if (an.Name == "0Harmony") continue;
//Use filename to avoid differences between repository & assembly name casing //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); AddUpdateModInList(mod);
installed.Add(mod.Name); installed.Add(mod.Name);
} }
@ -48,7 +48,6 @@ namespace GCMM
{ {
var an = AssemblyName.GetAssemblyName(ipath); var an = AssemblyName.GetAssemblyName(ipath);
gcipa.Version = an.Version; gcipa.Version = an.Version;
gcipa.LastUpdated = File.GetLastWriteTime(ipath);
} }
} }
catch (BadImageFormatException) catch (BadImageFormatException)
@ -61,7 +60,6 @@ namespace GCMM
{ {
var an = AssemblyName.GetAssemblyName(mmpath); var an = AssemblyName.GetAssemblyName(mmpath);
gcmm.Version = an.Version; gcmm.Version = an.Version;
gcmm.LastUpdated = File.GetLastWriteTime(mmpath);
} }
} }
catch (BadImageFormatException) catch (BadImageFormatException)
@ -178,7 +176,7 @@ namespace GCMM
omod.UpdateDetails = mod.UpdateDetails ?? omod.UpdateDetails; omod.UpdateDetails = mod.UpdateDetails ?? omod.UpdateDetails;
items[1].Text = omod.Author ?? ""; items[1].Text = omod.Author ?? "";
items[2].Text = (omod.Version ?? omod.LatestVersion)?.ToString(); 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"]; item.Group = omod.Installed ? modlist.Groups["installed"] : modlist.Groups["available"];
modlist.Sort(); modlist.Sort();
mod = omod; mod = omod;
@ -186,12 +184,14 @@ namespace GCMM
else else
{ {
mods.Add(mod.Name, mod); 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; item.Name = mod.Name;
modlist.Items.Add(item); modlist.Items.Add(item);
} }
if (mod.LatestVersion != null && mod.Version != null && mod.Version < mod.LatestVersion) if (mod.LatestVersion != null && mod.Version != null && mod.Version < mod.LatestVersion)
item.ForeColor = Color.Blue; item.ForeColor = Color.Blue;
else if (mod.LastUpdated < lastGameUpdateTime)
item.ForeColor = Color.DarkOrange;
else else
item.ForeColor = modlist.ForeColor; item.ForeColor = modlist.ForeColor;
} }

View file

@ -160,5 +160,26 @@ namespace GCMM
} }
return false; 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;
}
} }
} }

View file

@ -22,6 +22,9 @@ namespace GCMM
/// Can be null. /// Can be null.
/// </summary> /// </summary>
public string Author { get; set; } public string Author { get; set; }
/// <summary>
/// The time when the mod was last updated by its author.
/// </summary>
public DateTime LastUpdated { get; set; } public DateTime LastUpdated { get; set; }
public bool Installed => Version != null; public bool Installed => Version != null;
public string DownloadURL { get; set; } public string DownloadURL { get; set; }