Commits

gb2013 gb committed 2e9dd24

提交 HostsTool 源码;

Comments (0)

Files changed (14)

+# Ignore file for Visual Studio 2008
+
+# use glob syntax
+syntax: glob
+
+# Ignore Visual Studio 2008 files
+*.obj
+*.exe
+*.pdb
+*.user
+*.msi
+*.aps
+*.pch
+*.vspscc
+*_i.c
+*_p.c
+*.ncb
+*.suo
+*.tlb
+*.tlh
+*.bak
+*.cache
+*.ilk
+*.log
+*.lib
+*.sbr
+*.scc
+*.sws
+*.pdsync
+*.pdsyncu
+~*.doc
+[Tt]humbs.db
+packages/
+[Bb]in*/
+[Dd]ebug*/
+[Ll]ogs/
+Backup/
+obj/
+[Rr]elease*/
+_ReSharper*/
+_UpgradeReport_Files/
+[Tt]est[Rr]esult*
+[Bb]uild[Ll]og.*
+*.[Pp]ublish.xml
+UpgradeLog.XML
+*.csproj.user
+*.ncb
+*.suo
+.idea/
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HostsTool", "HostsTool\HostsTool.csproj", "{EE087638-BA5F-4A54-9FB4-936AD7BEC70B}"
+EndProject
+Global
+	GlobalSection(PowerDesigner) = preSolution
+		HasSWS = 1
+	EndGlobalSection
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{EE087638-BA5F-4A54-9FB4-936AD7BEC70B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{EE087638-BA5F-4A54-9FB4-936AD7BEC70B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{EE087638-BA5F-4A54-9FB4-936AD7BEC70B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{EE087638-BA5F-4A54-9FB4-936AD7BEC70B}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

HostsTool/HostsTool.csproj

+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.30729</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{EE087638-BA5F-4A54-9FB4-936AD7BEC70B}</ProjectGuid>
+    <OutputType>WinExe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>HostsTool</RootNamespace>
+    <AssemblyName>HostsTool</AssemblyName>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <ApplicationIcon>HostsTool.ico</ApplicationIcon>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Xml.Linq">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data.DataSetExtensions">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data" />
+    <Reference Include="System.Deployment" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="MainForm.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="MainForm.Designer.cs">
+      <DependentUpon>MainForm.cs</DependentUpon>
+    </Compile>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <EmbeddedResource Include="MainForm.resx">
+      <DependentUpon>MainForm.cs</DependentUpon>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Properties\Resources.resx">
+      <Generator>ResXFileCodeGenerator</Generator>
+      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+      <SubType>Designer</SubType>
+    </EmbeddedResource>
+    <Compile Include="Properties\Resources.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Resources.resx</DependentUpon>
+      <DesignTime>True</DesignTime>
+    </Compile>
+    <None Include="Properties\Settings.settings">
+      <Generator>SettingsSingleFileGenerator</Generator>
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+    </None>
+    <Compile Include="Properties\Settings.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Settings.settings</DependentUpon>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+    </Compile>
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="HostsTool.ico" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

HostsTool/HostsTool.ico

Added
New image

HostsTool/MainForm.Designer.cs

+using System;
+using System.IO;
+using System.Windows.Forms;
+
+namespace HostsTool
+{
+    partial class MainForm
+    {
+        private System.Windows.Forms.Button btnOpenHosts;
+        private System.Windows.Forms.Button btnRefresh;
+        private System.Windows.Forms.ToolStripMenuItem btnSetDisable;
+        private System.Windows.Forms.ToolStripMenuItem btnSetEnable;
+        private System.Windows.Forms.ToolStripMenuItem btnSetGroupNum;
+        private System.Windows.Forms.Button btnSetNotTogether;
+        private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
+        private string hostsFilePath = Path.Combine(Environment.SystemDirectory, @"drivers\etc\hosts");
+        private System.Windows.Forms.Panel panelBottom;
+        private System.Windows.Forms.Panel panelButtons;
+        private System.Windows.Forms.TreeView treeView;
+
+        /// <summary>
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows 窗体设计器生成的代码
+
+        /// <summary>
+        /// 设计器支持所需的方法 - 不要
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
+            this.treeView = new System.Windows.Forms.TreeView();
+            this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
+            this.btnSetDisable = new System.Windows.Forms.ToolStripMenuItem();
+            this.btnSetEnable = new System.Windows.Forms.ToolStripMenuItem();
+            this.btnSetGroupNum = new System.Windows.Forms.ToolStripMenuItem();
+            this.btnRefresh = new System.Windows.Forms.Button();
+            this.panelBottom = new System.Windows.Forms.Panel();
+            this.btnOpenHosts = new System.Windows.Forms.Button();
+            this.btnSetNotTogether = new System.Windows.Forms.Button();
+            this.panelButtons = new System.Windows.Forms.Panel();
+            this.contextMenuStrip.SuspendLayout();
+            this.panelBottom.SuspendLayout();
+            this.panelButtons.SuspendLayout();
+            this.SuspendLayout();
+            // 
+            // treeView
+            // 
+            this.treeView.AccessibleDescription = global::HostsTool.Properties.Resources.Icon;
+            this.treeView.BorderStyle = System.Windows.Forms.BorderStyle.None;
+            this.treeView.ContextMenuStrip = this.contextMenuStrip;
+            this.treeView.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.treeView.ItemHeight = 17;
+            this.treeView.Location = new System.Drawing.Point(0, 0);
+            this.treeView.Name = "treeView";
+            this.treeView.Size = new System.Drawing.Size(542, 666);
+            this.treeView.TabIndex = 0;
+            this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
+            this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
+            // 
+            // contextMenuStrip
+            // 
+            this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.btnSetDisable,
+            this.btnSetEnable,
+            this.btnSetGroupNum});
+            this.contextMenuStrip.Name = "contextMenuStrip";
+            this.contextMenuStrip.Size = new System.Drawing.Size(137, 70);
+            // 
+            // btnSetDisable
+            // 
+            this.btnSetDisable.Name = "btnSetDisable";
+            this.btnSetDisable.Size = new System.Drawing.Size(136, 22);
+            this.btnSetDisable.Text = "失效";
+            this.btnSetDisable.Click += new System.EventHandler(this.btnSetDisable_Click);
+            // 
+            // btnSetEnable
+            // 
+            this.btnSetEnable.Name = "btnSetEnable";
+            this.btnSetEnable.Size = new System.Drawing.Size(136, 22);
+            this.btnSetEnable.Text = "可用";
+            this.btnSetEnable.Click += new System.EventHandler(this.btnSetEnable_Click);
+            // 
+            // btnSetGroupNum
+            // 
+            this.btnSetGroupNum.Name = "btnSetGroupNum";
+            this.btnSetGroupNum.Size = new System.Drawing.Size(136, 22);
+            this.btnSetGroupNum.Text = "设置组编号";
+            this.btnSetGroupNum.Click += new System.EventHandler(this.btnSetGroupNum_Click);
+            // 
+            // btnRefresh
+            // 
+            this.btnRefresh.Location = new System.Drawing.Point(139, 6);
+            this.btnRefresh.Name = "btnRefresh";
+            this.btnRefresh.Size = new System.Drawing.Size(118, 23);
+            this.btnRefresh.TabIndex = 1;
+            this.btnRefresh.Text = "刷新显示";
+            this.btnRefresh.UseVisualStyleBackColor = true;
+            this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
+            // 
+            // panelBottom
+            // 
+            this.panelBottom.Controls.Add(this.btnOpenHosts);
+            this.panelBottom.Controls.Add(this.btnSetNotTogether);
+            this.panelBottom.Controls.Add(this.btnRefresh);
+            this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
+            this.panelBottom.Location = new System.Drawing.Point(0, 630);
+            this.panelBottom.Name = "panelBottom";
+            this.panelBottom.Size = new System.Drawing.Size(542, 36);
+            this.panelBottom.TabIndex = 2;
+            // 
+            // btnOpenHosts
+            // 
+            this.btnOpenHosts.Location = new System.Drawing.Point(412, 6);
+            this.btnOpenHosts.Name = "btnOpenHosts";
+            this.btnOpenHosts.Size = new System.Drawing.Size(118, 23);
+            this.btnOpenHosts.TabIndex = 2;
+            this.btnOpenHosts.Text = "打开Hosts文件";
+            this.btnOpenHosts.UseVisualStyleBackColor = true;
+            this.btnOpenHosts.Click += new System.EventHandler(this.btnOpenHosts_Click);
+            // 
+            // btnSetNotTogether
+            // 
+            this.btnSetNotTogether.Location = new System.Drawing.Point(273, 6);
+            this.btnSetNotTogether.Name = "btnSetNotTogether";
+            this.btnSetNotTogether.Size = new System.Drawing.Size(118, 23);
+            this.btnSetNotTogether.TabIndex = 2;
+            this.btnSetNotTogether.Text = "设置互斥组";
+            this.btnSetNotTogether.UseVisualStyleBackColor = true;
+            this.btnSetNotTogether.Click += new System.EventHandler(this.btnSetNotTogether_Click);
+            // 
+            // panelButtons
+            // 
+            this.panelButtons.Controls.Add(this.treeView);
+            this.panelButtons.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.panelButtons.Location = new System.Drawing.Point(0, 0);
+            this.panelButtons.Name = "panelButtons";
+            this.panelButtons.Size = new System.Drawing.Size(542, 666);
+            this.panelButtons.TabIndex = 3;
+            // 
+            // MainForm
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(542, 666);
+            this.Controls.Add(this.panelBottom);
+            this.Controls.Add(this.panelButtons);
+            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
+            this.MinimumSize = new System.Drawing.Size(550, 700);
+            this.Name = "MainForm";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+            this.Text = "HostsTool";
+            this.Load += new System.EventHandler(this.MainForm_Load);
+            this.contextMenuStrip.ResumeLayout(false);
+            this.panelBottom.ResumeLayout(false);
+            this.panelButtons.ResumeLayout(false);
+            this.ResumeLayout(false);
+
+        }
+        #endregion
+    }
+}
+

HostsTool/MainForm.cs

+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Diagnostics;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Windows.Forms;
+
+namespace HostsTool
+{
+    public partial class MainForm : Form
+    {
+        public MainForm()
+        {
+            InitializeComponent();
+        }
+
+        private void BindTree()
+        {
+            this.treeView.Nodes.Clear();
+            StreamReader reader = new StreamReader(this.hostsFilePath, Encoding.GetEncoding("gb2312"));
+            string s = "";
+            TreeNode node = null;
+            TreeNode node2 = null;
+            while ((s = reader.ReadLine()) != null)
+            {
+                Match match = this.CheckIsGroupLine(s);
+                if (match != null)
+                {
+                    node = new TreeNode
+                    {
+                        Text = this.ProcessLineStr(match.Groups[0].Value),
+                        Tag = match.Groups[1].Value
+                    };
+                    this.treeView.Nodes.Add(node);
+                }
+                else
+                {
+                    node2 = new TreeNode
+                    {
+                        Text = this.ProcessLineStr(s)
+                    };
+                    if (node != null)
+                    {
+                        node2.Tag = node.Tag.ToString() + "_child";
+                        node.Nodes.Add(node2);
+                        continue;
+                    }
+                    this.treeView.Nodes.Add(node2);
+                }
+            }
+            reader.Close();
+            reader.Dispose();
+            foreach (TreeNode node3 in this.treeView.Nodes)
+            {
+                node3.ExpandAll();
+            }
+            this.treeView.SelectedNode = this.treeView.Nodes[0];
+        }
+
+        private void btnOpenHosts_Click(object sender, EventArgs e)
+        {
+            new Process { StartInfo = { FileName = "notepad.exe", Arguments = this.hostsFilePath } }.Start();
+        }
+
+        private void btnRefresh_Click(object sender, EventArgs e)
+        {
+            this.BindTree();
+        }
+
+        private void btnSetDisable_Click(object sender, EventArgs e)
+        {
+            this.SetEnableOrDisable("disable", this.treeView.SelectedNode);
+            this.SaveHost();
+        }
+
+        private void btnSetEnable_Click(object sender, EventArgs e)
+        {
+            this.SetEnableOrDisable("enable", this.treeView.SelectedNode);
+            this.SaveHost();
+        }
+
+        private void btnSetGroupNum_Click(object sender, EventArgs e)
+        {
+
+        }
+
+        private void btnSetNotTogether_Click(object sender, EventArgs e)
+        {
+
+        }
+
+        private bool CheckGroupIsDisable(TreeNodeCollection treeNodes, ref int disableNum, ref int nullNum)
+        {
+            int num = 0;
+            int num2 = 0;
+            Regex regex = new Regex(@"^\s*$");
+            Match match = null;
+            Regex regex2 = new Regex(@"^\s*#+");
+            Match match2 = null;
+            foreach (TreeNode node in treeNodes)
+            {
+                match2 = regex2.Match(node.Text);
+                match = regex.Match(node.Text);
+                if (match2.Success)
+                {
+                    num++;
+                }
+                else if (match.Success)
+                {
+                    num2++;
+                }
+            }
+            disableNum = num;
+            nullNum = num2;
+            return ((num + num2) == treeNodes.Count);
+        }
+
+        private Match CheckIsGroupLine(string s)
+        {
+            Match match = new Regex(@"#Group_(.*?)\s(.*)").Match(s);
+            if (match.Success)
+            {
+                return match;
+            }
+            return null;
+        }
+
+        private string GetGroupNotTogether(string groupNum)
+        {
+            Match match = new Regex(@"#(\[.*\])+").Match(this.GetHostText());
+            if (!match.Success)
+            {
+                return "";
+            }
+            MatchCollection matchs = Regex.Matches(match.Groups[1].Value, @"\[(.*?)\]");
+            string str = "";
+            foreach (Match match2 in matchs)
+            {
+                str = match2.Groups[1].Value;
+                string[] strArray = str.Split(new char[] { ',' });
+                bool flag = false;
+                foreach (string str2 in strArray)
+                {
+                    if (str2 == groupNum)
+                    {
+                        flag = true;
+                        break;
+                    }
+                }
+                if (flag)
+                {
+                    return str;
+                }
+                str = "";
+            }
+            return str;
+        }
+
+        private string GetHostText()
+        {
+            string str = "";
+            StreamReader reader = new StreamReader(this.hostsFilePath, Encoding.GetEncoding("gb2312"));
+            str = reader.ReadToEnd();
+            reader.Close();
+            reader.Dispose();
+            return str;
+        }
+
+        private void MainForm_Load(object sender, EventArgs e)
+        {
+            this.BindTree();
+            this.btnSetGroupNum.Visible = false;
+            this.btnSetNotTogether.Visible = false;
+        }
+
+        private string ProcessLineStr(string s)
+        {
+            return Regex.Replace(s, @"\t+", "     ");
+        }
+
+        private void SaveHost()
+        {
+            try
+            {
+                StreamWriter writer = new StreamWriter(this.hostsFilePath, false, Encoding.GetEncoding("gb2312"));
+                foreach (TreeNode node in this.treeView.Nodes)
+                {
+                    writer.WriteLine(node.Text);
+                    if (node.Nodes.Count > 0)
+                    {
+                        foreach (TreeNode node2 in node.Nodes)
+                        {
+                            writer.WriteLine(node2.Text);
+                        }
+                        continue;
+                    }
+                }
+                writer.Close();
+                writer.Dispose();
+            }
+            catch
+            {
+                MessageBox.Show("没有保存权限,保存失败");
+                this.BindTree();
+            }
+        }
+
+        private void SetEnableOrDisable(string opType, TreeNode node)
+        {
+            if (this.CheckIsGroupLine(node.Text) != null)
+            {
+                if (opType == "disable")
+                {
+                    foreach (TreeNode node2 in node.Nodes)
+                    {
+                        if (!(node2.Text.Trim() == ""))
+                        {
+                            node2.Text = Regex.Replace(node2.Text, @"^\s*#*", "#");
+                        }
+                    }
+                }
+                else if (opType == "enable")
+                {
+                    foreach (TreeNode node3 in node.Nodes)
+                    {
+                        if (!(node3.Text.Trim() == ""))
+                        {
+                            node3.Text = Regex.Replace(node3.Text, @"^\s*#+", "");
+                        }
+                    }
+                    foreach (string str2 in this.GetGroupNotTogether(node.Tag.ToString()).Split(new char[] { ',' }))
+                    {
+                        if (str2 != node.Tag.ToString())
+                        {
+                            foreach (TreeNode node4 in this.treeView.Nodes)
+                            {
+                                if (node4.Nodes.Count > 0)
+                                {
+                                    foreach (TreeNode node5 in node4.Nodes)
+                                    {
+                                        if ((node5.Tag != null) && (node5.Tag.ToString() == (str2 + "_child")))
+                                        {
+                                            this.SetEnableOrDisable("disable", node5);
+                                        }
+                                    }
+                                    continue;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            else
+            {
+                if (node.Text.Trim() == "")
+                {
+                    return;
+                }
+                if (opType == "disable")
+                {
+                    node.Text = Regex.Replace(node.Text, @"^\s*#*", "#");
+                }
+                else if (opType == "enable")
+                {
+                    node.Text = Regex.Replace(node.Text, @"^\s*#+", "");
+                }
+            }
+            this.treeView.Refresh();
+        }
+
+        private void treeView_DoubleClick(object sender, EventArgs e)
+        {
+            if (this.CheckIsGroupLine(this.treeView.SelectedNode.Text) == null)
+            {
+                if (Regex.Match(this.treeView.SelectedNode.Text, @"^\s*#+").Success)
+                {
+                    this.btnSetEnable_Click(sender, e);
+                }
+                else
+                {
+                    this.btnSetDisable_Click(sender, e);
+                }
+            }
+            else
+            {
+                int disableNum = 0;
+                int nullNum = 0;
+                if (this.CheckGroupIsDisable(this.treeView.SelectedNode.Nodes, ref disableNum, ref nullNum))
+                {
+                    this.btnSetEnable_Click(sender, e);
+                }
+                else
+                {
+                    this.btnSetDisable_Click(sender, e);
+                }
+                this.treeView.SelectedNode.Expand();
+            }
+        }
+
+        private void treeView_MouseDown(object sender, MouseEventArgs e)
+        {
+            if (e.Button == MouseButtons.Right)
+            {
+                Point point2 = new Point
+                {
+                    X = e.X,
+                    Y = e.Y
+                };
+                Point pt = point2;
+                TreeNode nodeAt = this.treeView.GetNodeAt(pt);
+                if (nodeAt != null)
+                {
+                    this.treeView.SelectedNode = nodeAt;
+                    Regex regex = new Regex(@"^\s*#+");
+                    if (nodeAt.Nodes.Count > 0)
+                    {
+                        int disableNum = 0;
+                        int nullNum = 0;
+                        if (this.CheckGroupIsDisable(nodeAt.Nodes, ref disableNum, ref nullNum))
+                        {
+                            this.btnSetEnable.Visible = true;
+                            this.btnSetDisable.Visible = false;
+                        }
+                        else if (disableNum == 0)
+                        {
+                            this.btnSetEnable.Visible = false;
+                            this.btnSetDisable.Visible = true;
+                        }
+                        else
+                        {
+                            this.btnSetEnable.Visible = true;
+                            this.btnSetDisable.Visible = true;
+                        }
+                    }
+                    else if (nodeAt.Text.Trim() == "")
+                    {
+                        this.btnSetEnable.Visible = false;
+                        this.btnSetDisable.Visible = false;
+                    }
+                    else if (regex.Match(nodeAt.Text).Success)
+                    {
+                        this.btnSetEnable.Visible = true;
+                        this.btnSetDisable.Visible = false;
+                    }
+                    else
+                    {
+                        this.btnSetEnable.Visible = false;
+                        this.btnSetDisable.Visible = true;
+                    }
+                }
+            }
+        }
+    }
+}

HostsTool/MainForm.resx

+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="contextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+  <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>42</value>
+  </metadata>
+  <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+  <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+    <value>
+        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
+        AA/wAAAf+AAAP/wAAH//AAD//8AD///wP/8=
+</value>
+  </data>
+</root>

HostsTool/Program.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+
+namespace HostsTool
+{
+    static class Program
+    {
+        /// <summary>
+        /// 应用程序的主入口点。
+        /// </summary>
+        [STAThread]
+        static void Main()
+        {
+            Application.EnableVisualStyles();
+            Application.SetCompatibleTextRenderingDefault(false);
+            Application.Run(new MainForm());
+        }
+    }
+}

HostsTool/Properties/AssemblyInfo.cs

+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的常规信息通过下列属性集
+// 控制。更改这些属性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("HostsTool")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("HostsTool")]
+[assembly: AssemblyCopyright("Copyright ©  2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 使此程序集中的类型
+// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
+// 则将该类型上的 ComVisible 属性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("d05665b2-19c4-4631-9cfe-d47a91fc7627")]
+
+// 程序集的版本信息由下面四个值组成:
+//
+//      主版本
+//      次版本 
+//      内部版本号
+//      修订号
+//
+// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

HostsTool/Properties/Resources.Designer.cs

+//------------------------------------------------------------------------------
+// <auto-generated>
+//     此代码由工具生成。
+//     运行时版本:2.0.50727.4952
+//
+//     对此文件的更改可能会导致不正确的行为,并且如果
+//     重新生成代码,这些更改将会丢失。
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace HostsTool.Properties {
+    using System;
+    
+    
+    /// <summary>
+    ///   强类型资源类,用于查找本地化字符串等。
+    /// </summary>
+    // 此类是由 StronglyTypedResourceBuilder
+    // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
+    // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
+    // (以 /str 作为命令选项),或重新生成 VS 项目。
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    internal class Resources {
+        
+        private static global::System.Resources.ResourceManager resourceMan;
+        
+        private static global::System.Globalization.CultureInfo resourceCulture;
+        
+        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+        internal Resources() {
+        }
+        
+        /// <summary>
+        ///   返回此类使用的缓存 ResourceManager 实例。
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Resources.ResourceManager ResourceManager {
+            get {
+                if (object.ReferenceEquals(resourceMan, null)) {
+                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("HostsTool.Properties.Resources", typeof(Resources).Assembly);
+                    resourceMan = temp;
+                }
+                return resourceMan;
+            }
+        }
+        
+        /// <summary>
+        ///   为使用此强类型资源类的所有资源查找
+        ///   重写当前线程的 CurrentUICulture 属性。
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Globalization.CultureInfo Culture {
+            get {
+                return resourceCulture;
+            }
+            set {
+                resourceCulture = value;
+            }
+        }
+        
+        /// <summary>
+        ///   查找类似  的本地化字符串。
+        /// </summary>
+        internal static string Icon {
+            get {
+                return ResourceManager.GetString("Icon", resourceCulture);
+            }
+        }
+    }
+}

HostsTool/Properties/Resources.resx

+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <data name="Icon" xml:space="preserve">
+    <value />
+  </data>
+</root>

HostsTool/Properties/Settings.Designer.cs

+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:2.0.50727.4952
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace HostsTool.Properties
+{
+
+
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
+    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
+    {
+
+        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+        public static Settings Default
+        {
+            get
+            {
+                return defaultInstance;
+            }
+        }
+    }
+}

HostsTool/Properties/Settings.settings

+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
+  <Profiles>
+    <Profile Name="(Default)" />
+  </Profiles>
+  <Settings />
+</SettingsFile>