From edc4cc17067ee360de17be95a1a985d2ae82e315 Mon Sep 17 00:00:00 2001 From: SilasLaspada Date: Fri, 1 Apr 2022 10:58:02 -0600 Subject: [PATCH] Refactor Setup Factory detection (#115) * Refactor Setup Factory detection * Address Setup Factory PR comments * Fix whitespace --- BurnOutSharp/PackerType/SetupFactory.cs | 19 +++++++++++++++---- BurnOutSharp/Tools/Utilities.cs | 11 +++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/BurnOutSharp/PackerType/SetupFactory.cs b/BurnOutSharp/PackerType/SetupFactory.cs index 69143a04..6f49e872 100644 --- a/BurnOutSharp/PackerType/SetupFactory.cs +++ b/BurnOutSharp/PackerType/SetupFactory.cs @@ -19,14 +19,20 @@ namespace BurnOutSharp.PackerType if (sections == null) return null; + // Known to detect versions 7.0.5.1 - 9.1.0.0 string name = Utilities.GetLegalCopyright(pex); - if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("Setup Factory", StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("Setup Engine", StringComparison.OrdinalIgnoreCase)) return $"Setup Factory {GetVersion(pex)}"; name = Utilities.GetProductName(pex); if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("Setup Factory", StringComparison.OrdinalIgnoreCase)) return $"Setup Factory {GetVersion(pex)}"; + // Known to detect version 5.0.1 - 6.0.1.3 + name = Utilities.GetFileDescription(pex); + if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("Setup Factory", StringComparison.OrdinalIgnoreCase)) + return $"Setup Factory {GetVersion(pex)}"; + // Longer version of the check that can be used if false positves become an issue: // "Setup Factory is a trademark of Indigo Rose Corporation" @@ -55,16 +61,21 @@ namespace BurnOutSharp.PackerType private string GetVersion(PortableExecutable pex) { - // Check the manifest version first - string version = Utilities.GetManifestVersion(pex); + // Check the product version first + string version = Utilities.GetProductVersion(pex); if (!string.IsNullOrEmpty(version)) return version; - + // Then check the file version version = Utilities.GetFileVersion(pex); if (!string.IsNullOrEmpty(version)) return version; + // Then check the manifest version + version = Utilities.GetManifestVersion(pex); + if (!string.IsNullOrEmpty(version)) + return version; + return "(Unknown Version)"; } } diff --git a/BurnOutSharp/Tools/Utilities.cs b/BurnOutSharp/Tools/Utilities.cs index d93d39a1..cb98a2dc 100644 --- a/BurnOutSharp/Tools/Utilities.cs +++ b/BurnOutSharp/Tools/Utilities.cs @@ -237,9 +237,9 @@ namespace BurnOutSharp.Tools if (!string.IsNullOrWhiteSpace(version)) return version.Replace(", ", "."); - version = GetResourceString(pex, "ProductVersion"); + version = GetProductVersion(pex); if (!string.IsNullOrWhiteSpace(version)) - return version.Replace(", ", "."); + return version; return null; } @@ -366,6 +366,13 @@ namespace BurnOutSharp.Tools /// Product name string, null on error public static string GetProductName(PortableExecutable pex) => GetResourceString(pex, "ProductName"); + /// + /// Get the product name as reported by the filesystem + /// + /// PortableExecutable representing the file contents + /// Product version string, null on error + public static string GetProductVersion(PortableExecutable pex) => GetResourceString(pex, "ProductVersion")?.Replace(", ", "."); + /// /// Find resource data in a ResourceSection, if possible ///