private async Task CheckAndSave()
        {
            try
            {
                Settings.Default.sessionid     = txtSessionID.Text.Trim();
                Settings.Default.steamLogin    = txtSteamLogin.Text.Trim();
                Settings.Default.myProfileURL  = SteamProfile.GetSteamUrl();
                Settings.Default.steamparental = txtSteamParental.Text.Trim();

                if (await CookieClient.IsLogined())
                {
                    Settings.Default.Save();
                    Close();
                    return;
                }
            }
            catch (Exception ex)
            {
                Logger.Exception(ex, "frmSettingsAdvanced -> CheckAndSave");
            }

            // Invalid cookie data, reset the form
            btnUpdate.Text                = localization.strings.update;
            txtSessionID.Text             = "";
            txtSteamLogin.Text            = "";
            txtSteamParental.Text         = "";
            txtSessionID.PasswordChar     = '\0';
            txtSteamLogin.PasswordChar    = '\0';
            txtSteamParental.PasswordChar = '\0';
            txtSessionID.Enabled          = true;
            txtSteamLogin.Enabled         = true;
            txtSteamParental.Enabled      = true;
            txtSessionID.Focus();
            MessageBox.Show(localization.strings.validate_failed);
            btnUpdate.Enabled = true;
        }
Exemple #2
0
        // This code block executes each time a new document is loaded into the web browser control
        private void wbAuth_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            // Find the page header, and remove it.  This gives the login form a more streamlined look.
            dynamic htmldoc      = wbAuth.Document.DomDocument;
            dynamic globalHeader = htmldoc.GetElementById("global_header");

            if (globalHeader != null)
            {
                try
                {
                    globalHeader.parentNode.removeChild(globalHeader);
                }
                catch (Exception)
                {
                }
            }

            // Get the URL of the page that just finished loading
            var url = wbAuth.Url.AbsoluteUri;

            // If the page it just finished loading is the login page
            if (url == "https://steamcommunity.com/login/home/?goto=my/profile" ||
                url == "https://store.steampowered.com/login/transfer" ||
                url == "https://store.steampowered.com//login/transfer")
            {
                // Get a list of cookies from the current page
                CookieContainer container = GetUriCookieContainer(wbAuth.Url);
                var             cookies   = container.GetCookies(wbAuth.Url);
                foreach (Cookie cookie in cookies)
                {
                    if (cookie.Name.StartsWith("steamMachineAuth"))
                    {
                        Settings.Default.steamMachineAuth = cookie.Value;
                    }
                }
            }
            // If the page it just finished loading isn't the login page
            else if (url.StartsWith("javascript:") == false && url.StartsWith("about:") == false)
            {
                try
                {
                    dynamic parentalNotice = htmldoc.GetElementById("parental_notice");
                    if (parentalNotice != null)
                    {
                        if (parentalNotice.OuterHtml != "")
                        {
                            // Steam family options enabled
                            wbAuth.Show();
                            Width  = 1000;
                            Height = 350;
                            return;
                        }
                    }
                }
                catch (Exception)
                {
                }

                // Get a list of cookies from the current page
                var container = GetUriCookieContainer(wbAuth.Url);
                var cookies   = container.GetCookies(wbAuth.Url);

                // Go through the cookie data so that we can extract the cookies we are looking for
                foreach (Cookie cookie in cookies)
                {
                    // Save the "sessionid" cookie
                    if (cookie.Name == "sessionid")
                    {
                        Settings.Default.sessionid = cookie.Value;
                    }

                    // Save the "steamLogin" cookie and construct and save the user's profile link
                    else if (cookie.Name == "steamLogin")
                    {
                        Settings.Default.steamLogin   = cookie.Value;
                        Settings.Default.myProfileURL = SteamProfile.GetSteamUrl();
                    }

                    // Save the "steamparental" cookie"
                    else if (cookie.Name == "steamparental")
                    {
                        Settings.Default.steamparental = cookie.Value;
                    }

                    else if (cookie.Name == "steamRememberLogin")
                    {
                        Settings.Default.steamRememberLogin = cookie.Value;
                    }
                }

                // Save all of the data to the program settings file, and close this form
                Settings.Default.Save();
                Close();
            }
        }