mirror of
https://github.com/EpicMorg/atlassian-downloader.git
synced 2025-03-22 18:20:21 +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]
|
--action <Download|ListURLs|ListVersions|ShowRawJson> Action to perform [default: Download]
|
||||||
--about Show credits banner [default: False]
|
--about Show credits banner [default: False]
|
||||||
--product-version <product-version> Override target version to download some product. Advice: Use it with "customFeed". []
|
--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
|
--version Show version information
|
||||||
-?, -h, --help Show help and usage 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)
|
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('.')]);
|
var feedDir = Path.Combine(this.options.OutputDir, feedUrl[(feedUrl.LastIndexOf('/') + 1)..feedUrl.LastIndexOf('.')]);
|
||||||
this.logger.LogInformation("Download from JSON \"{feedUrl}\" started", feedUrl);
|
this.logger.LogInformation("Download from JSON \"{feedUrl}\" started", feedUrl);
|
||||||
foreach (var version in versions)
|
foreach (var version in versions)
|
||||||
@ -141,6 +142,8 @@ internal class DownloaderService : IHostedService
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var serverPath = file.ZipUrl.PathAndQuery;
|
var serverPath = file.ZipUrl.PathAndQuery;
|
||||||
var outputFile = Path.Combine(directory, serverPath[(serverPath.LastIndexOf('/') + 1)..]);
|
var outputFile = Path.Combine(directory, serverPath[(serverPath.LastIndexOf('/') + 1)..]);
|
||||||
if (!File.Exists(outputFile))
|
if (!File.Exists(outputFile))
|
||||||
@ -149,46 +152,54 @@ internal class DownloaderService : IHostedService
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.logger.LogWarning($"File \"{outputFile}\" already exists. File sizes will be compared.");
|
if (this.options.SkipFileCheck == false)
|
||||||
var localFileSize = new FileInfo(outputFile).Length;
|
|
||||||
this.logger.LogInformation($"Size of local file is {localFileSize} bytes.");
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
var httpClient = new HttpClient();
|
this.logger.LogWarning($"File \"{outputFile}\" already exists. File sizes will be compared.");
|
||||||
httpClient.DefaultRequestHeaders.Add("User-Agent", this.UserAgentString);
|
var localFileSize = new FileInfo(outputFile).Length;
|
||||||
var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Head, file.ZipUrl));
|
this.logger.LogInformation($"Size of local file is {localFileSize} bytes.");
|
||||||
if (response.IsSuccessStatusCode)
|
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;
|
if (response.Content.Headers.ContentLength.HasValue)
|
||||||
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.");
|
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
|
else
|
||||||
{
|
{
|
||||||
this.logger.LogWarning($"Size of remote and local files and are not same ({remoteFileSize} bytes and {localFileSize} bytes). Download started.");
|
this.logger.LogWarning($"Cant get size of remote file \"{file.ZipUrl}\". May be server not support it feature. Sorry.");
|
||||||
File.Delete(outputFile);
|
continue;
|
||||||
await this.DownloadFile(file, outputFile, cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.logger.LogWarning($"Cant get size of remote file \"{file.ZipUrl}\". May be server not support it feature. Sorry.");
|
this.logger.LogCritical($"Request execution error: \"{response.StatusCode}\". Sorry.");
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
namespace EpicMorg.Atlassian.Downloader;
|
||||||
using System;
|
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="customFeed">Override URIs to import</param>
|
||||||
/// <param name="about">Show credits banner</param>
|
/// <param name="about">Show credits banner</param>
|
||||||
/// <param name="productVersion">Override target version to download some product. Advice: Use it with "customFeed".</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
|
Host
|
||||||
.CreateDefaultBuilder()
|
.CreateDefaultBuilder()
|
||||||
.ConfigureHostConfiguration(configHost => configHost.AddEnvironmentVariables())
|
.ConfigureHostConfiguration(configHost => configHost.AddEnvironmentVariables())
|
||||||
@ -44,7 +45,7 @@ public class Program
|
|||||||
.AddSerilog(dispose: true);
|
.AddSerilog(dispose: true);
|
||||||
})
|
})
|
||||||
.AddHostedService<DownloaderService>()
|
.AddHostedService<DownloaderService>()
|
||||||
.AddSingleton(new DownloaderOptions(outputDir, customFeed, action, about, productVersion))
|
.AddSingleton(new DownloaderOptions(outputDir, customFeed, action, about, productVersion, skipFileCheck))
|
||||||
.AddHttpClient())
|
.AddHttpClient())
|
||||||
.RunConsoleAsync()
|
.RunConsoleAsync()
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"atlassian-downloader": {
|
"atlassian-downloader": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
//"commandLineArgs": "--help"
|
//"commandLineArgs": "--version"
|
||||||
"commandLineArgs": "--action=ShowRawJson --output-dir=F:\\temp\\atlassian\\test1"
|
"commandLineArgs": "--help"
|
||||||
|
// "commandLineArgs": "--action=ShowRawJson --output-dir=F:\\temp\\atlassian\\test1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user