Example #1
0
        private static bool YieldPackage(string path, string searchKey, Dictionary<string, string> properties, Request request)
        {
            var productName = properties.Get("DisplayName") ?? "";
            var productVersion = properties.Get("DisplayVersion") ?? "";
            var publisher = properties.Get("Publisher") ?? "";
            var uninstallString = properties.Get("QuietUninstallString") ?? properties.Get("UninstallString") ?? "";
            var comments = properties.Get("Comments") ?? "";
            var source = properties.Get("InstallLocation") ?? "";


            if (request.YieldSoftwareIdentity(path, productName, productVersion, "unknown", comments, source, searchKey, "", "") != null)
            {
                if (properties.Keys.Where(each => !string.IsNullOrWhiteSpace(each)).Any(k => request.AddMetadata(path, k.MakeSafeFileName(), properties[k]) == null))
                {
                    return false;
                }
            }
            return true;
        }
Example #2
0
        private static bool YieldPackages(string hive, RegistryKey regkey, string name, string displayname, string requiredVersion, string minimumVersion, string maximumVersion, PackageJson package, Request request)
        {
            //TODO make it wildcard match, follow the fastfrence format, get-package git no results, get-package git*

            if (regkey != null)
            {
                var includeSystemComponent = request.GetOptionValue("IncludeSystemComponent").IsTrue();

                foreach (var key in regkey.GetSubKeyNames())
                {
                    var subkey = regkey.OpenSubKey(key);
                    if (subkey != null)
                    {
                        var properties = subkey.GetValueNames().ToDictionaryNicely(each => each.ToString(), each => (subkey.GetValue(each) ?? string.Empty).ToString(), StringComparer.OrdinalIgnoreCase);

                        //if (!includeWindowsInstaller && properties.ContainsKey("WindowsInstaller") && properties["WindowsInstaller"] == "1")
                        //{
                        //    continue;
                        //}

                        if (!includeSystemComponent && properties.ContainsKey("SystemComponent") && properties["SystemComponent"] == "1")
                        {
                            continue;
                        }

                        var productName = "";

                        if (!properties.TryGetValue("DisplayName", out productName))
                        {
                            // no product name?
                            continue;
                        }

 
                        if (IsMatch(name, productName) || IsMatch(displayname, productName))
                        {
                            var productVersion = properties.Get("DisplayVersion") ?? "";
                            var publisher = properties.Get("Publisher") ?? "";
                            var uninstallString = properties.Get("QuietUninstallString") ?? properties.Get("UninstallString") ?? "";
                            var comments = properties.Get("Comments") ?? "";

                            var fp = hive + @"\" + subkey;

                            if (!string.IsNullOrEmpty(requiredVersion))
                            {
                                if (new SemanticVersion(requiredVersion) != new SemanticVersion(productVersion))
                                {
                                    continue;
                                }
                            }
                            else {
                                if (!string.IsNullOrEmpty(minimumVersion) && new SemanticVersion(minimumVersion) > new SemanticVersion(productVersion))
                                {
                                    continue;
                                }
                                if (!string.IsNullOrEmpty(maximumVersion) && new SemanticVersion(maximumVersion) < new SemanticVersion(productVersion))
                                {
                                    continue;
                                }
                            }

                            fp = PackageSourceListRequest.MakeFastPathComplex(package.Destination ?? "", package.Name, package.DisplayName, productVersion, fp);
  
                            var source = properties.Get("InstallLocation") ?? "";
                            //we use name here because find-package uses name (not displayname) in the PSL.json, 

                            if (request.YieldSoftwareIdentity(fp, name, productVersion, "unknown", comments, source, name, "", "") != null)
                            {
                                if (properties.Keys.Where(each => !string.IsNullOrWhiteSpace(each)).Any(k => request.AddMetadata(fp, k.MakeSafeFileName(), properties[k]) == null))
                                {
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
            return true;
        }