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

📄 installersupport.cs

📁 代码模版 codtemplate
💻 CS
字号:
using System;
using EnvDTE;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using Microsoft.Office.Core;
using System.Runtime.InteropServices;

namespace CodeTemplate
{
	/// <summary>
	/// Summary description for InstallerSupport.
	/// </summary>
	[ComVisible(false)]
	[RunInstaller(true)]
	public class InstallerSupport : Installer
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public InstallerSupport()
		{
			// This call is required by the Designer.
			InitializeComponent();
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if(disposing)
			{
				if(components != null)
					components.Dispose();
			}

			base.Dispose(disposing);
		}

		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			components = new System.ComponentModel.Container();
		}
		#endregion

		private static bool IsVisualStudioRunning()
		{
			System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcesses();

			try
			{
				foreach(System.Diagnostics.Process p in processes)
				{
					if(p != null && p.MainModule != null)
					{
						String fileName = Path.GetFileName(p.MainModule.FileName);
						if(String.Compare(fileName, "devenv.exe", true) == 0)
							return true;
					}
				}
			}
			catch
			{
			}

			return false;
		}
 
		public override void Install(IDictionary stateSaver)
		{
			Trace.WriteLine("Install...");

			while(IsVisualStudioRunning())
			{
				DialogResult res = MessageBox.Show(
					"A running instance of Visual Studio .NET was found.\n\n" + 
					"Please close all copies of Visual Studio .NET and press OK.",
					"Install...",
					MessageBoxButtons.OKCancel);

				if(res == DialogResult.Cancel)
					throw new InstallException("Installation cancelled by the user");
			}

			base.Install(stateSaver);
		}

		private void RemoveCommands(String progID)
		{
			DTE dte = null;

			try
			{
				Type type = Type.GetTypeFromProgID(progID);
				if(type == null)
					return;

				dte = Activator.CreateInstance(type, true) as DTE;
				if(dte == null)
					return;

				Commands cmds = dte.Commands;

				Command cmd = cmds.Item(Connect.ShowMenuCommand.FullCommand, -1);
				if(cmd != null)
					cmd.Delete();

				cmd = cmds.Item(Connect.InsertTemplateCommand.FullCommand, -1);
				if(cmd != null)
					cmd.Delete();

//TODO: Figure out a way to remove the darn commandbar
//				CommandBar cb = dte.CommandBars[Connect.ShowMenuCommand.ProgID];
//				if(cb != null)
//					cmds.RemoveCommandBar(cb);

			}
			catch(Exception ex)
			{
				Trace.WriteLine(ex.ToString());
			}
			finally
			{
				if(dte != null)
					dte.Quit();
			}
		}

		public override void Uninstall(IDictionary savedState)
		{
			Trace.WriteLine("Uninstall...");

			while(IsVisualStudioRunning())
			{
				DialogResult res = MessageBox.Show(
					"A running instance of Visual Studio .NET was found.\n\n" + 
					"Please close all copies of Visual Studio .NET and press OK.",
					"Uninstall...",
					MessageBoxButtons.OKCancel);

				if(res == DialogResult.Cancel)
					throw new InstallException("Installation cancelled by the user");
			}
	
			RemoveCommands("VisualStudio.DTE.7");	// VS2002
			RemoveCommands("VisualStudio.DTE.7.1");	// VS2003

			base.Uninstall(savedState);
		}
	}
}

⌨️ 快捷键说明

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