diff --git a/src/atlassian-downloader/Program.cs b/src/atlassian-downloader/Program.cs index b4829d1..12b5c39 100644 --- a/src/atlassian-downloader/Program.cs +++ b/src/atlassian-downloader/Program.cs @@ -3,18 +3,35 @@ using System.IO; using System.Linq; using System.Net.Http; using System.Text.Json; +using System.Threading.Tasks; -var appTitle = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; -var appVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; -var appStartupDate = DateTime.Now; -var appBuildType = "[Release]"; +/* + -o, --output-folder "path" --> set output folder +-v, --version --> show version +-h, --help --> show help +-l, --list, --links --> show all links to output +-f, -feed, --feed-url, -u, --url --> use json link +*/ + +namespace EpicMorg.Atlassian.Downloader { + class Program { + + /// An option whose argument is parsed as an int + /// An option whose argument is parsed as a bool + /// An option whose argument is parsed as a FileInfo + static async Task Main(string[] args) { + + var appTitle = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; + var appVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; + var appStartupDate = DateTime.Now; + var appBuildType = "[Release]"; #if DEBUG - appBuildType = "[Debug]"; + appBuildType = "[Debug]"; #endif -var outputDir = "atlassian"; -var feedUrls = - new[] { + var outputDir = "atlassian"; + var feedUrls = + new[] { "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/crowd.json", @@ -35,77 +52,72 @@ var feedUrls = "https://my.atlassian.com/download/feeds/current/jira-servicedesk.json", "https://my.atlassian.com/download/feeds/current/jira-software.json", "https://my.atlassian.com/download/feeds/current/stash.json", - - "https://my.atlassian.com/download/feeds/eap/bamboo.json", - "https://my.atlassian.com/download/feeds/eap/confluence.json", - "https://my.atlassian.com/download/feeds/eap/jira.json", - "https://my.atlassian.com/download/feeds/eap/jira-servicedesk.json" - }; -Console.Title = $"{appTitle} {appVersion} {appBuildType}"; -Console.WriteLine($"Download started at {appStartupDate}."); + "https://my.atlassian.com/download/feeds/eap/bamboo.json", + "https://my.atlassian.com/download/feeds/eap/confluence.json", + "https://my.atlassian.com/download/feeds/eap/jira.json", + "https://my.atlassian.com/download/feeds/eap/jira-servicedesk.json" + }; -var client = new HttpClient(); -foreach (var feedUrl in feedUrls) -{ - var feedDir = Path.Combine(outputDir, feedUrl[(feedUrl.LastIndexOf('/') + 1)..(feedUrl.LastIndexOf('.'))]); - var atlassianJson = await client.GetStringAsync(feedUrl); - var callString = "downloads("; - var json = atlassianJson[callString.Length..^1]; - var parsed = JsonSerializer.Deserialize(json, new JsonSerializerOptions - { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - }); - var versions = parsed.GroupBy(a => a.Version).ToDictionary(a => a.Key, a => a.ToArray()); + Console.Title = $"{appTitle} {appVersion} {appBuildType}"; + Console.WriteLine($"Download started at {appStartupDate}."); - foreach (var version in versions) - { - var directory = Path.Combine(feedDir, version.Key); - if (!Directory.Exists(directory)) - { - Directory.CreateDirectory(directory); - } - foreach (var file in version.Value) - { - 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); + var client = new HttpClient(); + foreach (var feedUrl in feedUrls) { + var feedDir = Path.Combine(outputDir, feedUrl[(feedUrl.LastIndexOf('/') + 1)..(feedUrl.LastIndexOf('.'))]); + var atlassianJson = await client.GetStringAsync(feedUrl); + var callString = "downloads("; + var json = atlassianJson[callString.Length..^1]; + var parsed = JsonSerializer.Deserialize(json, new JsonSerializerOptions { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + }); + var versions = parsed.GroupBy(a => a.Version).ToDictionary(a => a.Key, a => a.ToArray()); + + foreach (var version in versions) { + var directory = Path.Combine(feedDir, version.Key); + if (!Directory.Exists(directory)) { + 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(); + } + } } - 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($"Download complete at {appStartupDate}."); } } - Console.WriteLine($"[SUCCESS] All files from \"{feedUrl}\" successfully downloaded."); -} -Console.WriteLine($"Download complete at {appStartupDate}."); -public partial class ResponseArray -{ - public string Description { get; set; } - public string Edition { get; set; } - public Uri ZipUrl { get; set; } - public object TarUrl { get; set; } - public string Md5 { get; set; } - public string Size { get; set; } - public string Released { get; set; } - public string Type { get; set; } - public string Platform { get; set; } - public string Version { get; set; } - public Uri ReleaseNotes { get; set; } - public Uri UpgradeNotes { get; set; } + public partial class ResponseArray { + public string Description { get; set; } + public string Edition { get; set; } + public Uri ZipUrl { get; set; } + public object TarUrl { get; set; } + public string Md5 { get; set; } + public string Size { get; set; } + public string Released { get; set; } + public string Type { get; set; } + public string Platform { get; set; } + public string Version { get; set; } + public Uri ReleaseNotes { get; set; } + public Uri UpgradeNotes { get; set; } + } + } \ No newline at end of file diff --git a/src/atlassian-downloader/atlassian-downloader.csproj b/src/atlassian-downloader/atlassian-downloader.csproj index b8c6f5f..069c0d1 100644 --- a/src/atlassian-downloader/atlassian-downloader.csproj +++ b/src/atlassian-downloader/atlassian-downloader.csproj @@ -2,7 +2,7 @@ Exe - true + true true win-x64 true @@ -17,15 +17,16 @@ git https://github.com/EpicMorg/atlassian-downloader atlassian, donwloader, epicmorg - 1.0.0.5 - 1.0.0.5 - 1.0.0.5 + 1.0.0.6 + 1.0.0.6 + 1.0.0.6 EpicMorg 2021 Atlassian Downloader - true + true + True