105 lines
4.4 KiB
C#
Raw Normal View History

2021-01-13 15:24:10 +03:00
using System;
2021-01-13 15:52:47 +03:00
using System.Drawing;
2021-01-13 15:24:10 +03:00
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
2021-01-13 15:52:47 +03:00
var appTitle = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
var appVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
var appStartupDate = DateTime.Now;
2021-01-13 15:27:33 +03:00
var outputDir = "output";
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",
"https://my.atlassian.com/download/feeds/archived/crucible.json",
"https://my.atlassian.com/download/feeds/archived/fisheye.json",
"https://my.atlassian.com/download/feeds/archived/jira-core.json",
"https://my.atlassian.com/download/feeds/archived/jira-servicedesk.json",
"https://my.atlassian.com/download/feeds/archived/jira-software.json",
"https://my.atlassian.com/download/feeds/archived/jira.json",
"https://my.atlassian.com/download/feeds/archived/stash.json",
"https://my.atlassian.com/download/feeds/current/bamboo.json",
"https://my.atlassian.com/download/feeds/current/confluence.json",
"https://my.atlassian.com/download/feeds/current/crowd.json",
"https://my.atlassian.com/download/feeds/current/crucible.json",
"https://my.atlassian.com/download/feeds/current/fisheye.json",
"https://my.atlassian.com/download/feeds/current/jira-core.json",
"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"
};
2021-01-13 15:52:47 +03:00
Console.Title = $"{appTitle} {appVersion}";
Console.WriteLine($"Download started at {appStartupDate}.");
2021-01-13 15:24:10 +03:00
2021-01-13 15:27:33 +03:00
var client = new HttpClient();
foreach (var feedUrl in feedUrls)
2021-01-13 15:24:10 +03:00
{
2021-01-13 15:27:33 +03:00
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<ResponseArray[]>(json, new JsonSerializerOptions
2021-01-13 15:24:10 +03:00
{
2021-01-13 15:27:33 +03:00
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
});
var versions = parsed.GroupBy(a => a.Version).ToDictionary(a => a.Key, a => a.ToArray());
foreach (var version in versions)
2021-01-13 15:24:10 +03:00
{
2021-01-13 15:27:33 +03:00
var directory = Path.Combine(feedDir, version.Key);
if (!Directory.Exists(directory))
2021-01-13 15:24:10 +03:00
{
2021-01-13 15:27:33 +03:00
Directory.CreateDirectory(directory);
2021-01-13 15:24:10 +03:00
}
2021-01-13 15:27:33 +03:00
foreach (var file in version.Value)
2021-01-13 15:24:10 +03:00
{
2021-01-13 15:27:33 +03:00
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);
2021-01-13 15:52:47 +03:00
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"File \"{file.ZipUrl}\" downloaded to \"{outputFile}\".");
Console.ResetColor();
2021-01-13 15:27:33 +03:00
}
else
{
2021-01-13 15:52:47 +03:00
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"[WARN] File \"{outputFile}\" for \"{file.ZipUrl}\" already exists. Skip.");
Console.ResetColor();
2021-01-13 15:27:33 +03:00
}
2021-01-13 15:24:10 +03:00
}
}
2021-01-13 15:27:33 +03:00
Console.WriteLine($"Downloaded all files from " +
$"{feedUrl}");
2021-01-13 15:24:10 +03:00
}
2021-01-13 15:52:47 +03:00
Console.WriteLine("Download complete.");
2021-01-13 15:24:10 +03:00
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; }
}