Skip to content

Commit

Permalink
pre-2.0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
stamepicmorg committed Aug 4, 2024
1 parent b4e881a commit 45027c4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Atlassian Downloader - Changelog

## 2.x
* `2.0.0.2` - - minor update:
* Added `maxRetries (default: 5)` and `delayBetweenRetries (default: 2500, milliseconds)` args, to redownload file if connection will be reset.
* Updated dependencies.
* `2.0.0.1` - - minor update:
* Fix default output dir, enable nullables, fix compiler warnings #43
* Remove redundant parameters from publish profiles #42
Expand Down
46 changes: 29 additions & 17 deletions src/Core/DownloaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,31 +213,43 @@ private async Task DownloadFilesFromFeed(string feedUrl, IDictionary<string, Res

private async Task DownloadFile(ResponseItem file, string outputFile, CancellationToken cancellationToken)
{
if (!string.IsNullOrEmpty(file.Md5))
for (int attempt = 1; attempt <= options.MaxRetries; attempt++)
{
File.WriteAllText(outputFile + ".md5", file.Md5);
}
if (!string.IsNullOrEmpty(file.Md5))
{
File.WriteAllText(outputFile + ".md5", file.Md5);
}

try
{
using var outputStream = File.OpenWrite(outputFile);
using var request = await this.client.GetStreamAsync(file.ZipUrl, cancellationToken).ConfigureAwait(false);
await request.CopyToAsync(outputStream, cancellationToken).ConfigureAwait(false);
}
catch (Exception downloadEx)
{
this.logger.LogError(downloadEx, "Failed to download file \"{uri}\" to \"{outputFile}\".", file.ZipUrl, outputFile);
try
{
File.Delete(outputFile);
using var outputStream = File.OpenWrite(outputFile);
using var request = await this.client.GetStreamAsync(file.ZipUrl, cancellationToken).ConfigureAwait(false);
await request.CopyToAsync(outputStream, cancellationToken).ConfigureAwait(false);
}
catch (Exception removeEx)
catch (Exception downloadEx)
{
this.logger.LogError(removeEx, "Failed to remove incomplete file \"{outputFile}\".", outputFile);
this.logger.LogError(downloadEx, "Attempt {attempt} failed to download file \"{uri}\" to \"{outputFile}\".", attempt, file.ZipUrl, outputFile);

if (attempt == options.MaxRetries)
{
this.logger.LogError(downloadEx, "Failed to download file \"{uri}\" to \"{outputFile}\".", file.ZipUrl, outputFile);
try
{
File.Delete(outputFile);
}
catch (Exception removeEx)
{
this.logger.LogError(removeEx, "Failed to remove incomplete file \"{outputFile}\".", outputFile);
}
throw;
}
else
{
await Task.Delay(options.DelayBetweenRetries, cancellationToken).ConfigureAwait(false); // Çàäåðæêà ïåðåä ñëåäóþùåé ïîïûòêîé
}
}
this.logger.LogInformation("File \"{uri}\" successfully downloaded to \"{outputFile}\".", file.ZipUrl, outputFile);
}

this.logger.LogInformation("File \"{uri}\" successfully downloaded to \"{outputFile}\".", file.ZipUrl, outputFile);
}

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
Expand Down
5 changes: 4 additions & 1 deletion src/Models/DownloaderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ public record DownloaderOptions(
bool Version,
string? ProductVersion,
bool SkipFileCheck,
string UserAgent) { }
string UserAgent,
int MaxRetries,
int DelayBetweenRetries
) { }
8 changes: 7 additions & 1 deletion src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ public class Program
/// <param name="productVersion">Override target version to download some product. Advice: Use it with "customFeed".</param>
/// <param name="skipFileCheck">Skip compare of file sizes if a local file already exists. Existing file will be skipped to check and redownload.</param>
/// <param name="userAgent">Set custom user agent via this feature flag.</param>
/// <param name="maxRetries">Set custom count of download retries.</param>
/// <param name="delayBetweenRetries">Set custom delay between retries (in milliseconds).</param>
static async Task Main(
string? outputDir = default,
Uri[]? customFeed = null,
DownloadAction action = DownloadAction.Download,
bool about = false,
string? productVersion = null,
bool skipFileCheck = false,
int maxRetries = 5,
int delayBetweenRetries = 2500,
string userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0") => await
Host
.CreateDefaultBuilder()
Expand Down Expand Up @@ -60,7 +64,9 @@ static async Task Main(
about,
productVersion,
skipFileCheck,
userAgent))
userAgent,
maxRetries,
delayBetweenRetries))
.AddHttpClient())
.RunConsoleAsync()
.ConfigureAwait(false);
Expand Down
27 changes: 14 additions & 13 deletions src/atlassian-downloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<!--build props-->
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<ApplicationIcon>favicon.ico</ApplicationIcon>
Expand All @@ -26,25 +27,25 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/EpicMorg/atlassian-downloader</RepositoryUrl>
<PackageTags>atlassian, donwloader, epicmorg</PackageTags>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<Version>2.0.0.0</Version>
<Copyright>EpicMorg 2023</Copyright>
<AssemblyVersion>2.0.0.2</AssemblyVersion>
<FileVersion>2.0.0.2</FileVersion>
<Version>2.0.0.2</Version>
<Copyright>EpicMorg 2024</Copyright>
<Product>Atlassian Downloader</Product>
<Company>EpicMorg</Company>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RootNamespace>EpicMorg.Atlassian.Downloader</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.1-dev-10354" />
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.2-dev-00546" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.2.0-dev-00918" />
<PackageReference Include="Serilog" Version="3.1.0-dev-02078" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.4.0-alpha.22272.1" />
<None Include="..\README.md">
<Pack>True</Pack>
Expand Down

0 comments on commit 45027c4

Please sign in to comment.