src/WingetCreateCore/Common/PackageParser.cs
/// <summary>
/// Parses a package for available metadata including Version, Publisher, Name, Descripion, License, etc.
/// </summary>
/// <param name="installerMetadata">Helper class for storing an installer's metadata information.</param>
/// <param name="manifests">Wrapper object for manifest object models.</param>
/// <returns>True if package was successfully parsed and metadata extracted, false otherwise.</returns>
Parses a package for available metadata including Version, Publisher, Name, Descripion, License, etc.
Parses a package for available metadata including Version Publisher Name Descripion License etc .
private static bool ParsePackage(InstallerMetadata installerMetadata, Manifests manifests)
        {
            VersionManifest versionManifest = manifests.VersionManifest;
            InstallerManifest installerManifest = manifests.InstallerManifest;
            DefaultLocaleManifest defaultLocaleManifest = manifests.DefaultLocaleManifest;
            var versionInfo = FileVersionInfo.GetVersionInfo(installerMetadata.PackageFile);
            defaultLocaleManifest.PackageVersion ??= versionInfo.FileVersion?.Trim() ?? versionInfo.ProductVersion?.Trim();
            defaultLocaleManifest.Publisher ??= versionInfo.CompanyName?.Trim();
            defaultLocaleManifest.PackageName ??= versionInfo.ProductName?.Trim();
            defaultLocaleManifest.ShortDescription ??= versionInfo.FileDescription?.Trim();
            defaultLocaleManifest.License ??= versionInfo.LegalCopyright?.Trim();
            if (ParsePackageAndGenerateInstallerNodes(installerMetadata, manifests))
            {
                manifests.InstallerManifest.Installers.AddRange(installerMetadata.NewInstallers);
                if (!string.IsNullOrEmpty(defaultLocaleManifest.PackageVersion))
                {
                    versionManifest.PackageVersion = installerManifest.PackageVersion = RemoveInvalidCharsFromString(defaultLocaleManifest.PackageVersion);
                }
                string packageIdPublisher = defaultLocaleManifest.Publisher?.Remove(" ").Trim('.') ?? $"<{nameof(defaultLocaleManifest.Publisher)}>";
                string packageIdName = defaultLocaleManifest.PackageName?.Remove(" ").Trim('.') ?? $"<{nameof(defaultLocaleManifest.PackageName)}>";
                versionManifest.PackageIdentifier ??= $"{RemoveInvalidCharsFromString(packageIdPublisher)}.{RemoveInvalidCharsFromString(packageIdName)}";
                installerManifest.PackageIdentifier = defaultLocaleManifest.PackageIdentifier = versionManifest.PackageIdentifier;
                return true;
            }
            else
            {
                return false;
            }
        }
private static bool ParsePackage ( InstallerMetadata installerMetadata , Manifests manifests ) { VersionManifest versionManifest = manifests . VersionManifest ; InstallerManifest installerManifest = manifests . InstallerManifest ; DefaultLocaleManifest defaultLocaleManifest = manifests . DefaultLocaleManifest ; var versionInfo = FileVersionInfo . GetVersionInfo ( installerMetadata . PackageFile ) ; defaultLocaleManifest . PackageVersion ??= versionInfo . FileVersion ? . Trim ( ) ?? versionInfo . ProductVersion ? . Trim ( ) ; defaultLocaleManifest . Publisher ??= versionInfo . CompanyName ? . Trim ( ) ; defaultLocaleManifest . PackageName ??= versionInfo . ProductName ? . Trim ( ) ; defaultLocaleManifest . ShortDescription ??= versionInfo . FileDescription ? . Trim ( ) ; defaultLocaleManifest . License ??= versionInfo . LegalCopyright ? . Trim ( ) ; if ( ParsePackageAndGenerateInstallerNodes ( installerMetadata , manifests ) ) { manifests . InstallerManifest . Installers . AddRange ( installerMetadata . NewInstallers ) ; if ( ! string . IsNullOrEmpty ( defaultLocaleManifest . PackageVersion ) ) { versionManifest . PackageVersion = installerManifest . PackageVersion = RemoveInvalidCharsFromString ( defaultLocaleManifest . PackageVersion ) ; } string packageIdPublisher = defaultLocaleManifest . Publisher ? . Remove ( " " ) . Trim ( ' ' ) ?? $" < { nameof ( defaultLocaleManifest . Publisher ) } > " ; string packageIdName = defaultLocaleManifest . PackageName ? . Remove ( " " ) . Trim ( ' ' ) ?? $" < { nameof ( defaultLocaleManifest . PackageName ) } > " ; versionManifest . PackageIdentifier ??= $" { RemoveInvalidCharsFromString ( packageIdPublisher ) } . { RemoveInvalidCharsFromString ( packageIdName ) } " ; installerManifest . PackageIdentifier = defaultLocaleManifest . PackageIdentifier = versionManifest . PackageIdentifier ; return true ; } else { return false ; } }
Parses a package for available metadata including Version, Publisher, Name, Descripion, License, etc.
Parses a package for available metadata including Version Publisher Name Descripion License etc .
// Add range of new installers generates from parsing the package.
True if package was successfully parsed and metadata extracted, false otherwise.
True if package was successfully parsed and metadata extracted false otherwise .
installerMetadata
InstallerMetadata
Helper class for storing an installer's metadata information.
Helper class for storing an installer ' s metadata information .
manifests
Manifests
Wrapper object for manifest object models.
Wrapper object for manifest object models .