/// <summary> /// Enumerates related products and writes them to the pipeline. /// </summary> /// <param name="upgradeCode"></param> private void WriteProducts(string upgradeCode) { foreach (ProductInstallation product in ProductInstallation.GetRelatedProducts(upgradeCode)) { this.WriteProduct(product); } }
/// <summary> /// Returns the product version of the currently installed /// Microsoft.AccessibilityInsights application /// Returns null if the version could not be found /// - could occur if the application has not been installed at all /// - could occur if Windows Installer's cached MSI file is corrupted or deleted /// </summary> /// <returns></returns> public static string GetInstalledProductVersion(IExceptionReporter exceptionReporter) { if (exceptionReporter == null) { throw new ArgumentNullException(nameof(exceptionReporter)); } string targetUpgradeCode = UpdateGuid.ToUpperInvariant(); // Check whether application with target upgrade code is installed on this machine IEnumerable <ProductInstallation> installations = ProductInstallation.GetRelatedProducts(targetUpgradeCode); bool existingApp; try { existingApp = installations.Any(); } catch (ArgumentException e) { exceptionReporter.ReportException(e); // occurs when the upgrade code is formatted incorrectly // exception text: "Parameter is incorrect" return(null); } if (!existingApp) { // occurs when the upgrade code does not match any existing application return(null); } ProductInstallation existingInstall = installations.FirstOrDefault <ProductInstallation>(i => i.ProductVersion != null); if (existingInstall == null) { return(null); } string msiFilePath = existingInstall.LocalPackage; if (msiFilePath != null) { return(GetMSIProductVersion(msiFilePath)); } // Should only get here if LocalPackage not set return(null); }
///<inheritdoc/> public IEnumerable <IProductInstallation> GetRelatedProducts(string upgradeCode) { return(ProductInstallation.GetRelatedProducts(upgradeCode).Select(x => new ProductInstallationWrap(x) as IProductInstallation)); }