Пример #1
0
 public void DataBind()
 {
     if (ProxyData.ProxyList != null && ProxyData.ProxyList.Count > 0)
     {
         ProxyPage.BindData();
     }
 }
Пример #2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                #region 测试版

#if DEBUG
                try
                {
                    var      apiHelper = new ApiHelper();
                    DateTime now       = apiHelper.GetDate(DateType.SysDate);
                    if (now > AboutBox.PublishDate.AddMonths(1)) //发布一个月失效
                    {
                        SplashScreen.CloseSplashScreen();
                        MsgBox.ShowErrorMessage("该测试版已失效,请下在最新版!");
                        OpenIE(Config.ProxyHeroCloudSetting.UpdateUrl);
                        Exit_Click(Exit, new EventArgs());
                    }
                }
                catch (WebException)
                {
                    Config.InitErrorInfo = Config.LocalLanguage.Messages.InitializeFailed + "," +
                                           Config.LocalLanguage.Messages.PleaseCheckNetworkSettingsAreCorrect;
                }
#endif

                #endregion

                #region

                _languageLoader         = new LanguageLoader();
                TimerAutoSwitchingProxy = new Timer();
                TimerAutoChangeIcon     = new Timer();

                //SplashScreen.UpdateStatusText(Config.LocalLanguage.Messages.InitializeDatabase);
                //Config.InitDatabase();

                _deserializeDockContent = GetContentFromPersistString;

                SplashScreen.UpdateStatusText(Config.LocalLanguage.Messages.LoadingLanguages);
                Config.LanguageFileName = Config.LocalSetting.LanguageFileName;
                if (System.IO.File.Exists(Config.LanguageFileName))
                {
                    Config.LocalLanguage = XmlHelper.XmlDeserialize(
                        Config.LanguageFileName,
                        typeof(Language)) as Language;
                }
                LoadLanguage();

                #endregion

                #region 初始化配置

                GetNetConfigAndCheckVersion();

                #endregion

                #region 连接云引擎

                try
                {
                    DelegateVoid dv    = ConnectCloud;
                    var          thred = new Thread(new ThreadStart(dv));
                    thred.Start();
                }
                catch
                {
                    if (Config.LocalLanguage != null)
                    {
                        CloudStatus.Text = Config.LocalLanguage.Messages.ConnectCloudEngineFailed;
                    }
                    CloudStatus.Image = Resources.cloudno;
                }

                #endregion

                #region Hotkey

                //Hotkey hotkey = new Hotkey(this.Handle);
                //Hotkey1 = hotkey.RegisterHotkey(System.Windows.Forms.Keys.T, Hotkey.KeyFlags.MOD_CONTROL);
                //hotkey.OnHotkey += new HotkeyEventHandler(OnHotkey);

                #endregion

                #region UI

                MainToolbar.Visible = false;
                MainStatusBar.Items.Insert(2, new ToolStripSeparator());
                MainStatusBar.Items.Insert(4, new ToolStripSeparator());
                MainStatusBar.Items.Insert(6, new ToolStripSeparator());
                MainStatusBar.Items.Insert(8, new ToolStripSeparator());
                MainStatusBar.Items.Insert(10, new ToolStripSeparator());
                tsslVersion.Text = @"Version:" + Assembly.GetExecutingAssembly().GetName().Version;
                if (Config.LocalLanguage != null)
                {
                    CloudStatus.Text = Config.LocalLanguage.Messages.ConnectingCloudEngine;
                }

                _httpHelper.HttpOption.Timeout = 60 * 1000;

                SetProxyStatusLabel();
                if (Config.LocalLanguage != null)
                {
                    AutoSwitchProxyStatus.Text = Config.LocalLanguage.Messages.AutomaticSwitchingOff;
                }
                Status.Text   = Config.InitErrorInfo;
                Status.Spring = true;

                #endregion

                #region timer

                TimerAutoSwitchingProxy.Enabled  = false;
                TimerAutoSwitchingProxy.Interval = 1000;
                TimerAutoSwitchingProxy.Elapsed += timerAutoSwitchingProxy_Elapsed;

                TimerAutoChangeIcon.Enabled  = false;
                TimerAutoChangeIcon.Interval = 1000;
                TimerAutoChangeIcon.Elapsed += timerAutoChangeIcon_Elapsed;

                #endregion

                #region DockPanel

                if (Config.LocalLanguage != null)
                {
                    SplashScreen.UpdateStatusText(Config.LocalLanguage.Messages.InitializeDockPanel);
                    if (System.IO.File.Exists(Config.DockSettingFileName))
                    {
                        try
                        {
                            MainDockPanel.LoadFromXml(Config.DockSettingFileName, _deserializeDockContent);
                        }
                        catch
                        {
                            _hasDockSettingExceptioin = true;
                            if (System.IO.File.Exists(Config.DockSettingFileName))
                            {
                                SplashScreen.CloseSplashScreen();
                                System.IO.File.Delete(Config.DockSettingFileName);
                                MsgBox.ShowErrorMessage(Config.LocalLanguage.Messages.InitializeFailed);
                                Application.Exit();
                            }
                        }
                    }
                    else
                    {
                        #region dock

                        StartPage.Show(MainDockPanel, DockState.Document);
                        InfoPage.Show(MainDockPanel, DockState.DockBottomAutoHide);
                        InfoPage.Hide();
                        ProxyPage.Show(MainDockPanel, DockState.Document);

                        #endregion
                    }
                }

                #endregion

                #region

                LoadViewSetting();

                if (Config.LocalLanguage != null)
                {
                    SplashScreen.UpdateStatusText(Config.LocalLanguage.Messages.CheckUpdate);
                }
                CheckVersionAndDownLoad();

                #region 读取上次代理

                if (System.IO.File.Exists(Config.LastProxyFileName))
                {
                    ProxyData.ProxyList =
                        (List <ProxyServer>)
                        XmlHelper.XmlDeserialize(Config.LastProxyFileName, typeof(List <ProxyServer>));
                    ProxyPage.BindData();
                }

                #endregion

                if (Config.LocalLanguage != null)
                {
                    SplashScreen.UpdateStatusText(Config.LocalLanguage.Messages.LoadingPlugins);
                }
                PluginManager.LoadAllPlugins();
                //如果没有获取代理网页列表,则禁止使用
#if !DEBUG
                if (Config.ProxySiteUrlList.Count == 0)
                {
                    this.ProxyPage.Enabled = false;
                }
#endif

                SplashScreen.CloseSplashScreen();
                StartPage.Activate();
                Activate();
                if (Config.ProxyHeroCloudSetting.EnableCommercialPage == "1") //如果显示弹出广告
                {
#if !DEBUG
                    if (Config.IsChineseOs)
                    {
                        this.OpenNewTab(Config.ProxyHeroCloudSetting.CommercialUrl);
                    }
                    else
                    {
                        this.OpenNewTab(Config.ProxyHeroCloudSetting.EnglishCommercialUrl);
                    }
#else
                    OpenNewTab(Config.IsChineseLanguage
                                   ? Config.ProxyHeroCloudSetting.CommercialUrl
                                   : Config.ProxyHeroCloudSetting.EnglishCommercialUrl);
#endif
                }

                #endregion
            }
            catch (Exception ex)
            {
                SplashScreen.CloseSplashScreen();
                MsgBox.ShowExceptionMessage(ex);
            }
        }