-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
103 lines (90 loc) · 2.85 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using Octokit;
using System.Net;
var github = new GitHubClient(new ProductHeaderValue("LiveReleaseGet"));
Console.WriteLine("Live Release Get - Berkay Gediz");
start:
Console.WriteLine("\nGitHub Username:");
#pragma warning disable CS8600
string username = Console.ReadLine();
#pragma warning restore CS8600
Console.WriteLine("Repo:");
#pragma warning disable CS8600
string repo = Console.ReadLine();
#pragma warning restore CS8600
Console.WriteLine($"Do you want the {username}/{repo} source code? (1 or 0)");
#pragma warning disable CS8600
string request = Console.ReadLine();
#pragma warning restore CS8600
static void SourceCodeDownload(string username, string repo, string branch)
{
if (username != null || repo != null)
{
string url = $"https://github.com/{username}/{repo}/archive/{branch}.zip";
string filename = $"{repo}_{branch}.zip";
string filepath = Path.Combine(Environment.CurrentDirectory, filename);
using WebClient client = new();
try
{
client.DownloadFile(url, filepath);
Console.WriteLine("Source code downloaded: " + filename);
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}
try
{
Console.WriteLine("->Download started.");
var latestrelease = github.Repository.Release.GetLatest(username, repo).Result;
if (latestrelease != null)
{
var asset = latestrelease.Assets[0];
string api_downloadurl = asset.BrowserDownloadUrl;
string assetname = asset.Name;
string filepath = Path.Combine(Environment.CurrentDirectory, assetname);
using (WebClient client = new())
{
client.DownloadFile(api_downloadurl, filepath);
}
Console.WriteLine("Downloaded: " + assetname);
if (request == "1")
{
Console.WriteLine("\nEnter the branch name: (Default: master)");
#pragma warning disable CS8600
string branch = Console.ReadLine();
#pragma warning restore CS8600
if (string.IsNullOrEmpty(branch))
{
branch = "master";
}
#pragma warning disable CS8604
SourceCodeDownload(username, repo, branch);
#pragma warning restore CS8604
}
}
else
{
Console.WriteLine("No releases found.");
if (request == "1")
{
Console.WriteLine("\nBranch: (Default: master)");
#pragma warning disable CS8600
string branch = Console.ReadLine();
#pragma warning restore CS8600
if (string.IsNullOrEmpty(branch))
{
branch = "master";
}
#pragma warning disable CS8604
SourceCodeDownload(username, repo, branch);
#pragma warning restore CS8604
}
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR: " + ex.Message);
}
goto start;