Пример #1
0
        private YamlDefinition CreateFromMsi(string filePath)
        {
            var msiProps = new Msi().GetProperties(filePath);

            var yamlDefinition = new YamlDefinition
            {
                Name        = msiProps.TryGetValue("ProductName", out var pn) ? pn : null,
                Version     = msiProps.TryGetValue("ProductVersion", out var pv) ? pv : null,
                Publisher   = msiProps.TryGetValue("Manufacturer", out var pm) ? pm : null,
                Description = msiProps.TryGetValue("ARPCOMMENTS", out var arpc) ? arpc : null,
                License     = msiProps.TryGetValue("ARPCONTACT", out var arpcont) ? arpcont : null,
                LicenseUrl  = msiProps.TryGetValue("ARPURLINFOABOUT", out var arpurl) || msiProps.TryGetValue("ARPHELPLINK", out arpurl) ? arpurl : null,
                // Language = msiProps.TryGetValue("ProductLanguage", out var pl) ? pl : null,
                Installers = new List <YamlInstaller>
                {
                    new YamlInstaller
                    {
                        InstallerType = YamlInstallerType.msi,
                        Scope         = msiProps.TryGetValue("ALLUSERS", out var allusers) && allusers == "1" ? YamlScope.machine : YamlScope.none,
                        Arch          = msiProps.TryGetValue("Template", out var template) && (template.IndexOf("Intel64", StringComparison.OrdinalIgnoreCase) != -1 || template.IndexOf("x64", StringComparison.OrdinalIgnoreCase) != -1 || template.IndexOf("amd64", StringComparison.OrdinalIgnoreCase) != -1) ? YamlArchitecture.x64 : YamlArchitecture.x86,
                    }
                }
            };

            if (yamlDefinition.License != null)
            {
                yamlDefinition.License = yamlDefinition.License.Trim();
                if (string.IsNullOrWhiteSpace(yamlDefinition.License))
                {
                    yamlDefinition.License = null;
                }

                yamlDefinition.License = yamlDefinition.License.Trim();
                if (string.IsNullOrWhiteSpace(yamlDefinition.LicenseUrl))
                {
                    yamlDefinition.LicenseUrl = null;
                }
            }

            return(yamlDefinition);
        }
Пример #2
0
        private YamlManifest CreateFromMsi(string filePath)
        {
            var msiProps = new Msi().GetProperties(filePath);

            var lcid = msiProps.TryGetValue("ProductLanguage", out var language) ? language : null;

            var yamlDefinition = new YamlManifest
            {
                PackageName         = msiProps.TryGetValue("ProductName", out var name) ? name   : null,
                PackageVersion      = msiProps.TryGetValue("ProductVersion", out var version) ? version  : null,
                Publisher           = msiProps.TryGetValue("Manufacturer", out var publisher) ? publisher : null,
                ShortDescription    = msiProps.TryGetValue("ARPCOMMENTS", out var comments) ? comments  : null,
                PublisherUrl        = msiProps.TryGetValue("ARPCONTACT", out var contactUrl) ? contactUrl : null,
                CopyrightUrl        = msiProps.TryGetValue("ARPURLINFOABOUT", out var url) ? url : null,
                PublisherSupportUrl = msiProps.TryGetValue("ARPHELPLINK", out var supportUrl) ? supportUrl : null,
                Installers          = new List <YamlInstaller>
                {
                    new YamlInstaller
                    {
                        InstallerType = YamlInstallerType.Msi,
                        Scope         = msiProps.TryGetValue("ALLUSERS", out var allUsers) && allUsers == "1" ? YamlScope.Machine : YamlScope.None,
                        Architecture  = msiProps.TryGetValue("Template", out var template) && (template.IndexOf("Intel64", StringComparison.OrdinalIgnoreCase) != -1 || template.IndexOf("x64", StringComparison.OrdinalIgnoreCase) != -1 || template.IndexOf("amd64", StringComparison.OrdinalIgnoreCase) != -1) ? YamlArchitecture.X64 : YamlArchitecture.X86,
                        Platform      = new List <YamlPlatform>()
                        {
                            YamlPlatform.WindowsDesktop
                        },
                        ProductCode = msiProps.TryGetValue("ProductCode", out var productCode) ? productCode : null,
                        // InstallModes = new List<YamlInstallMode> {YamlInstallMode.Interactive, YamlInstallMode.Silent, YamlInstallMode.SilentWithProgress },
                    }
                }
            };

            if (lcid != null && int.TryParse(lcid, out var lcidCode))
            {
                try
                {
                    var culture = CultureInfo.GetCultureInfo(lcid);
                    yamlDefinition.PackageLocale = culture.Name.ToLowerInvariant();
                    yamlDefinition.Installers[0].InstallerLocale = culture.Name.ToLowerInvariant();
                }
                catch
                {
                    // could not get culture by LCID.
                }
            }

            if (yamlDefinition.Copyright != null)
            {
                yamlDefinition.Copyright = yamlDefinition.Copyright.Trim();
                if (string.IsNullOrWhiteSpace(yamlDefinition.Copyright))
                {
                    yamlDefinition.Copyright = null;
                }

                yamlDefinition.Copyright = yamlDefinition.Copyright.Trim();
                if (string.IsNullOrWhiteSpace(yamlDefinition.CopyrightUrl))
                {
                    yamlDefinition.CopyrightUrl = null;
                }
            }

            return(yamlDefinition);
        }