void finishSetup()
        {
            // Set up cookies
            CookieContainer cookies = CredentialStore.GetCommunityCookies();

            client.SetCookies(cookies);

            // Update right click menu
            loginMenuItem.Visible   = false;
            refreshMenuItem.Visible = true;

            // Set main icon visible
            ReplaceNotifyIcon(mainIcon, IconUtils.CreateIconWithBackground(Properties.Resources.NotificationDefault, Properties.Settings.Default.InboxNoneColor, SystemInformation.SmallIconSize));
            mainIcon.Visible = true;

            // Set up timer and fire
            refreshTimer.Start();
            updateNotifications();
        }
        private async void loginButton_Click(object sender, EventArgs e)
        {
            loginButton.Enabled  = false;
            cancelButton.Enabled = false;
            try
            {
                if (!validateEntry())
                {
                    return;
                }
                bool success = await Task.Run <bool>(() => doLogin());

                if (success)
                {
                    CredentialStore.SaveTransferParameters(loginResponse.TransferParameters);
                    DialogResult = System.Windows.Forms.DialogResult.OK;
                    Close();
                }
                else
                {
                    updateGuiFromResponse();
                    if (loginResponse == null)
                    {
                        messageLabel.Text = "Could not communicate with Steam Community.";
                    }
                    else if (!string.IsNullOrEmpty(loginResponse.Message))
                    {
                        messageLabel.Text = loginResponse.Message;
                    }
                    else
                    {
                        messageLabel.Text = string.Empty;
                        if (loginResponse.EmailAuthNeeded)
                        {
                            if (string.IsNullOrEmpty(loginResponse.EmailDomain))
                            {
                                messageLabel.Text += "Steam Guard code incorrect. ";
                            }
                            else
                            {
                                messageLabel.Text += "Steam Guard code required. ";
                            }
                        }
                        if (loginResponse.RequiresTwoFactor)
                        {
                            messageLabel.Text += "Mobile Authenticator code required. ";
                        }
                        if (loginResponse.CaptchaNeeded && !loginResponse.IsBadCaptcha)
                        {
                            messageLabel.Text += "CAPTCHA entry required. ";
                        }
                        if (loginResponse.IsBadCaptcha)
                        {
                            messageLabel.Text += "CAPTCHA entry incorrect. ";
                        }
                        if (loginResponse.DeniedIpt)
                        {
                            messageLabel.Text += "Intel® Identity Protection Technology access denied. ";
                        }
                    }
                    messageLabel.Visible = messageLabel.Text.Length > 0;
                    if (loginResponse != null && loginResponse.CaptchaNeeded)
                    {
                        await loadNewCaptcha();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Could not log in: " + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                loginButton.Enabled  = true;
                cancelButton.Enabled = true;
            }
        }
Exemplo n.º 3
0
        public TrayAppContext()
        {
            NotifyIcon_ShowContextMenu = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.NonPublic | BindingFlags.Instance);

            // Upgrade settings first
            var settings = Properties.Settings.Default;

            if (!settings.SettingsUpgraded)
            {
                settings.Upgrade();
                settings.SettingsUpgraded = true;
                settings.Save();
            }

            loginMenuItem = new MenuItem(Properties.Resources.LogIn, (sender, e) =>
            {
                promptLogin();
            })
            {
                Visible = false
            };
            refreshMenuItem = new MenuItem(Properties.Resources.RefreshNow, (sender, e) =>
            {
                updateNotifications();
            });
            muteMenuItem = new MenuItem(Properties.Resources.TempMute, (sender, e) =>
            {
                muted = !muted;
                muteMenuItem.Checked = muted;
            })
            {
                Visible = settings.EnableBalloons
            };

            appContextMenu = new ContextMenu(new MenuItem[] {
                loginMenuItem,
                refreshMenuItem,
                muteMenuItem,
                new MenuItem(Properties.Resources.Settings, (sender, e) =>
                {
                    var settingsForm              = new SettingsForm();
                    settingsForm.SettingsApplied += settingsForm_SettingsApplied;
                    settingsForm.LoggingOut      += settingsForm_LoggingOut;
                    settingsForm.Show();
                }),
                new MenuItem(Properties.Resources.Exit, (sender, e) => {
                    client.SaveCredentials();
                    Application.Exit();
                })
            });

            setupNotificationsPopup();

            refreshTimer.Interval = settings.RefreshInterval;
            refreshTimer.Tick    += refreshTimer_Tick;

            // Must do this true/false charade to get context menus associated for some reason
            countIcon.ContextMenu = appContextMenu;
            countIcon.Visible     = true;
            countIcon.Visible     = false;
            mainIcon.ContextMenu  = appContextMenu;
            mainIcon.Text         = Application.ProductName;
            mainIcon.Visible      = true;
            mainIcon.Visible      = false;

            mainIcon.MouseDown          += notifyIcon_MouseDown;
            mainIcon.MouseClick         += notifyIcon_MouseClick;
            mainIcon.MouseDoubleClick   += notifyIcon_MouseDoubleClick;
            countIcon.MouseDown         += notifyIcon_MouseDown;
            countIcon.MouseClick        += notifyIcon_MouseClick;
            countIcon.MouseDoubleClick  += notifyIcon_MouseDoubleClick;
            countIcon.BalloonTipClicked += countIcon_BalloonTipClicked;

            // If no cookies available, show login form
            //CredentialStore.ClearCredentials();
            if (!CredentialStore.CredentialsAvailable())
            {
                promptLogin();
            }
            else
            {
                finishSetup();
            }
        }