From 62ba319b50cf7bbea232a21702b0a627c268f599 Mon Sep 17 00:00:00 2001 From: josh-hemphill Date: Wed, 21 Dec 2022 17:04:45 -0800 Subject: [PATCH] Don't fail on exe's without embedded manifests --- src/WingetCreateCore/Common/PackageParser.cs | 62 ++++++++++++-------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/WingetCreateCore/Common/PackageParser.cs b/src/WingetCreateCore/Common/PackageParser.cs index 70091334..aee68e2a 100644 --- a/src/WingetCreateCore/Common/PackageParser.cs +++ b/src/WingetCreateCore/Common/PackageParser.cs @@ -676,31 +676,45 @@ private static bool ParseExeInstallerType(string path, Installer baseInstaller, { try { - ManifestResource rc = new ManifestResource(); - rc.LoadFrom(path); - string installerType = rc.Manifest.DocumentElement - .GetElementsByTagName("description") - .Cast() - .FirstOrDefault()? - .InnerText? - .Split(' ').First() - .ToLowerInvariant(); + ManifestResource rc = new ManifestResource(); + InstallerType? installerTypeEnum; + try + { + rc.LoadFrom(path); + string installerType = rc.Manifest.DocumentElement + .GetElementsByTagName("description") + .Cast() + .FirstOrDefault()? + .InnerText? + .Split(' ').First() + .ToLowerInvariant(); - InstallerType? installerTypeEnum; - - if (installerType.EqualsIC("wix")) - { - // See https://github.com/microsoft/winget-create/issues/26, a Burn installer is an exe-installer produced by the WiX toolset. - installerTypeEnum = InstallerType.Burn; - } - else if (KnownInstallerResourceNames.Contains(installerType)) - { - // If it's a known exe installer type, set as appropriately - installerTypeEnum = installerType.ToEnumOrDefault(); - } - else - { - installerTypeEnum = InstallerType.Exe; + if (installerType.EqualsIC("wix")) + { + // See https://github.com/microsoft/winget-create/issues/26, a Burn installer is an exe-installer produced by the WiX toolset. + installerTypeEnum = InstallerType.Burn; + } + else if (KnownInstallerResourceNames.Contains(installerType)) + { + // If it's a known exe installer type, set as appropriately + installerTypeEnum = installerType.ToEnumOrDefault(); + } + else + { + installerTypeEnum = InstallerType.Exe; + } + } + catch (Win32Exception err) + { + if (err.Message == "The specified resource type cannot be found in the image file." + && err.NativeErrorCode == 1813) + { + installerTypeEnum = InstallerType.Exe; + } + else + { + return false; + } } SetInstallerType(baseInstaller, installerTypeEnum.Value);