internal static void UpdateMachineConfigs(string rootPath, bool add)
 {
     string[] array = new string[]
     {
         "v2.0.50727",
         "v4.0.30319"
     };
     for (int i = 0; i < array.Length; i++)
     {
         string str  = array[i];
         string arg  = rootPath + str;
         string path = string.Format("{0}\\CONFIG", arg);
         if (Directory.Exists(path))
         {
             if (add)
             {
                 CustomInstaller.AddProviderToMachineConfigInDir(path);
             }
             else
             {
                 CustomInstaller.RemoveProviderFromMachineConfigInDir(path);
             }
         }
     }
 }
        private static void AddProviderToMachineConfig()
        {
            object expr_10 = Registry.GetValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\.NETFramework\\", "InstallRoot", null);

            if (expr_10 == null)
            {
                throw new Exception("Unable to retrieve install root for .NET framework");
            }
            CustomInstaller.UpdateMachineConfigs(expr_10.ToString(), true);
            string text = expr_10.ToString();

            text = text.Substring(0, text.Length - 1);
            text = string.Format("{0}64{1}", text, Path.DirectorySeparatorChar);
            if (Directory.Exists(text))
            {
                CustomInstaller.UpdateMachineConfigs(text, true);
            }
        }
Exemple #3
0
        private static void RemoveProviderFromMachineConfigInDir(string path)
        {
            string text = string.Format("{0}\\machine.config", path);

            if (!File.Exists(text))
            {
                return;
            }
            StreamReader streamReader = new StreamReader(text);
            string       xml          = streamReader.ReadToEnd();

            streamReader.Close();
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xml);
            XmlNodeList elementsByTagName = xmlDocument.GetElementsByTagName("DbProviderFactories");

            foreach (XmlNode xmlNode in elementsByTagName[0].ChildNodes)
            {
                if (xmlNode.Attributes != null)
                {
                    string value = xmlNode.Attributes["name"].Value;
                    if (value == "MySQL Data Provider")
                    {
                        elementsByTagName[0].RemoveChild(xmlNode);
                        break;
                    }
                }
            }
            try
            {
                xmlDocument = CustomInstaller.RemoveOldBindingRedirection(xmlDocument);
            }
            catch
            {
            }
            XmlTextWriter xmlTextWriter = new XmlTextWriter(text, null);

            xmlTextWriter.Formatting = Formatting.Indented;
            xmlDocument.Save(xmlTextWriter);
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
        }
 public override void Uninstall(IDictionary savedState)
 {
     base.Uninstall(savedState);
     CustomInstaller.RemoveProviderFromMachineConfig();
 }
 public override void Install(IDictionary stateSaver)
 {
     base.Install(stateSaver);
     CustomInstaller.AddProviderToMachineConfig();
 }
        private static void AddProviderToMachineConfigInDir(string path)
        {
            string text = string.Format("{0}\\machine.config", path);

            if (!File.Exists(text))
            {
                return;
            }
            StreamReader expr_1B = new StreamReader(text);
            string       xml     = expr_1B.ReadToEnd();

            expr_1B.Close();
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xml);
            xmlDocument = CustomInstaller.RemoveOldBindingRedirection(xmlDocument);
            XmlElement xmlElement = (XmlElement)xmlDocument.CreateNode(XmlNodeType.Element, "add", "");

            xmlElement.SetAttribute("name", "MySQL Data Provider");
            xmlElement.SetAttribute("invariant", "MySql.Data.MySqlClient");
            xmlElement.SetAttribute("description", ".Net Framework Data Provider for MySQL");
            Assembly executingAssembly = Assembly.GetExecutingAssembly();
            string   value             = string.Format("MySql.Data.MySqlClient.MySqlClientFactory, {0}", executingAssembly.FullName.Replace("Installers", "Data"));

            xmlElement.SetAttribute("type", value);
            XmlNodeList elementsByTagName = xmlDocument.GetElementsByTagName("DbProviderFactories");

            foreach (XmlNode xmlNode in elementsByTagName[0].ChildNodes)
            {
                if (xmlNode.Attributes != null)
                {
                    foreach (XmlAttribute xmlAttribute in xmlNode.Attributes)
                    {
                        if (xmlAttribute.Name == "invariant" && xmlAttribute.Value == "MySql.Data.MySqlClient")
                        {
                            elementsByTagName[0].RemoveChild(xmlNode);
                            break;
                        }
                    }
                }
            }
            elementsByTagName[0].AppendChild(xmlElement);
            try
            {
                XmlElement xmlElement2;
                if (xmlDocument.GetElementsByTagName("assemblyBinding").Count == 0)
                {
                    xmlElement2 = (XmlElement)xmlDocument.CreateNode(XmlNodeType.Element, "assemblyBinding", "");
                    xmlElement2.SetAttribute("xmlns", "urn:schemas-microsoft-com:asm.v1");
                }
                else
                {
                    xmlElement2 = (XmlElement)xmlDocument.GetElementsByTagName("assemblyBinding")[0];
                }
                string newVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                xmlElement2 = CustomInstaller.CreateNodeAssemblyBindingRedirection(xmlElement2, xmlDocument, "6.7.4.0", newVersion);
                xmlDocument.GetElementsByTagName("runtime")[0].AppendChild(xmlElement2);
            }
            catch
            {
            }
            XmlTextWriter xmlTextWriter = new XmlTextWriter(text, null);

            xmlTextWriter.Formatting = Formatting.Indented;
            xmlDocument.Save(xmlTextWriter);
            xmlTextWriter.Flush();
            xmlTextWriter.Close();
        }