CardIdleRemastered.BrowserWindow.wbAuth_Navigated C# (CSharp) Метод

wbAuth_Navigated() приватный Метод

private wbAuth_Navigated ( object sender, System.Windows.Navigation.NavigationEventArgs e ) : void
sender object
e System.Windows.Navigation.NavigationEventArgs
Результат void
        private void wbAuth_Navigated(object sender, NavigationEventArgs e)
        {
            // Find the page header, and remove it.  This gives the login form a more streamlined look.
            dynamic htmldoc = wbAuth.Document;
            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 src = wbAuth.Source;
            var url = wbAuth.Source.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(src);
                var cookies = container.GetCookies(src);
                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(src);
                var cookies = container.GetCookies(src);

                // 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")
                    {
                        string login = cookie.Value;
                        Settings.Default.steamLogin = login;

                        var steamId = WebUtility.UrlDecode(login);
                        var index = steamId.IndexOf('|');
                        if (index >= 0)
                            steamId = steamId.Remove(index);
                        Settings.Default.myProfileURL = "http://steamcommunity.com/profiles/" + steamId;
                    }

                    // 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();
            }
        }