コード例 #1
0
ファイル: Engine.cs プロジェクト: liftir/airvpn-client
        public Engine() : base(false)
        {
			Instance = this;
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: liftir/airvpn-client
        public void RefreshUi(Engine.RefreshUiMode mode)
        {
            if (this.IsHandleCreated == false)
                return;

			if (m_lockCoordUpdate)
				return;

            if (this.InvokeRequired)
            {
                RefreshUiDelegate inv = new RefreshUiDelegate(this.RefreshUi);

                //this.Invoke(inv, new object[] { mode });
                this.BeginInvoke(inv, new object[] { mode });
            }
            else
            {
				if (m_formReady == false) // To avoid useless calling that Windows.Forms do when initializing controls 
					return;

				// lock (Engine) // TOCLEAN 2.9
                {
					if( (mode == Core.Engine.RefreshUiMode.MainMessage) || (mode == Core.Engine.RefreshUiMode.Full) )
					{
						// Status message
						String text1 = Engine.WaitMessage;
						lblWait1.Text = text1;

						if (Engine.IsWaiting())
						{
							pnlWelcome.Visible = false;
							pnlWaiting.Visible = true;
							pnlConnected.Visible = false;
							cmdCancel.Visible = Engine.IsWaitingCancelAllowed();
							cmdCancel.Enabled = (Engine.IsWaitingCancelPending() == false);
							mnuConnect.Enabled = cmdCancel.Enabled;

							mnuStatus.Image = global::AirVPN.Lib.Forms.Properties.Resources.status_yellow_16;

						}
						else if (Engine.IsConnected())
						{
							pnlWelcome.Visible = false;
							pnlWaiting.Visible = false;
							pnlConnected.Visible = true;

							lblConnectedServerName.Text = Engine.CurrentServer.PublicName;
							lblConnectedLocation.Text = Engine.CurrentServer.CountryName + ", " + Engine.CurrentServer.Location;
							txtConnectedExitIp.Text = Engine.CurrentServer.IpExit;
							string iconFlagCode = Engine.CurrentServer.CountryCode;
							Image iconFlag = null;
							if (imgCountries.Images.ContainsKey(iconFlagCode))
							{
								iconFlag = imgCountries.Images[iconFlagCode];
								lblConnectedCountry.Image = iconFlag;
							}
							else
								lblConnectedCountry.Image = null;

							mnuStatus.Image = global::AirVPN.Lib.Forms.Properties.Resources.status_green_16;
						}
						else
						{
							pnlWelcome.Visible = true;
							pnlWaiting.Visible = false;
							pnlConnected.Visible = false;

							mnuStatus.Image = global::AirVPN.Lib.Forms.Properties.Resources.status_red_16;
						}
						
						// Icon                    
						{
							Icon icon;

							//if(pageView == PageView.Stats)
							if (Engine.IsConnected())
							{
								icon = global::AirVPN.Lib.Forms.Properties.Resources.icon1;
							}
							else
							{
								icon = global::AirVPN.Lib.Forms.Properties.Resources.icon_gray1;
							}

							if (this.Icon != icon)
							{
								this.Icon = icon;								
								if (m_notifyIcon != null)
									m_notifyIcon.Icon = icon;
							}
						}

						// Repaint
						Invalidate();

						EnabledUi();
					}

					if ((mode == Core.Engine.RefreshUiMode.Log) || (mode == Core.Engine.RefreshUiMode.Full))
					{
						lock (Engine.LogEntries)
						{
							while (Engine.LogEntries.Count > 0)
							{
								LogEntry l = Engine.LogEntries[0];
								Engine.LogEntries.RemoveAt(0);

								Log(l);
							}

							if (Engine.IsWaiting())
							{
								lblWait2.Text = Engine.GetLogDetailTitle();
							}
						}
					}

                    if( (mode == Core.Engine.RefreshUiMode.Stats) || (mode == Core.Engine.RefreshUiMode.Full))
                    {
						if (Engine.IsConnected())
						{
							txtConnectedSince.Text = Engine.Stats.GetValue("VpnConnectionStart");

							txtConnectedDownload.Text = Core.Utils.FormatBytes(Engine.ConnectedLastDownloadStep, true, false);
							txtConnectedUpload.Text = Core.Utils.FormatBytes(Engine.ConnectedLastUploadStep, true, false);

							string notifyText = Messages.Format(Messages.StatusTextConnected, Core.Utils.FormatBytes(Engine.ConnectedLastDownloadStep, true, false), Core.Utils.FormatBytes(Engine.ConnectedLastUploadStep, true, false), Engine.CurrentServer.PublicName, Engine.CurrentServer.CountryName);
							string notifyText2 = Constants.Name + " - " + notifyText;
							Text = notifyText2;
							mnuStatus.Text = "> " + notifyText;
							if (m_notifyIcon != null)
							{
								if (notifyText2.Length > 62)
									notifyText2 = notifyText2.Substring(0, 62);
								m_notifyIcon.Text = notifyText2;
							}
						}						
                    }

					if (mode == Core.Engine.RefreshUiMode.Full)
					{
						// TOCLEAN
						//bool welcome = ((Engine.IsWaiting() == false) && (Engine.IsConnected() == false));
						//bool connected = ((Engine.IsWaiting() == false) && (Engine.IsConnected() == true));

						m_listViewServers.UpdateList();
						m_listViewAreas.UpdateList();
					}
                }

                
            }
        }