Make file version finding safer

This commit is contained in:
Matt Nadareski
2021-08-23 20:45:13 -07:00
parent 5e560661d4
commit 5aae9b01d4
4 changed files with 32 additions and 18 deletions

View File

@@ -232,8 +232,8 @@ namespace BurnOutSharp.ProtectionType
{
if (files.Length > 0)
{
FileVersionInfo fvinfo = FileVersionInfo.GetVersionInfo(files[0]);
if (fvinfo.FileVersion != "")
var fvinfo = Utilities.GetFileVersionInfo(files[0]);
if (!string.IsNullOrWhiteSpace(fvinfo?.FileVersion))
{
version = fvinfo.FileVersion.Replace(" ", "").Replace(",", ".");
//ProtectDisc 9 uses a ProtectDisc-Core dll version 8.0.x
@@ -249,8 +249,8 @@ namespace BurnOutSharp.ProtectionType
files = Directory.GetFiles(Path.GetTempPath(), "a*.tmp");
if (files.Length > 0)
{
FileVersionInfo fvinfo = FileVersionInfo.GetVersionInfo(files[0]);
if (fvinfo.FileVersion != "")
var fvinfo = Utilities.GetFileVersionInfo(files[0]);
if (!string.IsNullOrWhiteSpace(fvinfo?.FileVersion))
{
version = fvinfo.FileVersion.Replace(" ", "").Replace(",", ".");
fvinfo = null;

View File

@@ -123,11 +123,8 @@ namespace BurnOutSharp.ProtectionType
public static string GetFileVersion(string file, byte[] fileContent, List<int> positions)
{
string companyName = string.Empty;
if (file != null)
companyName = FileVersionInfo.GetVersionInfo(file).CompanyName.ToLower();
if (companyName.Contains("solidshield") || companyName.Contains("tages"))
string companyName = Utilities.GetFileVersionInfo(file)?.CompanyName.ToLowerInvariant();
if (!string.IsNullOrWhiteSpace(companyName) && (companyName.Contains("solidshield") || companyName.Contains("tages")))
return Utilities.GetFileVersion(file);
return null;

View File

@@ -156,8 +156,8 @@ namespace BurnOutSharp.ProtectionType
{
if (files.Length > 0)
{
FileVersionInfo fvinfo = FileVersionInfo.GetVersionInfo(files[0]);
if (fvinfo.FileVersion != "")
var fvinfo = Utilities.GetFileVersionInfo(files[0]);
if (!string.IsNullOrWhiteSpace(fvinfo?.FileVersion))
{
version = fvinfo.FileVersion.Replace(" ", "").Replace(",", ".");
//ProtectDisc 9 uses a ProtectDisc-Core dll version 8.0.x
@@ -173,8 +173,8 @@ namespace BurnOutSharp.ProtectionType
files = Directory.GetFiles(Path.GetTempPath(), "a*.tmp");
if (files.Length > 0)
{
FileVersionInfo fvinfo = FileVersionInfo.GetVersionInfo(files[0]);
if (fvinfo.FileVersion != "")
var fvinfo = Utilities.GetFileVersionInfo(files[0]);
if (!string.IsNullOrWhiteSpace(fvinfo?.FileVersion))
{
version = fvinfo.FileVersion.Replace(" ", "").Replace(",", ".");
fvinfo = null;