Use Windows FileVersion utils instead to get file versions, use that info when saving Game Downloader states.

This commit is contained in:
Timothy Baldridge 2020-01-03 10:00:57 -07:00
parent b9e9acbd53
commit 408ade8a38
3 changed files with 41 additions and 10 deletions

View File

@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using Alphaleonis.Win32.Filesystem;
using Microsoft.Win32;
@ -68,6 +70,21 @@ namespace Wabbajack.Common
// file to check if the game is present, useful when steamIds and gogIds dont help
public List<string> RequiredFiles { get; internal set; }
public bool Disabled { get; internal set; }
public string InstalledVersion
{
get
{
if (GameLocation() == null)
throw new GameNotInstalledException(this);
if (MainExecutable == null)
throw new NotImplementedException();
return FileVersionInfo.GetVersionInfo(Path.Combine(GameLocation(), MainExecutable)).ProductVersion;
}
}
public string MainExecutable { get; internal set; }
public string GameLocation()
{
@ -79,6 +96,13 @@ namespace Wabbajack.Common
}
}
public class GameNotInstalledException : Exception
{
public GameNotInstalledException(GameMetaData gameMetaData) : base($"Game {gameMetaData.Game} does not appear to be installed.")
{
}
}
public class GameRegistry
{
public static GameMetaData GetByMO2ArchiveName(string gameName)
@ -125,7 +149,8 @@ namespace Wabbajack.Common
RequiredFiles = new List<string>
{
"oblivion.exe"
}
},
MainExecutable = "Oblivion.exe"
}
},
@ -143,7 +168,8 @@ namespace Wabbajack.Common
{
"falloutlauncher.exe",
"data\\fallout3.esm"
}
},
MainExecutable = "Fallout3.exe"
}
},
{
@ -159,7 +185,8 @@ namespace Wabbajack.Common
RequiredFiles = new List<string>
{
"FalloutNV.exe"
}
},
MainExecutable = "FalloutNV.exe"
}
},
{
@ -175,7 +202,8 @@ namespace Wabbajack.Common
RequiredFiles = new List<string>
{
"tesv.exe"
}
},
MainExecutable = "TESV.exe"
}
},
{
@ -191,7 +219,8 @@ namespace Wabbajack.Common
RequiredFiles = new List<string>
{
"SkyrimSE.exe"
}
},
MainExecutable = "SkyrimSE.exe"
}
},
{
@ -207,7 +236,8 @@ namespace Wabbajack.Common
RequiredFiles = new List<string>
{
"Fallout4.exe"
}
},
MainExecutable = "Fallout4.exe"
}
},
/*{

View File

@ -132,8 +132,6 @@ namespace Wabbajack.Common
return;
if(l.Contains("\"name\""))
steamGame.Name = GetVdfValue(l);
if (l.Contains("\"buildid\""))
steamGame.BuildId = GetVdfValue(l);
if (l.Contains("\"installdir\""))
{
var path = Path.Combine(p, "common", GetVdfValue(l));

View File

@ -37,6 +37,7 @@ namespace Wabbajack.Lib.Downloaders
Game = GameRegistry.GetByMO2ArchiveName(gameName).Game,
GameFile = gameFile,
Hash = hash,
GameVersion = GameRegistry.GetByMO2ArchiveName(gameName).InstalledVersion
};
}
@ -49,10 +50,12 @@ namespace Wabbajack.Lib.Downloaders
public Game Game { get; set; }
public string GameFile { get; set; }
public string Hash { get; set; }
public string GameVersion { get; set; }
internal string SourcePath => Path.Combine(Game.MetaData().GameLocation(), GameFile);
public override object[] PrimaryKey { get => new object[] {Game, GameFile}; }
public override object[] PrimaryKey { get => new object[] {Game, GameVersion, GameFile}; }
public override bool IsWhitelisted(ServerWhitelist whitelist)
{