コード例 #1
0
ファイル: HunterProxyFilter.cs プロジェクト: zhangrl/Hunter3
        public HunterProxyFilter(HunterConfig c)
        {
            config = c;
            InitializeComponent();
            FormClosing += new FormClosingEventHandler(HunterProxyFilter_FormClosing);
            foreach (String s in config.ProxyFilterKeywords)
            {
                hContent.AppendText(s + Environment.NewLine);
            }
            Button e = new Button();

            e.Click += new EventHandler((object sender, EventArgs ex) =>
            {
                Close();
            });
            this.CancelButton = e;
        }
コード例 #2
0
 public static HunterConfig Load()
 {
     try
     {
         HunterConfig  hConfig;
         XmlSerializer ser = new XmlSerializer(typeof(HunterConfig));
         FileStream    fs  = new FileStream("config.xml", FileMode.Open, FileAccess.Read);
         hConfig = (HunterConfig)ser.Deserialize(fs);
         fs.Close();
         return(hConfig);
     }
     catch
     {
         HunterConfig t = new HunterConfig();
         t.ProxyFilterKeywords.Add("'请把需要使用的代理信息输入在此,如输入\"广州\",Hunter将会使用所有代理描述中含有\"广州\"二字的代理服务器。不支持空格分词,若什么都不输入,则表示使用所有可用的代理服务器。关闭此窗口,将自动保存内容。");
         t.Save();
         return(t);
     }
 }
コード例 #3
0
ファイル: HunterEditor.cs プロジェクト: zhangrl/Hunter3
        //asReflectionObject 表示此编辑器是用反射、序列化来处理文本,还是作为普通文本编辑器来处理文本
        public HunterEditor(HunterConsole c, HunterConfig config, String LoadFile, bool AsAModel, String fileFilter, bool asReflectionObject, Type objectType, object loadObject, Hunter3.HunterRichTextBox.TextType textType)
        {
            FileFilter              = fileFilter;
            this.AsAModel           = AsAModel;
            this.LoadFile           = LoadFile;
            ObjectType              = objectType;
            Config                  = config;
            Console                 = c;
            this.AsReflectionObject = asReflectionObject;
            LoadObject              = loadObject;
            InitializeComponent();

            hSearchBar.Init(hTextBox, tsLabel, HunterConfig.ColorBarForeColor);
            hHTMLGetterBar.Init(hTextBox, HunterConfig.ColorBarForeColor);
            hTextBox.ContentType = textType;
            tsLabel.BackColor    = Color.Transparent;
            FormBorderStyle      = FormBorderStyle.Sizable;
            MainToolStrip        = msMenu;
            try
            {
                if (LoadFile != null)
                {
                    hTextBox.LoadFile(LoadFile);
                    if (AsAModel)
                    {
                        FileSaved = false;
                    }
                    else
                    {
                        Filename = LoadFile;
                    }

                    ClearDirty();
                }
            }
            catch (Exception ex)
            {
                Console.WriteException(ex);
            }

            if (!AsReflectionObject)
            {
                sContainer.Panel2Collapsed = true;
            }
            else
            {
                try
                {
                    RefreshXML();
                    LoadProperty();
                }
                catch (Exception ex)
                {
                    Console.WriteException(ex);
                }
            }

            FormClosing += new FormClosingEventHandler(HunterEditor_FormClosing);
            propertyGrid.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid_PropertyValueChanged);
            hTextBox.SelectionChanged         += new EventHandler(hTextBox_SelectionChanged);
            hTextBox.TextChanged += new EventHandler((object s, EventArgs ea) =>
            {
                if (hTextBox.Modified)
                {
                    FileSaved = false;
                    Text      = CaptionFilename + " *";
                }
                RefreshUI();
                RefreshPropertyGrid();
            });
            RefreshUI();
        }
コード例 #4
0
        private void Init()
        {
            hunterFormTitle.Owner          = this;
            HunterNotify.MouseDoubleClick += NotifyDbClick;
            HunterNotify.MouseMove        += NotifyMove;

            //绑定事件
            this.miQuick.Click         += new System.EventHandler(this.miQuick_Click);
            this.miNew.Click           += new System.EventHandler(this.miNew_Click);
            this.miOpen.Click          += new System.EventHandler(this.miOpen_Click);
            this.miClose.Click         += new System.EventHandler(this.miClose_Click);
            this.miModify.Click        += new System.EventHandler(this.miModify_Click);
            this.miQuit.Click          += new System.EventHandler(this.miQuit_Click);
            this.miNewStrategy.Click   += new System.EventHandler(this.miNewStrategy_Click);
            this.miEditStrategy.Click  += new System.EventHandler(this.miEditStrategy_Click);
            this.miConfig.Size          = new System.Drawing.Size(60, 21);
            this.miProxyList.Click     += new System.EventHandler(this.miProxyList_Click);
            this.miFilter.Click        += new System.EventHandler(this.miFilter_Click);
            this.miToogleProxy.Click   += new System.EventHandler(this.miToogleProxy_Click);
            this.miCls.Click           += new System.EventHandler(this.miCls_Click);
            this.miDownloaded.Click    += new System.EventHandler(this.miDownloaded_Click);
            this.miAbandonLinks.Click  += new System.EventHandler(this.miAbandonLinks_Click);
            this.miAbandonFiles.Size    = new System.Drawing.Size(181, 22);
            this.miAbandonFiles.Text    = "显示已抛弃文件";
            this.miAbandonFiles.Click  += new System.EventHandler(this.miAbandonFiles_Click);
            this.miExceptions.Click    += new System.EventHandler(this.miExceptions_Click);
            this.miPause.Click         += new System.EventHandler(this.miPause_Click);
            this.miHunter3Editor.Click += new System.EventHandler(this.miOpenH3Editor_Click);
            this.miAbout.Click         += new System.EventHandler(this.miAbout_Click);

            //---

            cbViewAbandonFiles.ForeColor = HunterConfig.ColorAbandonFile;
            cbViewDetails.ForeColor      = HunterConfig.ColorDetails;
            cbViewDownloads.ForeColor    = HunterConfig.ColorDownload;
            cbViewExceptions.ForeColor   = HunterConfig.ColorException;
            cbViewAbandonLinks.ForeColor = HunterConfig.ColorAbandonLink;
            cbViewProxy.ForeColor        = HunterConfig.ColorProxy;
            cbViewHTML.ForeColor         = HunterConfig.ColorHTML;

            lbDownloads.ForeColor    = HunterConfig.ColorDownload;
            lbExceptions.ForeColor   = HunterConfig.ColorException;
            lbAbandonFiles.ForeColor = HunterConfig.ColorAbandonFile;
            lbAbandonLinks.ForeColor = HunterConfig.ColorAbandonLink;

            hunterTextBox.Dock        = DockStyle.Fill;
            hunterTextBox.ReadOnly    = true;
            hunterTextBox.ScrollBars  = RichTextBoxScrollBars.Vertical;
            hunterTextBox.BorderStyle = BorderStyle.None;
            HContainer.Panel1.Controls.Add(hunterTextBox);
            HContainer.SplitterDistance = splitterdistance;


            lbDownloads.Text    = strDownloads + Downloads;
            lbExceptions.Text   = strExceptions + Exceptions;
            lbAbandonFiles.Text = strAbandonFiles + AbandonFiles;
            lbAbandonLinks.Text = strAbandonLinks + AbandonLinks;

            mHunterConfig = HunterConfig.Load();
            cbViewAbandonFiles.Checked = mHunterConfig.viewOption.AbandonFiles;
            cbViewAbandonLinks.Checked = mHunterConfig.viewOption.AbandonLinks;
            cbViewDownloads.Checked    = mHunterConfig.viewOption.DownloadItems;
            cbViewDetails.Checked      = mHunterConfig.viewOption.Details;
            cbViewExceptions.Checked   = mHunterConfig.viewOption.Exceptions;
            cbViewProxy.Checked        = mHunterConfig.viewOption.Proxies;
            cbViewHTML.Checked         = mHunterConfig.viewOption.HTML;
            miToogleProxy.Checked      = mHunterConfig.UseProxy;
            miPause.Enabled            = false;

            switch (mHunterConfig.HunterCore)
            {
            case HunterConfig.Core.Default:
                miCoreAuto.Checked = true;
                break;

            case HunterConfig.Core.IE:
                miCoreIE.Checked = true;
                break;

            case HunterConfig.Core.WebRequest:
                miCoreHunter.Checked = true;
                break;
            }

            WriteMessage("搜索策略文件:" + mHunterConfig.CurrentStrategyFile);
            try
            {
                LoadStrategy(mHunterConfig.CurrentStrategyFile).GetStrategyInformation();
                WriteMessage("Hunter 准备就绪,可以打开任务进行爬虫下载了!");
            }
            catch (Exception ex)
            {
                WriteMessage("错误:" + ex.Message);
            }

            LoadStrategyList();
            LoadPluginList();

            if (mHunterConfig.notifyOption.FirstBallon)
            {
                HunterNotify.ShowBalloonTip(2, "Hunter 3", "这里是Hunter 3 的通知区域图标,单击它可以隐藏窗口。", ToolTipIcon.Info);
                mHunterConfig.notifyOption.FirstBallon = false;
            }

            flowMain.MouseDown  += SaveLocation;
            flowMain.MouseMove  += MoveWindow;
            flowMain.MouseLeave += ResetLocOffset;

            picLogo.MouseDown  += SaveLocation;
            picLogo.MouseMove  += MoveWindow;
            picLogo.MouseLeave += ResetLocOffset;

            msMenu.MouseDown  += SaveLocation;
            msMenu.MouseMove  += MoveWindow;
            msMenu.MouseLeave += ResetLocOffset;

            hunterFormTitle.AddMouseDown(SaveLocation);
            hunterFormTitle.AddMouseMove(MoveWindow);
            hunterFormTitle.AddMouseLeave(ResetLocOffset);
        }
コード例 #5
0
        public Hunter(HunterConsole oh, HunterConfig config, ProjectInfo _pj, HunterForm main)
        {
            try
            {
                MainForm       = main;
                Error          = false;
                mHunterConsole = oh;
                projectInfo    = _pj;
                mHunterConfig  = config;
                ProxyFetcher   = new HunterProxyFetcher(AvailableProxies);
                projectInfo    = ProjectInfo.LoadProject(_pj.mHunterConsole, _pj.projectPath, _pj.strategyPath, true);

                downloadThreadNum = int.Parse(projectInfo.threadnum);
                hunterThreads     = new HunterDownloadThread[downloadThreadNum];

                //获取代理的线程
                ProxyGetThreads = new Thread[downloadThreadNum];

                if (mHunterConfig.UseProxy == true)
                {
                    FileStream   fs = new FileStream("proxy.hip", FileMode.Open, FileAccess.Read);
                    StreamReader sr = new StreamReader(fs);
                    ProxyText = sr.ReadToEnd();
                    sr.Close();
                    fs.Close();
                    AllProxies = HunterProxy.GetProxy(ProxyText, mHunterConfig.ProxyFilterKeywords);
                }

                mHunterConsole.WriteMessage(projectInfo.ConfigInformation());
                mHunterConsole.WriteMessage("");
                mHunterConsole.WriteMessage(projectInfo.strategy.GetStrategyInformation());

                xmlDatabase = new XMLDatabase(projectInfo.database, mHunterConsole);
                xmlDatabase.openDatabase();

                try
                {
                    if (downloadThreadNum <= 0)
                    {
                        mHunterConsole.WriteMessage("配置错误:下载线程数不能小于0。");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    mHunterConsole.WriteException(ex);
                    return;
                }

                for (int i = 0; i < hunterThreads.Length; i++)
                {
                    hunterThreads[i] = new HunterDownloadThread();
                    hunterThreads[i].downloadThread = new Thread(threadDownloadUris);
                }

                if (mHunterConfig.UseProxy)
                {
                    for (int i = 0; i < ProxyGetThreads.Length; i++)
                    {
                        ProxyGetThreads[i] = new Thread(GetAvaliableProxies);
                    }
                }

                if (projectInfo.strategy.Keywords.Count <= 0)
                {
                    projectInfo.mHunterConsole.WriteMessage("没有找到关键字,任务取消。");
                    Error = true;
                    return;
                }

                thHuntUris = new Thread(threadHuntUris);
                thHuntUris.SetApartmentState(ApartmentState.STA);

                hUri = new HunterUri(this);
                projectInfo.strategy.RecordFirstWord();

                mHunterConsole.WriteMessage("下载线程总数:" + hunterThreads.Length);
                mHunterConsole.WriteMessage("读取配置完毕。");
                mHunterConsole.WriteMessage("正在运行任务...");
            }
            catch (Exception e)
            {
                mHunterConsole.WriteException(e);
            }
        }