From cf71d9401838a3b671006188a531a2ffedc95258 Mon Sep 17 00:00:00 2001 From: VahidN Date: Sat, 26 Oct 2019 20:09:27 +0330 Subject: [PATCH] Improve image file name's detection --- .github/lock.yml | 14 ++++++++++++++ PersianBingCalendar/Core/BingImagesDownloader.cs | 16 +++++++++++++++- PersianBingCalendar/PersianBingCalendar.csproj | 1 + PersianBingCalendar/Properties/AssemblyInfo.cs | 4 ++-- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 .github/lock.yml diff --git a/.github/lock.yml b/.github/lock.yml new file mode 100644 index 0000000..d0aae88 --- /dev/null +++ b/.github/lock.yml @@ -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 diff --git a/PersianBingCalendar/Core/BingImagesDownloader.cs b/PersianBingCalendar/Core/BingImagesDownloader.cs index 17c1f50..cf3768b 100644 --- a/PersianBingCalendar/Core/BingImagesDownloader.cs +++ b/PersianBingCalendar/Core/BingImagesDownloader.cs @@ -4,6 +4,7 @@ using System.Text; using PersianBingCalendar.Models; using PersianBingCalendar.Utils; +using System.Net.Http; namespace PersianBingCalendar.Core { @@ -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(); @@ -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(); + } } } \ No newline at end of file diff --git a/PersianBingCalendar/PersianBingCalendar.csproj b/PersianBingCalendar/PersianBingCalendar.csproj index 336e2ae..343e5da 100644 --- a/PersianBingCalendar/PersianBingCalendar.csproj +++ b/PersianBingCalendar/PersianBingCalendar.csproj @@ -41,6 +41,7 @@ + diff --git a/PersianBingCalendar/Properties/AssemblyInfo.cs b/PersianBingCalendar/Properties/AssemblyInfo.cs index b290e70..13f89b0 100644 --- a/PersianBingCalendar/Properties/AssemblyInfo.cs +++ b/PersianBingCalendar/Properties/AssemblyInfo.cs @@ -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")]