Skip to content

Commit

Permalink
v.2.0.1.0: fix batch mode and minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
crouvpony47 committed Jan 11, 2025
1 parent 15f3c2b commit 1c7a379
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 32 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ Yet another mass downloader for FurAffinity.net.

[Download stable win32 builds.](https://github.com/crouvpony47/furdown/releases)

### Changelog (v.0.5.5.0)
- adapt to site changes
### Changelog (v.2.0.1.0)
- Switched to Edge-based embedded browser for authentification and human verification.

### A note about CF's "I'm Under Attack" mode
- If you are already logged in but are shown the login form anyway, simply navigate to the FA main page.
- If you are already logged in but are shown the login form anyway, simply navigate to the FA front page.

### System requirements
- Windows 7 or newer, might not work on server editions
- .NET 4.6.2
- IE11 (for systems where IE11 is not available, compile Furdown from source after adjusting `src/Program.cs:WebBrowserEmulationSet()` accordingly)
- Windows 7 SP1, 8.1, or 10+. Windows 10 or 11 recommended.
- .NET Framework 4.6.2
- Microsoft Edge WebView2 (usually preinstalled on Windows 10 or newer)

IE11 requirement can be bypassed if you implement an alternative cookie provider, see "Advanced options" section below.
Edge WebView2 requirement can be bypassed if you implement an alternative cookie provider, see "Advanced options" section below.

### Portable mode

Expand Down Expand Up @@ -66,7 +66,7 @@ Override descriptions naming template with TMPLT. __*__
__*__ As templates use the syntax much like that used for environment variables, you may get unexpected results if, say, %FILEPART% is an existing variable.

**Other notes**:
- You must login in GUI mode at least once before using batch/CLI mode.
- You must login in GUI mode at least once before using batch/CLI mode unless the cookies/user-agent are provided using the environment variables.
- For non-overridden parameters the value from a current configuration file (the same file used in GUI mode) is used.

**Examples**:
Expand All @@ -78,6 +78,6 @@ Note that `%` might need to be escaped as `%%` in batch scripts.

### Advanced options

The builtin authentication mechanism based on the embedded Internet Explorer can be bypassed by setting FURDOWN_COOKIES and FURDOWN_USERAGENT environment variables to the appropriate values. If only FURDOWN_USERAGENT is set, furdown and its embedded IE will use the User-Agent value provided, and if only FURDOWN_COOKIES is set, it is your responsibility to match the User-Agent of the cookies source and the one used by furdown.
The builtin authentication mechanism based on the embedded Edge can be bypassed by setting `FURDOWN_COOKIES` and `FURDOWN_USERAGENT` environment variables to the appropriate values. Setting just the `FURDOWN_USERAGENT` has no effect.

Note that the FURDOWN_COOKIES is expected to contain the entire cookie header value (something like `b=XXX; __gads=XXX; a=XXX; s=XXX; __qca=XXX; sz=XXX; cc=XXX; __cfduid=XXX` where `XXX`s are some values)
Note that the `FURDOWN_COOKIES` is expected to contain the entire cookie header value (something like `b=XXX; __gads=XXX; a=XXX; s=XXX; __qca=XXX; sz=XXX; cc=XXX; __cfduid=XXX` where `XXX`s are some values)
11 changes: 1 addition & 10 deletions src/AppCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ public class AppCore

public bool isInitialized = false;

/// <summary>
/// Gets all, including http-only, cookies from WebBrowser component
/// </summary>
/// <param name="uri">URI which is used to get the cookies for</param>
/// <returns></returns>
private static string GetGlobalCookies(string uri) //fixme
{
return CookiesStorage.GetCookieString();
}

/// <summary>
/// Reads network stream to another stream, throwing excepton if no data was received in reasonable time
/// </summary>
Expand Down Expand Up @@ -153,6 +143,7 @@ public async Task<bool> Init()
{
Console.WriteLine("Warning :: could not determine the username to use for the default target gallery url");
}
isInitialized = true;
return true;
}
else
Expand Down
23 changes: 19 additions & 4 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,35 @@ static void Main()
var args = Environment.GetCommandLineArgs();
if (args.Count() < 2 || args[1] != "-b")
{
// GUI mode
if (args.Count() >= 2)
{
Console.WriteLine("Note: found some invalid command line arguments");
Console.WriteLine("For CLI usage notes run this app with -b -help");
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var af = new authForm();
Application.Run(af);
Application.Run(new authForm());
}
else
{
bool AuthRes = AppCore.Core.Init().Result;
if (!AuthRes)
// batch mode
bool hasEnvCookies = (Environment.GetEnvironmentVariable("FURDOWN_COOKIES") != null);
bool authRes = false;
if (hasEnvCookies)
{
authRes = AppCore.Core.Init().Result;
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var aForm = new authForm();
aForm.BackgroundMode = true;
Application.Run(aForm);
authRes = AppCore.Core.isInitialized;
}
if (!authRes)
{
Console.WriteLine("Not authorized! Log in at least once using GUI first.");
Console.WriteLine("Alternatively, provide the 'cookie' and 'user-agent' header values");
Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

[assembly: Guid("8b45577e-b5d1-4056-96e6-b2647e18b867")]

[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]
[assembly: NeutralResourcesLanguage("en")]

2 changes: 1 addition & 1 deletion src/app.manifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="2.0.0.0" name="Furdown.app"/>
<assemblyIdentity version="2.0.1.0" name="Furdown.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
Expand Down
38 changes: 33 additions & 5 deletions src/authForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,27 @@ public async Task<bool> Start()
// initialize WebView2 fully
await edgeWebView.EnsureCoreWebView2Async(null);
// initialize request interception
edgeWebView.CoreWebView2.AddWebResourceRequestedFilter(
"https://www.furaffinity.net/*",
CoreWebView2WebResourceContext.Document,
CoreWebView2WebResourceRequestSourceKinds.All);
try
{
edgeWebView.CoreWebView2.AddWebResourceRequestedFilter(
"https://www.furaffinity.net/*",
CoreWebView2WebResourceContext.Document,
CoreWebView2WebResourceRequestSourceKinds.All);
}
catch (Exception)
{
// fallback to an older (deprecated) filter interface
// for legacy WebView versions (i.e. v.109 on Win 7)
edgeWebView.CoreWebView2.AddWebResourceRequestedFilter(
"https://www.furaffinity.net/*",
CoreWebView2WebResourceContext.Document);
}
edgeWebView.CoreWebView2.WebResourceRequested += async delegate (
object _sender, CoreWebView2WebResourceRequestedEventArgs args)
{
var uri = new Uri(args.Request.Uri);
if (uri.AbsolutePath.ToString() == "/" || uri.AbsolutePath.ToString().StartsWith("/user"))
if (uri.AbsolutePath.ToString() == "/" || uri.AbsolutePath.ToString().StartsWith("/user")
|| (uri.AbsolutePath.ToString().StartsWith("/login") && uri.Query.ToString().Contains("__cf")))
{
CoreWebView2HttpRequestHeaders requestHeaders = args.Request.Headers;
if (requestHeaders.Contains("Cookie"))
Expand Down Expand Up @@ -67,6 +79,11 @@ public async Task<bool> Start()

private void OnAuthSuccessful()
{
if (BackgroundMode)
{
Close();
return;
}
Hide();
taskForm tf = new taskForm(this, AppCore.Core.defaultUserId);
tf.Show();
Expand Down Expand Up @@ -99,6 +116,11 @@ private async void WebViewLoginFlow()
else
{
Console.WriteLine("Does not seem to be authorized (or need to pass CF validation)...");
if (BackgroundMode)
{
Close();
return;
}

// set up a new login callback
onShouldValidateCookies = async delegate ()
Expand Down Expand Up @@ -160,8 +182,14 @@ private async void authForm_Shown(object sender, EventArgs e)
private void authForm_Load(object sender, EventArgs e)
{
Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath);
if (BackgroundMode)
{
WindowState = FormWindowState.Minimized;
}
}

public bool BackgroundMode = false;

delegate Task CookieValidationCallback();
private CookieValidationCallback onShouldValidateCookies = null;
}
Expand Down

0 comments on commit 1c7a379

Please sign in to comment.