?? installdesigner.cs
字號:
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
{
Registry.LocalMachine.DeleteSubKey("Software\\Microsoft\\.NETFramework\\v2.0.50727\\AssemblyFoldersEx\\SQLite");
for (int n = 0; n < compactFrameworks.Length; n++)
{
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\.NETCompactFramework\\v2.0.0.0\\{0}\\DataProviders", compactFrameworks[n]), 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
{
// Remove any entries in the machine.config if they're still there
string xmlFileName = Environment.ExpandEnvironmentVariables(String.Format("%WinDir%\\Microsoft.NET\\{0}\\v2.0.50727\\CONFIG\\machine.config", (n == 0) ? "Framework" : "Framework64"));
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);
} 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);
AssemblyCache.InstallAssembly(Path.GetFullPath("SQLite.Designer.DLL"), null, AssemblyCommitFlags.Default);
AssemblyCache.InstallAssembly(SQLiteLocation, null, AssemblyCommitFlags.Default);
}
}
}
catch
{
throw;
}
FixXmlLibPaths(install);
}
private void ReplaceJet(string keyname)
{
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataProviders", keyname, _regRoot), true))
{
using (RegistryKey source = key.OpenSubKey(oledbDataProviderGuid.ToString("B")))
{
using (RegistryKey dest = key.CreateSubKey(oledbAltDataProviderGuid.ToString("B")))
{
if (source == null) return;
CopyKey(source, dest);
}
}
key.DeleteSubKeyTree(oledbDataProviderGuid.ToString("B"));
}
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataSources", keyname, _regRoot), true))
{
using (RegistryKey source = key.OpenSubKey(jetDataSourcesGuid.ToString("B")))
{
using (RegistryKey dest = key.CreateSubKey(jetAltDataSourcesGuid.ToString("B")))
{
if (source == null) return;
CopyKey(source, dest);
}
}
key.DeleteSubKeyTree(jetDataSourcesGuid.ToString("B"));
}
Install(keyname, oledbDataProviderGuid, jetDataSourcesGuid);
}
private void RestoreJet(string keyname)
{
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataProviders", keyname, _regRoot), true))
{
using (RegistryKey source = key.OpenSubKey(oledbAltDataProviderGuid.ToString("B")))
{
if (source == null) return;
}
}
Uninstall(keyname, oledbDataProviderGuid, jetDataSourcesGuid);
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataProviders", keyname, _regRoot), true))
{
using (RegistryKey source = key.OpenSubKey(oledbAltDataProviderGuid.ToString("B")))
{
if (source != null)
{
using (RegistryKey dest = key.CreateSubKey(oledbDataProviderGuid.ToString("B")))
{
CopyKey(source, dest);
}
key.DeleteSubKeyTree(oledbAltDataProviderGuid.ToString("B"));
}
}
}
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataSources", keyname, _regRoot), true))
{
using (RegistryKey source = key.OpenSubKey(jetAltDataSourcesGuid.ToString("B")))
{
if (source != null)
{
using (RegistryKey dest = key.CreateSubKey(jetDataSourcesGuid.ToString("B")))
{
CopyKey(source, dest);
}
key.DeleteSubKeyTree(jetAltDataSourcesGuid.ToString("B"));
}
}
}
}
private void Install(string keyname, Guid provider, Guid source)
{
bool usePackage = (keyname == "VisualStudio");
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataProviders", keyname, _regRoot), true))
{
using (RegistryKey subkey = key.CreateSubKey(provider.ToString("B"), RegistryKeyPermissionCheck.ReadWriteSubTree))
{
subkey.SetValue(null, ".NET Framework Data Provider for SQLite");
subkey.SetValue("InvariantName", "System.Data.SQLite");
subkey.SetValue("Technology", "{77AB9A9D-78B9-4ba7-91AC-873F5338F1D2}");
subkey.SetValue("CodeBase", Path.GetFullPath("SQLite.Designer.DLL"));
if (usePackage)
subkey.SetValue("FactoryService", "{DCBE6C8D-0E57-4099-A183-98FF74C64D9D}");
using (RegistryKey subsubkey = subkey.CreateSubKey("SupportedObjects", RegistryKeyPermissionCheck.ReadWriteSubTree))
{
using (RegistryKey subsubsubkey = subsubkey.CreateSubKey("DataConnectionUIControl", RegistryKeyPermissionCheck.ReadWriteSubTree))
{
if (!usePackage)
subsubsubkey.SetValue(null, "SQLite.Designer.SQLiteConnectionUIControl");
}
using (RegistryKey subsubsubkey = subsubkey.CreateSubKey("DataConnectionProperties", RegistryKeyPermissionCheck.ReadWriteSubTree))
{
if (!usePackage)
subsubsubkey.SetValue(null, "SQLite.Designer.SQLiteConnectionProperties");
}
subsubkey.CreateSubKey("DataObjectSupport").Close();
subsubkey.CreateSubKey("DataViewSupport").Close();
using (RegistryKey subsubsubkey = subsubkey.CreateSubKey("DataConnectionSupport", RegistryKeyPermissionCheck.ReadWriteSubTree))
{
if (!usePackage)
subsubsubkey.SetValue(null, "SQLite.Designer.SQLiteDataConnectionSupport");
}
}
}
}
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataSources", keyname, _regRoot), true))
{
using (RegistryKey subkey = key.CreateSubKey(source.ToString("B"), RegistryKeyPermissionCheck.ReadWriteSubTree))
{
subkey.SetValue(null, "SQLite Database File");
using (RegistryKey subsubkey = subkey.CreateSubKey("SupportingProviders", RegistryKeyPermissionCheck.ReadWriteSubTree))
{
subsubkey.CreateSubKey(provider.ToString("B")).Close();
}
}
}
//try
//{
// using (RegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", true))
// {
// string libpath = (string)key.GetValue("LIB");
// string path = Path.GetDirectoryName(SQLiteLocation);
// if (libpath.IndexOf(path, StringComparison.InvariantCultureIgnoreCase) == -1)
// {
// libpath += (";" + path);
// key.SetValue("LIB", libpath);
// }
// }
//}
//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}\\DataProviders", compactFrameworks[n]), true))
{
if (key != null)
{
using (RegistryKey subkey = key.CreateSubKey(standardDataProviderGuid.ToString("B"), RegistryKeyPermissionCheck.ReadWriteSubTree))
{
subkey.SetValue(null, ".NET Framework Data Provider for SQLite");
subkey.SetValue("InvariantName", "System.Data.SQLite");
subkey.SetValue("RuntimeAssembly", "System.Data.SQLite.DLL");
}
}
}
}
if (usePackage)
{
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\Packages", keyname, _regRoot), true))
{
using (RegistryKey subkey = key.CreateSubKey("{DCBE6C8D-0E57-4099-A183-98FF74C64D9C}", RegistryKeyPermissionCheck.ReadWriteSubTree))
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -