public void AddMissingInformation(ApplicationUninstallerEntry target)
        {
            if (string.IsNullOrEmpty(target.DisplayVersion))
            {
                return;
            }

            ApplicationEntryTools.CleanupDisplayVersion(target.DisplayVersion);
        }
Exemple #2
0
        /// <summary>
        ///     A valid guid is REQUIRED. It doesn't have to be set on the entry, but should be.
        /// </summary>
        private static void ApplyMsiInfo(ApplicationUninstallerEntry entry, Guid guid)
        {
            //IMPORTANT: If MsiGetProductInfo returns null it means that the guid is invalid or app is not installed
            if (MsiTools.MsiGetProductInfo(guid, MsiWrapper.INSTALLPROPERTY.PRODUCTNAME) == null)
            {
                return;
            }

            FillInMissingInfoMsiHelper(() => entry.RawDisplayName, x => entry.RawDisplayName = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.INSTALLEDPRODUCTNAME, MsiWrapper.INSTALLPROPERTY.PRODUCTNAME);

            FillInMissingInfoMsiHelper(() => entry.DisplayVersion, x => entry.DisplayVersion = ApplicationEntryTools.CleanupDisplayVersion(x), guid,
                                       MsiWrapper.INSTALLPROPERTY.VERSIONSTRING, MsiWrapper.INSTALLPROPERTY.VERSION);

            FillInMissingInfoMsiHelper(() => entry.Publisher, x => entry.Publisher = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.PUBLISHER);

            FillInMissingInfoMsiHelper(() => entry.InstallLocation, x => entry.InstallLocation = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.INSTALLLOCATION);

            FillInMissingInfoMsiHelper(() => entry.InstallSource, x => entry.InstallSource = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.INSTALLSOURCE);

            FillInMissingInfoMsiHelper(() => entry.UninstallerFullFilename, x => entry.UninstallerFullFilename = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.LOCALPACKAGE);

            FillInMissingInfoMsiHelper(() => entry.DisplayIcon, x => entry.DisplayIcon = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.PRODUCTICON);

            FillInMissingInfoMsiHelper(() => entry.AboutUrl, x => entry.AboutUrl = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.HELPLINK, MsiWrapper.INSTALLPROPERTY.URLUPDATEINFO,
                                       MsiWrapper.INSTALLPROPERTY.URLINFOABOUT);

            if (!entry.InstallDate.IsDefault())
            {
                return;
            }
            var temp = MsiTools.MsiGetProductInfo(guid, MsiWrapper.INSTALLPROPERTY.INSTALLDATE);

            if (!temp.IsNotEmpty())
            {
                return;
            }
            try
            {
                entry.InstallDate = new DateTime(int.Parse(temp.Substring(0, 4)),
                                                 int.Parse(temp.Substring(4, 2)),
                                                 int.Parse(temp.Substring(6, 2)));
            }
            catch
            {
                // Date had invalid format, default to nothing
            }
        }
Exemple #3
0
        /// <summary>
        /// Add information from FileVersionInfo of specified file to the targetEntry
        /// </summary>
        /// <param name="targetEntry">Entry to update</param>
        /// <param name="infoSourceFilename">Binary file to get the information from</param>
        /// <param name="onlyUnpopulated">Only update unpopulated fields of the targetEntry</param>
        internal static void FillInformationFromFileAttribs(ApplicationUninstallerEntry targetEntry, string infoSourceFilename, bool onlyUnpopulated)
        {
            FileVersionInfo verInfo;

            try
            {
                verInfo = FileVersionInfo.GetVersionInfo(infoSourceFilename);
            }
            catch
            {
                return;
            }

            Func <string, bool> unpopulatedCheck;

            if (onlyUnpopulated)
            {
                unpopulatedCheck = target => string.IsNullOrEmpty(target?.Trim());
            }
            else
            {
                unpopulatedCheck = target => true;
            }

            var companyName = verInfo.CompanyName?.Trim();

            if (unpopulatedCheck(targetEntry.Publisher) && !string.IsNullOrEmpty(companyName))
            {
                targetEntry.Publisher = companyName;
            }

            if (unpopulatedCheck(targetEntry.RawDisplayName))
            {
                var productName = StringTools.StripStringFromVersionNumber(verInfo.FileDescription?.Trim());
                if (!string.IsNullOrEmpty(productName))
                {
                    targetEntry.RawDisplayName = productName;
                }
                else
                {
                    productName = verInfo.ProductName?.Trim();
                    if (!string.IsNullOrEmpty(productName))
                    {
                        targetEntry.RawDisplayName = productName;
                    }
                }
            }

            var comment = verInfo.Comments?.Trim();

            if (unpopulatedCheck(targetEntry.Comment) && !string.IsNullOrEmpty(comment))
            {
                targetEntry.Comment = comment;
            }

            if (unpopulatedCheck(targetEntry.DisplayVersion))
            {
                var productVersion = verInfo.ProductVersion?.Trim();
                if (string.IsNullOrEmpty(productVersion))
                {
                    productVersion = verInfo.FileVersion?.Trim();
                }

                if (!string.IsNullOrEmpty(productVersion))
                {
                    targetEntry.DisplayVersion = ApplicationEntryTools.CleanupDisplayVersion(productVersion);
                }
            }
        }