Example #1
0
 /// <summary>
 /// Enumerates the selected components and write them to the pipeline.
 /// </summary>
 protected override void EndProcessing()
 {
     this.allParameters.ForEach((param) =>
     {
         if (param.ParameterSetName == ParameterSet.Component)
         {
             if (param.ComponentCode != null && param.ComponentCode.Length > 0)
             {
                 // Enumerate all clients for a component.
                 foreach (string componentCode in param.ComponentCode)
                 {
                     ComponentInstallation component = new ComponentInstallation(componentCode);
                     this.WriteSharedComponent(component);
                 }
             }
             else
             {
                 // Enumerate all components.
                 foreach (ComponentInstallation component in ComponentInstallation.AllComponents)
                 {
                     this.WriteSharedComponent(component);
                 }
             }
         }
         else if (param.ParameterSetName == ParameterSet.Product)
         {
             // Enumerate all components for the specified product.
             foreach (string componentCode in param.ComponentCode)
             {
                 ComponentInstallation component = new ComponentInstallation(componentCode, param.ProductCode);
                 this.WriteComponent(component);
             }
         }
     });
 }
Example #2
0
        public static string GetComponentInfo(string prodCode, string compId, MsiComponentSearchType type)
        {
            string msiComponent      = string.Empty;
            ComponentInstallation ci = null;

            if (string.IsNullOrEmpty(prodCode))
            {
                ci = new ComponentInstallation(compId);
            }
            else
            {
                ci = new ComponentInstallation(compId, prodCode);
            }

            switch (type)
            {
            case MsiComponentSearchType.directory:
                msiComponent = ci.Path;     // TODO
                break;

            case MsiComponentSearchType.keyPath:
                msiComponent = ci.Path;
                break;

            case MsiComponentSearchType.state:
                msiComponent = ci.State.ToString();
                break;
            }

            return(msiComponent);
        }
        private static string GetPreviousVersionInstallPath()
        {
            var retVal = String.Empty;

            var products = ProductInstallation.GetProducts("{944871E7-9F8D-47B7-BE04-103E4C8F2254}", null, UserContexts.All);
            var product  = products?.FirstOrDefault();
            var location = product?.LocalPackage;

            if (location != null)
            {
                var package     = new InstallPackage(location, DatabaseOpenMode.ReadOnly);
                var componentId = package.Files.FirstOrDefault(kvp => kvp.Value.SourceName == "UO Bulk Order Deeds.exe").Key;

                if (componentId != null)
                {
                    var results = package.ExecuteQuery($"SELECT `ComponentId` FROM `Component` WHERE `Component` = 'C_{componentId}'");
                    var result  = results?.Count > 0 ? results[0].ToString() : null;

                    if (result != null)
                    {
                        var componentInstallation = new ComponentInstallation(result);
                        var componentPath         = componentInstallation.Path;

                        retVal = Path.GetDirectoryName(componentPath);
                    }
                }
            }

            return(retVal);
        }
Example #4
0
        /// <summary>
        /// Returns the component path if any component is installed.
        /// </summary>
        /// <param name="what">What component to find.</param>
        /// <returns>The component path if any component is installed.</returns>
        internal static string Find(KnownComponent what)
        {
            ICollection <string> componentIds = null;

            switch (what)
            {
            case KnownComponent.Orca:
                componentIds = new string[]
                {
                    "{958A3933-8CE7-6189-F0EF-CAE467FABFF4}",     // Orca > 8.0
                    "{BE928E10-272A-11D2-B2E4-006097C99860}",     // Orca <= 5.0
                };
                break;

            case KnownComponent.Darice:
                componentIds = new string[]
                {
                    "{D865CA5E-9B46-B345-B3A6-43C5EAF209E0}",     // Orca > 8.0
                    "{EAB27DFE-90C6-11D2-88AC-00A0C981B015}",     // Orca <= 5.0
                };
                break;
            }

            foreach (var componentId in componentIds)
            {
                var component = new ComponentInstallation(componentId);
                if (InstallState.Local == component.State)
                {
                    return(component.Path);
                }
            }

            return(null);
        }
Example #5
0
 /// <summary>
 /// Enumerates clients of the component and writes each client-specific component to the pipeline.
 /// </summary>
 /// <param name="component">The shared <see cref="ComponentInstallation"/> object to write to the pipeline.</param>
 private void WriteSharedComponent(ComponentInstallation component)
 {
     foreach (ProductInstallation client in component.ClientProducts)
     {
         ComponentInstallation shared = new ComponentInstallation(component.ComponentCode, client.ProductCode);
         this.WriteComponent(shared);
     }
 }
Example #6
0
        /// <summary>
        /// Increments the use count and sets the last used date if the Module installer was installed.
        /// </summary>
        public static void Use()
        {
            // Enumerate all clients for the primary component if installed.
            ComponentInstallation comp = new ComponentInstallation(ModuleId);

            foreach (ProductInstallation product in comp.ClientProducts)
            {
                // If the feature is installed locally for this client, increment usage.
                FeatureInstallation feature = new FeatureInstallation(FeatureName, product.ProductCode);
                if (feature.State == InstallState.Local)
                {
                    Installer.UseFeature(product.ProductCode, FeatureName, InstallMode.NoDetection);
                }
            }
        }
Example #7
0
        public DataView GetComponentProductsData(string componentCode)
        {
            DataTable table = new DataTable("ComponentProducts");

            table.Locale = CultureInfo.InvariantCulture;
            table.Columns.Add("ComponentProductsProductName", typeof(string));
            table.Columns.Add("ComponentProductsProductCode", typeof(string));
            table.Columns.Add("ComponentProductsComponentPath", typeof(string));

            if (this.componentProductsMap != null)
            {
                ArrayList componentProducts = (ArrayList)this.componentProductsMap[componentCode];
                foreach (string productCode in componentProducts)
                {
                    string productName   = MsiUtils.GetProductName(productCode);
                    string componentPath = new ComponentInstallation(componentCode, productCode).Path;
                    table.Rows.Add(new object[] { productName, productCode, componentPath });
                }
                return(new DataView(table, "", "ComponentProductsProductName ASC", DataViewRowState.CurrentRows));
            }
            return(null);
        }
Example #8
0
        /// <summary>
        /// Attaches additional properties to the component and writes it to the pipeline.
        /// </summary>
        /// <param name="component">The <see cref="ComponentInstallation"/> object to write to the pipeline.</param>
        private void WriteComponent(ComponentInstallation component)
        {
            PSObject obj = PSObject.AsPSObject(component);

            this.WriteObject(obj);
        }
Example #9
0
        private object[][] GetComponentRegistryRows(string productCode, string componentCode, Session session, bool includeComponent)
        {
            ArrayList rows          = new ArrayList();
            string    componentPath = new ComponentInstallation(componentCode, productCode).Path;

            string componentKey = (string)session.Database.ExecuteScalar(
                "SELECT `Component` FROM `Component` WHERE `ComponentId` = '{0}'", componentCode);

            if (componentKey == null)
            {
                return(null);
            }
            int attributes = Convert.ToInt32(session.Database.ExecuteScalar(
                                                 "SELECT `Attributes` FROM `Component` WHERE `Component` = '{0}'", componentKey));
            bool registryKeyPath = (attributes & (int)ComponentAttributes.RegistryKeyPath) != 0;

            if (!registryKeyPath && componentPath.Length > 0)
            {
                componentPath = Path.GetDirectoryName(componentPath);
            }
            string keyPath = (string)session.Database.ExecuteScalar(
                "SELECT `KeyPath` FROM `Component` WHERE `Component` = '{0}'", componentKey);

            using (View view = session.Database.OpenView("SELECT `Registry`, `Root`, `Key`, `Name`, " +
                                                         "`Value` FROM `Registry` WHERE `Component_` = '{0}'", componentKey))
            {
                view.Execute();

                foreach (Record rec in view)
                {
                    using (rec)
                    {
                        string regName = (string)rec["Name"];
                        if (regName == "-")
                        {
                            continue;                                 // Don't list deleted keys
                        }
                        string regTableKey = (string)rec["Registry"];
                        bool   isKey       = registryKeyPath && keyPath == regTableKey;
                        string regPath     = this.GetRegistryPath(session, (RegistryRoot)Convert.ToInt32(rec["Root"]),
                                                                  (string)rec["Key"], (string)rec["Name"]);

                        string dbValue;
                        using (Record formatRec = new Record(0))
                        {
                            formatRec[0] = rec["Value"];
                            dbValue      = session.FormatRecord(formatRec);
                        }

                        string installedValue = this.GetRegistryValue(regPath);
                        bool   exists         = installedValue != null;
                        if (!exists)
                        {
                            installedValue = "";
                        }
                        bool match = installedValue == dbValue;

                        object[] row;
                        if (includeComponent)
                        {
                            row = new object[] { isKey, regTableKey, regPath, exists, dbValue, installedValue, match, componentCode }
                        }
                        ;
                        else
                        {
                            row = new object[] { isKey, regTableKey, regPath, exists, dbValue, installedValue, match }
                        };
                        rows.Add(row);
                    }
                }
            }

            return((object[][])rows.ToArray(typeof(object[])));
        }
Example #10
0
        private object[][] GetComponentFilesRows(string productCode, string componentCode, Session session, bool includeComponent)
        {
            ArrayList rows          = new ArrayList();
            string    componentPath = new ComponentInstallation(componentCode, productCode).Path;

            string componentKey = (string)session.Database.ExecuteScalar(
                "SELECT `Component` FROM `Component` WHERE `ComponentId` = '{0}'", componentCode);

            if (componentKey == null)
            {
                return(null);
            }
            int attributes = Convert.ToInt32(session.Database.ExecuteScalar(
                                                 "SELECT `Attributes` FROM `Component` WHERE `Component` = '{0}'", componentKey));
            bool registryKeyPath = (attributes & (int)ComponentAttributes.RegistryKeyPath) != 0;

            if (!registryKeyPath && componentPath.Length > 0)
            {
                componentPath = Path.GetDirectoryName(componentPath);
            }
            string keyPath = (string)session.Database.ExecuteScalar(
                "SELECT `KeyPath` FROM `Component` WHERE `Component` = '{0}'", componentKey);

            using (View view = session.Database.OpenView("SELECT `File`, `FileName`, `Version`, `Language`, " +
                                                         "`Attributes` FROM `File` WHERE `Component_` = '{0}'", componentKey))
            {
                view.Execute();

                foreach (Record rec in view)
                {
                    using (rec)
                    {
                        string fileKey = (string)rec["File"];
                        bool   isKey   = !registryKeyPath && keyPath == fileKey;

                        string dbVersion     = (string)rec["Version"];
                        bool   versionedFile = dbVersion.Length != 0;
                        if (versionedFile)
                        {
                            string language = (string)rec["Language"];
                            if (language.Length > 0)
                            {
                                dbVersion = dbVersion + " (" + language + ")";
                            }
                        }
                        else if (session.Database.Tables.Contains("MsiFileHash"))
                        {
                            IList <int> hash = session.Database.ExecuteIntegerQuery("SELECT `HashPart1`, `HashPart2`, " +
                                                                                    "`HashPart3`, `HashPart4` FROM `MsiFileHash` WHERE `File_` = '{0}'", fileKey);
                            if (hash != null && hash.Count == 4)
                            {
                                dbVersion = this.GetFileHashString(hash);
                            }
                        }

                        string filePath         = GetLongFileName((string)rec["FileName"]);
                        bool   exists           = false;
                        bool   installedMatch   = false;
                        string installedVersion = "";
                        if (!registryKeyPath && componentPath.Length > 0)
                        {
                            filePath = Path.Combine(componentPath, filePath);

                            if (File.Exists(filePath))
                            {
                                exists = true;
                                if (versionedFile)
                                {
                                    installedVersion = Installer.GetFileVersion(filePath);
                                    string language = Installer.GetFileLanguage(filePath);
                                    if (language.Length > 0)
                                    {
                                        installedVersion = installedVersion + " (" + language + ")";
                                    }
                                }
                                else
                                {
                                    int[] hash = new int[4];
                                    Installer.GetFileHash(filePath, hash);
                                    installedVersion = this.GetFileHashString(hash);
                                }
                                installedMatch = installedVersion == dbVersion;
                            }
                        }

                        object[] row;
                        if (includeComponent)
                        {
                            row = new object[] { isKey, fileKey, filePath, exists, dbVersion, installedVersion, installedMatch, componentCode }
                        }
                        ;
                        else
                        {
                            row = new object[] { isKey, fileKey, filePath, exists, dbVersion, installedVersion, installedMatch }
                        };
                        rows.Add(row);
                    }
                }
            }

            return((object[][])rows.ToArray(typeof(object[])));
        }