mirror of
https://github.com/EpicMorg/atlassian-downloader.git
synced 2025-03-13 05:40:18 +03:00
Feature #33: added --skip-file-check flag
This commit is contained in:
parent
ce023a7358
commit
4f59498482
@ -59,6 +59,8 @@ Options:
|
||||
--action <Download|ListURLs|ListVersions|ShowRawJson> Action to perform [default: Download]
|
||||
--about Show credits banner [default: False]
|
||||
--product-version <product-version> Override target version to download some product. Advice: Use it with "customFeed". []
|
||||
--skip-file-check Skip compare of file sizes if a local file already exists.
|
||||
Existing file will be skipped to check and redownload. [default: False]
|
||||
--version Show version information
|
||||
-?, -h, --help Show help and usage information
|
||||
```
|
||||
|
@ -113,6 +113,7 @@ internal class DownloaderService : IHostedService
|
||||
private async Task DownloadFilesFromFeed(string feedUrl, IDictionary<string, ResponseItem[]> versions, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
|
||||
var feedDir = Path.Combine(this.options.OutputDir, feedUrl[(feedUrl.LastIndexOf('/') + 1)..feedUrl.LastIndexOf('.')]);
|
||||
this.logger.LogInformation("Download from JSON \"{feedUrl}\" started", feedUrl);
|
||||
foreach (var version in versions)
|
||||
@ -141,6 +142,8 @@ internal class DownloaderService : IHostedService
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var serverPath = file.ZipUrl.PathAndQuery;
|
||||
var outputFile = Path.Combine(directory, serverPath[(serverPath.LastIndexOf('/') + 1)..]);
|
||||
if (!File.Exists(outputFile))
|
||||
@ -149,46 +152,54 @@ internal class DownloaderService : IHostedService
|
||||
}
|
||||
else
|
||||
{
|
||||
this.logger.LogWarning($"File \"{outputFile}\" already exists. File sizes will be compared.");
|
||||
var localFileSize = new FileInfo(outputFile).Length;
|
||||
this.logger.LogInformation($"Size of local file is {localFileSize} bytes.");
|
||||
try
|
||||
if (this.options.SkipFileCheck == false)
|
||||
{
|
||||
var httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.Add("User-Agent", this.UserAgentString);
|
||||
var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Head, file.ZipUrl));
|
||||
if (response.IsSuccessStatusCode)
|
||||
this.logger.LogWarning($"File \"{outputFile}\" already exists. File sizes will be compared.");
|
||||
var localFileSize = new FileInfo(outputFile).Length;
|
||||
this.logger.LogInformation($"Size of local file is {localFileSize} bytes.");
|
||||
try
|
||||
{
|
||||
if (response.Content.Headers.ContentLength.HasValue)
|
||||
var httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.Add("User-Agent", this.UserAgentString);
|
||||
var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Head, file.ZipUrl));
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var remoteFileSize = response.Content.Headers.ContentLength.Value;
|
||||
this.logger.LogInformation($"Size of remote file is \"{remoteFileSize}\" bytes.");
|
||||
|
||||
if (remoteFileSize == localFileSize)
|
||||
if (response.Content.Headers.ContentLength.HasValue)
|
||||
{
|
||||
this.logger.LogInformation($"Size of remote and local files and are same ({remoteFileSize} bytes and {localFileSize} bytes). Nothing to download. Operation skipped.");
|
||||
var remoteFileSize = response.Content.Headers.ContentLength.Value;
|
||||
this.logger.LogInformation($"Size of remote file is \"{remoteFileSize}\" bytes.");
|
||||
|
||||
if (remoteFileSize == localFileSize)
|
||||
{
|
||||
this.logger.LogInformation($"Size of remote and local files and are same ({remoteFileSize} bytes and {localFileSize} bytes). Nothing to download. Operation skipped.");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.logger.LogWarning($"Size of remote and local files and are not same ({remoteFileSize} bytes and {localFileSize} bytes). Download started.");
|
||||
File.Delete(outputFile);
|
||||
await this.DownloadFile(file, outputFile, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.logger.LogWarning($"Size of remote and local files and are not same ({remoteFileSize} bytes and {localFileSize} bytes). Download started.");
|
||||
File.Delete(outputFile);
|
||||
await this.DownloadFile(file, outputFile, cancellationToken).ConfigureAwait(false);
|
||||
this.logger.LogWarning($"Cant get size of remote file \"{file.ZipUrl}\". May be server not support it feature. Sorry.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.logger.LogWarning($"Cant get size of remote file \"{file.ZipUrl}\". May be server not support it feature. Sorry.");
|
||||
continue;
|
||||
this.logger.LogCritical($"Request execution error: \"{response.StatusCode}\". Sorry.");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
this.logger.LogCritical($"Request execution error: \"{response.StatusCode}\". Sorry.");
|
||||
this.logger.LogCritical($"HTTP request error: \"{ex.Message}\", \"{ex.StackTrace}\", \"{ex.StatusCode}\". Sorry.");
|
||||
}
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
}
|
||||
else
|
||||
{
|
||||
this.logger.LogCritical($"HTTP request error: \"{ex.Message}\", \"{ex.StackTrace}\", \"{ex.StatusCode}\". Sorry.");
|
||||
logger.LogWarning($"File \"{outputFile}\" already exists. Download from \"{file.ZipUrl}\" skipped.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace EpicMorg.Atlassian.Downloader;
|
||||
using System;
|
||||
|
||||
public record DownloaderOptions(string OutputDir, Uri[] CustomFeed, DownloadAction Action,bool Version, string ProductVersion) { }
|
||||
public record DownloaderOptions(string OutputDir, Uri[] CustomFeed, DownloadAction Action, bool Version, string ProductVersion, bool SkipFileCheck) { }
|
@ -22,7 +22,8 @@ public class Program
|
||||
/// <param name="customFeed">Override URIs to import</param>
|
||||
/// <param name="about">Show credits banner</param>
|
||||
/// <param name="productVersion">Override target version to download some product. Advice: Use it with "customFeed".</param>
|
||||
static async Task Main(string outputDir, Uri[] customFeed = null, DownloadAction action = DownloadAction.Download, bool about = false, string productVersion = null) => await
|
||||
/// <param name="skipFileCheck">Skip compare of file sizes if a local file already exists. Existing file will be skipped to check and redownload.</param>
|
||||
static async Task Main(string outputDir, Uri[] customFeed = null, DownloadAction action = DownloadAction.Download, bool about = false, string productVersion = null, bool skipFileCheck = false) => await
|
||||
Host
|
||||
.CreateDefaultBuilder()
|
||||
.ConfigureHostConfiguration(configHost => configHost.AddEnvironmentVariables())
|
||||
@ -44,7 +45,7 @@ public class Program
|
||||
.AddSerilog(dispose: true);
|
||||
})
|
||||
.AddHostedService<DownloaderService>()
|
||||
.AddSingleton(new DownloaderOptions(outputDir, customFeed, action, about, productVersion))
|
||||
.AddSingleton(new DownloaderOptions(outputDir, customFeed, action, about, productVersion, skipFileCheck))
|
||||
.AddHttpClient())
|
||||
.RunConsoleAsync()
|
||||
.ConfigureAwait(false);
|
||||
|
@ -2,8 +2,9 @@
|
||||
"profiles": {
|
||||
"atlassian-downloader": {
|
||||
"commandName": "Project",
|
||||
//"commandLineArgs": "--help"
|
||||
"commandLineArgs": "--action=ShowRawJson --output-dir=F:\\temp\\atlassian\\test1"
|
||||
//"commandLineArgs": "--version"
|
||||
"commandLineArgs": "--help"
|
||||
// "commandLineArgs": "--action=ShowRawJson --output-dir=F:\\temp\\atlassian\\test1"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user