Skip to content

Commit

Permalink
1.1.0.0
Browse files Browse the repository at this point in the history
1.1.0.0
  • Loading branch information
stamepicmorg committed Oct 6, 2023
2 parents d764d0f + 43504ae commit 6ae51f9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
50 changes: 46 additions & 4 deletions src/DonloaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace EpicMorg.Atlassian.Downloader
{
class DonloaderService : IHostedService
{
private readonly string UserAgentString = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0";

private readonly ILogger<DonloaderService> logger;
private readonly DownloaderOptions options;
private readonly HttpClient client;
Expand All @@ -40,7 +42,7 @@ public DonloaderService(IHostApplicationLifetime hostApplicationLifetime, ILogge
{
this.logger = logger;
this.client = client;
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0");
client.DefaultRequestHeaders.Add("User-Agent", UserAgentString);
this.options = options;
this.hostApplicationLifetime = hostApplicationLifetime;
}
Expand Down Expand Up @@ -326,7 +328,47 @@ private async Task DownloadFilesFromFeed(string feedUrl, IDictionary<string, Res
}
else
{
logger.LogWarning($"File \"{outputFile}\" already exists. Download from \"{file.ZipUrl}\" skipped.");
logger.LogWarning($"File \"{outputFile}\" already exists. File sizes will be compared.");
long localFileSize = new System.IO.FileInfo(outputFile).Length;
logger.LogInformation($"Size of local file is {localFileSize} bytes.");
try
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("User-Agent", UserAgentString);
HttpResponseMessage response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Head, file.ZipUrl));
if (response.IsSuccessStatusCode)
{
if (response.Content.Headers.ContentLength.HasValue)
{
long remoteFileSize = response.Content.Headers.ContentLength.Value;
logger.LogInformation($"Size of remote file is \"{remoteFileSize}\" bytes.");

if (remoteFileSize == localFileSize) {
logger.LogInformation($"Size of remote and local files and are same ({remoteFileSize} bytes and {localFileSize} bytes). Nothing to download. Operation skipped.");
}
else
{
logger.LogWarning($"Size of remote and local files and are not same ({remoteFileSize} bytes and {localFileSize} bytes). Download started.");
File.Delete(outputFile);
await DownloadFile(file, outputFile, cancellationToken).ConfigureAwait(false);
}

}
else
{
logger.LogWarning($"Cant get size of remote file \"{file.ZipUrl}\". May be server not support it feature. Sorry.");
continue;
}
}
else
{
logger.LogCritical($"Request execution error: \"{response.StatusCode}\". Sorry.");
}
}
catch (HttpRequestException ex)
{
logger.LogCritical($"HTTP request error: \"{ex.Message}\", \"{ex.StackTrace}\", \"{ex.StatusCode}\". Sorry.");
}
}
}
}
Expand All @@ -348,14 +390,14 @@ private async Task DownloadFile(ResponseItem file, string outputFile, Cancellati
}
catch (Exception downloadEx)
{
logger.LogError(downloadEx, $"Failed to download file {file.ZipUrl} to {outputFile}.");
logger.LogError(downloadEx, $"Failed to download file \"{file.ZipUrl}\" to \"{outputFile}\".");
try
{
File.Delete(outputFile);
}
catch (Exception removeEx)
{
logger.LogError(removeEx, $"Failed to remove incomplete file {outputFile}.");
logger.LogError(removeEx, $"Failed to remove incomplete file \"{outputFile}\".");
}
}
logger.LogInformation($"File \"{file.ZipUrl}\" successfully downloaded to \"{outputFile}\".");
Expand Down
7 changes: 4 additions & 3 deletions src/atlassian-downloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<PublishSingleFile>true</PublishSingleFile>
<PublishAot>false</PublishAot>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishTrimmed>true</PublishTrimmed>
Expand All @@ -17,9 +18,9 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/EpicMorg/atlassian-downloader</RepositoryUrl>
<PackageTags>atlassian, donwloader, epicmorg</PackageTags>
<AssemblyVersion>1.0.1.1</AssemblyVersion>
<FileVersion>1.0.1.1</FileVersion>
<Version>1.0.1.1</Version>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<Version>1.1.0.0</Version>
<Copyright>EpicMorg 2023</Copyright>
<Product>Atlassian Downloader</Product>
<IsPackable>true</IsPackable>
Expand Down

0 comments on commit 6ae51f9

Please sign in to comment.