src/AppCore.cs
/// <summary>
/// Checks whether valid cookies are present in system or not
/// </summary>
/// <returns>True if valid cookies are found</returns>
Checks whether valid cookies are present in system or not
Checks whether valid cookies are present in system or not
public async Task<bool> Init()
        {
            Console.WriteLine("Checking authorization...");
            string cookies = GetGlobalCookies("https://www.furaffinity.net/");
            if (cookies == null) return false;
            Console.WriteLine("Found some cookies.");
            try
            {
                http.DefaultRequestHeaders.Clear();
                http.DefaultRequestHeaders.Add("User-Agent", Utils.EmbeddedIeUtils.GetKnownUserAgentValue());
                http.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate");
                http.DefaultRequestHeaders.Add("Accept", "*/*");
                http.DefaultRequestHeaders.Add("Cookie", cookies);
                string cpage = await http.GetStringAsync("https://www.furaffinity.net/");
                if (Regex.Match(cpage, "class=\"[^\"]*logout-link[^\"]*\"", RegexOptions.CultureInvariant).Success)
                {
                    if (!cpage.Contains("/themes/classic/"))
                    {
                        Console.WriteLine("Auth check completed successfully.");
                        var defUsrMatch = Regex.Match(cpage, @"href=""/commissions/(.+?)/""", RegexOptions.CultureInvariant);
                        if (defUsrMatch.Success)
                        {
                            defaultUserId = defUsrMatch.Groups[1].Value;
                        }
                        else
                        {
                            Console.WriteLine("Warning :: could not determine the username to use for the default target gallery url");
                        }
                        return true;
                    }
                    else
                    {
                        Console.WriteLine("Error: classic theme detected.");
                        System.Windows.Forms.MessageBox.Show(
                            "It seems you're using the classic style." + Environment.NewLine
                            + "Please switch over to the new one and return to the title page once again."
                            );
                        return false;
                    }
                }
                else
                {
                    Console.WriteLine("Not authorized!");
                    return false;
                }
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine("Error: " + e.Message);
                Console.WriteLine("If it is caused by Clouflare validation, pass it and navigate to the FA main page.");
                return false;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return false;
            };
        }
public async Task < bool > Init ( ) { Console . WriteLine ( " " ) ; string cookies = GetGlobalCookies ( " " ) ; if ( cookies == null ) return false ; Console . WriteLine ( " " ) ; try { http . DefaultRequestHeaders . Clear ( ) ; http . DefaultRequestHeaders . Add ( " " , Utils . EmbeddedIeUtils . GetKnownUserAgentValue ( ) ) ; http . DefaultRequestHeaders . Add ( " " , " " ) ; http . DefaultRequestHeaders . Add ( " " , " " ) ; http . DefaultRequestHeaders . Add ( " " , cookies ) ; string cpage = await http . GetStringAsync ( " " ) ; if ( Regex . Match ( cpage , " \" \" \" \" " , RegexOptions . CultureInvariant ) . Success ) { if ( ! cpage . Contains ( " " ) ) { Console . WriteLine ( " " ) ; var defUsrMatch = Regex . Match ( cpage , @"href=""/commissions/(.+?)/""" , RegexOptions . CultureInvariant ) ; if ( defUsrMatch . Success ) { defaultUserId = defUsrMatch . Groups [ 1 ] . Value ; } else { Console . WriteLine ( " " ) ; } return true ; } else { Console . WriteLine ( " " ) ; System . Windows . Forms . MessageBox . Show ( " " + Environment . NewLine + " " ) ; return false ; } } else { Console . WriteLine ( " " ) ; return false ; } } catch ( HttpRequestException e ) { Console . WriteLine ( " " + e . Message ) ; Console . WriteLine ( " " ) ; return false ; } catch ( Exception e ) { Console . WriteLine ( e . Message ) ; return false ; } ; }
Checks whether valid cookies are present in system or not
Checks whether valid cookies are present in system or not
// Console.WriteLine("Found cookies: "+cookies); // IE's and HttpClient's UAs MUST match for Cloudflare to recognize us // test:  "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko" //http.DefaultRequestHeaders.Add("Accept-Language", "en-US;q=0.8,en;q=0.5,ja;q=0.3"); // not strictly neccessary // authorized // and not using classic style //Console.WriteLine("Hi " + defaultUserId); // not authorized // any unaccounted errors
True if valid cookies are found
True if valid cookies are found