/// <summary>
        /// Converts a <see cref="String"/> in the short form like "omus" to a <see cref="ReinstallModes"/> enumeration.
        /// </summary>
        /// <param name="context">Additional context for conversion.</param>
        /// <param name="culture">The culture to use for conversion.</param>
        /// <param name="value">The <see cref="String"/> value to convert.</param>
        /// <returns>The converted <see cref="ReinstallModes"/> enumeration.</returns>
        /// <exception cref="ArgumentException">The short form string contains invalid characters.</exception>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (null != value && this.CanConvertFrom(context, value.GetType()))
            {
                string         s    = value as string;
                ReinstallModes mode = 0;

                // Attempt the simple coversion.
                if (TryParse(s, out mode))
                {
                    return(mode);
                }
                else
                {
                    // Try parsing the REINSTALLMODE property values.
                    foreach (char c in s)
                    {
                        if (CharToModeMap.ContainsKey(c))
                        {
                            mode |= CharToModeMap[c];
                        }
                        else
                        {
                            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Error_InvalidReinstallMode, c), "value");
                        }
                    }

                    return(mode);
                }
            }

            return(base.ConvertFrom(context, culture, value));
        }
Beispiel #2
0
        /// <summary>
        /// Reinstalls a product.
        /// </summary>
        /// <param name="product">Product code for the product to be reinstalled</param>
        /// <param name="reinstallModes">Reinstall modes</param>
        /// <exception cref="InstallCanceledException">the user exited the installation</exception>
        /// <remarks><p>
        /// Win32 MSI API:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msireinstallproduct.asp">MsiReinstallProduct</a>
        /// </p></remarks>
        public static void ReinstallProduct(string product, ReinstallModes reinstallModes)
        {
            uint ret = NativeMethods.MsiReinstallProduct(product, (uint)reinstallModes);

            if (ret != 0)
            {
                throw InstallerException.ExceptionFromReturnCode(ret);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Reinstalls a feature.
        /// </summary>
        /// <param name="product">Product code for the product containing the feature to be reinstalled</param>
        /// <param name="feature">Feature to be reinstalled</param>
        /// <param name="reinstallModes">Reinstall modes</param>
        /// <exception cref="InstallCanceledException">the user exited the installation</exception>
        /// <remarks><p>
        /// Win32 MSI API:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msireinstallfeature.asp">MsiReinstallFeature</a>
        /// </p></remarks>
        internal static void ReinstallFeature(string product, string feature, ReinstallModes reinstallModes)
        {
            uint ret = NativeMethods.MsiReinstallFeature(product, feature, (uint)reinstallModes);

            if (ret != 0)
            {
                throw InstallerException.ExceptionFromReturnCode(ret);
            }
        }
 private static bool TryParse(string value, out ReinstallModes mode)
 {
     try
     {
         mode = (ReinstallModes)Enum.Parse(typeof(ReinstallModes), value, true);
         return(true);
     }
     catch
     {
         mode = 0;
         return(false);
     }
 }
        /// <summary>
        /// Converts a <see cref="ReinstallModes"/> to a short form <see cref="String"/> like "omus".
        /// </summary>
        /// <param name="context">Additional context for conversion.</param>
        /// <param name="culture">The culture to use for conversion.</param>
        /// <param name="value">The <see cref="ReinstallModes"/> to convert.</param>
        /// <param name="destinationType">The type of the destination object.</param>
        /// <returns></returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (null != value && this.CanConvertTo(context, destinationType))
            {
                string         s    = string.Empty;
                ReinstallModes mode = (ReinstallModes)value;

                // Return the REINSTALLMODE property value form.
                foreach (ReinstallModes val in Enum.GetValues(typeof(ReinstallModes)))
                {
                    if (0 != (val & mode))
                    {
                        s += ModeToCharMap[val];
                    }
                }

                return(s);
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Beispiel #6
0
 /// <summary>
 /// Reinstalls a product.
 /// </summary>
 /// <param name="product">Product code for the product to be reinstalled</param>
 /// <param name="reinstallModes">Reinstall modes</param>
 /// <exception cref="InstallCanceledException">the user exited the installation</exception>
 /// <remarks><p>
 /// Win32 MSI API:
 /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msireinstallproduct.asp">MsiReinstallProduct</a>
 /// </p></remarks>
 public static void ReinstallProduct(string product, ReinstallModes reinstallModes)
 {
     uint ret = NativeMethods.MsiReinstallProduct(product, (uint) reinstallModes);
     if (ret != 0)
     {
         throw InstallerException.ExceptionFromReturnCode(ret);
     }
 }
Beispiel #7
0
 /// <summary>
 /// Reinstalls a feature.
 /// </summary>
 /// <param name="product">Product code for the product containing the feature to be reinstalled</param>
 /// <param name="feature">Feature to be reinstalled</param>
 /// <param name="reinstallModes">Reinstall modes</param>
 /// <exception cref="InstallCanceledException">the user exited the installation</exception>
 /// <remarks><p>
 /// Win32 MSI API:
 /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msireinstallfeature.asp">MsiReinstallFeature</a>
 /// </p></remarks>
 internal static void ReinstallFeature(string product, string feature, ReinstallModes reinstallModes)
 {
     uint ret = NativeMethods.MsiReinstallFeature(product, feature, (uint) reinstallModes);
     if (ret != 0)
     {
     throw InstallerException.ExceptionFromReturnCode(ret);
     }
 }
 private static bool TryParse(string value, out ReinstallModes mode)
 {
     try
     {
         mode = (ReinstallModes)Enum.Parse(typeof(ReinstallModes), value, true);
         return true;
     }
     catch
     {
         mode = 0;
         return false;
     }
 }