src/WingetCreateCore/Common/PackageParser.cs
/// <summary>
/// Finds an existing installer that matches the new installer by checking the installerType and the following:
/// 1. Matching based on architecture specified as an override.
/// 2. Matching based on architecture detected from URL string or binary.
/// </summary>
/// <param name="newInstaller">New installer to be matched.</param>
/// <param name="existingInstallers">List of existing installers to be matched.</param>
/// <param name="installerManifest">Installer manifest.</param>
/// <param name="installerMetadata">Helper class for storing an installer's metadata information.</param>
/// <param name="unmatchedInstallers">List of unmatched installers.</param>
/// <param name="multipleMatchedInstallers">List of installers with multiple matches..</param>
/// <returns>The installer match from the list of existing installers.</returns>
Finds an existing installer that matches the new installer by checking the installerType and the following:
1. Matching based on architecture specified as an override.
2. Matching based on architecture detected from URL string or binary.
Finds an existing installer that matches the new installer by checking the installerType and the following : 1 . Matching based on architecture specified as an override . 2 . Matching based on architecture detected from URL string or binary .
private static Installer FindInstallerMatch(
            Installer newInstaller,
            List<Installer> existingInstallers,
            InstallerManifest installerManifest,
            InstallerMetadata installerMetadata,
            ref List<Installer> unmatchedInstallers,
            ref List<Installer> multipleMatchedInstallers)
        {
            var archMatches = existingInstallers.Where(
                i => (i.InstallerType ?? installerManifest.InstallerType) == newInstaller.InstallerType);
            var overrideArchMatches = archMatches.Where(i => i.Architecture == installerMetadata.OverrideArchitecture);
            if (overrideArchMatches.Count() == 1)
            {
                return overrideArchMatches.Single();
            }
            var binaryArchitecture = installerMetadata.BinaryArchitecture ?? newInstaller.Architecture;
            var binaryArchMatches = archMatches.Where(i => i.Architecture == binaryArchitecture);
            var urlArchMatches = archMatches.Where(i => i.Architecture == installerMetadata.UrlArchitecture);
            int numOfBinaryArchMatches = binaryArchMatches.Count();
            int numOfUrlArchMatches = urlArchMatches.Count();
            if (numOfUrlArchMatches > 1)
            {
                multipleMatchedInstallers.Add(newInstaller);
            }
            else if (numOfUrlArchMatches == 0)
            {
                if (numOfBinaryArchMatches == 0)
                {
                    unmatchedInstallers.Add(newInstaller);
                }
                else if (numOfBinaryArchMatches > 1)
                {
                    multipleMatchedInstallers.Add(newInstaller);
                }
            }
            var matchingExistingInstaller = numOfUrlArchMatches == 1 ? urlArchMatches.Single() : numOfBinaryArchMatches == 1 ? binaryArchMatches.Single() : null;
            return matchingExistingInstaller;
        }
private static Installer FindInstallerMatch ( Installer newInstaller , List < Installer > existingInstallers , InstallerManifest installerManifest , InstallerMetadata installerMetadata , ref List < Installer > unmatchedInstallers , ref List < Installer > multipleMatchedInstallers ) { var archMatches = existingInstallers . Where ( i => ( i . InstallerType ?? installerManifest . InstallerType ) == newInstaller . InstallerType ) ; var overrideArchMatches = archMatches . Where ( i => i . Architecture == installerMetadata . OverrideArchitecture ) ; if ( overrideArchMatches . Count ( ) == 1 ) { return overrideArchMatches . Single ( ) ; } var binaryArchitecture = installerMetadata . BinaryArchitecture ?? newInstaller . Architecture ; var binaryArchMatches = archMatches . Where ( i => i . Architecture == binaryArchitecture ) ; var urlArchMatches = archMatches . Where ( i => i . Architecture == installerMetadata . UrlArchitecture ) ; int numOfBinaryArchMatches = binaryArchMatches . Count ( ) ; int numOfUrlArchMatches = urlArchMatches . Count ( ) ; if ( numOfUrlArchMatches > 1 ) { multipleMatchedInstallers . Add ( newInstaller ) ; } else if ( numOfUrlArchMatches == 0 ) { if ( numOfBinaryArchMatches == 0 ) { unmatchedInstallers . Add ( newInstaller ) ; } else if ( numOfBinaryArchMatches > 1 ) { multipleMatchedInstallers . Add ( newInstaller ) ; } } var matchingExistingInstaller = numOfUrlArchMatches == 1 ? urlArchMatches . Single ( ) : numOfBinaryArchMatches == 1 ? binaryArchMatches . Single ( ) : null ; return matchingExistingInstaller ; }
Finds an existing installer that matches the new installer by checking the installerType and the following:
1.
Finds an existing installer that matches the new installer by checking the installerType and the following : 1 .
// If we can find an exact match by comparing the installerType and the override architecture, then return match. // Otherwise, continue and try matching based on arch detected from url and binary detection, as the user could be trying overwrite with a new architecture. // Msixbundle installers can have multiple installers with different architectures // For those installers, the binaryArchitecture will be detected as null, therefore we default to the architecture specified in the newInstaller object. // Count > 1 indicates multiple matches were found. Count == 0 indicates no matches were found. // Since url string matching isn't always reliable, failing to find a match is okay. // We only want to show an error if a string match finds multiple matches. // If url string matching fails to find a match, show all errors that may occur from ArchAndTypeMatches.
The installer match from the list of existing installers.
The installer match from the list of existing installers .
newInstaller
Installer
New installer to be matched.
New installer to be matched .
existingInstallers
List<Installer>
List of existing installers to be matched.
List of existing installers to be matched .
installerManifest
InstallerManifest
None
installerMetadata
InstallerMetadata
Helper class for storing an installer's metadata information.
Helper class for storing an installer ' s metadata information .
List<Installer>
ref
unmatchedInstallers
List of unmatched installers.
List of unmatched installers .
multipleMatchedInstallers
List of installers with multiple matches
List of installers with multiple matches