Esempio n. 1
0
        private void UpdateCheckForm_Load(object sender, EventArgs e)
        {
            // set the initial status
            versionInfoLabel.Text = GetHtmlText("<p>Latest Version: checking</p></body></html>");

            // set checkboxes and dropdown
            autoDropdown.Items.Clear();
            autoDropdown.Items.Add(new UpdateIntervalItem {
                Name = "Every Time", Interval = new TimeSpan(0, 0, 0, 0)
            });
            autoDropdown.Items.Add(new UpdateIntervalItem {
                Name = "Every Day", Interval = new TimeSpan(1, 0, 0, 0)
            });
            autoDropdown.Items.Add(new UpdateIntervalItem {
                Name = "Every 3 Days", Interval = new TimeSpan(3, 0, 0, 0)
            });
            autoDropdown.Items.Add(new UpdateIntervalItem {
                Name = "Every Week", Interval = new TimeSpan(7, 0, 0, 0)
            });
            autoDropdown.Items.Add(
                new UpdateIntervalItem {
                Name = "Every 2 Weeks", Interval = new TimeSpan(14, 0, 0, 0)
            });
            autoDropdown.Items.Add(new UpdateIntervalItem {
                Name = "Every Month", Interval = new TimeSpan(30, 0, 0, 0)
            });

            if (Updater == null)
            {
                Updater = new WinAuthUpdater(Config);
            }

            if (Updater.IsAutoCheck == false)
            {
                autoCheckbox.Checked       = false;
                autoDropdown.SelectedIndex = -1;
            }
            else
            {
                autoCheckbox.Checked = true;
                var interval = Updater.UpdateInterval;
                if (interval != null)
                {
                    foreach (UpdateIntervalItem item in autoDropdown.Items)
                    {
                        if (item.Interval == interval)
                        {
                            autoDropdown.SelectedItem = item;
                            break;
                        }
                    }
                }
            }

            // initiate async call to get latest version
            Updater.GetLatestVersion(Updater_GetLatestVersionCompleted);
        }
Esempio n. 2
0
		/// <summary>
		/// Initialise the current form and UI
		/// </summary>
		private void InitializeForm()
		{
			// create the updater and check for update if appropriate
			if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed == false)
			{
				Updater = new WinAuthUpdater(this.Config);

				// the very first time, we set it to update each time
				if (Updater.LastCheck == DateTime.MinValue)
				{
					Updater.SetUpdateInterval(new TimeSpan(0, 0, 0));
				}
				if (Updater.IsAutoCheck == true)
				{
					Version latest = Updater.LastKnownLatestVersion;
					if (latest != null && latest > Updater.CurrentVersion)
					{
						newVersionLink.Text = "New version " + latest + " available";
						newVersionLink.Visible = true;
					}
				}
				// spin up the autocheck thread and assign callback
				Updater.AutoCheck(NewVersionAvailable);
			}

			// set up list
			loadAuthenticatorList();

			// set always on top
			this.TopMost = this.Config.AlwaysOnTop;

			// size the form based on the authenticators
			setAutoSize();

			// initialize UI
			LoadAddAuthenticatorTypes();
			loadOptionsMenu(this.optionsMenu);
			loadNotifyMenu(this.notifyMenu);
			loadingPanel.Visible = false;
			passwordPanel.Visible = false;
			yubiPanel.Visible = false;
			commandPanel.Visible = true;
			introLabel.Visible = (this.Config.Count == 0);
			authenticatorList.Visible = (this.Config.Count != 0);
			this.addAuthenticatorButton.Visible = !this.Config.IsReadOnly;

			// set title
			notifyIcon.Visible = this.Config.UseTrayIcon;
			notifyIcon.Text = this.Text = WinAuthMain.APPLICATION_TITLE;

			// hook hotkeys
			HookHotkeys();

			// save the position of the list within the form else starting as minimized breaks the size
			_listoffset = new Rectangle(authenticatorList.Left, authenticatorList.Top, (this.Width - authenticatorList.Width), (this.Height - authenticatorList.Height));

			// set the shadow type (change in config for compatibility)
			MetroFormShadowType shadow;
			if (Enum.TryParse<MetroFormShadowType>(this.Config.ShadowType, true, out shadow) == true)
			{
				this.ShadowType = shadow;
			}

			// set positions
			if (this.Config.Position.IsEmpty == false)
			{
				// check we aren't out of bounds in case of multi-monitor change
				var v = SystemInformation.VirtualScreen;
				if ((this.Config.Position.X + this.Width) >= v.Left && this.Config.Position.X < v.Width && this.Config.Position.Y > v.Top)
				{
					try
					{
						this.StartPosition = FormStartPosition.Manual;
						this.Left = this.Config.Position.X;
						this.Top = this.Config.Position.Y;
					}
					catch (Exception) { }
				}

				// check we aren't below the taskbar
				int lowesty = Screen.GetWorkingArea(this).Bottom;
				var bottom = this.Top + this.Height;
				if (bottom > lowesty)
				{
					this.Top -= (bottom - lowesty);
					if (this.Top < 0)
					{
						this.Height += this.Top;
						Top = 0;
					}
				}
			}
			else if (this.Config.AutoSize == true)
			{
				this.CenterToScreen();
			}

			// if we passed "-min" flag
			if (_initiallyMinimised == true)
			{
				this.WindowState = FormWindowState.Minimized;
				this.ShowInTaskbar = true;
			}
			if (this.Config.UseTrayIcon == true)
			{
				notifyIcon.Visible = true;
				notifyIcon.Text = this.Text;

				// if initially minimized, we need to hide
				if (WindowState == FormWindowState.Minimized)
				{
					// hide this and metro owner
					Form form = this;
					do
					{
						form.Hide();
					} while ((form = form.Owner) != null);
				}
			}
		}
Esempio n. 3
0
		private void UpdateCheckForm_Load(object sender, EventArgs e)
		{
			// set the initial status
			versionInfoLabel.Text = GetHtmlText("<p>Latest Version: checking</p></body></html>");

			// set checkboxes and dropdown
			autoDropdown.Items.Clear();
			autoDropdown.Items.Add(new UpdateIntervalItem { Name = "Every Time", Interval = new TimeSpan(0, 0, 0, 0) });
			autoDropdown.Items.Add(new UpdateIntervalItem { Name = "Every Day", Interval = new TimeSpan(1, 0, 0, 0) });
			autoDropdown.Items.Add(new UpdateIntervalItem { Name = "Every 3 Days", Interval = new TimeSpan(3, 0, 0, 0) });
			autoDropdown.Items.Add(new UpdateIntervalItem { Name = "Every Week", Interval = new TimeSpan(7, 0, 0, 0) });
			autoDropdown.Items.Add(new UpdateIntervalItem { Name = "Every 2 Weeks", Interval = new TimeSpan(14, 0, 0, 0) });
			autoDropdown.Items.Add(new UpdateIntervalItem { Name = "Every Month", Interval = new TimeSpan(30, 0, 0, 0) });

			if (Updater == null)
			{
				Updater = new WinAuthUpdater(this.Config);
			}

			if (Updater.IsAutoCheck == false)
			{
				autoCheckbox.Checked = false;
				autoDropdown.SelectedIndex = -1;
			}
			else
			{
				autoCheckbox.Checked = true;
				TimeSpan? interval = Updater.UpdateInterval;
				if (interval != null)
				{
					foreach (UpdateIntervalItem item in autoDropdown.Items)
					{
						if (item.Interval == interval)
						{
							autoDropdown.SelectedItem = item;
							break;
						}
					}
				}
			}

			// initiate async call to get latest version
			Updater.GetLatestVersion(Updater_GetLatestVersionCompleted);
		}