Skip to content

Commit

Permalink
Improve image file name's detection
Browse files Browse the repository at this point in the history
  • Loading branch information
VahidN committed Oct 26, 2019
1 parent ffe60e5 commit cf71d94
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
14 changes: 14 additions & 0 deletions .github/lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
daysUntilLock: 90

skipCreatedBefore: false

exemptLabels: []

lockLabel: false

lockComment: >
This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related problems.
setLockReason: true
16 changes: 15 additions & 1 deletion PersianBingCalendar/Core/BingImagesDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using PersianBingCalendar.Models;
using PersianBingCalendar.Utils;
using System.Net.Http;

namespace PersianBingCalendar.Core
{
Expand Down Expand Up @@ -55,7 +56,7 @@ private static void downloadImage(

var imageInfo = getFullUrl(xmlData);

var imageName = Path.GetFileName(imageInfo.Url).CleanFileName();
var imageName = getImageName(imageInfo);
var imagePath = Path.Combine(dir, $"{imageName}");

var xmlFileName = imageName.Split('_').First();
Expand All @@ -78,5 +79,18 @@ private static void downloadImage(
File.Delete(imagePath);
}
}

private static string getImageName(ImageInfo imageInfo)
{
var imageName = Path.GetFileName(imageInfo.Url).CleanFileName();
if (imageName.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase))
{
return imageName;
}

var nameValueCollection = new Uri(imageInfo.Url).ParseQueryString();
var id = nameValueCollection["id"];
return string.IsNullOrWhiteSpace(id) ? imageName : id.CleanFileName();
}
}
}
1 change: 1 addition & 0 deletions PersianBingCalendar/PersianBingCalendar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions PersianBingCalendar/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]

0 comments on commit cf71d94

Please sign in to comment.