mirror of
https://github.com/EpicMorg/atlassian-downloader.git
synced 2025-01-14 20:57:56 +03:00
1.0.0.6
* support of args https://github.com/EpicMorg/atlassian-downloader/issues/5
This commit is contained in:
parent
5a7836ec54
commit
90568e975e
@ -15,12 +15,15 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace EpicMorg.Atlassian.Downloader {
|
namespace EpicMorg.Atlassian.Downloader {
|
||||||
class Program {
|
class Program {
|
||||||
|
/// <summary>
|
||||||
/// <param name="intOption">An option whose argument is parsed as an int</param>
|
///
|
||||||
/// <param name="boolOption">An option whose argument is parsed as a bool</param>
|
/// </summary>
|
||||||
/// <param name="fileOption">An option whose argument is parsed as a FileInfo</param>
|
/// <param name="outputDir">Override output directory to download</param>
|
||||||
static async Task Main(string[] args) {
|
/// <param name="list">Show all download links from feed without downloading</param>
|
||||||
|
/// <param name="customFeed">Override URIs to import.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
static async Task Main(string outputDir = "atlassian", bool list = false, Uri[] customFeed=null) {
|
||||||
|
|
||||||
var appTitle = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
var appTitle = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
||||||
var appVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
var appVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
||||||
var appStartupDate = DateTime.Now;
|
var appStartupDate = DateTime.Now;
|
||||||
@ -28,10 +31,10 @@ namespace EpicMorg.Atlassian.Downloader {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
appBuildType = "[Debug]";
|
appBuildType = "[Debug]";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var outputDir = "atlassian";
|
var feedUrls = customFeed != null
|
||||||
var feedUrls =
|
? customFeed.Select(a=>a.ToString()).ToArray()
|
||||||
new[] {
|
: new[] {
|
||||||
"https://my.atlassian.com/download/feeds/archived/bamboo.json",
|
"https://my.atlassian.com/download/feeds/archived/bamboo.json",
|
||||||
"https://my.atlassian.com/download/feeds/archived/confluence.json",
|
"https://my.atlassian.com/download/feeds/archived/confluence.json",
|
||||||
"https://my.atlassian.com/download/feeds/archived/crowd.json",
|
"https://my.atlassian.com/download/feeds/archived/crowd.json",
|
||||||
@ -60,9 +63,10 @@ namespace EpicMorg.Atlassian.Downloader {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Console.Title = $"{appTitle} {appVersion} {appBuildType}";
|
Console.Title = $"{appTitle} {appVersion} {appBuildType}";
|
||||||
Console.WriteLine($"Download started at {appStartupDate}.");
|
Console.WriteLine($"Task started at {appStartupDate}.");
|
||||||
|
|
||||||
var client = new HttpClient();
|
var client = new HttpClient();
|
||||||
|
|
||||||
foreach (var feedUrl in feedUrls) {
|
foreach (var feedUrl in feedUrls) {
|
||||||
var feedDir = Path.Combine(outputDir, feedUrl[(feedUrl.LastIndexOf('/') + 1)..(feedUrl.LastIndexOf('.'))]);
|
var feedDir = Path.Combine(outputDir, feedUrl[(feedUrl.LastIndexOf('/') + 1)..(feedUrl.LastIndexOf('.'))]);
|
||||||
var atlassianJson = await client.GetStringAsync(feedUrl);
|
var atlassianJson = await client.GetStringAsync(feedUrl);
|
||||||
@ -71,37 +75,47 @@ namespace EpicMorg.Atlassian.Downloader {
|
|||||||
var parsed = JsonSerializer.Deserialize<ResponseArray[]>(json, new JsonSerializerOptions {
|
var parsed = JsonSerializer.Deserialize<ResponseArray[]>(json, new JsonSerializerOptions {
|
||||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||||
});
|
});
|
||||||
var versions = parsed.GroupBy(a => a.Version).ToDictionary(a => a.Key, a => a.ToArray());
|
var versionsProg = parsed.GroupBy(a => a.Version).ToDictionary(a => a.Key, a => a.ToArray());
|
||||||
|
if (list) {
|
||||||
foreach (var version in versions) {
|
foreach (var versionProg in versionsProg) {
|
||||||
var directory = Path.Combine(feedDir, version.Key);
|
foreach (var file in versionProg.Value) {
|
||||||
if (!Directory.Exists(directory)) {
|
Console.WriteLine(file.ZipUrl);
|
||||||
Directory.CreateDirectory(directory);
|
|
||||||
}
|
|
||||||
foreach (var file in version.Value) {
|
|
||||||
if (file.ZipUrl == null) { continue; }
|
|
||||||
var serverPath = file.ZipUrl.PathAndQuery;
|
|
||||||
var outputFile = Path.Combine(directory, serverPath[(serverPath.LastIndexOf("/") + 1)..]);
|
|
||||||
if (!File.Exists(outputFile)) {
|
|
||||||
if (!string.IsNullOrEmpty(file.Md5)) {
|
|
||||||
File.WriteAllText(outputFile + ".md5", file.Md5);
|
|
||||||
}
|
|
||||||
using var outputStream = File.OpenWrite(outputFile);
|
|
||||||
using var request = await client.GetStreamAsync(file.ZipUrl).ConfigureAwait(false);
|
|
||||||
await request.CopyToAsync(outputStream).ConfigureAwait(false);
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
|
||||||
Console.WriteLine($"[INFO] File \"{file.ZipUrl}\" successfully downloaded to \"{outputFile}\".");
|
|
||||||
Console.ResetColor();
|
|
||||||
} else {
|
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
||||||
Console.WriteLine($"[WARN] File \"{outputFile}\" already exists. Download from \"{file.ZipUrl}\" skipped.");
|
|
||||||
Console.ResetColor();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Console.WriteLine($"[INFO] Download from JSON \"{feedUrl}\" started at {appStartupDate}.");
|
||||||
|
foreach (var versionProg in versionsProg) {
|
||||||
|
var directory = Path.Combine(feedDir, versionProg.Key);
|
||||||
|
if (!Directory.Exists(directory)) {
|
||||||
|
Directory.CreateDirectory(directory);
|
||||||
|
}
|
||||||
|
foreach (var file in versionProg.Value) {
|
||||||
|
if (file.ZipUrl == null) { continue; }
|
||||||
|
var serverPath = file.ZipUrl.PathAndQuery;
|
||||||
|
var outputFile = Path.Combine(directory, serverPath[(serverPath.LastIndexOf("/") + 1)..]);
|
||||||
|
if (!File.Exists(outputFile)) {
|
||||||
|
if (!string.IsNullOrEmpty(file.Md5)) {
|
||||||
|
File.WriteAllText(outputFile + ".md5", file.Md5);
|
||||||
|
}
|
||||||
|
using var outputStream = File.OpenWrite(outputFile);
|
||||||
|
using var request = await client.GetStreamAsync(file.ZipUrl).ConfigureAwait(false);
|
||||||
|
await request.CopyToAsync(outputStream).ConfigureAwait(false);
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine($"[INFO] File \"{file.ZipUrl}\" successfully downloaded to \"{outputFile}\".");
|
||||||
|
Console.ResetColor();
|
||||||
|
} else {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
Console.WriteLine($"[WARN] File \"{outputFile}\" already exists. Download from \"{file.ZipUrl}\" skipped.");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Console.WriteLine($"[SUCCESS] All files from \"{feedUrl}\" successfully downloaded.");
|
||||||
}
|
}
|
||||||
Console.WriteLine($"[SUCCESS] All files from \"{feedUrl}\" successfully downloaded.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"Download complete at {appStartupDate}.");
|
Console.WriteLine($"Download complete at {appStartupDate}.");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user