Skip to content

Commit

Permalink
v.0.4.1.0
Browse files Browse the repository at this point in the history
+ updates checker
+ better fuzzy date handling
  • Loading branch information
crouvpony47 committed Jan 1, 2020
1 parent 992880a commit 62552ce
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 13 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ Yet another mass downloader for FurAffinity.net.

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

### Changelog (v.0.4.0.0)
- adapt to the FA template changes
### Changelog (v.0.4.1.0)
- adapt to the FA template changes (fix date parsing when not using "fuzzy date format")
- checking for updates

### System requirements
- Windows Vista SP2 or newer, might not work on server editions
Expand Down
26 changes: 19 additions & 7 deletions src/AppCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public AppCore()
httph.UseCookies = false; // disable internal cookies handling to help with import
http = new HttpClient(httph);
http.DefaultRequestHeaders.Clear();

System.Net.ServicePointManager.SecurityProtocol =
System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;
}

/// <summary>
Expand Down Expand Up @@ -283,7 +286,6 @@ public async Task<ProcessingResults> ProcessSubmissionsList(List<string> subs, b

// process submission page
string downbtnkey = "<a href=\"//d.facdn.net/";
string desckey = "<div class=\"submission-description-container";
SubmissionProps sp = new SubmissionProps();
sp.SUBMID = subId;
int keypos = cpage.IndexOf(downbtnkey, StringComparison.Ordinal);
Expand Down Expand Up @@ -325,9 +327,18 @@ public async Task<ProcessingResults> ProcessSubmissionsList(List<string> subs, b
{
string dateMatchVal = dateMatch.Value;
string dateTimeStr = dateMatch.Groups[1].Value; // fixed format date

string dateTimeStrFuzzy = dateMatch.Groups[2].Value;

// depending on user settings, fuzzy and fixed times may be swapped
if (dateTimeStrFuzzy.Contains(" PM") || dateTimeStrFuzzy.Contains(" AM"))
{
var temporary = dateTimeStr;
dateTimeStr = dateTimeStrFuzzy;
dateTimeStrFuzzy = temporary;
}

// replace relative date with a fixed format one
sub_date_strong = dateMatchVal.Replace(dateMatch.Groups[2].Value, dateTimeStr);
sub_date_strong = dateMatchVal.Replace(dateTimeStrFuzzy, dateTimeStr);

// parse date
dateTimeStr = dateTimeStr.Replace(",", "");
Expand All @@ -341,6 +352,7 @@ public async Task<ProcessingResults> ProcessSubmissionsList(List<string> subs, b
catch (Exception e)
{
Console.WriteLine("Warning :: cannot parse date :: " + e.Message);
Console.WriteLine("Info :: date string :: " + dateTimeStr);
}
}
}
Expand All @@ -355,10 +367,10 @@ public async Task<ProcessingResults> ProcessSubmissionsList(List<string> subs, b
cpage = cpage.Replace("href=\"/", "href=\"https://furaffinity.net/");
cpage = cpage.Replace("src=\"//", "src=\"https://");

cpage = @"<div class=""submission-description-container link-override"">
<div class=""submission-title"">
<h2 class=""submission-title-header"">{{{title}}}</h2>
Posted {{{date}}}
cpage = @"<div class=""submission-description-container link-override"">
<div class=""submission-title"">
<h2 class=""submission-title-header"">{{{title}}}</h2>
Posted {{{date}}}
</div><hr>".Replace("{{{title}}}", sp.TITLE).Replace("{{{date}}}", sub_date_strong) + cpage;
}

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("0.4.0.0")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyVersion("0.4.1.0")]
[assembly: AssemblyFileVersion("0.4.1.0")]
[assembly: NeutralResourcesLanguage("en")]

75 changes: 75 additions & 0 deletions src/UpdatesChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

namespace furdown
{
class UpdatesChecker
{
internal static async Task<bool> CheckRemoteVersion()
{
try
{
var httph = new HttpClientHandler();
var http = new HttpClient(httph);
http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0");
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
serializer.MaxJsonLength = 2097152; // 2 Mb

string[] thisVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.');

var jsonString = await http.GetStringAsync(@"https://api.github.com/repos/crouvpony47/furdown/releases");
var jsonRoot = (object[])serializer.DeserializeObject(jsonString);

if (jsonRoot.Length == 0)
{
Console.WriteLine("Updater :: Warning :: no releases found on GitHub");
return false;
}

foreach (var releaseJson in jsonRoot)
{
var releaseDict = releaseJson as Dictionary<string, object>;
var tag = (string)releaseDict["tag_name"];
tag = tag.Replace("v.", "");
var prerelease = (bool)releaseDict["prerelease"];
if (prerelease)
{
Console.WriteLine("Updater :: Note :: found prerelease, " + tag);
continue;
}

Console.WriteLine("Updater :: Note :: found release, " + tag);

var remoteVersion = tag.Split('.');
var versionComp = thisVersion.Zip(remoteVersion, (tvp, rvp) =>
{
return string.Compare(tvp, rvp, StringComparison.Ordinal);
});

foreach (int c in versionComp)
{
if (c < 0)
{
Console.WriteLine("Updater :: Note :: an update is available");
return true;
}
else if (c > 0)
{
Console.WriteLine("Updater :: Note :: current version is newer than the latest released one");
return false;
}
}
return false;
}
}
catch (Exception exc)
{
Console.WriteLine("Updater :: Error :: " + exc.Message);
}
return false;
}
}
}
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="0.4.0.0" name="Furdown.app"/>
<assemblyIdentity version="0.4.1.0" name="Furdown.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
Expand Down
2 changes: 2 additions & 0 deletions src/furdown.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -87,6 +88,7 @@
<Compile Include="taskForm.Designer.cs">
<DependentUpon>taskForm.cs</DependentUpon>
</Compile>
<Compile Include="UpdatesChecker.cs" />
<Compile Include="Utils.cs" />
<EmbeddedResource Include="authForm.resx">
<DependentUpon>authForm.cs</DependentUpon>
Expand Down
23 changes: 22 additions & 1 deletion src/taskForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,34 @@ private void applyNSaveBtn_Click(object sender, EventArgs e)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void taskForm_Shown(object sender, EventArgs e)
private async void taskForm_Shown(object sender, EventArgs e)
{
downloadPathBox.Text = GlobalSettings.Settings.downloadPath;
systemPathBox.Text = GlobalSettings.Settings.systemPath;
filenameTemplateBox.Text = GlobalSettings.Settings.filenameTemplate;
descrFilenameBox.Text = GlobalSettings.Settings.descrFilenameTemplate;
neverDownloadTwiceCheckBox.Checked = GlobalSettings.Settings.downloadOnlyOnce;

// ceck for updates
bool hasUpdates = await UpdatesChecker.CheckRemoteVersion();
const string urlToOpen = "https://github.com/crouvpony47/furdown/releases";
if (hasUpdates && Visible)
{
var dlgResult = MessageBox.Show("A newer version of furdown is available, would you like to download it?",
"Update Available",
MessageBoxButtons.YesNo);
if (dlgResult == DialogResult.Yes)
{
try
{
System.Diagnostics.Process.Start(urlToOpen);
}
catch (Exception)
{
Console.WriteLine("Could not open URL in the default browser:\n" + urlToOpen);
}
}
}
}

private async void galleryDownloadBtn_Click(object sender, EventArgs e)
Expand Down

0 comments on commit 62552ce

Please sign in to comment.