private static void InitIsSystemAssembly() { SystemAssemblies = new List<string>(); AssemblyCacheEnum asmEnum = new AssemblyCacheEnum(null); string nextAsm; while ((nextAsm = asmEnum.GetNextAssembly()) != null) { SystemAssemblies.Add(nextAsm.Split(',')[0]); } int count1 = SystemAssemblies.Count(); SystemAssemblies = SystemAssemblies.Distinct().OrderBy(a => a).ToList(); int count2 = SystemAssemblies.Count(); }
private static void InitIsSystemAssembly() { SystemAssemblies = new List<string>(); AssemblyCacheEnum asmEnum = new AssemblyCacheEnum(null); string nextAsm; while ((nextAsm = asmEnum.GetNextAssembly()) != null) { SystemAssemblies.Add(nextAsm.Split(',')[0]); } int count1 = SystemAssemblies.Count(); SystemAssemblies = SystemAssemblies.Distinct().OrderBy(a => a).ToList(); int count2 = SystemAssemblies.Count(); ConsoleHelper.WriteLine("Found " + count1 + " GAC assemblies, " + count2 + " unique names.", true); foreach (string gacass in SystemAssemblies) { ConsoleHelper.WriteLine("'" + gacass + "'", true); } }
private void GlobalAddRemove(string version) { bool install = false; // bool installed; //// Check to see if SQLite is installed in the GAC //try //{ // string file = AssemblyCache.QueryAssemblyInfo("System.Data.SQLite"); // installed = true; //} //catch //{ // installed = false; //} // Check to see if any checkboxes in the list are checked for (int n = 0; n < installList.Items.Count; n++) { if (installList.Items[n].Checked == true) { install = true; break; } } // If at least 1 item is checked, then install some global settings if (install) { string path = Path.GetDirectoryName(SQLiteLocation); foreach (string framework in _frameworks) { using (RegistryKey key = Registry.LocalMachine.CreateSubKey(String.Format("Software\\Microsoft\\.NETFramework\\{0}\\AssemblyFoldersEx\\SQLite", framework), RegistryKeyPermissionCheck.ReadWriteSubTree)) { key.SetValue(null, path); } } while (String.IsNullOrEmpty(path) == false) { if (File.Exists(path + "\\CompactFramework\\System.Data.SQLite.DLL") == false) { path = Path.GetDirectoryName(path); } else break; } if (String.IsNullOrEmpty(path) == false) { path += "\\CompactFramework\\"; for (int n = 0; n < compactFrameworks.Length; n++) { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\.NETCompactFramework\\v2.0.0.0\\{0}\\AssemblyFoldersEx", compactFrameworks[n]), true)) { if (key != null) { using (RegistryKey subkey = key.CreateSubKey("SQLite", RegistryKeyPermissionCheck.ReadWriteSubTree)) { subkey.SetValue(null, path); } } } } for (int n = 0; n < compactFrameworks.Length; n++) { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\.NETCompactFramework\\v3.5.0.0\\{0}\\AssemblyFoldersEx", compactFrameworks[n]), true)) { if (key != null) { using (RegistryKey subkey = key.CreateSubKey("SQLite", RegistryKeyPermissionCheck.ReadWriteSubTree)) { subkey.SetValue(null, path); } } } } } for (int n = 0; n < 2; n++) { foreach (string framework in _frameworks) { // Add factory support to the machine.config file. try { string xmlFileName = Environment.ExpandEnvironmentVariables(String.Format("%WinDir%\\Microsoft.NET\\{0}\\{1}\\CONFIG\\machine.config", (n == 0) ? "Framework" : "Framework64", framework)); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.PreserveWhitespace = true; xmlDoc.Load(xmlFileName); XmlNode xmlNode = xmlDoc.SelectSingleNode("configuration/system.data/DbProviderFactories/add[@invariant=\"System.Data.SQLite\"]"); if (xmlNode == null) { XmlNode xmlConfig = xmlDoc.SelectSingleNode("configuration"); if (xmlConfig != null) { XmlNode xmlData = xmlConfig.SelectSingleNode("system.data"); if (xmlData == null) { xmlData = xmlDoc.CreateNode(XmlNodeType.Element, "system.data", ""); xmlConfig.AppendChild(xmlData); } XmlNode xmlParent = xmlData.SelectSingleNode("DbProviderFactories"); if (xmlParent == null) { xmlParent = xmlDoc.CreateNode(XmlNodeType.Element, "DbProviderFactories", ""); xmlData.AppendChild(xmlParent); } //xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "remove", ""); //xmlNode.Attributes.SetNamedItem(xmlDoc.CreateAttribute("invariant")); //xmlParent.AppendChild(xmlNode); //xmlNode.Attributes.GetNamedItem("invariant").Value = "System.Data.SQLite"; xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "add", ""); xmlNode.Attributes.SetNamedItem(xmlDoc.CreateAttribute("name")); xmlNode.Attributes.SetNamedItem(xmlDoc.CreateAttribute("invariant")); xmlNode.Attributes.SetNamedItem(xmlDoc.CreateAttribute("description")); xmlNode.Attributes.SetNamedItem(xmlDoc.CreateAttribute("type")); xmlParent.AppendChild(xmlNode); } } xmlNode.Attributes.GetNamedItem("name").Value = "SQLite Data Provider"; xmlNode.Attributes.GetNamedItem("invariant").Value = "System.Data.SQLite"; xmlNode.Attributes.GetNamedItem("description").Value = ".Net Framework Data Provider for SQLite"; xmlNode.Attributes.GetNamedItem("type").Value = "System.Data.SQLite.SQLiteFactory, " + SQLite.GetName().FullName; xmlDoc.Save(xmlFileName); } catch { } } } } else // No checkboxes are checked, remove some global settings { try { foreach (string framework in _frameworks) { Registry.LocalMachine.DeleteSubKey(String.Format("Software\\Microsoft\\.NETFramework\\{0}\\AssemblyFoldersEx\\SQLite", framework)); } string[] versions = { "v2.0.0.0", "v3.5.0.0" }; for (int x = 0; x < versions.Length; x++) { for (int n = 0; n < compactFrameworks.Length; n++) { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\.NETCompactFramework\\{1}\\{0}\\DataProviders", compactFrameworks[n], versions[x]), true)) { try { if (key != null) key.DeleteSubKey(standardDataProviderGuid.ToString("B")); } catch { } } } } for (int n = 0; n < compactFrameworks.Length; n++) { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\.NETCompactFramework\\v2.0.0.0\\{0}\\AssemblyFoldersEx", compactFrameworks[n]), true)) { try { if (key != null) key.DeleteSubKey("SQLite"); } catch { } } } for (int n = 0; n < 2; n++) { try { foreach (string framework in _frameworks) { // Remove any entries in the machine.config if they're still there string xmlFileName = Environment.ExpandEnvironmentVariables(String.Format("%WinDir%\\Microsoft.NET\\{0}\\{1}\\CONFIG\\machine.config", (n == 0) ? "Framework" : "Framework64", framework)); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.PreserveWhitespace = true; xmlDoc.Load(xmlFileName); XmlNode xmlNode = xmlDoc.SelectSingleNode("configuration/system.data/DbProviderFactories/add[@invariant=\"System.Data.SQLite\"]"); if (xmlNode != null) xmlNode.ParentNode.RemoveChild(xmlNode); xmlNode = xmlDoc.SelectSingleNode("configuration/system.data/DbProviderFactories/remove[@invariant=\"System.Data.SQLite\"]"); if (xmlNode != null) xmlNode.ParentNode.RemoveChild(xmlNode); xmlDoc.Save(xmlFileName); } } catch { } } } catch { } } try { if (!install) // Remove SQLite from the GAC if its there { AssemblyCacheUninstallDisposition disp; string s; AssemblyCacheEnum entries = new AssemblyCacheEnum("System.Data.SQLite"); while (true) { s = entries.GetNextAssembly(); if (String.IsNullOrEmpty(s)) break; AssemblyCache.UninstallAssembly(s, null, out disp); } entries = new AssemblyCacheEnum("SQLite.Designer"); while (true) { s = entries.GetNextAssembly(); if (String.IsNullOrEmpty(s)) break; AssemblyCache.UninstallAssembly(s, null, out disp); } entries = new AssemblyCacheEnum("System.Data.SQLite.Linq"); while (true) { s = entries.GetNextAssembly(); if (String.IsNullOrEmpty(s)) break; AssemblyCache.UninstallAssembly(s, null, out disp); } SQLite = null; } else // Install SQLite into the GAC { byte[] cfdt = Properties.Resources.System_Data_SQLite; string tempPath = Path.GetTempPath(); tempPath = Path.Combine(tempPath, "System.Data.SQLite.DLL"); using (FileStream fs = File.Open(tempPath, FileMode.Create, FileAccess.Write, FileShare.None)) { fs.Write(cfdt, 0, cfdt.Length); } try { AssemblyCache.InstallAssembly(tempPath, null, AssemblyCommitFlags.Default); AssemblyCache.InstallAssembly(Path.Combine(Path.GetDirectoryName(SQLiteLocation), "x64\\System.Data.SQLite.DLL"), null, AssemblyCommitFlags.Default); AssemblyCache.InstallAssembly(Path.Combine(Path.GetDirectoryName(SQLiteLocation), "itanium\\System.Data.SQLite.DLL"), null, AssemblyCommitFlags.Default); } catch { } finally { File.Delete(tempPath); if (File.Exists(Path.GetFullPath("..\\System.Data.SQLite.Linq.DLL")) == true) AssemblyCache.InstallAssembly(Path.GetFullPath("..\\System.Data.SQLite.Linq.DLL"), null, AssemblyCommitFlags.Default); AssemblyCache.InstallAssembly(Path.GetFullPath("SQLite.Designer.DLL"), null, AssemblyCommitFlags.Default); AssemblyCache.InstallAssembly(SQLiteLocation, null, AssemblyCommitFlags.Default); } } } catch { throw; } FixXmlLibPaths(install, version); }
public IEnumerator<string> GetEnumerator(string assemblyName) { AssemblyCacheEnum v = new AssemblyCacheEnum(assemblyName); yield return v.GetNextAssembly(); }