From 67d0dc1ce7ceb7d95e42e7bd1aaef4c8e7380e48 Mon Sep 17 00:00:00 2001 From: Ben Richards Date: Thu, 11 Jul 2024 17:46:44 +0200 Subject: [PATCH] Fix for Loading Invalid Manifests - Added new GetManifest, wrapped in try/catch. - Updated ParseExeInstallerType to use GetManifest --- src/WingetCreateCore/Common/PackageParser.cs | 26 +++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/WingetCreateCore/Common/PackageParser.cs b/src/WingetCreateCore/Common/PackageParser.cs index c56312ed..bae69c9c 100644 --- a/src/WingetCreateCore/Common/PackageParser.cs +++ b/src/WingetCreateCore/Common/PackageParser.cs @@ -765,12 +765,11 @@ private static bool ParseExeInstallerType(string path, Installer baseInstaller, { try { - ManifestResource rc = new ManifestResource(); + XmlDocument manifest = GetManifest(path); InstallerType? installerTypeEnum; try { - rc.LoadFrom(path); - string installerType = rc.Manifest.DocumentElement + string installerType = manifest?.DocumentElement? .GetElementsByTagName("description") .Cast() .FirstOrDefault()? @@ -1049,5 +1048,26 @@ private static string RemoveInvalidCharsFromString(string value) { return Regex.Replace(value, InvalidCharacters, string.Empty); } + + /// + /// Gets the manifest from the specified path. + /// The path to the manifest. + /// XmlDocument of the manifest. + private static XmlDocument GetManifest(string path) + { + var rc = new ManifestResource(); + var manifest = new XmlDocument(); + + try + { + rc.LoadFrom(path); + manifest = rc.Manifest; + } + catch (Exception ex) + { + } + + return manifest; + } } }