⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 installdesigner.cs

📁 sqlite 3.3.8 支持加密的版本
💻 CS
📖 第 1 页 / 共 3 页
字号:
            subkey.SetValue(null, "SQLite Designer Package");
            subkey.SetValue("Class", "SQLite.Designer.SQLitePackage");
            subkey.SetValue("CodeBase", Path.GetFullPath("SQLite.Designer.DLL"));
            subkey.SetValue("ID", 400);
            subkey.SetValue("InprocServer32", "mscoree.dll");
            subkey.SetValue("CompanyName", "Black Castle Software, LLC");
            subkey.SetValue("MinEdition", "standard");
            subkey.SetValue("ProductName", "SQLite Data Provider");
            subkey.SetValue("ProductVersion", "1.0");
          }
        }

        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\Menus", keyname, _regRoot), true))
        {
          key.SetValue("{DCBE6C8D-0E57-4099-A183-98FF74C64D9C}", ", 1000, 1");
        }

        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\Services", keyname, _regRoot), true))
        {
          using (RegistryKey subkey = key.CreateSubKey("{DCBE6C8D-0E57-4099-A183-98FF74C64D9D}", RegistryKeyPermissionCheck.ReadWriteSubTree))
          {
            subkey.SetValue(null, "{DCBE6C8D-0E57-4099-A183-98FF74C64D9C}");
            subkey.SetValue("Name", "SQLite Provider Object Factory");
          }
        }
      }
    }

    private XmlDocument GetConfig(string keyname, out string xmlFileName)
    {
      try
      {
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}", keyname, _regRoot), true))
        {
          xmlFileName = (string)key.GetValue("InstallDir");
          if (String.Compare(keyname, "VisualStudio", true) == 0)
            xmlFileName += "devenv.exe.config";
          else
            xmlFileName += keyname + ".exe.config";
        }

        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.PreserveWhitespace = true;
        xmlDoc.Load(xmlFileName);

        return xmlDoc;
      }
      catch
      {
        xmlFileName = null;
      }
      return null;
    }

    private void Uninstall(string keyname, Guid provider, Guid source)
    {
      try
      {
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataProviders", keyname, _regRoot), true))
        {
          if (key != null) key.DeleteSubKeyTree(provider.ToString("B"));
        }
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\DataSources", keyname, _regRoot), true))
        {
          if (key != null) key.DeleteSubKeyTree(source.ToString("B"));
        }

        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\Packages", keyname, _regRoot), true))
        {
          if (key != null) key.DeleteSubKeyTree("{DCBE6C8D-0E57-4099-A183-98FF74C64D9C}");
        }

        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\Services", keyname, _regRoot), true))
        {
          if (key != null) key.DeleteSubKeyTree("{DCBE6C8D-0E57-4099-A183-98FF74C64D9D}");
        }

        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(String.Format("Software\\Microsoft\\{0}\\{1}\\Menus", keyname, _regRoot), true))
        {
          key.DeleteValue("{DCBE6C8D-0E57-4099-A183-98FF74C64D9C}");
        }

        //using (RegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", true))
        //{
        //  string libpath = (string)key.GetValue("LIB");
        //  string path = ";" + Path.GetDirectoryName(SQLiteLocation);

        //  libpath = libpath.Replace(path, "");
        //  key.SetValue("LIB", libpath);
        //}
      }
      catch
      {
      }

      // Remove factory support from the development environment config file
      string xmlFileName;
      XmlDocument xmlDoc = GetConfig(keyname, out xmlFileName);

      if (xmlDoc == null) return;

      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);
    }


    private static void CopyKey(RegistryKey keySource, RegistryKey keyDest)
    {
      if (keySource.SubKeyCount > 0)
      {
        string[] subkeys = keySource.GetSubKeyNames();
        for (int n = 0; n < subkeys.Length; n++)
        {
          using (RegistryKey subkeysource = keySource.OpenSubKey(subkeys[n]))
          {
            using (RegistryKey subkeydest = keyDest.CreateSubKey(subkeys[n], RegistryKeyPermissionCheck.ReadWriteSubTree))
            {
              CopyKey(subkeysource, subkeydest);
            }
          }
        }
      }
      string[] values = keySource.GetValueNames();
      for (int n = 0; n < values.Length; n++)
      {
        keyDest.SetValue(values[n], keySource.GetValue(values[n]), keySource.GetValueKind(values[n]));
      }
    }

    private void FixXmlLibPaths(bool install)
    {
      string installDir = null;
      RegistryKey key = null;

      try
      {
        key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\VisualStudio\\8.0");
        if (key != null)
        {
          try
          {
            installDir = (string)key.GetValue("InstallDir");
          }
          catch
          {
          }
          finally
          {
            if (String.IsNullOrEmpty(installDir))
            {
              ((IDisposable)key).Dispose();
              key = null;
            }
          }
        }

        if (key == null)
        {
          key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\VCExpress\\8.0");
          if (key == null) return;
        }

        try
        {
          installDir = (string)key.GetValue("InstallDir");
        }
        catch
        {
        }
      }
      finally
      {
        if (key != null) ((IDisposable)key).Dispose();
      }

      if (String.IsNullOrEmpty(installDir)) return;

      installDir = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(installDir))), "VC");

      string currentDir;
      string[] lookIn = new string[] { "vcpackages", "bin\\amd64", "bin\\ia64" };
      string sqlitePath = Path.GetDirectoryName(SQLiteLocation);

      foreach (string subfolder in lookIn)
      {
        try
        {
          currentDir = Path.Combine(installDir, subfolder);
          FixXmlLibPaths(currentDir, "VCProjectEngine.DLL*.config", sqlitePath, install);
          FixXmlLibPaths(currentDir, "AMD64.VCPlatform.config", Path.Combine(sqlitePath, "x64"), install);
          FixXmlLibPaths(currentDir, "Itanium.VCPlatform.config", Path.Combine(sqlitePath, "itanium"), install);
          FixXmlLibPaths(currentDir, "WCE.VCPlatform.config", Path.Combine(sqlitePath, "CompactFramework"), install);
        }
        catch
        {
        }
      }

      FixLocalUserPaths(install);
    }

    private void FixLocalUserPaths(bool install)
    {
      string file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\VisualStudio\\8.0\\VCComponents.dat");
      StringBuilder output = new StringBuilder();
      string line;
      string sqlitePath = Path.GetDirectoryName(SQLiteLocation);
      string currPath = sqlitePath;

      try
      {
        using (StreamReader rd = new StreamReader(file))
        {
          while (rd.EndOfStream == false)
          {
            line = rd.ReadLine();
            line = line.Trim();
            if (String.IsNullOrEmpty(line)) continue;
            if (line[0] == '[')
            {
              if (line.IndexOf("Win32", StringComparison.InvariantCultureIgnoreCase) != -1)
                currPath = sqlitePath;
              else if (line.IndexOf("x64", StringComparison.InvariantCultureIgnoreCase) != -1)
                currPath = Path.Combine(sqlitePath, "x64");
              else if (line.IndexOf("Itanium", StringComparison.InvariantCultureIgnoreCase) != -1)
                currPath = Path.Combine(sqlitePath, "x64");
              else if (line.IndexOf("ARM", StringComparison.InvariantCultureIgnoreCase) != -1)
                currPath = Path.Combine(sqlitePath, "CompactFramework");
            }
            else if (line.StartsWith("Reference Dirs", StringComparison.InvariantCultureIgnoreCase) == true)
            {
              int n = line.IndexOf(";" + currPath, StringComparison.InvariantCultureIgnoreCase);
              if (n > -1) line = line.Remove(n, currPath.Length + 1);

              if (install)
              {
                if (line[line.Length - 1] == '=')
                  line += currPath;
                else
                  line += (";" + currPath);
              }
            }

            output.AppendLine(line);
          }
          rd.Close();
        }

        File.Delete(file);
        using (StreamWriter writer = new StreamWriter(file, false, Encoding.Unicode))
        {          
          writer.Write(output.ToString());
          writer.Close();
        }
      }
      catch
      {
      }
    }

    private void FixXmlLibPaths(string path, string lookFor, string sqlitePath, bool install)
    {
      // Win32
      string[] files = Directory.GetFiles(path, lookFor);
      if (files.Length > 0)
      {
        foreach (string file in files)
        {
          FixXmlLibPath(file, sqlitePath, install);
        }
      }
    }

    private void FixXmlLibPath(string fileName, string sqlitePath, bool install)
    {
      XmlDocument xmlDoc = new XmlDocument();
      xmlDoc.PreserveWhitespace = true;
      xmlDoc.Load(fileName);
      
      XmlNodeList xmlNodes = xmlDoc.SelectNodes("VCPlatformConfigurationFile/Platform/Directories");
      if (xmlNodes == null) return;

      foreach(XmlNode xmlNode in xmlNodes)
      {
        string libpath = xmlNode.Attributes.GetNamedItem("Reference").Value;
        if (String.Compare(libpath, sqlitePath, true) == 0)
          libpath = "";
        else
        {
          int n = libpath.IndexOf(";" + sqlitePath, StringComparison.InvariantCultureIgnoreCase);
          if (n > -1) libpath = libpath.Remove(n, sqlitePath.Length + 1);
        }

        if (install)
        {
          if (String.IsNullOrEmpty(libpath)) libpath = sqlitePath;
          else libpath += (";" + sqlitePath);
        }
        xmlNode.Attributes.GetNamedItem("Reference").Value = libpath;
      }

      xmlDoc.Save(fileName);
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -