mirror of
https://github.com/EpicMorg/atlassian-downloader.git
synced 2024-12-28 13:05:29 +03:00
1.0.0.7
* version page * code improvments
This commit is contained in:
parent
f57c6e3986
commit
0b95530eed
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -18,6 +19,20 @@ namespace EpicMorg.Atlassian.Downloader
|
|||||||
private readonly DownloaderOptions options;
|
private readonly DownloaderOptions options;
|
||||||
private readonly HttpClient client;
|
private readonly HttpClient client;
|
||||||
private readonly IHostApplicationLifetime hostApplicationLifetime;
|
private readonly IHostApplicationLifetime hostApplicationLifetime;
|
||||||
|
private readonly string assemblyEnvironment = string.Format("[{1}, {0}]",
|
||||||
|
System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(),
|
||||||
|
System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);
|
||||||
|
private readonly string assemblyVersion = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
||||||
|
|
||||||
|
private readonly string assemblyName = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyProductAttribute>().Product;
|
||||||
|
const string assemblyBuildType =
|
||||||
|
#if DEBUG
|
||||||
|
"[Debug]"
|
||||||
|
#else
|
||||||
|
|
||||||
|
"[Release]"
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
public DonloaderService(IHostApplicationLifetime hostApplicationLifetime, ILogger<DonloaderService> logger, HttpClient client, DownloaderOptions options)
|
public DonloaderService(IHostApplicationLifetime hostApplicationLifetime, ILogger<DonloaderService> logger, HttpClient client, DownloaderOptions options)
|
||||||
{
|
{
|
||||||
@ -26,50 +41,138 @@ namespace EpicMorg.Atlassian.Downloader
|
|||||||
this.options = options;
|
this.options = options;
|
||||||
this.hostApplicationLifetime = hostApplicationLifetime;
|
this.hostApplicationLifetime = hostApplicationLifetime;
|
||||||
}
|
}
|
||||||
|
public const ConsoleColor DEFAULT = ConsoleColor.Blue;
|
||||||
|
|
||||||
|
public static void WriteColorLine(string text, params object[] args)
|
||||||
|
{
|
||||||
|
Dictionary<char, ConsoleColor> colors = new()
|
||||||
|
{
|
||||||
|
{ '!', ConsoleColor.Red },
|
||||||
|
{ '@', ConsoleColor.Green },
|
||||||
|
{ '#', ConsoleColor.Blue },
|
||||||
|
{ '$', ConsoleColor.Magenta },
|
||||||
|
{ '&', ConsoleColor.Yellow },
|
||||||
|
{ '%', ConsoleColor.Cyan }
|
||||||
|
};
|
||||||
|
// TODO: word wrap, backslash escapes
|
||||||
|
text = string.Format(text, args);
|
||||||
|
string chunk = "";
|
||||||
|
bool paren = false;
|
||||||
|
for (int i = 0; i < text.Length; i++)
|
||||||
|
{
|
||||||
|
char c = text[i];
|
||||||
|
if (colors.ContainsKey(c) && StringNext(text, i) != ' ')
|
||||||
|
{
|
||||||
|
Console.Write(chunk);
|
||||||
|
chunk = "";
|
||||||
|
if (StringNext(text, i) == '(')
|
||||||
|
{
|
||||||
|
i++; // skip past the paren
|
||||||
|
paren = true;
|
||||||
|
}
|
||||||
|
Console.ForegroundColor = colors[c];
|
||||||
|
}
|
||||||
|
else if (paren && c == ')')
|
||||||
|
{
|
||||||
|
paren = false;
|
||||||
|
Console.ForegroundColor = DEFAULT;
|
||||||
|
}
|
||||||
|
else if (Console.ForegroundColor != DEFAULT)
|
||||||
|
{
|
||||||
|
Console.Write(c);
|
||||||
|
if (c == ' ' && !paren)
|
||||||
|
Console.ForegroundColor = DEFAULT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
chunk += c;
|
||||||
|
}
|
||||||
|
Console.WriteLine(chunk);
|
||||||
|
Console.ForegroundColor = DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static char StringPrev(string text, int index)
|
||||||
|
{
|
||||||
|
return (index == 0 || text.Length == 0) ? '\0' : text[index - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static char StringNext(string text, int index)
|
||||||
|
{
|
||||||
|
return (index < text.Length) ? text[index + 1] : '\0';
|
||||||
|
}
|
||||||
|
|
||||||
public async Task StartAsync(CancellationToken cancellationToken)
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
this.SetConsoleTitle();
|
SetConsoleTitle();
|
||||||
var feedUrls = this.GetFeedUrls();
|
if (options.Version)
|
||||||
|
|
||||||
logger.LogInformation($"Task started");
|
|
||||||
foreach (var feedUrl in feedUrls)
|
|
||||||
{
|
{
|
||||||
if (cancellationToken.IsCancellationRequested)
|
logger.LogInformation($"{assemblyName} {assemblyVersion} {assemblyEnvironment} {assemblyBuildType}");
|
||||||
{
|
Console.BackgroundColor = ConsoleColor.Black;
|
||||||
return;
|
WriteColorLine("%╔═╦═══════════════════════════════════════════════════════════════════════════════════════╦═╗");
|
||||||
}
|
WriteColorLine("%╠═╝ .''. %╚═%╣");
|
||||||
var (json, versions) = await this.GetJson(feedUrl, cancellationToken).ConfigureAwait(false);
|
WriteColorLine("%║ .:cc;. %║");
|
||||||
|
WriteColorLine("%║ .;cccc;. %║");
|
||||||
|
WriteColorLine("%║ .;cccccc;. !╔══════════════════════════════════════════════╗ %║");
|
||||||
|
WriteColorLine("%║ .:ccccccc;. !║ "+ assemblyName +" !║ %║");
|
||||||
|
WriteColorLine("%║ 'ccccccccc;. !╠══════════════════════════════════════════════╣ %║");
|
||||||
|
WriteColorLine("%║ ,cccccccccc;. !║ &Code: @kastkack !║ %║");
|
||||||
|
WriteColorLine("%║ ,ccccccccccc;. !║ &GFX: @stam !║ %║");
|
||||||
|
WriteColorLine("%║ .... .:ccccccccccc;. !╠══════════════════════════════════════════════╣ %║");
|
||||||
|
WriteColorLine("%║ .',,'..;cccccccccccc;. !║ &Version: "+ assemblyVersion + " !║ %║");
|
||||||
|
WriteColorLine("%║ .,,,,,'.';cccccccccccc;. !║ &GitHub: $EpicMorg/atlassian-downloader !║ %║");
|
||||||
|
WriteColorLine("%║ .,;;;;;,'.':cccccccccccc;. !╚══════════════════════════════════════════════╝ %║");
|
||||||
|
WriteColorLine("%║ .;:;;;;;;,...:cccccccccccc;. %║");
|
||||||
|
WriteColorLine("%║ .;:::::;;;;'. .;:ccccccccccc;. %║");
|
||||||
|
WriteColorLine("%║ .:cc::::::::,. ..:ccccccccccc;. %║");
|
||||||
|
WriteColorLine("%║ .:cccccc:::::' .:ccccccccccc;. %║");
|
||||||
|
WriteColorLine("%║ .;:::::::::::,. .;:::::::::::,. %║");
|
||||||
|
WriteColorLine("%╠═╗ ............ ............ %╔═╣");
|
||||||
|
WriteColorLine("%╚═╩═══════════════════════════════════════════════════════════════════════════════════════╩═╝");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var feedUrls = this.GetFeedUrls();
|
||||||
|
|
||||||
switch (options.Action)
|
logger.LogInformation($"Task started");
|
||||||
|
foreach (var feedUrl in feedUrls)
|
||||||
{
|
{
|
||||||
case DownloadAction.ShowRawJson:
|
if (cancellationToken.IsCancellationRequested)
|
||||||
Console.Out.WriteLine(json);
|
{
|
||||||
break;
|
return;
|
||||||
case DownloadAction.Download:
|
}
|
||||||
await this.DownloadFilesFromFreed(feedUrl, versions, cancellationToken).ConfigureAwait(false);
|
var (json, versions) = await this.GetJson(feedUrl, cancellationToken).ConfigureAwait(false);
|
||||||
break;
|
|
||||||
case DownloadAction.ListURLs:
|
switch (options.Action)
|
||||||
foreach (var versionProg in versions)
|
{
|
||||||
{
|
case DownloadAction.ShowRawJson:
|
||||||
foreach (var file in versionProg.Value)
|
Console.Out.WriteLine(json);
|
||||||
|
break;
|
||||||
|
case DownloadAction.Download:
|
||||||
|
await this.DownloadFilesFromFreed(feedUrl, versions, cancellationToken).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
case DownloadAction.ListURLs:
|
||||||
|
foreach (var versionProg in versions)
|
||||||
{
|
{
|
||||||
Console.Out.WriteLine(file.ZipUrl);
|
foreach (var file in versionProg.Value)
|
||||||
|
{
|
||||||
|
Console.Out.WriteLine(file.ZipUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case DownloadAction.ListVersions:
|
||||||
case DownloadAction.ListVersions:
|
foreach (var versionProg in versions)
|
||||||
foreach (var versionProg in versions)
|
|
||||||
{
|
|
||||||
foreach (var file in versionProg.Value)
|
|
||||||
{
|
{
|
||||||
Console.Out.WriteLine(file.Version);
|
foreach (var file in versionProg.Value)
|
||||||
|
{
|
||||||
|
Console.Out.WriteLine(file.Version);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.LogInformation($"Complete");
|
logger.LogInformation($"Complete");
|
||||||
|
|
||||||
this.hostApplicationLifetime.StopApplication();
|
this.hostApplicationLifetime.StopApplication();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,56 +229,49 @@ namespace EpicMorg.Atlassian.Downloader
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private void SetConsoleTitle()
|
private void SetConsoleTitle()
|
||||||
{
|
{
|
||||||
const string appBuildType =
|
Console.Title = $@"{assemblyName} {assemblyVersion} {assemblyEnvironment} - {assemblyBuildType}";
|
||||||
#if DEBUG
|
|
||||||
"[Debug]"
|
|
||||||
#else
|
|
||||||
|
|
||||||
"[Release]"
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
var assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName();
|
|
||||||
Console.Title = $@"{assemblyName.Name} {assemblyName.Version} {appBuildType}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task DownloadFilesFromFreed(string feedUrl, IDictionary<string, ResponseItem[]> versions, CancellationToken cancellationToken)
|
private async Task DownloadFilesFromFreed(string feedUrl, IDictionary<string, ResponseItem[]> versions, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var feedDir = Path.Combine(options.OutputDir, feedUrl[(feedUrl.LastIndexOf('/') + 1)..(feedUrl.LastIndexOf('.'))]);
|
|
||||||
logger.LogInformation($"Download from JSON \"{feedUrl}\" started");
|
|
||||||
foreach (var version in versions)
|
|
||||||
{
|
|
||||||
if (cancellationToken.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var directory = Path.Combine(feedDir, version.Key);
|
var feedDir = Path.Combine(options.OutputDir, feedUrl[(feedUrl.LastIndexOf('/') + 1)..(feedUrl.LastIndexOf('.'))]);
|
||||||
if (!Directory.Exists(directory))
|
logger.LogInformation($"Download from JSON \"{feedUrl}\" started");
|
||||||
{
|
foreach (var version in versions)
|
||||||
Directory.CreateDirectory(directory);
|
|
||||||
}
|
|
||||||
foreach (var file in version.Value)
|
|
||||||
{
|
{
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (file.ZipUrl == null) { continue; }
|
|
||||||
var serverPath = file.ZipUrl.PathAndQuery;
|
var directory = Path.Combine(feedDir, version.Key);
|
||||||
var outputFile = Path.Combine(directory, serverPath[(serverPath.LastIndexOf("/") + 1)..]);
|
if (!Directory.Exists(directory))
|
||||||
if (!File.Exists(outputFile))
|
|
||||||
{
|
{
|
||||||
await DownloadFile(file, outputFile, cancellationToken).ConfigureAwait(false);
|
Directory.CreateDirectory(directory);
|
||||||
}
|
}
|
||||||
else
|
foreach (var file in version.Value)
|
||||||
{
|
{
|
||||||
logger.LogWarning($"File \"{outputFile}\" already exists. Download from \"{file.ZipUrl}\" skipped.");
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (file.ZipUrl == null) { continue; }
|
||||||
|
var serverPath = file.ZipUrl.PathAndQuery;
|
||||||
|
var outputFile = Path.Combine(directory, serverPath[(serverPath.LastIndexOf("/") + 1)..]);
|
||||||
|
if (!File.Exists(outputFile))
|
||||||
|
{
|
||||||
|
await DownloadFile(file, outputFile, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.LogWarning($"File \"{outputFile}\" already exists. Download from \"{file.ZipUrl}\" skipped.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
logger.LogInformation($"All files from \"{feedUrl}\" successfully downloaded.");
|
||||||
logger.LogInformation($"All files from \"{feedUrl}\" successfully downloaded.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task DownloadFile(ResponseItem file, string outputFile, CancellationToken cancellationToken)
|
private async Task DownloadFile(ResponseItem file, string outputFile, CancellationToken cancellationToken)
|
||||||
@ -205,6 +301,8 @@ namespace EpicMorg.Atlassian.Downloader
|
|||||||
logger.LogInformation($"File \"{file.ZipUrl}\" successfully downloaded to \"{outputFile}\".");
|
logger.LogInformation($"File \"{file.ZipUrl}\" successfully downloaded to \"{outputFile}\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||||
public async Task StopAsync(CancellationToken cancellationToken) { }
|
public async Task StopAsync(CancellationToken cancellationToken) { }
|
||||||
|
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
namespace EpicMorg.Atlassian.Downloader
|
namespace EpicMorg.Atlassian.Downloader
|
||||||
{
|
{
|
||||||
public record DownloaderOptions(string OutputDir, Uri[] CustomFeed, DownloadAction Action) { }
|
public record DownloaderOptions(string OutputDir, Uri[] CustomFeed, DownloadAction Action,bool Version) { }
|
||||||
}
|
}
|
@ -16,9 +16,10 @@ namespace EpicMorg.Atlassian.Downloader
|
|||||||
/// Atlassian archive downloader. See https://github.com/EpicMorg/atlassian-downloader for more info
|
/// Atlassian archive downloader. See https://github.com/EpicMorg/atlassian-downloader for more info
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Action">Action to perform</param>
|
/// <param name="Action">Action to perform</param>
|
||||||
/// <param name="OutputDir">Override output directory to download.</param>
|
/// <param name="OutputDir">Override output directory to download</param>
|
||||||
/// <param name="customFeed">Override URIs to import.</param>
|
/// <param name="customFeed">Override URIs to import</param>
|
||||||
static async Task Main(string OutputDir = "atlassian", Uri[] customFeed = null, DownloadAction Action = DownloadAction.Download) => await
|
/// <param name="Version">Show credits" banner</param>
|
||||||
|
static async Task Main(string OutputDir = "atlassian", Uri[] customFeed = null, DownloadAction Action = DownloadAction.Download, bool Version = false) => await
|
||||||
Host
|
Host
|
||||||
.CreateDefaultBuilder()
|
.CreateDefaultBuilder()
|
||||||
.ConfigureHostConfiguration(configHost => configHost.AddEnvironmentVariables())
|
.ConfigureHostConfiguration(configHost => configHost.AddEnvironmentVariables())
|
||||||
@ -40,7 +41,7 @@ namespace EpicMorg.Atlassian.Downloader
|
|||||||
.AddSerilog(dispose: true);
|
.AddSerilog(dispose: true);
|
||||||
})
|
})
|
||||||
.AddHostedService<DonloaderService>()
|
.AddHostedService<DonloaderService>()
|
||||||
.AddSingleton(new DownloaderOptions(OutputDir, customFeed, Action))
|
.AddSingleton(new DownloaderOptions(OutputDir, customFeed, Action, Version))
|
||||||
.AddHttpClient())
|
.AddHttpClient())
|
||||||
.RunConsoleAsync()
|
.RunConsoleAsync()
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<ApplicationIcon>favicon.ico</ApplicationIcon>
|
<ApplicationIcon>favicon.ico</ApplicationIcon>
|
||||||
<PackageId>EpicMorg.Atlassian.Downloader</PackageId>
|
<PackageId>EpicMorg.Atlassian.Downloader</PackageId>
|
||||||
<Authors>Atlassian Downloader</Authors>
|
<Authors>EpicMorg, kasthack, stam</Authors>
|
||||||
<Description>Atlassian Downloader by EpicMorg</Description>
|
<Description>Atlassian Downloader by EpicMorg</Description>
|
||||||
<PackageProjectUrl>https://github.com/EpicMorg/atlassian-downloader</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/EpicMorg/atlassian-downloader</PackageProjectUrl>
|
||||||
<PackageIcon>favicon.png</PackageIcon>
|
<PackageIcon>favicon.png</PackageIcon>
|
||||||
@ -23,6 +23,7 @@
|
|||||||
<Copyright>EpicMorg 2021</Copyright>
|
<Copyright>EpicMorg 2021</Copyright>
|
||||||
<Product>Atlassian Downloader</Product>
|
<Product>Atlassian Downloader</Product>
|
||||||
<IsPackable>true</IsPackable>
|
<IsPackable>true</IsPackable>
|
||||||
|
<Company>EpicMorg</Company>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user