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

📄 hostfiledetectaction.cs

📁 破解的飞信源代码
💻 CS
字号:
namespace Imps.Client.CommLayer.NetworkDetect
{
    using Imps.Client.Resource;
    using Imps.Client.Utils;
    using Imps.Utils;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Threading;

    public class HostFileDetectAction : DetectAction
    {
        private const string NTHostFileName = @"drivers\etc\hosts";
        private const string WinHostFileName = "Hosts";

        public HostFileDetectAction()
        {
            base.Description = "主机文件";
            base.NextStage = NetworkDetectStage.DNS;
        }

        public override void BeginDetectAction()
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(this.StartDetect), this);
        }

        public override void CancelDetectAction()
        {
        }

        private bool ParseHosts(string file, List<DetectResult> details)
        {
            char[] separator = new char[] { ' ', '\t' };
            if (File.Exists(file))
            {
                try
                {
                    bool flag = true;
                    using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read))
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            string text;
                            while ((text = reader.ReadLine()) != null)
                            {
                                if (!text.Trim().StartsWith("#"))
                                {
                                    if (!text.Trim().StartsWith("127.0.0.1") && !text.Trim().StartsWith("169"))
                                    {
                                        string[] textArray = text.Split(separator);
                                        if ((textArray.Length > 1) && (base.DetectData.ServerDnsName.IndexOf(textArray[textArray.Length - 1]) > -1))
                                        {
                                            details.Add(new DetectResult(DetectStatus.Suspect, textArray[textArray.Length - 1].Trim()));
                                        }
                                    }
                                    else
                                    {
                                        string[] textArray2 = text.Split(separator);
                                        if ((textArray2.Length > 1) && (base.DetectData.ServerDnsName.IndexOf(textArray2[textArray2.Length - 1]) > -1))
                                        {
                                            details.Add(new DetectResult(DetectStatus.Failed, textArray2[textArray2.Length - 1].Trim()));
                                            flag = false;
                                            base.CanResume = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    return flag;
                }
                catch (UnauthorizedAccessException exception)
                {
                    ClientLogger.WriteGeneral(exception.ToString());
                    details.Add(new DetectResult(DetectStatus.Failed, StringTable.NetworkDetect.CanNotReadHostFile));
                    base.CanResume = false;
                    return false;
                }
                catch (Exception exception2)
                {
                    ClientLogger.WriteGeneral(exception2.ToString());
                    details.Add(new DetectResult(DetectStatus.Failed, StringTable.NetworkDetect.ErrorOccour));
                    base.CanResume = true;
                    return false;
                }
            }
            details.Add(new DetectResult(DetectStatus.Passed, StringTable.NetworkDetect.HostFileNotExist));
            return true;
        }

        private void StartDetect(object state)
        {
            Thread.CurrentThread.Name = "Imps.Client.Pc.NetworkDetect.HostFileDetectAction";
            List<DetectResult> details = new List<DetectResult>();
            string file = string.Empty;
            if (Environment.OSVersion.Version >= OS.Windows2000)
            {
                file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"drivers\etc\hosts");
            }
            else
            {
                file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "Hosts");
            }
            bool passed = true;
            if (!string.IsNullOrEmpty(file))
            {
                passed = this.ParseHosts(file, details);
            }
            else
            {
                details.Add(new DetectResult(DetectStatus.Passed, StringTable.NetworkDetect.HostFileNotExist));
            }
            base.FireDetecFinsihedEvent(this, new DetectEventArgs(passed, details));
        }

        public override NetworkDetectStage CurrentStage
        {
            get
            {
                return NetworkDetectStage.HostFile;
            }
        }
    }
}

⌨️ 快捷键说明

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